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

Side by Side Diff: tools/testing/dart/dartino_session_command.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 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) 2015, the Dartino project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dartino 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.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 /// Provides a [Command] interface for interacting with a Fletch driver session. 5 /// Provides a [Command] interface for interacting with a Dartino driver session .
6 /// 6 ///
7 /// Normally, this is used by test.dart, but is also has a [main] method that 7 /// Normally, this is used by test.dart, but is also has a [main] method that
8 /// makes it possible to run a test outside test.dart. 8 /// makes it possible to run a test outside test.dart.
9 library test.fletch_session_command; 9 library test.dartino_session_command;
10 10
11 import 'dart:async' show 11 import 'dart:async' show
12 Completer, 12 Completer,
13 EventSink, 13 EventSink,
14 Future, 14 Future,
15 Stream, 15 Stream,
16 StreamController, 16 StreamController,
17 StreamTransformer, 17 StreamTransformer,
18 Timer; 18 Timer;
19 19
(...skipping 10 matching lines...) Expand all
30 Process, 30 Process,
31 ProcessSignal; 31 ProcessSignal;
32 32
33 import 'test_runner.dart' show 33 import 'test_runner.dart' show
34 Command, 34 Command,
35 CommandOutputImpl; 35 CommandOutputImpl;
36 36
37 import 'decode_exit_code.dart' show 37 import 'decode_exit_code.dart' show
38 DecodeExitCode; 38 DecodeExitCode;
39 39
40 import '../../../pkg/fletchc/lib/src/hub/exit_codes.dart' show 40 import '../../../pkg/dartino_compiler/lib/src/hub/exit_codes.dart' show
41 COMPILER_EXITCODE_CONNECTION_ERROR, 41 COMPILER_EXITCODE_CONNECTION_ERROR,
42 COMPILER_EXITCODE_CRASH, 42 COMPILER_EXITCODE_CRASH,
43 DART_VM_EXITCODE_COMPILE_TIME_ERROR, 43 DART_VM_EXITCODE_COMPILE_TIME_ERROR,
44 DART_VM_EXITCODE_UNCAUGHT_EXCEPTION; 44 DART_VM_EXITCODE_UNCAUGHT_EXCEPTION;
45 45
46 import '../../../pkg/fletchc/lib/fletch_vm.dart' show 46 import '../../../pkg/dartino_compiler/lib/dartino_vm.dart' show
47 FletchVm; 47 DartinoVm;
48 48
49 const String settingsFileNameFlag = "test.fletch_settings_file_name"; 49 const String settingsFileNameFlag = "test.dartino_settings_file_name";
50 const String settingsFileName = 50 const String settingsFileName =
51 const String.fromEnvironment(settingsFileNameFlag); 51 const String.fromEnvironment(settingsFileNameFlag);
52 52
53 /// Default timeout value (in seconds) used for running commands that are 53 /// Default timeout value (in seconds) used for running commands that are
54 /// assumed to complete fast. 54 /// assumed to complete fast.
55 // TODO(ahe): Lower this to 5 seconds. 55 // TODO(ahe): Lower this to 5 seconds.
56 const int defaultTimeout = 20; 56 const int defaultTimeout = 20;
57 57
58 final Queue<FletchSessionMirror> sessions = new Queue<FletchSessionMirror>(); 58 final Queue<DartinoSessionMirror> sessions = new Queue<DartinoSessionMirror>();
59 59
60 int sessionCount = 0; 60 int sessionCount = 0;
61 61
62 /// Return an available [FletchSessionMirror] or construct a new. 62 /// Return an available [DartinoSessionMirror] or construct a new.
63 FletchSessionMirror getAvailableSession() { 63 DartinoSessionMirror getAvailableSession() {
64 if (sessions.isEmpty) { 64 if (sessions.isEmpty) {
65 return new FletchSessionMirror(sessionCount++); 65 return new DartinoSessionMirror(sessionCount++);
66 } else { 66 } else {
67 return sessions.removeFirst(); 67 return sessions.removeFirst();
68 } 68 }
69 } 69 }
70 70
71 void returnSession(FletchSessionMirror session) { 71 void returnSession(DartinoSessionMirror session) {
72 sessions.addLast(session); 72 sessions.addLast(session);
73 } 73 }
74 74
75 String explainExitCode(int code) { 75 String explainExitCode(int code) {
76 String exit_message; 76 String exit_message;
77 if (code == null) { 77 if (code == null) {
78 exit_message = "no exit code"; 78 exit_message = "no exit code";
79 } else if (code == 0) { 79 } else if (code == 0) {
80 exit_message = "(success exit code)"; 80 exit_message = "(success exit code)";
81 } else if (code > 0) { 81 } else if (code > 0) {
(...skipping 23 matching lines...) Expand all
105 exit_message += " (internal error)"; 105 exit_message += " (internal error)";
106 } else if (code == -2) { 106 } else if (code == -2) {
107 exit_message += " (control-C)"; 107 exit_message += " (control-C)";
108 } else { 108 } else {
109 exit_message += " (see man 7 signal)"; 109 exit_message += " (see man 7 signal)";
110 } 110 }
111 } 111 }
112 return exit_message; 112 return exit_message;
113 } 113 }
114 114
115 class FletchSessionCommand implements Command { 115 class DartinoSessionCommand implements Command {
116 final String executable; 116 final String executable;
117 final String script; 117 final String script;
118 final List<String> arguments; 118 final List<String> arguments;
119 final Map<String, String> environmentOverrides; 119 final Map<String, String> environmentOverrides;
120 final String snapshotFileName; 120 final String snapshotFileName;
121 final String settingsFileName; 121 final String settingsFileName;
122 122
123 FletchSessionCommand( 123 DartinoSessionCommand(
124 this.executable, 124 this.executable,
125 this.script, 125 this.script,
126 this.arguments, 126 this.arguments,
127 this.environmentOverrides, 127 this.environmentOverrides,
128 {this.snapshotFileName, 128 {this.snapshotFileName,
129 this.settingsFileName: ".fletch-settings"}); 129 this.settingsFileName: ".dartino-settings"});
130 130
131 String get displayName => "fletch_session"; 131 String get displayName => "dartino_session";
132 132
133 int get maxNumRetries => 0; 133 int get maxNumRetries => 0;
134 134
135 String get reproductionCommand { 135 String get reproductionCommand {
136 var dartVm = Uri.parse(executable).resolve('dart'); 136 var dartVm = Uri.parse(executable).resolve('dart');
137 String fletchPath = Uri.parse(executable).resolve('fletch-vm').toString(); 137 String dartinoPath = Uri.parse(executable).resolve('dartino-vm').toString();
138 String versionFlag = '-Dfletch.version=`$fletchPath --version`'; 138 String versionFlag = '-Ddartino.version=`$dartinoPath --version`';
139 String settingsFileFlag = "-D$settingsFileNameFlag=$settingsFileName"; 139 String settingsFileFlag = "-D$settingsFileNameFlag=$settingsFileName";
140 140
141 return """ 141 return """
142 142
143 143
144 144
145 There are three ways to reproduce this error: 145 There are three ways to reproduce this error:
146 146
147 1. Run the test exactly as in this test framework. This is the hardest to 147 1. Run the test exactly as in this test framework. This is the hardest to
148 debug using gdb: 148 debug using gdb:
149 149
150 ${Platform.executable} -c $settingsFileFlag \\ 150 ${Platform.executable} -c $settingsFileFlag \\
151 $versionFlag \\ 151 $versionFlag \\
152 tools/testing/dart/fletch_session_command.dart $executable \\ 152 tools/testing/dart/dartino_session_command.dart $executable \\
153 ${arguments.join(' ')} 153 ${arguments.join(' ')}
154 154
155 155
156 2. Run the helper program `tests/fletchc/run.dart` under `gdb` using 156 2. Run the helper program `tests/dartino_compiler/run.dart` under `gdb` using
157 `set follow-fork-mode child`. This can be confusing, but makes it 157 `set follow-fork-mode child`. This can be confusing, but makes it
158 easy to run a reproduction command in a loop: 158 easy to run a reproduction command in a loop:
159 159
160 gdb -ex 'set follow-fork-mode child' -ex run --args \\ 160 gdb -ex 'set follow-fork-mode child' -ex run --args \\
161 $dartVm $settingsFileFlag \\ 161 $dartVm $settingsFileFlag \\
162 $versionFlag \\ 162 $versionFlag \\
163 -c tests/fletchc/run.dart $script 163 -c tests/dartino_compiler/run.dart $script
164 164
165 3. Run the `fletch-vm` in gdb and attach to it via the helper program. This 165 3. Run the `dartino-vm` in gdb and attach to it via the helper program. This
166 is the easiest way to debug using both gdb and lldb. You need to start two 166 is the easiest way to debug using both gdb and lldb. You need to start two
167 processes, each in their own terminal window: 167 processes, each in their own terminal window:
168 168
169 gdb -ex run --args $executable-vm --port=54321 169 gdb -ex run --args $executable-vm --port=54321
170 170
171 $dartVm $settingsFileFlag \\ 171 $dartVm $settingsFileFlag \\
172 $versionFlag \\ 172 $versionFlag \\
173 -c -DattachToVm=54321 tests/fletchc/run.dart $script 173 -c -DattachToVm=54321 tests/dartino_compiler/run.dart $script
174 174
175 175
176 """; 176 """;
177 } 177 }
178 178
179 Future<FletchTestCommandOutput> run( 179 Future<DartinoTestCommandOutput> run(
180 int timeout, 180 int timeout,
181 bool verbose, 181 bool verbose,
182 {bool superVerbose: false}) async { 182 {bool superVerbose: false}) async {
183 if (arguments.length > 1) { 183 if (arguments.length > 1) {
184 String options = arguments 184 String options = arguments
185 .where((String argument) => argument != script) 185 .where((String argument) => argument != script)
186 .join(' '); 186 .join(' ');
187 // TODO(ahe): Passing options to the incremental compiler isn't 187 // TODO(ahe): Passing options to the incremental compiler isn't
188 // trivial. We don't want to reset the compiler each time an option 188 // trivial. We don't want to reset the compiler each time an option
189 // changes. For example, when changing the package root, the compiler 189 // changes. For example, when changing the package root, the compiler
190 // should refresh all package files to see if they have changed. 190 // should refresh all package files to see if they have changed.
191 return compilerFail("Compiler options not implemented: $options"); 191 return compilerFail("Compiler options not implemented: $options");
192 } 192 }
193 193
194 FletchSessionHelper fletch = 194 DartinoSessionHelper dartino =
195 new FletchSessionHelper( 195 new DartinoSessionHelper(
196 getAvailableSession(), executable, environmentOverrides, 196 getAvailableSession(), executable, environmentOverrides,
197 verbose, superVerbose); 197 verbose, superVerbose);
198 198
199 fletch.sessionMirror.printLoggedCommands(fletch.stdout, executable); 199 dartino.sessionMirror.printLoggedCommands(dartino.stdout, executable);
200 200
201 Stopwatch sw = new Stopwatch()..start(); 201 Stopwatch sw = new Stopwatch()..start();
202 int exitCode; 202 int exitCode;
203 bool endedSession = false; 203 bool endedSession = false;
204 try { 204 try {
205 Future vmTerminationFuture; 205 Future vmTerminationFuture;
206 try { 206 try {
207 await fletch.createSession(settingsFileName); 207 await dartino.createSession(settingsFileName);
208 208
209 // Now that the session is created, start a Fletch VM. 209 // Now that the session is created, start a Dartino VM.
210 String vmSocketAddress = await fletch.spawnVm(); 210 String vmSocketAddress = await dartino.spawnVm();
211 // Timeout of the VM is implemented by shutting down the Fletch VM 211 // Timeout of the VM is implemented by shutting down the Dartino VM
212 // after [timeout] seconds. This ensures that compilation+runtime never 212 // after [timeout] seconds. This ensures that compilation+runtime never
213 // exceed [timeout] seconds (plus whatever time is spent in setting up 213 // exceed [timeout] seconds (plus whatever time is spent in setting up
214 // the session above). 214 // the session above).
215 vmTerminationFuture = fletch.shutdownVm(timeout); 215 vmTerminationFuture = dartino.shutdownVm(timeout);
216 await fletch.runInSession(["attach", "tcp_socket", vmSocketAddress]); 216 await dartino.runInSession(["attach", "tcp_socket", vmSocketAddress]);
217 if (snapshotFileName != null) { 217 if (snapshotFileName != null) {
218 exitCode = await fletch.runInSession( 218 exitCode = await dartino.runInSession(
219 ["export", script, 'to', 'file', snapshotFileName], 219 ["export", script, 'to', 'file', snapshotFileName],
220 checkExitCode: false, timeout: timeout); 220 checkExitCode: false, timeout: timeout);
221 } else { 221 } else {
222 exitCode = await fletch.runInSession(["compile", script], 222 exitCode = await dartino.runInSession(["compile", script],
223 checkExitCode: false, timeout: timeout); 223 checkExitCode: false, timeout: timeout);
224 fletch.stderr.writeln("Compilation took: ${sw.elapsed}"); 224 dartino.stderr.writeln("Compilation took: ${sw.elapsed}");
225 if (exitCode == 0) { 225 if (exitCode == 0) {
226 exitCode = await fletch.runInSession( 226 exitCode = await dartino.runInSession(
227 ["run", "--terminate-debugger"], 227 ["run", "--terminate-debugger"],
228 checkExitCode: false, timeout: timeout); 228 checkExitCode: false, timeout: timeout);
229 } 229 }
230 } 230 }
231 } finally { 231 } finally {
232 if (exitCode == COMPILER_EXITCODE_CRASH) { 232 if (exitCode == COMPILER_EXITCODE_CRASH) {
233 // If the compiler crashes, chances are that it didn't close the 233 // If the compiler crashes, chances are that it didn't close the
234 // connection to the Fletch VM. So we kill it. 234 // connection to the Dartino VM. So we kill it.
235 fletch.killVmProcess(ProcessSignal.SIGTERM); 235 dartino.killVmProcess(ProcessSignal.SIGTERM);
236 } 236 }
237 int vmExitCode = await vmTerminationFuture; 237 int vmExitCode = await vmTerminationFuture;
238 fletch.stdout.writeln("Fletch VM exitcode is $vmExitCode " 238 dartino.stdout.writeln("Dartino VM exitcode is $vmExitCode "
239 "${explainExitCode(vmExitCode)}\n" 239 "${explainExitCode(vmExitCode)}\n"
240 "Exit code reported by ${fletch.executable} is $exitCode " 240 "Exit code reported by ${dartino.executable} is $exitCode "
241 "${explainExitCode(exitCode)}\n"); 241 "${explainExitCode(exitCode)}\n");
242 if (exitCode == COMPILER_EXITCODE_CONNECTION_ERROR) { 242 if (exitCode == COMPILER_EXITCODE_CONNECTION_ERROR) {
243 fletch.stderr.writeln("Connection error from compiler"); 243 dartino.stderr.writeln("Connection error from compiler");
244 exitCode = vmExitCode; 244 exitCode = vmExitCode;
245 } else if (exitCode != vmExitCode) { 245 } else if (exitCode != vmExitCode) {
246 if (!fletch.killedVmProcess || vmExitCode == null || 246 if (!dartino.killedVmProcess || vmExitCode == null ||
247 vmExitCode >= 0) { 247 vmExitCode >= 0) {
248 throw new UnexpectedExitCode( 248 throw new UnexpectedExitCode(
249 vmExitCode, "${fletch.executable}-vm", <String>[]); 249 vmExitCode, "${dartino.executable}-vm", <String>[]);
250 } 250 }
251 } 251 }
252 } 252 }
253 } on UnexpectedExitCode catch (error) { 253 } on UnexpectedExitCode catch (error) {
254 fletch.stderr.writeln("$error"); 254 dartino.stderr.writeln("$error");
255 exitCode = combineExitCodes(exitCode, error.exitCode); 255 exitCode = combineExitCodes(exitCode, error.exitCode);
256 try { 256 try {
257 if (!endedSession) { 257 if (!endedSession) {
258 // TODO(ahe): Only end if there's a crash. 258 // TODO(ahe): Only end if there's a crash.
259 endedSession = true; 259 endedSession = true;
260 await fletch.run(["x-end", "session", fletch.sessionName]); 260 await dartino.run(["x-end", "session", dartino.sessionName]);
261 } 261 }
262 } on UnexpectedExitCode catch (error) { 262 } on UnexpectedExitCode catch (error) {
263 fletch.stderr.writeln("$error"); 263 dartino.stderr.writeln("$error");
264 // TODO(ahe): Error ignored, long term we should be able to guarantee 264 // TODO(ahe): Error ignored, long term we should be able to guarantee
265 // that shutting down a session never leads to an error. 265 // that shutting down a session never leads to an error.
266 } 266 }
267 } 267 }
268 268
269 if (exitCode == null) { 269 if (exitCode == null) {
270 exitCode = COMPILER_EXITCODE_CRASH; 270 exitCode = COMPILER_EXITCODE_CRASH;
271 fletch.stdout.writeln( 271 dartino.stdout.writeln(
272 '**test.py** could not determine a good exitcode, using $exitCode.'); 272 '**test.py** could not determine a good exitcode, using $exitCode.');
273 } 273 }
274 274
275 if (endedSession) { 275 if (endedSession) {
276 returnSession(new FletchSessionMirror(fletch.sessionMirror.id)); 276 returnSession(new DartinoSessionMirror(dartino.sessionMirror.id));
277 } else { 277 } else {
278 returnSession(fletch.sessionMirror); 278 returnSession(dartino.sessionMirror);
279 } 279 }
280 280
281 return new FletchTestCommandOutput( 281 return new DartinoTestCommandOutput(
282 this, exitCode, fletch.hasTimedOut, 282 this, exitCode, dartino.hasTimedOut,
283 fletch.combinedStdout, fletch.combinedStderr, sw.elapsed, -1); 283 dartino.combinedStdout, dartino.combinedStderr, sw.elapsed, -1);
284 } 284 }
285 285
286 FletchTestCommandOutput compilerFail(String message) { 286 DartinoTestCommandOutput compilerFail(String message) {
287 return new FletchTestCommandOutput( 287 return new DartinoTestCommandOutput(
288 this, DART_VM_EXITCODE_COMPILE_TIME_ERROR, false, <int>[], 288 this, DART_VM_EXITCODE_COMPILE_TIME_ERROR, false, <int>[],
289 UTF8.encode(message), const Duration(seconds: 0), -1); 289 UTF8.encode(message), const Duration(seconds: 0), -1);
290 } 290 }
291 291
292 String toString() => reproductionCommand; 292 String toString() => reproductionCommand;
293 293
294 set displayName(_) => throw "not supported"; 294 set displayName(_) => throw "not supported";
295 295
296 get commandLine => throw "not supported"; 296 get commandLine => throw "not supported";
297 set commandLine(_) => throw "not supported"; 297 set commandLine(_) => throw "not supported";
298 298
299 get outputIsUpToDate => throw "not supported"; 299 get outputIsUpToDate => throw "not supported";
300 } 300 }
301 301
302 /// [compiler] is assumed to be coming from `fletch` in which case 302 /// [compiler] is assumed to be coming from `dartino` in which case
303 /// [COMPILER_EXITCODE_CRASH], [DART_VM_EXITCODE_COMPILE_TIME_ERROR], and 303 /// [COMPILER_EXITCODE_CRASH], [DART_VM_EXITCODE_COMPILE_TIME_ERROR], and
304 /// [DART_VM_EXITCODE_UNCAUGHT_EXCEPTION] all represent a compiler crash. 304 /// [DART_VM_EXITCODE_UNCAUGHT_EXCEPTION] all represent a compiler crash.
305 /// 305 ///
306 /// [runtime] is assumed to be coming from `fletch-vm` in which case which case 306 /// [runtime] is assumed to be coming from `dartino-vm` in which case which case
307 /// [DART_VM_EXITCODE_COMPILE_TIME_ERROR], and 307 /// [DART_VM_EXITCODE_COMPILE_TIME_ERROR], and
308 /// [DART_VM_EXITCODE_UNCAUGHT_EXCEPTION] is just the result of running a test 308 /// [DART_VM_EXITCODE_UNCAUGHT_EXCEPTION] is just the result of running a test
309 /// that has an error (not a crash). 309 /// that has an error (not a crash).
310 int combineExitCodes(int compiler, int runtime) { 310 int combineExitCodes(int compiler, int runtime) {
311 if (compiler == null) return runtime; 311 if (compiler == null) return runtime;
312 312
313 if (runtime == null) return compiler; 313 if (runtime == null) return compiler;
314 314
315 switch (compiler) { 315 switch (compiler) {
316 case COMPILER_EXITCODE_CRASH: 316 case COMPILER_EXITCODE_CRASH:
(...skipping 22 matching lines...) Expand all
339 final List<String> arguments; 339 final List<String> arguments;
340 340
341 UnexpectedExitCode(this.exitCode, this.executable, this.arguments); 341 UnexpectedExitCode(this.exitCode, this.executable, this.arguments);
342 342
343 String toString() { 343 String toString() {
344 return "Non-zero exit code ($exitCode) from: " 344 return "Non-zero exit code ($exitCode) from: "
345 "$executable ${arguments.join(' ')}"; 345 "$executable ${arguments.join(' ')}";
346 } 346 }
347 } 347 }
348 348
349 class FletchTestCommandOutput extends CommandOutputImpl with DecodeExitCode { 349 class DartinoTestCommandOutput extends CommandOutputImpl with DecodeExitCode {
350 FletchTestCommandOutput( 350 DartinoTestCommandOutput(
351 Command command, 351 Command command,
352 int exitCode, 352 int exitCode,
353 bool timedOut, 353 bool timedOut,
354 List<int> stdout, 354 List<int> stdout,
355 List<int> stderr, 355 List<int> stderr,
356 Duration time, 356 Duration time,
357 int pid) 357 int pid)
358 : super(command, exitCode, timedOut, stdout, stderr, time, false, pid); 358 : super(command, exitCode, timedOut, stdout, stderr, time, false, pid);
359 } 359 }
360 360
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 402
403 void writeText(String text) { 403 void writeText(String text) {
404 add(UTF8.encode(text)); 404 add(UTF8.encode(text));
405 } 405 }
406 406
407 void close() { 407 void close() {
408 verboseSink.close(); 408 verboseSink.close();
409 } 409 }
410 } 410 }
411 411
412 class FletchSessionHelper { 412 class DartinoSessionHelper {
413 final String executable; 413 final String executable;
414 414
415 final FletchSessionMirror sessionMirror; 415 final DartinoSessionMirror sessionMirror;
416 416
417 final String sessionName; 417 final String sessionName;
418 418
419 final Map<String, String> environmentOverrides; 419 final Map<String, String> environmentOverrides;
420 420
421 final bool isVerbose; 421 final bool isVerbose;
422 422
423 final BytesOutputSink stdout; 423 final BytesOutputSink stdout;
424 424
425 final BytesOutputSink stderr; 425 final BytesOutputSink stderr;
426 426
427 final BytesOutputSink vmStdout; 427 final BytesOutputSink vmStdout;
428 428
429 final BytesOutputSink vmStderr; 429 final BytesOutputSink vmStderr;
430 430
431 Process vmProcess; 431 Process vmProcess;
432 432
433 Future<int> vmExitCodeFuture; 433 Future<int> vmExitCodeFuture;
434 434
435 bool killedVmProcess = false; 435 bool killedVmProcess = false;
436 436
437 bool hasTimedOut = false; 437 bool hasTimedOut = false;
438 438
439 FletchSessionHelper( 439 DartinoSessionHelper(
440 FletchSessionMirror sessionMirror, 440 DartinoSessionMirror sessionMirror,
441 this.executable, 441 this.executable,
442 this.environmentOverrides, 442 this.environmentOverrides,
443 this.isVerbose, 443 this.isVerbose,
444 bool superVerbose) 444 bool superVerbose)
445 : sessionMirror = sessionMirror, 445 : sessionMirror = sessionMirror,
446 sessionName = sessionMirror.makeSessionName(), 446 sessionName = sessionMirror.makeSessionName(),
447 stdout = new BytesOutputSink(superVerbose), 447 stdout = new BytesOutputSink(superVerbose),
448 stderr = new BytesOutputSink(superVerbose), 448 stderr = new BytesOutputSink(superVerbose),
449 vmStdout = new BytesOutputSink(superVerbose), 449 vmStdout = new BytesOutputSink(superVerbose),
450 vmStderr = new BytesOutputSink(superVerbose); 450 vmStderr = new BytesOutputSink(superVerbose);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 .listen(stderr.add) 494 .listen(stderr.add)
495 .asFuture(); 495 .asFuture();
496 await process.stdin.close(); 496 await process.stdin.close();
497 497
498 // Can't reuse [hasTimedOut] as we don't want to throw when calling 'x-end' 498 // Can't reuse [hasTimedOut] as we don't want to throw when calling 'x-end'
499 // in the finally block above. 499 // in the finally block above.
500 bool thisCommandTimedout = false; 500 bool thisCommandTimedout = false;
501 501
502 int exitCode = await exitCodeWithTimeout(process, timeout, () { 502 int exitCode = await exitCodeWithTimeout(process, timeout, () {
503 stdout.writeln( 503 stdout.writeln(
504 "\n=> Reached command timeout (sent SIGTERM to fletch-vm)"); 504 "\n=> Reached command timeout (sent SIGTERM to dartino-vm)");
505 thisCommandTimedout = true; 505 thisCommandTimedout = true;
506 hasTimedOut = true; 506 hasTimedOut = true;
507 if (vmProcess != null) { 507 if (vmProcess != null) {
508 killedVmProcess = vmProcess.kill(ProcessSignal.SIGTERM); 508 killedVmProcess = vmProcess.kill(ProcessSignal.SIGTERM);
509 } 509 }
510 }); 510 });
511 await stdoutFuture; 511 await stdoutFuture;
512 await stderrFuture; 512 await stderrFuture;
513 513
514 stdout.writeln("\n => $exitCode ${explainExitCode(exitCode)}\n"); 514 stdout.writeln("\n => $exitCode ${explainExitCode(exitCode)}\n");
(...skipping 18 matching lines...) Expand all
533 if (sessionMirror.isCreated) { 533 if (sessionMirror.isCreated) {
534 return 0; 534 return 0;
535 } else { 535 } else {
536 sessionMirror.isCreated = true; 536 sessionMirror.isCreated = true;
537 return await run( 537 return await run(
538 ["create", "session", sessionName, "with", settingsFileName]); 538 ["create", "session", sessionName, "with", settingsFileName]);
539 } 539 }
540 } 540 }
541 541
542 Future<String> spawnVm() async { 542 Future<String> spawnVm() async {
543 FletchVm fletchVm = await FletchVm.start( 543 DartinoVm dartinoVm = await DartinoVm.start(
544 "$executable-vm", environment: environmentOverrides); 544 "$executable-vm", environment: environmentOverrides);
545 vmProcess = fletchVm.process; 545 vmProcess = dartinoVm.process;
546 String commandDescription = "$executable-vm"; 546 String commandDescription = "$executable-vm";
547 if (isVerbose) { 547 if (isVerbose) {
548 print("Running $commandDescription"); 548 print("Running $commandDescription");
549 } 549 }
550 String commandDescriptionForLog = "\$ $commandDescription"; 550 String commandDescriptionForLog = "\$ $commandDescription";
551 vmStdout.writeln(commandDescriptionForLog); 551 vmStdout.writeln(commandDescriptionForLog);
552 stdout.writeln('$commandDescriptionForLog &'); 552 stdout.writeln('$commandDescriptionForLog &');
553 553
554 Future stdoutFuture = 554 Future stdoutFuture =
555 fletchVm.stdoutLines.listen(vmStdout.writeln).asFuture(); 555 dartinoVm.stdoutLines.listen(vmStdout.writeln).asFuture();
556 bool isFirstStderrLine = true; 556 bool isFirstStderrLine = true;
557 Future stderrFuture = 557 Future stderrFuture =
558 fletchVm.stderrLines.listen( 558 dartinoVm.stderrLines.listen(
559 (String line) { 559 (String line) {
560 if (isFirstStderrLine) { 560 if (isFirstStderrLine) {
561 vmStdout.writeln(commandDescriptionForLog); 561 vmStdout.writeln(commandDescriptionForLog);
562 isFirstStderrLine = false; 562 isFirstStderrLine = false;
563 } 563 }
564 vmStdout.writeln(line); 564 vmStdout.writeln(line);
565 }) 565 })
566 .asFuture(); 566 .asFuture();
567 567
568 vmExitCodeFuture = fletchVm.exitCode.then((int exitCode) async { 568 vmExitCodeFuture = dartinoVm.exitCode.then((int exitCode) async {
569 if (isVerbose) print("Exiting Fletch VM with exit code $exitCode."); 569 if (isVerbose) print("Exiting Dartino VM with exit code $exitCode.");
570 await stdoutFuture; 570 await stdoutFuture;
571 if (isVerbose) print("Stdout of Fletch VM process closed."); 571 if (isVerbose) print("Stdout of Dartino VM process closed.");
572 await stderrFuture; 572 await stderrFuture;
573 if (isVerbose) print("Stderr of Fletch VM process closed."); 573 if (isVerbose) print("Stderr of Dartino VM process closed.");
574 return exitCode; 574 return exitCode;
575 }); 575 });
576 576
577 return "${fletchVm.host}:${fletchVm.port}"; 577 return "${dartinoVm.host}:${dartinoVm.port}";
578 } 578 }
579 579
580 /// Returns a future that completes when the fletch VM exits using 580 /// Returns a future that completes when the dartino VM exits using
581 /// [exitCodeWithTimeout] to ensure termination within [timeout] seconds. 581 /// [exitCodeWithTimeout] to ensure termination within [timeout] seconds.
582 Future<int> shutdownVm(int timeout) async { 582 Future<int> shutdownVm(int timeout) async {
583 await exitCodeWithTimeout(vmProcess, timeout, () { 583 await exitCodeWithTimeout(vmProcess, timeout, () {
584 stdout.writeln( 584 stdout.writeln(
585 "\n**fletch-vm** Reached total timeout (sent SIGTERM to fletch-vm)"); 585 "\n**dartino-vm** Reached total timeout (sent SIGTERM to dartino-vm)") ;
586 killedVmProcess = true; 586 killedVmProcess = true;
587 hasTimedOut = true; 587 hasTimedOut = true;
588 }); 588 });
589 return vmExitCodeFuture; 589 return vmExitCodeFuture;
590 } 590 }
591 591
592 void killVmProcess(ProcessSignal signal) { 592 void killVmProcess(ProcessSignal signal) {
593 if (vmProcess == null) return; 593 if (vmProcess == null) return;
594 killedVmProcess = vmProcess.kill(ProcessSignal.SIGTERM); 594 killedVmProcess = vmProcess.kill(ProcessSignal.SIGTERM);
595 } 595 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 } 628 }
629 629
630 timer = new Timer(new Duration(seconds: timeout), firstTimeout); 630 timer = new Timer(new Duration(seconds: timeout), firstTimeout);
631 631
632 int exitCode = await process.exitCode; 632 int exitCode = await process.exitCode;
633 done = true; 633 done = true;
634 timer.cancel(); 634 timer.cancel();
635 return exitCode; 635 return exitCode;
636 } 636 }
637 637
638 /// Represents a session in the persistent Fletch client process. 638 /// Represents a session in the persistent Dartino client process.
639 class FletchSessionMirror { 639 class DartinoSessionMirror {
640 static const int RINGBUFFER_SIZE = 15; 640 static const int RINGBUFFER_SIZE = 15;
641 641
642 final int id; 642 final int id;
643 643
644 final Queue<List<String>> internalLoggedCommands = new Queue<List<String>>(); 644 final Queue<List<String>> internalLoggedCommands = new Queue<List<String>>();
645 645
646 bool isCreated = false; 646 bool isCreated = false;
647 647
648 FletchSessionMirror(this.id); 648 DartinoSessionMirror(this.id);
649 649
650 void logCommand(List<String> command) { 650 void logCommand(List<String> command) {
651 internalLoggedCommands.add(command); 651 internalLoggedCommands.add(command);
652 if (internalLoggedCommands.length >= RINGBUFFER_SIZE) { 652 if (internalLoggedCommands.length >= RINGBUFFER_SIZE) {
653 internalLoggedCommands.removeFirst(); 653 internalLoggedCommands.removeFirst();
654 } 654 }
655 } 655 }
656 656
657 void printLoggedCommands(BytesOutputSink sink, String executable) { 657 void printLoggedCommands(BytesOutputSink sink, String executable) {
658 sink.writeln("Previous commands in this session:"); 658 sink.writeln("Previous commands in this session:");
(...skipping 13 matching lines...) Expand all
672 672
673 Future<Null> main(List<String> arguments) async { 673 Future<Null> main(List<String> arguments) async {
674 // Setting [sessionCount] to the current time in milliseconds ensures that it 674 // Setting [sessionCount] to the current time in milliseconds ensures that it
675 // is highly unlikely that reproduction commands conflicts with an existing 675 // is highly unlikely that reproduction commands conflicts with an existing
676 // session in a persistent process that wasn't killed. 676 // session in a persistent process that wasn't killed.
677 sessionCount = new DateTime.now().millisecondsSinceEpoch; 677 sessionCount = new DateTime.now().millisecondsSinceEpoch;
678 String executable = arguments.first; 678 String executable = arguments.first;
679 String script = arguments[1]; 679 String script = arguments[1];
680 arguments = arguments.skip(2).toList(); 680 arguments = arguments.skip(2).toList();
681 Map<String, String> environmentOverrides = <String, String>{}; 681 Map<String, String> environmentOverrides = <String, String>{};
682 FletchSessionCommand command = new FletchSessionCommand( 682 DartinoSessionCommand command = new DartinoSessionCommand(
683 executable, script, arguments, environmentOverrides, 683 executable, script, arguments, environmentOverrides,
684 settingsFileName: settingsFileName); 684 settingsFileName: settingsFileName);
685 FletchTestCommandOutput output = 685 DartinoTestCommandOutput output =
686 await command.run(0, true, superVerbose: true); 686 await command.run(0, true, superVerbose: true);
687 print("Test outcome: ${output.decodeExitCode()}"); 687 print("Test outcome: ${output.decodeExitCode()}");
688 } 688 }
OLDNEW
« no previous file with comments | « tools/testing/dart/compiler_configuration.dart ('k') | tools/testing/dart/dartino_test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698