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 --verbose_debug --trac
e_service |
| 5 |
| 6 import 'dart:async'; |
| 7 import 'dart:developer'; |
| 8 |
| 9 import 'test_helper.dart'; |
| 10 |
| 11 import 'package:observatory/service_io.dart'; |
| 12 import 'package:unittest/unittest.dart'; |
| 13 |
| 14 // This tests the low level synthetic breakpoint added / paused / removed |
| 15 // machinery triggered by the step OverAwait command. |
| 16 asyncWithoutAwait() async { |
| 17 debugger(); |
| 18 print('a'); |
| 19 await new Future.delayed(new Duration(seconds: 2)); |
| 20 print('b'); |
| 21 debugger(); |
| 22 debugger(); |
| 23 } |
| 24 |
| 25 testMain() { |
| 26 asyncWithoutAwait(); |
| 27 } |
| 28 |
| 29 Breakpoint syntheticBreakpoint; |
| 30 |
| 31 Future<Isolate> testLowLevelAwaitOver( |
| 32 Isolate isolate) { |
| 33 assert(isolate.pauseEvent.atAsyncSuspension); |
| 34 |
| 35 int state = 0; |
| 36 bool firstResume = true; |
| 37 handleBreakpointAdded(ServiceEvent event) { |
| 38 expect(syntheticBreakpoint, isNull); |
| 39 expect(state, 0); |
| 40 if (!event.breakpoint.isSyntheticAsyncContinuation) { |
| 41 // Not a synthetic async breakpoint. |
| 42 return; |
| 43 } |
| 44 if (event.owner != isolate) { |
| 45 // Wrong isolate. |
| 46 return; |
| 47 } |
| 48 syntheticBreakpoint = event.breakpoint; |
| 49 print('!!!! Synthetic async breakpoint added ${syntheticBreakpoint}'); |
| 50 state = 1; |
| 51 } |
| 52 |
| 53 handleResume(ServiceEvent event) { |
| 54 if (firstResume) { |
| 55 expect(state, 1); |
| 56 if (event.owner != isolate) { |
| 57 // Wrong isolate. |
| 58 return; |
| 59 } |
| 60 print('!!!! Got first resume.'); |
| 61 state = 2; |
| 62 firstResume = false; |
| 63 } else { |
| 64 expect(state, 3); |
| 65 if (event.owner != isolate) { |
| 66 // Wrong isolate. |
| 67 return; |
| 68 } |
| 69 print('!!!! Got second resume.'); |
| 70 state = 4; |
| 71 } |
| 72 |
| 73 } |
| 74 |
| 75 handlePauseBreakpoint(ServiceEvent event) { |
| 76 expect(syntheticBreakpoint, isNotNull); |
| 77 expect(state, 2); |
| 78 if (!event.breakpoint.isSyntheticAsyncContinuation) { |
| 79 // Not a synthetic async breakpoint. |
| 80 return; |
| 81 } |
| 82 if (event.owner != isolate) { |
| 83 // Wrong isolate. |
| 84 return; |
| 85 } |
| 86 expect(event.breakpoint, equals(syntheticBreakpoint)); |
| 87 print('!!!! Paused at synthetic async breakpoint ${syntheticBreakpoint}'); |
| 88 state = 3; |
| 89 } |
| 90 |
| 91 handleBreakpointRemoved(ServiceEvent event) { |
| 92 expect(syntheticBreakpoint, isNotNull); |
| 93 expect(state, 4); |
| 94 if (!event.breakpoint.isSyntheticAsyncContinuation) { |
| 95 // Not a synthetic async breakpoint. |
| 96 return; |
| 97 } |
| 98 if (event.owner != isolate) { |
| 99 // Wrong isolate. |
| 100 return; |
| 101 } |
| 102 expect(event.breakpoint, equals(syntheticBreakpoint)); |
| 103 print('!!!! Synthetic async breakpoint removed ${syntheticBreakpoint}'); |
| 104 state = 5; |
| 105 syntheticBreakpoint = null; |
| 106 } |
| 107 |
| 108 // Set up a listener to wait for debugger events. |
| 109 Completer completer = new Completer(); |
| 110 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
| 111 var subscription; |
| 112 subscription = stream.listen((ServiceEvent event) async { |
| 113 if (event.kind == ServiceEvent.kBreakpointAdded) { |
| 114 handleBreakpointAdded(event); |
| 115 expect(state, 1); |
| 116 } else if (event.kind == ServiceEvent.kResume) { |
| 117 if (firstResume) { |
| 118 handleResume(event); |
| 119 expect(state, 2); |
| 120 } else { |
| 121 handleResume(event); |
| 122 expect(state, 4); |
| 123 } |
| 124 } else if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 125 handlePauseBreakpoint(event); |
| 126 expect(state, 3); |
| 127 // Check that we are paused after the await statement. |
| 128 await (stoppedAtLine(20)(isolate)); |
| 129 // Resume the isolate so that we trigger the breakpoint removal. |
| 130 print('!!!! Triggering synthetic breakpoint removal.'); |
| 131 isolate.resume(); |
| 132 } else if (event.kind == ServiceEvent.kBreakpointRemoved) { |
| 133 handleBreakpointRemoved(event); |
| 134 expect(state, 5); |
| 135 subscription.cancel(); |
| 136 if (completer != null) { |
| 137 // Reload to update isolate.pauseEvent. |
| 138 completer.complete(isolate.reload()); |
| 139 completer = null; |
| 140 } |
| 141 } |
| 142 }); |
| 143 }); |
| 144 |
| 145 isolate.stepOverAsyncSuspension(); |
| 146 |
| 147 return completer.future; // Will complete when breakpoint added. |
| 148 } |
| 149 |
| 150 |
| 151 var tests = [ |
| 152 hasStoppedAtBreakpoint, |
| 153 stoppedAtLine(18), |
| 154 stepOver, |
| 155 stepOver, |
| 156 stepOver, |
| 157 (Isolate isolate) async { |
| 158 expect(isolate.pauseEvent.atAsyncSuspension, isTrue); |
| 159 expect(syntheticBreakpoint, isNull); |
| 160 }, |
| 161 testLowLevelAwaitOver, |
| 162 hasStoppedAtBreakpoint, |
| 163 stoppedAtLine(22), |
| 164 resumeIsolate, |
| 165 hasStoppedAtBreakpoint, |
| 166 stoppedAtLine(23), |
| 167 resumeIsolate, |
| 168 ]; |
| 169 |
| 170 main(args) => runIsolateTests(args, tests, testeeConcurrent: testMain); |
OLD | NEW |