| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked | 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override --checked |
| 5 | 5 |
| 6 library test_helper; | 6 library test_helper; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 | 137 |
| 138 // Cancel the subscription and complete the completer when finished processing | 138 // Cancel the subscription and complete the completer when finished processing |
| 139 // events. | 139 // events. |
| 140 typedef void ServiceEventHandler(ServiceEvent event, | 140 typedef void ServiceEventHandler(ServiceEvent event, |
| 141 StreamSubscription subscription, | 141 StreamSubscription subscription, |
| 142 Completer completer); | 142 Completer completer); |
| 143 | 143 |
| 144 Future processServiceEvents(VM vm, ServiceEventHandler handler) { | 144 Future processServiceEvents(VM vm, |
| 145 String streamId, |
| 146 ServiceEventHandler handler) { |
| 145 Completer completer = new Completer(); | 147 Completer completer = new Completer(); |
| 146 var subscription; | 148 vm.getEventStream(streamId).then((stream) { |
| 147 subscription = vm.events.stream.listen((ServiceEvent event) { | 149 var subscription; |
| 148 handler(event, subscription, completer); | 150 subscription = stream.listen((ServiceEvent event) { |
| 151 handler(event, subscription, completer); |
| 152 }); |
| 149 }); | 153 }); |
| 150 return completer.future; | 154 return completer.future; |
| 151 } | 155 } |
| 152 | 156 |
| 153 | 157 |
| 154 Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) { | 158 Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) { |
| 155 if ((isolate.pauseEvent != null) && | 159 if ((isolate.pauseEvent != null) && |
| 156 (isolate.pauseEvent.kind == ServiceEvent.kPauseBreakpoint)) { | 160 (isolate.pauseEvent.kind == ServiceEvent.kPauseBreakpoint)) { |
| 157 // Already waiting at a breakpoint. | 161 // Already waiting at a breakpoint. |
| 158 print('Breakpoint reached'); | 162 print('Breakpoint reached'); |
| 159 return new Future.value(isolate); | 163 return new Future.value(isolate); |
| 160 } | 164 } |
| 161 | 165 |
| 162 // Set up a listener to wait for breakpoint events. | 166 // Set up a listener to wait for breakpoint events. |
| 163 Completer completer = new Completer(); | 167 Completer completer = new Completer(); |
| 164 var subscription; | 168 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
| 165 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 169 var subscription; |
| 166 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 170 subscription = stream.listen((ServiceEvent event) { |
| 167 print('Breakpoint reached'); | 171 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 168 subscription.cancel(); | 172 print('Breakpoint reached'); |
| 169 completer.complete(isolate); | 173 subscription.cancel(); |
| 170 } | 174 completer.complete(); |
| 175 } |
| 176 }); |
| 171 }); | 177 }); |
| 172 | 178 |
| 173 return completer.future; // Will complete when breakpoint hit. | 179 return completer.future; // Will complete when breakpoint hit. |
| 174 } | 180 } |
| 175 | 181 |
| 176 | 182 |
| 177 Future<Isolate> resumeIsolate(Isolate isolate) { | 183 Future<Isolate> resumeIsolate(Isolate isolate) { |
| 178 Completer completer = new Completer(); | 184 Completer completer = new Completer(); |
| 179 var subscription; | 185 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
| 180 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 186 var subscription; |
| 181 if (event.kind == ServiceEvent.kResume) { | 187 subscription = stream.listen((ServiceEvent event) { |
| 182 subscription.cancel(); | 188 if (event.kind == ServiceEvent.kResume) { |
| 183 completer.complete(); | 189 subscription.cancel(); |
| 184 } | 190 completer.complete(); |
| 191 } |
| 192 }); |
| 185 }); | 193 }); |
| 186 isolate.resume(); | 194 isolate.resume(); |
| 187 return completer.future; | 195 return completer.future; |
| 188 } | 196 } |
| 189 | 197 |
| 190 | 198 |
| 191 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 199 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
| 192 /// return a [Future]. Code for setting up state can run before and/or | 200 /// return a [Future]. Code for setting up state can run before and/or |
| 193 /// concurrently with the tests. Uses [mainArgs] to determine whether | 201 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 194 /// to run tests or testee in this invokation of the script. | 202 /// to run tests or testee in this invokation of the script. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 }, onError: (e, st) { | 235 }, onError: (e, st) { |
| 228 process.requestExit(); | 236 process.requestExit(); |
| 229 if (!_isWebSocketDisconnect(e)) { | 237 if (!_isWebSocketDisconnect(e)) { |
| 230 print('Unexpected exception in service tests: $e $st'); | 238 print('Unexpected exception in service tests: $e $st'); |
| 231 throw e; | 239 throw e; |
| 232 } | 240 } |
| 233 }); | 241 }); |
| 234 }); | 242 }); |
| 235 } | 243 } |
| 236 } | 244 } |
| OLD | NEW |