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