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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 bool killedByTester = false; | 84 bool killedByTester = false; |
85 | 85 |
86 _ServiceTesteeLauncher() : | 86 _ServiceTesteeLauncher() : |
87 args = [Platform.script.toFilePath()] {} | 87 args = [Platform.script.toFilePath()] {} |
88 | 88 |
89 // Spawn the testee process. | 89 // Spawn the testee process. |
90 Future<Process> _spawnProcess(bool pause_on_start, | 90 Future<Process> _spawnProcess(bool pause_on_start, |
91 bool pause_on_exit, | 91 bool pause_on_exit, |
92 bool pause_on_unhandled_exceptions, | 92 bool pause_on_unhandled_exceptions, |
93 bool trace_service, | 93 bool trace_service, |
94 bool trace_compiler) { | 94 bool trace_compiler, |
| 95 bool testeeControlsServer) { |
95 assert(pause_on_start != null); | 96 assert(pause_on_start != null); |
96 assert(pause_on_exit != null); | 97 assert(pause_on_exit != null); |
97 assert(pause_on_unhandled_exceptions != null); | 98 assert(pause_on_unhandled_exceptions != null); |
98 assert(trace_service != null); | 99 assert(trace_service != null); |
99 assert(trace_compiler != null); | 100 assert(trace_compiler != null); |
| 101 assert(testeeControlsServer != null); |
100 | 102 |
101 if (_shouldLaunchSkyShell()) { | 103 if (_shouldLaunchSkyShell()) { |
102 return _spawnSkyProcess(pause_on_start, | 104 return _spawnSkyProcess(pause_on_start, |
103 pause_on_exit, | 105 pause_on_exit, |
104 pause_on_unhandled_exceptions, | 106 pause_on_unhandled_exceptions, |
105 trace_service, | 107 trace_service, |
106 trace_compiler); | 108 trace_compiler, |
| 109 testeeControlsServer); |
107 } else { | 110 } else { |
108 return _spawnDartProcess(pause_on_start, | 111 return _spawnDartProcess(pause_on_start, |
109 pause_on_exit, | 112 pause_on_exit, |
110 pause_on_unhandled_exceptions, | 113 pause_on_unhandled_exceptions, |
111 trace_service, | 114 trace_service, |
112 trace_compiler); | 115 trace_compiler, |
| 116 testeeControlsServer); |
113 } | 117 } |
114 } | 118 } |
115 | 119 |
116 Future<Process> _spawnDartProcess(bool pause_on_start, | 120 Future<Process> _spawnDartProcess(bool pause_on_start, |
117 bool pause_on_exit, | 121 bool pause_on_exit, |
118 bool pause_on_unhandled_exceptions, | 122 bool pause_on_unhandled_exceptions, |
119 bool trace_service, | 123 bool trace_service, |
120 bool trace_compiler) { | 124 bool trace_compiler, |
| 125 bool testeeControlsServer) { |
121 assert(!_shouldLaunchSkyShell()); | 126 assert(!_shouldLaunchSkyShell()); |
122 | 127 |
123 String dartExecutable = Platform.executable; | 128 String dartExecutable = Platform.executable; |
124 | 129 |
125 var fullArgs = []; | 130 var fullArgs = []; |
126 if (trace_service) { | 131 if (trace_service) { |
127 fullArgs.add('--trace-service'); | 132 fullArgs.add('--trace-service'); |
128 fullArgs.add('--trace-service-verbose'); | 133 fullArgs.add('--trace-service-verbose'); |
129 } | 134 } |
130 if (trace_compiler) { | 135 if (trace_compiler) { |
131 fullArgs.add('--trace-compiler'); | 136 fullArgs.add('--trace-compiler'); |
132 } | 137 } |
133 if (pause_on_start) { | 138 if (pause_on_start) { |
134 fullArgs.add('--pause-isolates-on-start'); | 139 fullArgs.add('--pause-isolates-on-start'); |
135 } | 140 } |
136 if (pause_on_exit) { | 141 if (pause_on_exit) { |
137 fullArgs.add('--pause-isolates-on-exit'); | 142 fullArgs.add('--pause-isolates-on-exit'); |
138 } | 143 } |
139 if (pause_on_unhandled_exceptions) { | 144 if (pause_on_unhandled_exceptions) { |
140 fullArgs.add('--pause-isolates-on-unhandled-exceptions'); | 145 fullArgs.add('--pause-isolates-on-unhandled-exceptions'); |
141 } | 146 } |
142 | 147 |
143 fullArgs.addAll(Platform.executableArguments); | 148 fullArgs.addAll(Platform.executableArguments); |
144 fullArgs.add('--enable-vm-service:0'); | 149 if (!testeeControlsServer) { |
| 150 fullArgs.add('--enable-vm-service:0'); |
| 151 } |
145 fullArgs.addAll(args); | 152 fullArgs.addAll(args); |
146 | 153 |
147 return _spawnCommon(dartExecutable, fullArgs); | 154 return _spawnCommon(dartExecutable, fullArgs); |
148 } | 155 } |
149 | 156 |
150 Future<Process> _spawnSkyProcess(bool pause_on_start, | 157 Future<Process> _spawnSkyProcess(bool pause_on_start, |
151 bool pause_on_exit, | 158 bool pause_on_exit, |
152 bool pause_on_unhandled_exceptions, | 159 bool pause_on_unhandled_exceptions, |
153 bool trace_service, | 160 bool trace_service, |
154 bool trace_compiler) { | 161 bool trace_compiler) { |
(...skipping 17 matching lines...) Expand all Loading... |
172 if (pause_on_exit) { | 179 if (pause_on_exit) { |
173 dartFlags.add('--pause_isolates_on_exit'); | 180 dartFlags.add('--pause_isolates_on_exit'); |
174 } | 181 } |
175 if (pause_on_unhandled_exceptions) { | 182 if (pause_on_unhandled_exceptions) { |
176 dartFlags.add('--pause_isolates_on_unhandled_exceptions'); | 183 dartFlags.add('--pause_isolates_on_unhandled_exceptions'); |
177 } | 184 } |
178 // Override mirrors. | 185 // Override mirrors. |
179 dartFlags.add('--enable_mirrors=true'); | 186 dartFlags.add('--enable_mirrors=true'); |
180 | 187 |
181 fullArgs.addAll(Platform.executableArguments); | 188 fullArgs.addAll(Platform.executableArguments); |
182 fullArgs.add('--observatory-port=0'); | 189 if (!testeeControlsServer) { |
| 190 fullArgs.add('--observatory-port=0'); |
| 191 } |
183 fullArgs.add('--dart-flags=${dartFlags.join(' ')}'); | 192 fullArgs.add('--dart-flags=${dartFlags.join(' ')}'); |
184 fullArgs.addAll(args); | 193 fullArgs.addAll(args); |
185 | 194 |
186 return _spawnCommon(dartExecutable, fullArgs); | 195 return _spawnCommon(dartExecutable, fullArgs); |
187 } | 196 } |
188 | 197 |
189 Future<Process> _spawnCommon(String executable, List<String> arguments) { | 198 Future<Process> _spawnCommon(String executable, List<String> arguments) { |
190 var environment = _TESTEE_SPAWN_ENV; | 199 var environment = _TESTEE_SPAWN_ENV; |
191 var bashEnvironment = new StringBuffer(); | 200 var bashEnvironment = new StringBuffer(); |
192 environment.forEach((k, v) => bashEnvironment.write("$k=$v ")); | 201 environment.forEach((k, v) => bashEnvironment.write("$k=$v ")); |
193 print('** Launching $bashEnvironment$executable ${arguments.join(' ')}'); | 202 print('** Launching $bashEnvironment$executable ${arguments.join(' ')}'); |
194 return Process.start(executable, arguments, environment: environment); | 203 return Process.start(executable, arguments, environment: environment); |
195 } | 204 } |
196 | 205 |
197 Future<int> launch(bool pause_on_start, | 206 Future<int> launch(bool pause_on_start, |
198 bool pause_on_exit, | 207 bool pause_on_exit, |
199 bool pause_on_unhandled_exceptions, | 208 bool pause_on_unhandled_exceptions, |
200 bool trace_service, | 209 bool trace_service, |
201 bool trace_compiler) { | 210 bool trace_compiler, |
| 211 bool testeeControlsServer) { |
202 return _spawnProcess(pause_on_start, | 212 return _spawnProcess(pause_on_start, |
203 pause_on_exit, | 213 pause_on_exit, |
204 pause_on_unhandled_exceptions, | 214 pause_on_unhandled_exceptions, |
205 trace_service, | 215 trace_service, |
206 trace_compiler).then((p) { | 216 trace_compiler, |
| 217 testeeControlsServer).then((p) { |
207 Completer completer = new Completer(); | 218 Completer completer = new Completer(); |
208 process = p; | 219 process = p; |
209 var portNumber; | 220 var portNumber; |
210 var blank; | 221 var blank; |
211 var first = true; | 222 var first = true; |
212 process.stdout.transform(UTF8.decoder) | 223 process.stdout.transform(UTF8.decoder) |
213 .transform(new LineSplitter()).listen((line) { | 224 .transform(new LineSplitter()).listen((line) { |
214 if (line.startsWith('Observatory listening on http://')) { | 225 if (line.startsWith('Observatory listening on http://')) { |
215 RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)"); | 226 RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)"); |
216 var port = portExp.firstMatch(line).group(1); | 227 var port = portExp.firstMatch(line).group(1); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 321 |
311 class _ServiceTesterRunner { | 322 class _ServiceTesterRunner { |
312 void run({List<String> mainArgs, | 323 void run({List<String> mainArgs, |
313 List<VMTest> vmTests, | 324 List<VMTest> vmTests, |
314 List<IsolateTest> isolateTests, | 325 List<IsolateTest> isolateTests, |
315 bool pause_on_start: false, | 326 bool pause_on_start: false, |
316 bool pause_on_exit: false, | 327 bool pause_on_exit: false, |
317 bool trace_service: false, | 328 bool trace_service: false, |
318 bool trace_compiler: false, | 329 bool trace_compiler: false, |
319 bool verbose_vm: false, | 330 bool verbose_vm: false, |
320 bool pause_on_unhandled_exceptions: false}) { | 331 bool pause_on_unhandled_exceptions: false, |
| 332 bool testeeControlsServer: false}) { |
321 var process = new _ServiceTesteeLauncher(); | 333 var process = new _ServiceTesteeLauncher(); |
322 process.launch(pause_on_start, pause_on_exit, | 334 process.launch(pause_on_start, pause_on_exit, |
323 pause_on_unhandled_exceptions, | 335 pause_on_unhandled_exceptions, |
324 trace_service, trace_compiler).then((port) async { | 336 trace_service, trace_compiler, |
| 337 testeeControlsServer).then((port) async { |
325 if (mainArgs.contains("--gdb")) { | 338 if (mainArgs.contains("--gdb")) { |
326 var pid = process.process.pid; | 339 var pid = process.process.pid; |
327 var wait = new Duration(seconds: 10); | 340 var wait = new Duration(seconds: 10); |
328 print("Testee has pid $pid, waiting $wait before continuing"); | 341 print("Testee has pid $pid, waiting $wait before continuing"); |
329 sleep(wait); | 342 sleep(wait); |
330 } | 343 } |
331 serviceWebsocketAddress = 'ws://localhost:$port/ws'; | 344 serviceWebsocketAddress = 'ws://localhost:$port/ws'; |
332 serviceHttpAddress = 'http://localhost:$port'; | 345 serviceHttpAddress = 'http://localhost:$port'; |
333 var name = Platform.script.pathSegments.last; | 346 var name = Platform.script.pathSegments.last; |
334 Chain.capture(() async { | 347 Chain.capture(() async { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 /// to run tests or testee in this invokation of the script. | 392 /// to run tests or testee in this invokation of the script. |
380 Future runIsolateTests(List<String> mainArgs, | 393 Future runIsolateTests(List<String> mainArgs, |
381 List<IsolateTest> tests, | 394 List<IsolateTest> tests, |
382 {testeeBefore(), | 395 {testeeBefore(), |
383 testeeConcurrent(), | 396 testeeConcurrent(), |
384 bool pause_on_start: false, | 397 bool pause_on_start: false, |
385 bool pause_on_exit: false, | 398 bool pause_on_exit: false, |
386 bool trace_service: false, | 399 bool trace_service: false, |
387 bool trace_compiler: false, | 400 bool trace_compiler: false, |
388 bool verbose_vm: false, | 401 bool verbose_vm: false, |
389 bool pause_on_unhandled_exceptions: false}) async { | 402 bool pause_on_unhandled_exceptions: false, |
| 403 bool testeeControlsServer: false}) async { |
390 assert(!pause_on_start || testeeBefore == null); | 404 assert(!pause_on_start || testeeBefore == null); |
391 if (_isTestee()) { | 405 if (_isTestee()) { |
392 new _ServiceTesteeRunner().run(testeeBefore: testeeBefore, | 406 new _ServiceTesteeRunner().run(testeeBefore: testeeBefore, |
393 testeeConcurrent: testeeConcurrent, | 407 testeeConcurrent: testeeConcurrent, |
394 pause_on_start: pause_on_start, | 408 pause_on_start: pause_on_start, |
395 pause_on_exit: pause_on_exit); | 409 pause_on_exit: pause_on_exit); |
396 } else { | 410 } else { |
397 new _ServiceTesterRunner().run( | 411 new _ServiceTesterRunner().run( |
398 mainArgs: mainArgs, | 412 mainArgs: mainArgs, |
399 isolateTests: tests, | 413 isolateTests: tests, |
400 pause_on_start: pause_on_start, | 414 pause_on_start: pause_on_start, |
401 pause_on_exit: pause_on_exit, | 415 pause_on_exit: pause_on_exit, |
402 trace_service: trace_service, | 416 trace_service: trace_service, |
403 trace_compiler: trace_compiler, | 417 trace_compiler: trace_compiler, |
404 verbose_vm: verbose_vm, | 418 verbose_vm: verbose_vm, |
405 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); | 419 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions, |
| 420 testeeControlsServer: testeeControlsServer); |
406 } | 421 } |
407 } | 422 } |
408 | 423 |
409 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 424 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
410 /// return a [Future]. Code for setting up state can run before and/or | 425 /// return a [Future]. Code for setting up state can run before and/or |
411 /// concurrently with the tests. Uses [mainArgs] to determine whether | 426 /// concurrently with the tests. Uses [mainArgs] to determine whether |
412 /// to run tests or testee in this invokation of the script. | 427 /// to run tests or testee in this invokation of the script. |
413 /// | 428 /// |
414 /// This is a special version of this test harness specifically for the | 429 /// This is a special version of this test harness specifically for the |
415 /// pause_on_unhandled_exceptions_test, which cannot properly function | 430 /// pause_on_unhandled_exceptions_test, which cannot properly function |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 mainArgs: mainArgs, | 484 mainArgs: mainArgs, |
470 vmTests: tests, | 485 vmTests: tests, |
471 pause_on_start: pause_on_start, | 486 pause_on_start: pause_on_start, |
472 pause_on_exit: pause_on_exit, | 487 pause_on_exit: pause_on_exit, |
473 trace_service: trace_service, | 488 trace_service: trace_service, |
474 trace_compiler: trace_compiler, | 489 trace_compiler: trace_compiler, |
475 verbose_vm: verbose_vm, | 490 verbose_vm: verbose_vm, |
476 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); | 491 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); |
477 } | 492 } |
478 } | 493 } |
OLD | NEW |