Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: runtime/observatory/tests/service/test_helper.dart

Issue 1276243004: Allow stepping when paused at isolate start. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 bool _isWebSocketDisconnect(e) { 13 bool _isWebSocketDisconnect(e) {
14 return e is NetworkRpcException; 14 return e is NetworkRpcException;
15 } 15 }
16 16
17 // This invocation should set up the state being tested. 17 // This invocation should set up the state being tested.
18 const String _TESTEE_MODE_FLAG = "--testee-mode"; 18 const String _TESTEE_MODE_FLAG = "--testee-mode";
19 19
20 class _TestLauncher { 20 class _TestLauncher {
21 Process process; 21 Process process;
22 final List<String> args; 22 final List<String> args;
23 bool killedByTester = false; 23 bool killedByTester = false;
24 24
25 _TestLauncher() : args = ['--enable-vm-service:0', 25 _TestLauncher() : args = ['--enable-vm-service:0',
26 Platform.script.toFilePath(), 26 Platform.script.toFilePath(),
27 _TESTEE_MODE_FLAG] {} 27 _TESTEE_MODE_FLAG] {}
28 28
29 Future<int> launch(bool pause_on_exit) { 29 Future<int> launch(bool pause_on_start, bool pause_on_exit) {
30 String dartExecutable = Platform.executable; 30 String dartExecutable = Platform.executable;
31 var fullArgs = []; 31 var fullArgs = [];
32 if (pause_on_start == true) {
33 fullArgs.add('--pause-isolates-on-start');
34 }
32 if (pause_on_exit == true) { 35 if (pause_on_exit == true) {
33 fullArgs.add('--pause-isolates-on-exit'); 36 fullArgs.add('--pause-isolates-on-exit');
34 } 37 }
35 fullArgs.addAll(Platform.executableArguments); 38 fullArgs.addAll(Platform.executableArguments);
36 fullArgs.addAll(args); 39 fullArgs.addAll(args);
37 print('** Launching $dartExecutable ${fullArgs.join(' ')}'); 40 print('** Launching $dartExecutable ${fullArgs.join(' ')}');
38 return Process.start(dartExecutable, fullArgs).then((p) { 41 return Process.start(dartExecutable, fullArgs).then((p) {
39 42
40 Completer completer = new Completer(); 43 Completer completer = new Completer();
41 process = p; 44 process = p;
42 var portNumber; 45 var portNumber;
43 var blank; 46 var blank;
44 var first = true; 47 var first = true;
45 process.stdout.transform(UTF8.decoder) 48 process.stdout.transform(UTF8.decoder)
46 .transform(new LineSplitter()).listen((line) { 49 .transform(new LineSplitter()).listen((line) {
47 if (line.startsWith('Observatory listening on http://')) { 50 if (line.startsWith('Observatory listening on http://')) {
48 RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)"); 51 RegExp portExp = new RegExp(r"\d+.\d+.\d+.\d+:(\d+)");
49 var port = portExp.firstMatch(line).group(1); 52 var port = portExp.firstMatch(line).group(1);
50 portNumber = int.parse(port); 53 portNumber = int.parse(port);
51 } 54 }
52 if (line == '') { 55 if (pause_on_start || line == '') {
53 // Received blank line. 56 // Received blank line.
54 blank = true; 57 blank = true;
55 } 58 }
56 if (portNumber != null && blank == true && first == true) { 59 if (portNumber != null && blank == true && first == true) {
57 completer.complete(portNumber); 60 completer.complete(portNumber);
58 // Stop repeat completions. 61 // Stop repeat completions.
59 first = false; 62 first = false;
60 print('** Signaled to run test queries on $portNumber'); 63 print('** Signaled to run test queries on $portNumber');
61 } 64 }
62 print(line); 65 print(line);
(...skipping 28 matching lines...) Expand all
91 String serviceHttpAddress; 94 String serviceHttpAddress;
92 95
93 /// Runs [tests] in sequence, each of which should take an [Isolate] and 96 /// Runs [tests] in sequence, each of which should take an [Isolate] and
94 /// return a [Future]. Code for setting up state can run before and/or 97 /// return a [Future]. Code for setting up state can run before and/or
95 /// concurrently with the tests. Uses [mainArgs] to determine whether 98 /// concurrently with the tests. Uses [mainArgs] to determine whether
96 /// to run tests or testee in this invokation of the script. 99 /// to run tests or testee in this invokation of the script.
97 void runIsolateTests(List<String> mainArgs, 100 void runIsolateTests(List<String> mainArgs,
98 List<IsolateTest> tests, 101 List<IsolateTest> tests,
99 {void testeeBefore(), 102 {void testeeBefore(),
100 void testeeConcurrent(), 103 void testeeConcurrent(),
104 bool pause_on_start,
101 bool pause_on_exit}) { 105 bool pause_on_exit}) {
106 assert(!pause_on_start || testeeBefore == null);
102 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { 107 if (mainArgs.contains(_TESTEE_MODE_FLAG)) {
103 if (testeeBefore != null) { 108 if (!pause_on_start) {
104 testeeBefore(); 109 if (testeeBefore != null) {
110 testeeBefore();
111 }
112 print(''); // Print blank line to signal that we are ready.
105 } 113 }
106 print(''); // Print blank line to signal that we are ready.
107 if (testeeConcurrent != null) { 114 if (testeeConcurrent != null) {
108 testeeConcurrent(); 115 testeeConcurrent();
109 } 116 }
110 // Wait around for the process to be killed. 117 // Wait around for the process to be killed.
111 stdin.first.then((_) => exit(0)); 118 stdin.first.then((_) => exit(0));
112 } else { 119 } else {
113 var process = new _TestLauncher(); 120 var process = new _TestLauncher();
114 process.launch(pause_on_exit).then((port) { 121 process.launch(pause_on_start, pause_on_exit).then((port) {
115 if (mainArgs.contains("--gdb")) { 122 if (mainArgs.contains("--gdb")) {
116 port = 8181; 123 port = 8181;
117 } 124 }
118 String addr = 'ws://localhost:$port/ws'; 125 String addr = 'ws://localhost:$port/ws';
119 serviceHttpAddress = 'http://localhost:$port'; 126 serviceHttpAddress = 'http://localhost:$port';
120 var testIndex = 1; 127 var testIndex = 1;
121 var totalTests = tests.length; 128 var totalTests = tests.length;
122 var name = Platform.script.pathSegments.last; 129 var name = Platform.script.pathSegments.last;
123 runZoned(() { 130 runZoned(() {
124 new WebSocketVM(new WebSocketVMTarget(addr)).load() 131 new WebSocketVM(new WebSocketVMTarget(addr)).load()
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 286
280 287
281 /// Runs [tests] in sequence, each of which should take an [Isolate] and 288 /// Runs [tests] in sequence, each of which should take an [Isolate] and
282 /// return a [Future]. Code for setting up state can run before and/or 289 /// return a [Future]. Code for setting up state can run before and/or
283 /// concurrently with the tests. Uses [mainArgs] to determine whether 290 /// concurrently with the tests. Uses [mainArgs] to determine whether
284 /// to run tests or testee in this invokation of the script. 291 /// to run tests or testee in this invokation of the script.
285 Future runVMTests(List<String> mainArgs, 292 Future runVMTests(List<String> mainArgs,
286 List<VMTest> tests, 293 List<VMTest> tests,
287 {Future testeeBefore(), 294 {Future testeeBefore(),
288 Future testeeConcurrent(), 295 Future testeeConcurrent(),
296 bool pause_on_start,
289 bool pause_on_exit}) async { 297 bool pause_on_exit}) async {
290 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { 298 if (mainArgs.contains(_TESTEE_MODE_FLAG)) {
291 if (testeeBefore != null) { 299 if (testeeBefore != null) {
292 await testeeBefore(); 300 await testeeBefore();
293 } 301 }
294 print(''); // Print blank line to signal that we are ready. 302 print(''); // Print blank line to signal that we are ready.
295 if (testeeConcurrent != null) { 303 if (testeeConcurrent != null) {
296 await testeeConcurrent(); 304 await testeeConcurrent();
297 } 305 }
298 // Wait around for the process to be killed. 306 // Wait around for the process to be killed.
299 stdin.first.then((_) => exit(0)); 307 stdin.first.then((_) => exit(0));
300 } else { 308 } else {
301 var process = new _TestLauncher(); 309 var process = new _TestLauncher();
302 process.launch(pause_on_exit).then((port) async { 310 process.launch(pause_on_start, pause_on_exit).then((port) async {
303 if (mainArgs.contains("--gdb")) { 311 if (mainArgs.contains("--gdb")) {
304 port = 8181; 312 port = 8181;
305 } 313 }
306 String addr = 'ws://localhost:$port/ws'; 314 String addr = 'ws://localhost:$port/ws';
307 serviceHttpAddress = 'http://localhost:$port'; 315 serviceHttpAddress = 'http://localhost:$port';
308 var testIndex = 1; 316 var testIndex = 1;
309 var totalTests = tests.length; 317 var totalTests = tests.length;
310 var name = Platform.script.pathSegments.last; 318 var name = Platform.script.pathSegments.last;
311 runZoned(() { 319 runZoned(() {
312 new WebSocketVM(new WebSocketVMTarget(addr)).load() 320 new WebSocketVM(new WebSocketVMTarget(addr)).load()
313 .then((VM vm) => Future.forEach(tests, (test) { 321 .then((VM vm) => Future.forEach(tests, (test) {
314 print('Running $name [$testIndex/$totalTests]'); 322 print('Running $name [$testIndex/$totalTests]');
315 testIndex++; 323 testIndex++;
316 return test(vm); 324 return test(vm);
317 })).then((_) => process.requestExit()); 325 })).then((_) => process.requestExit());
318 }, onError: (e, st) { 326 }, onError: (e, st) {
319 process.requestExit(); 327 process.requestExit();
320 if (!_isWebSocketDisconnect(e)) { 328 if (!_isWebSocketDisconnect(e)) {
321 print('Unexpected exception in service tests: $e $st'); 329 print('Unexpected exception in service tests: $e $st');
322 throw e; 330 throw e;
323 } 331 }
324 }); 332 });
325 }); 333 });
326 } 334 }
327 } 335 }
OLDNEW
« no previous file with comments | « runtime/observatory/tests/service/pause_on_start_then_step_test.dart ('k') | runtime/vm/debugger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698