| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 print('** Killing script'); | 79 print('** Killing script'); |
| 80 if (process.kill()) { | 80 if (process.kill()) { |
| 81 killedByTester = true; | 81 killedByTester = true; |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 typedef Future IsolateTest(Isolate isolate); | 86 typedef Future IsolateTest(Isolate isolate); |
| 87 typedef Future VMTest(VM vm); | 87 typedef Future VMTest(VM vm); |
| 88 | 88 |
| 89 /// Will be set to the http address of the VM's service protocol before |
| 90 /// any tests are invoked. |
| 91 String serviceHttpAddress; |
| 92 |
| 89 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 93 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
| 90 /// return a [Future]. Code for setting up state can run before and/or | 94 /// return a [Future]. Code for setting up state can run before and/or |
| 91 /// concurrently with the tests. Uses [mainArgs] to determine whether | 95 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 92 /// to run tests or testee in this invokation of the script. | 96 /// to run tests or testee in this invokation of the script. |
| 93 void runIsolateTests(List<String> mainArgs, | 97 void runIsolateTests(List<String> mainArgs, |
| 94 List<IsolateTest> tests, | 98 List<IsolateTest> tests, |
| 95 {void testeeBefore(), | 99 {void testeeBefore(), |
| 96 void testeeConcurrent(), | 100 void testeeConcurrent(), |
| 97 bool pause_on_exit}) { | 101 bool pause_on_exit}) { |
| 98 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { | 102 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { |
| 99 if (testeeBefore != null) { | 103 if (testeeBefore != null) { |
| 100 testeeBefore(); | 104 testeeBefore(); |
| 101 } | 105 } |
| 102 print(''); // Print blank line to signal that we are ready. | 106 print(''); // Print blank line to signal that we are ready. |
| 103 if (testeeConcurrent != null) { | 107 if (testeeConcurrent != null) { |
| 104 testeeConcurrent(); | 108 testeeConcurrent(); |
| 105 } | 109 } |
| 106 // Wait around for the process to be killed. | 110 // Wait around for the process to be killed. |
| 107 stdin.first.then((_) => exit(0)); | 111 stdin.first.then((_) => exit(0)); |
| 108 } else { | 112 } else { |
| 109 var process = new _TestLauncher(); | 113 var process = new _TestLauncher(); |
| 110 process.launch(pause_on_exit).then((port) { | 114 process.launch(pause_on_exit).then((port) { |
| 111 if (mainArgs.contains("--gdb")) { | 115 if (mainArgs.contains("--gdb")) { |
| 112 port = 8181; | 116 port = 8181; |
| 113 } | 117 } |
| 114 String addr = 'ws://localhost:$port/ws'; | 118 String addr = 'ws://localhost:$port/ws'; |
| 119 serviceHttpAddress = 'http://localhost:$port'; |
| 115 var testIndex = 1; | 120 var testIndex = 1; |
| 116 var totalTests = tests.length; | 121 var totalTests = tests.length; |
| 117 var name = Platform.script.pathSegments.last; | 122 var name = Platform.script.pathSegments.last; |
| 118 runZoned(() { | 123 runZoned(() { |
| 119 new WebSocketVM(new WebSocketVMTarget(addr)).load() | 124 new WebSocketVM(new WebSocketVMTarget(addr)).load() |
| 120 .then((VM vm) => vm.isolates.first.load()) | 125 .then((VM vm) => vm.isolates.first.load()) |
| 121 .then((Isolate isolate) => Future.forEach(tests, (test) { | 126 .then((Isolate isolate) => Future.forEach(tests, (test) { |
| 122 print('Running $name [$testIndex/$totalTests]'); | 127 print('Running $name [$testIndex/$totalTests]'); |
| 123 testIndex++; | 128 testIndex++; |
| 124 return test(isolate); | 129 return test(isolate); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 297 } |
| 293 // Wait around for the process to be killed. | 298 // Wait around for the process to be killed. |
| 294 stdin.first.then((_) => exit(0)); | 299 stdin.first.then((_) => exit(0)); |
| 295 } else { | 300 } else { |
| 296 var process = new _TestLauncher(); | 301 var process = new _TestLauncher(); |
| 297 process.launch(pause_on_exit).then((port) async { | 302 process.launch(pause_on_exit).then((port) async { |
| 298 if (mainArgs.contains("--gdb")) { | 303 if (mainArgs.contains("--gdb")) { |
| 299 port = 8181; | 304 port = 8181; |
| 300 } | 305 } |
| 301 String addr = 'ws://localhost:$port/ws'; | 306 String addr = 'ws://localhost:$port/ws'; |
| 307 serviceHttpAddress = 'http://localhost:$port'; |
| 302 var testIndex = 1; | 308 var testIndex = 1; |
| 303 var totalTests = tests.length; | 309 var totalTests = tests.length; |
| 304 var name = Platform.script.pathSegments.last; | 310 var name = Platform.script.pathSegments.last; |
| 305 runZoned(() { | 311 runZoned(() { |
| 306 new WebSocketVM(new WebSocketVMTarget(addr)).load() | 312 new WebSocketVM(new WebSocketVMTarget(addr)).load() |
| 307 .then((VM vm) => Future.forEach(tests, (test) { | 313 .then((VM vm) => Future.forEach(tests, (test) { |
| 308 print('Running $name [$testIndex/$totalTests]'); | 314 print('Running $name [$testIndex/$totalTests]'); |
| 309 testIndex++; | 315 testIndex++; |
| 310 return test(vm); | 316 return test(vm); |
| 311 })).then((_) => process.requestExit()); | 317 })).then((_) => process.requestExit()); |
| 312 }, onError: (e, st) { | 318 }, onError: (e, st) { |
| 313 process.requestExit(); | 319 process.requestExit(); |
| 314 if (!_isWebSocketDisconnect(e)) { | 320 if (!_isWebSocketDisconnect(e)) { |
| 315 print('Unexpected exception in service tests: $e $st'); | 321 print('Unexpected exception in service tests: $e $st'); |
| 316 throw e; | 322 throw e; |
| 317 } | 323 } |
| 318 }); | 324 }); |
| 319 }); | 325 }); |
| 320 } | 326 } |
| 321 } | 327 } |
| OLD | NEW |