| 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 | 4 |
| 5 library test_helper; | 5 library test_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'package:observatory/service_io.dart'; | 10 import 'package:observatory/service_io.dart'; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 typedef Future VMTest(VM vm); | 102 typedef Future VMTest(VM vm); |
| 103 | 103 |
| 104 /// Will be set to the http address of the VM's service protocol before | 104 /// Will be set to the http address of the VM's service protocol before |
| 105 /// any tests are invoked. | 105 /// any tests are invoked. |
| 106 String serviceHttpAddress; | 106 String serviceHttpAddress; |
| 107 | 107 |
| 108 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 108 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
| 109 /// return a [Future]. Code for setting up state can run before and/or | 109 /// return a [Future]. Code for setting up state can run before and/or |
| 110 /// concurrently with the tests. Uses [mainArgs] to determine whether | 110 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 111 /// to run tests or testee in this invokation of the script. | 111 /// to run tests or testee in this invokation of the script. |
| 112 void runIsolateTests(List<String> mainArgs, | 112 Future runIsolateTests(List<String> mainArgs, |
| 113 List<IsolateTest> tests, | 113 List<IsolateTest> tests, |
| 114 {void testeeBefore(), | 114 {testeeBefore(), |
| 115 void testeeConcurrent(), | 115 void testeeConcurrent(), |
| 116 bool pause_on_start: false, | 116 bool pause_on_start: false, |
| 117 bool pause_on_exit: false, | 117 bool pause_on_exit: false, |
| 118 bool trace_service: false, | 118 bool trace_service: false, |
| 119 bool verbose_vm: false, | 119 bool verbose_vm: false, |
| 120 bool pause_on_unhandled_exceptions: false}) { | 120 bool pause_on_unhandled_exceptions: false}) async { |
| 121 assert(!pause_on_start || testeeBefore == null); | 121 assert(!pause_on_start || testeeBefore == null); |
| 122 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { | 122 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { |
| 123 if (!pause_on_start) { | 123 if (!pause_on_start) { |
| 124 if (testeeBefore != null) { |
| 125 var result = testeeBefore(); |
| 126 if (result is Future) { |
| 127 await result; |
| 128 } |
| 129 } |
| 130 print(''); // Print blank line to signal that we are ready. |
| 131 } |
| 132 if (testeeConcurrent != null) { |
| 133 testeeConcurrent(); |
| 134 } |
| 135 if (!pause_on_exit) { |
| 136 // Wait around for the process to be killed. |
| 137 stdin.first.then((_) => exit(0)); |
| 138 } |
| 139 } else { |
| 140 var process = new _TestLauncher(); |
| 141 process.launch(pause_on_start, pause_on_exit, |
| 142 pause_on_unhandled_exceptions, trace_service).then((port) { |
| 143 if (mainArgs.contains("--gdb")) { |
| 144 port = 8181; |
| 145 } |
| 146 String addr = 'ws://localhost:$port/ws'; |
| 147 serviceHttpAddress = 'http://localhost:$port'; |
| 148 var testIndex = 1; |
| 149 var totalTests = tests.length; |
| 150 var name = Platform.script.pathSegments.last; |
| 151 runZoned(() { |
| 152 new WebSocketVM(new WebSocketVMTarget(addr)).load() |
| 153 .then((VM vm) => vm.isolates.first.load()) |
| 154 .then((Isolate isolate) => Future.forEach(tests, (test) { |
| 155 isolate.vm.verbose = verbose_vm; |
| 156 print('Running $name [$testIndex/$totalTests]'); |
| 157 testIndex++; |
| 158 return test(isolate); |
| 159 })).then((_) => process.requestExit()); |
| 160 }, onError: (e, st) { |
| 161 process.requestExit(); |
| 162 if (!_isWebSocketDisconnect(e)) { |
| 163 print('Unexpected exception in service tests: $e $st'); |
| 164 throw e; |
| 165 } |
| 166 }); |
| 167 }); |
| 168 } |
| 169 } |
| 170 |
| 171 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
| 172 /// return a [Future]. Code for setting up state can run before and/or |
| 173 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 174 /// to run tests or testee in this invokation of the script. |
| 175 /// |
| 176 /// This is a special version of this test harness specifically for the |
| 177 /// pause_on_unhandled_exceptions_test, which cannot properly function |
| 178 /// in an async context (because exceptions are *always* handled in async |
| 179 /// functions). |
| 180 /// |
| 181 /// TODO(johnmccutchan): Don't use the shared harness for the |
| 182 /// pause_on_unhandled_exceptions_test. |
| 183 void runIsolateTestsSynchronous(List<String> mainArgs, |
| 184 List<IsolateTest> tests, |
| 185 {void testeeBefore(), |
| 186 void testeeConcurrent(), |
| 187 bool pause_on_start: false, |
| 188 bool pause_on_exit: false, |
| 189 bool trace_service: false, |
| 190 bool verbose_vm: false, |
| 191 bool pause_on_unhandled_exceptions: false}) { |
| 192 assert(!pause_on_start || testeeBefore == null); |
| 193 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { |
| 194 if (!pause_on_start) { |
| 124 if (testeeBefore != null) { | 195 if (testeeBefore != null) { |
| 125 testeeBefore(); | 196 testeeBefore(); |
| 126 } | 197 } |
| 127 print(''); // Print blank line to signal that we are ready. | 198 print(''); // Print blank line to signal that we are ready. |
| 128 } | 199 } |
| 129 if (testeeConcurrent != null) { | 200 if (testeeConcurrent != null) { |
| 130 testeeConcurrent(); | 201 testeeConcurrent(); |
| 131 } | 202 } |
| 132 if (!pause_on_exit) { | 203 if (!pause_on_exit) { |
| 133 // Wait around for the process to be killed. | 204 // Wait around for the process to be killed. |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 }, onError: (e, st) { | 469 }, onError: (e, st) { |
| 399 process.requestExit(); | 470 process.requestExit(); |
| 400 if (!_isWebSocketDisconnect(e)) { | 471 if (!_isWebSocketDisconnect(e)) { |
| 401 print('Unexpected exception in service tests: $e $st'); | 472 print('Unexpected exception in service tests: $e $st'); |
| 402 throw e; | 473 throw e; |
| 403 } | 474 } |
| 404 }); | 475 }); |
| 405 }); | 476 }); |
| 406 } | 477 } |
| 407 } | 478 } |
| OLD | NEW |