| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import 'service_test_common.dart'; |
| 9 import 'test_helper.dart'; |
| 10 |
| 11 import 'dart:async'; |
| 12 |
| 13 const int LINE_A = 24; |
| 14 const int LINE_B = 26; |
| 15 |
| 16 int value = 0; |
| 17 |
| 18 int incValue(int amount) { |
| 19 value += amount; |
| 20 return amount; |
| 21 } |
| 22 |
| 23 Future testMain() async { |
| 24 incValue(incValue(1)); // line A. |
| 25 |
| 26 incValue(incValue(1)); // line B. |
| 27 } |
| 28 |
| 29 var tests = [ |
| 30 hasPausedAtStart, |
| 31 |
| 32 // Test future breakpoints. |
| 33 (Isolate isolate) async { |
| 34 var rootLib = isolate.rootLibrary; |
| 35 await rootLib.load(); |
| 36 var script = rootLib.scripts[0]; |
| 37 |
| 38 // Future breakpoint. |
| 39 var futureBpt1 = await isolate.addBreakpoint(script, LINE_A); |
| 40 expect(futureBpt1.number, equals(1)); |
| 41 expect(futureBpt1.resolved, isFalse); |
| 42 expect(await futureBpt1.location.getLine(), equals(LINE_A)); |
| 43 expect(await futureBpt1.location.getColumn(), equals(null)); |
| 44 |
| 45 // Future breakpoint with specific column. |
| 46 var futureBpt2 = await isolate.addBreakpoint(script, LINE_A, 3); |
| 47 expect(futureBpt2.number, equals(2)); |
| 48 expect(futureBpt2.resolved, isFalse); |
| 49 expect(await futureBpt2.location.getLine(), equals(LINE_A)); |
| 50 expect(await futureBpt2.location.getColumn(), equals(3)); |
| 51 |
| 52 int resolvedCount = |
| 53 await resumeAndCountResolvedBreakpointsUntilPause(isolate); |
| 54 |
| 55 // After resolution the breakpoints have assigned line & column. |
| 56 expect(resolvedCount, equals(2)); |
| 57 expect(futureBpt1.resolved, isTrue); |
| 58 expect(await futureBpt1.location.getLine(), equals(LINE_A)); |
| 59 expect(await futureBpt1.location.getColumn(), equals(12)); |
| 60 expect(futureBpt2.resolved, isTrue); |
| 61 expect(await futureBpt2.location.getLine(), equals(LINE_A)); |
| 62 expect(await futureBpt2.location.getColumn(), equals(3)); |
| 63 |
| 64 // The first breakpoint hits before value is modified. |
| 65 expect((await rootLib.evaluate('value')).valueAsString, equals('0')); |
| 66 |
| 67 isolate.resume(); |
| 68 await hasStoppedAtBreakpoint(isolate); |
| 69 |
| 70 // The second breakpoint hits after value has been modified once. |
| 71 expect((await rootLib.evaluate('value')).valueAsString, equals('1')); |
| 72 |
| 73 // Remove the breakpoints. |
| 74 expect( |
| 75 (await isolate.removeBreakpoint(futureBpt1)).type, equals('Success')); |
| 76 expect( |
| 77 (await isolate.removeBreakpoint(futureBpt2)).type, equals('Success')); |
| 78 }, |
| 79 |
| 80 // Test resolution of column breakpoints. |
| 81 (Isolate isolate) async { |
| 82 var script = isolate.rootLibrary.scripts[0]; |
| 83 // Try all columns, including some columns that are too big. |
| 84 for (int col = 1; col <= 50; col++) { |
| 85 var bpt = await isolate.addBreakpoint(script, LINE_A, col); |
| 86 expect(bpt.resolved, isTrue); |
| 87 int resolvedLine = await bpt.location.getLine(); |
| 88 int resolvedCol = await bpt.location.getColumn(); |
| 89 print('$LINE_A:${col} -> ${resolvedLine}:${resolvedCol}'); |
| 90 if (col <= 10) { |
| 91 expect(resolvedLine, equals(LINE_A)); |
| 92 expect(resolvedCol, equals(3)); |
| 93 } else if (col <= 19) { |
| 94 expect(resolvedLine, equals(LINE_A)); |
| 95 expect(resolvedCol, equals(12)); |
| 96 } else { |
| 97 expect(resolvedLine, equals(LINE_B)); |
| 98 expect(resolvedCol, equals(12)); |
| 99 } |
| 100 expect((await isolate.removeBreakpoint(bpt)).type, equals('Success')); |
| 101 } |
| 102 |
| 103 // Make sure that a zero column is an error. |
| 104 var caughtException = false; |
| 105 try { |
| 106 await isolate.addBreakpoint(script, 20, 0); |
| 107 expect(false, isTrue, reason: 'Unreachable'); |
| 108 } on ServerRpcException catch (e) { |
| 109 caughtException = true; |
| 110 expect(e.code, equals(ServerRpcException.kInvalidParams)); |
| 111 expect(e.message, "addBreakpoint: invalid 'column' parameter: 0"); |
| 112 } |
| 113 expect(caughtException, isTrue); |
| 114 }, |
| 115 ]; |
| 116 |
| 117 Future<int> resumeAndCountResolvedBreakpointsUntilPause(Isolate isolate) async { |
| 118 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 119 Completer completer = new Completer(); |
| 120 var subscription; |
| 121 int resolvedCount = 0; |
| 122 subscription = stream.listen((ServiceEvent event) async { |
| 123 if (event.kind == ServiceEvent.kBreakpointResolved) { |
| 124 resolvedCount++; |
| 125 } |
| 126 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 127 subscription.cancel(); |
| 128 completer.complete(); |
| 129 } |
| 130 }); |
| 131 await isolate.resume(); |
| 132 await completer.future; |
| 133 return resolvedCount; |
| 134 } |
| 135 |
| 136 main(args) => runIsolateTests(args, tests, |
| 137 testeeConcurrent: testMain, pause_on_start: true); |
| OLD | NEW |