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

Side by Side Diff: tests/standalone/debugger/debug_lib.dart

Issue 14773038: Fixed debugger_test to wait until target process is dead (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 used by debugger wire protocol tests (standalone VM debugging). 5 // Library used by debugger wire protocol tests (standalone VM debugging).
6 6
7 library DartDebugger; 7 library DartDebugger;
8 8
9 import "dart:async"; 9 import "dart:async";
10 import "dart:io"; 10 import "dart:io";
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 onError: (e) { 481 onError: (e) {
482 String msg = "Error while connecting to debugee: $e"; 482 String msg = "Error while connecting to debugee: $e";
483 var trace = getAttachedStackTrace(e); 483 var trace = getAttachedStackTrace(e);
484 if (trace != null) msg += "\nStackTrace: $trace"; 484 if (trace != null) msg += "\nStackTrace: $trace";
485 error(msg); 485 error(msg);
486 close(killDebugee: true); 486 close(killDebugee: true);
487 }); 487 });
488 } 488 }
489 489
490 void close({killDebugee: false}) { 490 void close({killDebugee: false}) {
491 void exit() {
492 if (errorsDetected) throw "Errors detected";
493 exit(errors.length);
494 }
491 if (errorsDetected) { 495 if (errorsDetected) {
492 for (int i = 0; i < errors.length; i++) print(errors[i]); 496 for (int i = 0; i < errors.length; i++) print(errors[i]);
493 } 497 }
494 if (socket != null) socket.close(); 498 if (socket != null) {
499 socket.close().catchError((error) {
500 print("Error occured while closing socket: $error");
501 };
502 }
495 if (killDebugee) { 503 if (killDebugee) {
496 targetProcess.kill(); 504 if (!targetProcess.kill()) {
497 print("Target process killed"); 505 print("Could not send kill signal to target process.");
506 } else {
507 print("Successfully sent kill signal to target process.");
508 }
509 // If the process was already dead exitCode is already
510 // available and we call exit() in the next event loop cycle.
511 // Otherwise this will wait for the process to exit.
512 targetProcess.exitCode.then((exitCode) {
513 exit();
514 });
515 } else {
516 exit();
498 } 517 }
499 if (errorsDetected) throw "Errors detected";
500 exit(errors.length);
501 } 518 }
502 } 519 }
503 520
504 521
505 bool RunScript(List script) { 522 bool RunScript(List script) {
506 var options = new Options(); 523 var options = new Options();
507 if (options.arguments.contains("--debuggee")) { 524 if (options.arguments.contains("--debuggee")) {
508 return false; 525 return false;
509 } 526 }
510 verboseWire = options.arguments.contains("--wire"); 527 verboseWire = options.arguments.contains("--wire");
511 528
512 // Pick a port in the upper half of the port number range. 529 // Pick a port in the upper half of the port number range.
513 var seed = new DateTime.now().millisecondsSinceEpoch; 530 var seed = new DateTime.now().millisecondsSinceEpoch;
514 Random random = new Random(seed); 531 Random random = new Random(seed);
515 var debugPort = random.nextInt(32000) + 32000; 532 var debugPort = random.nextInt(32000) + 32000;
516 print('using debug port $debugPort ...'); 533 print('using debug port $debugPort ...');
517 ServerSocket.bind('127.0.0.1', debugPort).then((ServerSocket s) { 534 ServerSocket.bind('127.0.0.1', debugPort).then((ServerSocket s) {
518 s.close(); 535 s.close();
519 var targetOpts = [ "--debug:$debugPort" ]; 536 var targetOpts = [ "--debug:$debugPort" ];
520 // --verbose_debug is necessary so the test knows when the debuggee 537 // --verbose_debug is necessary so the test knows when the debuggee
521 // is initialized. 538 // is initialized.
522 targetOpts.add("--verbose_debug"); 539 targetOpts.add("--verbose_debug");
523 targetOpts.add(options.script); 540 targetOpts.add(options.script);
524 targetOpts.add("--debuggee"); 541 targetOpts.add("--debuggee");
525 print('args: ${targetOpts.join(" ")}'); 542 print('args: ${targetOpts.join(" ")}');
526 543
527 Process.start(options.executable, targetOpts).then((Process process) { 544 Process.start(options.executable, targetOpts).then((Process process) {
528 print("Debug target process started"); 545 print("Debug target process started");
529 process.stdin.close(); 546 process.stdin.close();
530 process.exitCode.then((int exitCode) { 547 process.exitCode.then((int exitCode) {
531 if (exitCode != 0) throw "bad exit code: $exitCode"; 548 if (exitCode != 0) throw "bad exit code: $exitCode";
532 print("Debug target process exited with exit code $exitCode"); 549 print("Debug target process exited with exit code $exitCode");
533 }); 550 });
534 var debugger = 551 var debugger =
535 new Debugger(process, debugPort, new DebugScript(script)); 552 new Debugger(process, debugPort, new DebugScript(script));
536 }); 553 });
537 }, 554 },
538 onError: (e) { 555 onError: (e) {
539 if (++retries >= 3) { 556 if (++retries >= 3) {
540 print('unable to find unused port: $e'); 557 print('unable to find unused port: $e');
541 var trace = getAttachedStackTrace(e); 558 var trace = getAttachedStackTrace(e);
542 if (trace != null) print("StackTrace: $trace"); 559 if (trace != null) print("StackTrace: $trace");
543 return -1; 560 return -1;
544 } else { 561 } else {
545 // Retry with another random port. 562 // Retry with another random port.
546 RunScript(script); 563 RunScript(script);
547 } 564 }
548 }); 565 });
549 return true; 566 return true;
550 } 567 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698