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

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

Issue 12796012: Use random debug port in basic_debugger_test. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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:io"; 9 import "dart:io";
10 import "dart:math";
10 import "dart:utf"; 11 import "dart:utf";
11 import "dart:json" as JSON; 12 import "dart:json" as JSON;
12 13
13 // TODO(hausner): need to select a different port number for each
14 // test that runs in parallel.
15 var debugPort = 5860;
16
17 // Whether or not to print debug target process on the console. 14 // Whether or not to print debug target process on the console.
18 var showDebuggeeOutput = true; 15 var showDebuggeeOutput = true;
19 16
20 // Whether or not to print the debugger wire messages on the console. 17 // Whether or not to print the debugger wire messages on the console.
21 var verboseWire = false; 18 var verboseWire = false;
22 19
20 // The number of attempts made to find an unused debugger port.
21 var retries = 0;
22
23 // Class to buffer wire protocol data from debug target and 23 // Class to buffer wire protocol data from debug target and
24 // break it down to individual json messages. 24 // break it down to individual json messages.
25 class JsonBuffer { 25 class JsonBuffer {
26 String buffer = null; 26 String buffer = null;
27 27
28 append(String s) { 28 append(String s) {
29 if (buffer == null || buffer.length == 0) { 29 if (buffer == null || buffer.length == 0) {
30 buffer = s; 30 buffer = s;
31 } else { 31 } else {
32 buffer += s; 32 buffer += s;
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 void close({killDebugee: false}) { 491 void close({killDebugee: false}) {
492 if (errorsDetected) { 492 if (errorsDetected) {
493 for (int i = 0; i < errors.length; i++) print(errors[i]); 493 for (int i = 0; i < errors.length; i++) print(errors[i]);
494 } 494 }
495 socket.close(); 495 socket.close();
496 if (killDebugee) { 496 if (killDebugee) {
497 targetProcess.kill(); 497 targetProcess.kill();
498 print("Target process killed"); 498 print("Target process killed");
499 } 499 }
500 Expect.isTrue(!errorsDetected); 500 Expect.isTrue(!errorsDetected);
501 stdin.close(); 501 exit(errors.length);
502 stdout.close();
503 stderr.close();
504 } 502 }
505 } 503 }
506 504
507 505
508 bool RunScript(List script) { 506 bool RunScript(List script) {
509 var options = new Options(); 507 var options = new Options();
510 if (options.arguments.contains("--debuggee")) { 508 if (options.arguments.contains("--debuggee")) {
511 return false; 509 return false;
512 } 510 }
513 // The default is to show debugging output. 511 // The default is to show debugging output.
514 showDebuggeeOutput = !options.arguments.contains("--non-verbose"); 512 showDebuggeeOutput = !options.arguments.contains("--non-verbose");
515 verboseWire = options.arguments.contains("--wire"); 513 verboseWire = options.arguments.contains("--wire");
514
515 // Pick a port in the upper half of the port number range.
516 var seed = new DateTime.now().millisecondsSinceEpoch;
517 Random random = new Random(seed);
518 var debugPort = random.nextInt(32000) + 32000;
519 print('using debug port $debugPort ...');
520 ServerSocket.bind('127.0.0.1', debugPort).then((ServerSocket s) {
521 s.close();
522 var targetOpts = [ "--debug:$debugPort" ];
523 if (showDebuggeeOutput) targetOpts.add("--verbose_debug");
524 targetOpts.add(options.script);
525 targetOpts.add("--debuggee");
516 526
517 var targetOpts = [ "--debug:$debugPort" ]; 527 Process.start(options.executable, targetOpts).then((Process process) {
518 if (showDebuggeeOutput) targetOpts.add("--verbose_debug"); 528 print("Debug target process started");
519 targetOpts.add(options.script); 529 process.stdin.close();
520 targetOpts.add("--debuggee"); 530 process.exitCode.then((int exitCode) {
521 531 Expect.equals(0, exitCode);
522 Process.start(options.executable, targetOpts).then((Process process) { 532 print("Debug target process exited with exit code $exitCode");
523 print("Debug target process started"); 533 });
524 process.stdin.close(); 534 var debugger = new Debugger(process, debugPort);
525 process.exitCode.then((int exitCode) { 535 debugger.runScript(script);
526 Expect.equals(0, exitCode); 536 });
527 print("Debug target process exited with exit code $exitCode"); 537 },
538 onError: (e) {
539 if (++retries >= 3) {
540 print('unable to find unused port: $e');
541 return -1;
542 } else {
543 // Retry with another random port.
544 RunScript(script);
545 }
528 }); 546 });
529 var debugger = new Debugger(process, debugPort);
530 debugger.runScript(script);
531 });
532 return true; 547 return true;
533 } 548 }
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