| 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'; |
| 11 import 'service_test_common.dart'; | 11 import 'service_test_common.dart'; |
| 12 | 12 |
| 13 /// Will be set to the http address of the VM's service protocol before | 13 /// Will be set to the http address of the VM's service protocol before |
| 14 /// any tests are invoked. | 14 /// any tests are invoked. |
| 15 String serviceHttpAddress; | 15 String serviceHttpAddress; |
| 16 String serviceWebsocketAddress; | 16 String serviceWebsocketAddress; |
| 17 | 17 |
| 18 bool _isWebSocketDisconnect(e) { | 18 bool _isWebSocketDisconnect(e) { |
| 19 return e is NetworkRpcException; | 19 return e is NetworkRpcException; |
| 20 } | 20 } |
| 21 | 21 |
| 22 |
| 22 const String _TESTEE_ENV_KEY = 'SERVICE_TEST_TESTEE'; | 23 const String _TESTEE_ENV_KEY = 'SERVICE_TEST_TESTEE'; |
| 23 const Map<String, String> _TESTEE_SPAWN_ENV = const { | 24 const Map<String, String> _TESTEE_SPAWN_ENV = const { |
| 24 _TESTEE_ENV_KEY: 'true' | 25 _TESTEE_ENV_KEY: 'true' |
| 25 }; | 26 }; |
| 26 bool _isTestee() { | 27 bool _isTestee() { |
| 27 return Platform.environment.containsKey(_TESTEE_ENV_KEY); | 28 return Platform.environment.containsKey(_TESTEE_ENV_KEY); |
| 28 } | 29 } |
| 29 | 30 |
| 31 const String _SKY_SHELL_ENV_KEY = 'SERVICE_TEST_SKY_SHELL'; |
| 32 bool _shouldLaunchSkyShell() { |
| 33 return Platform.environment.containsKey(_SKY_SHELL_ENV_KEY); |
| 34 } |
| 35 String _skyShellPath() { |
| 36 return Platform.environment[_SKY_SHELL_ENV_KEY]; |
| 37 } |
| 38 |
| 30 class _SerivceTesteeRunner { | 39 class _SerivceTesteeRunner { |
| 31 Future run({testeeBefore(): null, | 40 Future run({testeeBefore(): null, |
| 32 testeeConcurrent(): null, | 41 testeeConcurrent(): null, |
| 33 bool pause_on_start: false, | 42 bool pause_on_start: false, |
| 34 bool pause_on_exit: false}) async { | 43 bool pause_on_exit: false}) async { |
| 35 if (!pause_on_start) { | 44 if (!pause_on_start) { |
| 36 if (testeeBefore != null) { | 45 if (testeeBefore != null) { |
| 37 var result = testeeBefore(); | 46 var result = testeeBefore(); |
| 38 if (result is Future) { | 47 if (result is Future) { |
| 39 await result; | 48 await result; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 81 } |
| 73 } | 82 } |
| 74 } | 83 } |
| 75 | 84 |
| 76 class _ServiceTesteeLauncher { | 85 class _ServiceTesteeLauncher { |
| 77 Process process; | 86 Process process; |
| 78 final List<String> args; | 87 final List<String> args; |
| 79 bool killedByTester = false; | 88 bool killedByTester = false; |
| 80 | 89 |
| 81 _ServiceTesteeLauncher() : | 90 _ServiceTesteeLauncher() : |
| 82 args = ['--enable-vm-service:0', | 91 args = [Platform.script.toFilePath()] {} |
| 83 Platform.script.toFilePath()] {} | |
| 84 | |
| 85 String get executablePath => Platform.executable; | |
| 86 | 92 |
| 87 // Spawn the testee process. | 93 // Spawn the testee process. |
| 88 Future<Process> _spawnProcess(bool pause_on_start, | 94 Future<Process> _spawnProcess(bool pause_on_start, |
| 89 bool pause_on_exit, | 95 bool pause_on_exit, |
| 90 bool pause_on_unhandled_exceptions, | 96 bool pause_on_unhandled_exceptions, |
| 91 bool trace_service, | 97 bool trace_service, |
| 92 bool trace_compiler) { | 98 bool trace_compiler) { |
| 93 assert(pause_on_start != null); | 99 assert(pause_on_start != null); |
| 94 assert(pause_on_exit != null); | 100 assert(pause_on_exit != null); |
| 101 assert(pause_on_unhandled_exceptions != null); |
| 95 assert(trace_service != null); | 102 assert(trace_service != null); |
| 103 assert(trace_compiler != null); |
| 104 |
| 96 // TODO(turnidge): I have temporarily turned on service tracing for | 105 // TODO(turnidge): I have temporarily turned on service tracing for |
| 97 // all tests to help diagnose flaky tests. | 106 // all tests to help diagnose flaky tests. |
| 98 trace_service = true; | 107 trace_service = true; |
| 108 |
| 109 if (_shouldLaunchSkyShell()) { |
| 110 return _spawnSkyProcess(pause_on_start, |
| 111 pause_on_exit, |
| 112 pause_on_unhandled_exceptions, |
| 113 trace_service, |
| 114 trace_compiler); |
| 115 } else { |
| 116 return _spawnDartProcess(pause_on_start, |
| 117 pause_on_exit, |
| 118 pause_on_unhandled_exceptions, |
| 119 trace_service, |
| 120 trace_compiler); |
| 121 } |
| 122 } |
| 123 |
| 124 Future<Process> _spawnDartProcess(bool pause_on_start, |
| 125 bool pause_on_exit, |
| 126 bool pause_on_unhandled_exceptions, |
| 127 bool trace_service, |
| 128 bool trace_compiler) { |
| 129 assert(!_shouldLaunchSkyShell()); |
| 130 |
| 99 String dartExecutable = Platform.executable; | 131 String dartExecutable = Platform.executable; |
| 132 |
| 100 var fullArgs = []; | 133 var fullArgs = []; |
| 101 if (trace_service) { | 134 if (trace_service) { |
| 102 fullArgs.add('--trace-service'); | 135 fullArgs.add('--trace-service'); |
| 103 fullArgs.add('--trace-service-verbose'); | 136 fullArgs.add('--trace-service-verbose'); |
| 104 } | 137 } |
| 105 if (trace_compiler) { | 138 if (trace_compiler) { |
| 106 fullArgs.add('--trace-compiler'); | 139 fullArgs.add('--trace-compiler'); |
| 107 } | 140 } |
| 108 if (pause_on_start) { | 141 if (pause_on_start) { |
| 109 fullArgs.add('--pause-isolates-on-start'); | 142 fullArgs.add('--pause-isolates-on-start'); |
| 110 } | 143 } |
| 111 if (pause_on_exit) { | 144 if (pause_on_exit) { |
| 112 fullArgs.add('--pause-isolates-on-exit'); | 145 fullArgs.add('--pause-isolates-on-exit'); |
| 113 } | 146 } |
| 114 if (pause_on_unhandled_exceptions) { | 147 if (pause_on_unhandled_exceptions) { |
| 115 fullArgs.add('--pause-isolates-on-unhandled-exceptions'); | 148 fullArgs.add('--pause-isolates-on-unhandled-exceptions'); |
| 116 } | 149 } |
| 150 |
| 117 fullArgs.addAll(Platform.executableArguments); | 151 fullArgs.addAll(Platform.executableArguments); |
| 152 fullArgs.add('--enable-vm-service:0'); |
| 118 fullArgs.addAll(args); | 153 fullArgs.addAll(args); |
| 119 print('** Launching $dartExecutable ${fullArgs.join(' ')}'); | 154 |
| 120 return Process.start(dartExecutable, | 155 return _spawnCommon(dartExecutable, fullArgs); |
| 121 fullArgs, | 156 } |
| 122 environment: _TESTEE_SPAWN_ENV); | 157 |
| 158 Future<Process> _spawnSkyProcess(bool pause_on_start, |
| 159 bool pause_on_exit, |
| 160 bool pause_on_unhandled_exceptions, |
| 161 bool trace_service, |
| 162 bool trace_compiler) { |
| 163 assert(_shouldLaunchSkyShell()); |
| 164 |
| 165 String dartExecutable = _skyShellPath(); |
| 166 |
| 167 var dartFlags = []; |
| 168 var fullArgs = []; |
| 169 if (trace_service) { |
| 170 dartFlags.add('--trace_service'); |
| 171 dartFlags.add('--trace_service_verbose'); |
| 172 } |
| 173 if (trace_compiler) { |
| 174 dartFlags.add('--trace_compiler'); |
| 175 } |
| 176 if (pause_on_start) { |
| 177 dartFlags.add('--pause_isolates_on_start'); |
| 178 fullArgs.add('--start-paused'); |
| 179 } |
| 180 if (pause_on_exit) { |
| 181 dartFlags.add('--pause_isolates_on_exit'); |
| 182 } |
| 183 if (pause_on_unhandled_exceptions) { |
| 184 dartFlags.add('--pause_isolates_on_unhandled_exceptions'); |
| 185 } |
| 186 // Override mirrors. |
| 187 dartFlags.add('--enable_mirrors=true'); |
| 188 |
| 189 fullArgs.addAll(Platform.executableArguments); |
| 190 fullArgs.add('--observatory-port=0'); |
| 191 fullArgs.add('--dart-flags=${dartFlags.join(' ')}'); |
| 192 fullArgs.addAll(args); |
| 193 |
| 194 return _spawnCommon(dartExecutable, fullArgs); |
| 195 } |
| 196 |
| 197 Future<Process> _spawnCommon(String executable, List<String> arguments) { |
| 198 print('** Launching $executable ${arguments.join(' ')}'); |
| 199 return Process.start(executable, arguments, environment: _TESTEE_SPAWN_ENV); |
| 123 } | 200 } |
| 124 | 201 |
| 125 Future<int> launch(bool pause_on_start, | 202 Future<int> launch(bool pause_on_start, |
| 126 bool pause_on_exit, | 203 bool pause_on_exit, |
| 127 bool pause_on_unhandled_exceptions, | 204 bool pause_on_unhandled_exceptions, |
| 128 bool trace_service, | 205 bool trace_service, |
| 129 bool trace_compiler) { | 206 bool trace_compiler) { |
| 130 return _spawnProcess(pause_on_start, | 207 return _spawnProcess(pause_on_start, |
| 131 pause_on_exit, | 208 pause_on_exit, |
| 132 pause_on_unhandled_exceptions, | 209 pause_on_unhandled_exceptions, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 mainArgs: mainArgs, | 413 mainArgs: mainArgs, |
| 337 vmTests: tests, | 414 vmTests: tests, |
| 338 pause_on_start: pause_on_start, | 415 pause_on_start: pause_on_start, |
| 339 pause_on_exit: pause_on_exit, | 416 pause_on_exit: pause_on_exit, |
| 340 trace_service: trace_service, | 417 trace_service: trace_service, |
| 341 trace_compiler: trace_compiler, | 418 trace_compiler: trace_compiler, |
| 342 verbose_vm: verbose_vm, | 419 verbose_vm: verbose_vm, |
| 343 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); | 420 pause_on_unhandled_exceptions: pause_on_unhandled_exceptions); |
| 344 } | 421 } |
| 345 } | 422 } |
| OLD | NEW |