| 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 processDebugEvents(VM vm, ServiceEventHandler handler) { |
| 145 Completer completer = new Completer(); | 145 Completer completer = new Completer(); |
| 146 var subscription; | 146 vm.getDebugEventStream().then((stream) { |
| 147 subscription = vm.events.stream.listen((ServiceEvent event) { | 147 var subscription; |
| 148 handler(event, subscription, completer); | 148 subscription = stream.listen((ServiceEvent event) { |
| 149 handler(event, subscription, completer); |
| 150 }); |
| 149 }); | 151 }); |
| 150 return completer.future; | 152 return completer.future; |
| 151 } | 153 } |
| 154 |
| 155 |
| 156 Future processIsolateEvents(VM vm, ServiceEventHandler handler) { |
| 157 Completer completer = new Completer(); |
| 158 vm.getIsolateEventStream().then((stream) { |
| 159 var subscription; |
| 160 subscription = stream.listen((ServiceEvent event) { |
| 161 handler(event, subscription, completer); |
| 162 }); |
| 163 }); |
| 164 return completer.future; |
| 165 } |
| 152 | 166 |
| 153 | 167 |
| 154 Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) { | 168 Future<Isolate> hasStoppedAtBreakpoint(Isolate isolate) { |
| 155 if ((isolate.pauseEvent != null) && | 169 if ((isolate.pauseEvent != null) && |
| 156 (isolate.pauseEvent.kind == ServiceEvent.kPauseBreakpoint)) { | 170 (isolate.pauseEvent.kind == ServiceEvent.kPauseBreakpoint)) { |
| 157 // Already waiting at a breakpoint. | 171 // Already waiting at a breakpoint. |
| 158 print('Breakpoint reached'); | 172 print('Breakpoint reached'); |
| 159 return new Future.value(isolate); | 173 return new Future.value(isolate); |
| 160 } | 174 } |
| 161 | 175 |
| 162 // Set up a listener to wait for breakpoint events. | 176 // Set up a listener to wait for breakpoint events. |
| 163 Completer completer = new Completer(); | 177 Completer completer = new Completer(); |
| 164 var subscription; | 178 isolate.vm.getDebugEventStream().then((stream) { |
| 165 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 179 var subscription; |
| 166 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 180 subscription = stream.listen((ServiceEvent event) { |
| 167 print('Breakpoint reached'); | 181 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 168 subscription.cancel(); | 182 print('Breakpoint reached'); |
| 169 completer.complete(isolate); | 183 subscription.cancel(); |
| 170 } | 184 completer.complete(); |
| 185 } |
| 186 }); |
| 171 }); | 187 }); |
| 172 | 188 |
| 173 return completer.future; // Will complete when breakpoint hit. | 189 return completer.future; // Will complete when breakpoint hit. |
| 174 } | 190 } |
| 175 | 191 |
| 176 | 192 |
| 177 Future<Isolate> resumeIsolate(Isolate isolate) { | 193 Future<Isolate> resumeIsolate(Isolate isolate) { |
| 178 Completer completer = new Completer(); | 194 Completer completer = new Completer(); |
| 179 var subscription; | 195 isolate.vm.getDebugEventStream().then((stream) { |
| 180 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 196 var subscription; |
| 181 if (event.kind == ServiceEvent.kResume) { | 197 subscription = stream.listen((ServiceEvent event) { |
| 182 subscription.cancel(); | 198 if (event.kind == ServiceEvent.kResume) { |
| 183 completer.complete(); | 199 subscription.cancel(); |
| 184 } | 200 completer.complete(); |
| 201 } |
| 202 }); |
| 185 }); | 203 }); |
| 186 isolate.resume(); | 204 isolate.resume(); |
| 187 return completer.future; | 205 return completer.future; |
| 188 } | 206 } |
| 189 | 207 |
| 190 | 208 |
| 191 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 209 /// 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 | 210 /// return a [Future]. Code for setting up state can run before and/or |
| 193 /// concurrently with the tests. Uses [mainArgs] to determine whether | 211 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 194 /// to run tests or testee in this invokation of the script. | 212 /// 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) { | 245 }, onError: (e, st) { |
| 228 process.requestExit(); | 246 process.requestExit(); |
| 229 if (!_isWebSocketDisconnect(e)) { | 247 if (!_isWebSocketDisconnect(e)) { |
| 230 print('Unexpected exception in service tests: $e $st'); | 248 print('Unexpected exception in service tests: $e $st'); |
| 231 throw e; | 249 throw e; |
| 232 } | 250 } |
| 233 }); | 251 }); |
| 234 }); | 252 }); |
| 235 } | 253 } |
| 236 } | 254 } |
| OLD | NEW |