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 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:math"; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 isMatch = false; | 147 isMatch = false; |
148 } | 148 } |
149 } else { | 149 } else { |
150 isMatch = false; | 150 isMatch = false; |
151 } | 151 } |
152 }); | 152 }); |
153 return isMatch; | 153 return isMatch; |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 class Matcher { | |
158 void match(Debugger debugger); | |
159 } | |
160 | |
161 | |
162 class Command { | 157 class Command { |
163 var template; | 158 var template; |
164 | 159 |
165 void send(Debugger debugger) { | 160 void send(Debugger debugger) { |
166 debugger.sendMessage(template); | 161 debugger.sendMessage(template); |
167 } | 162 } |
168 | 163 |
169 void matchResponse(Debugger debugger) { | 164 void matchResponse(Debugger debugger) { |
170 Map response = debugger.currentMessage; | 165 Map response = debugger.currentMessage; |
171 var id = template["id"]; | 166 var id = template["id"]; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 } | 416 } |
422 | 417 |
423 bool get errorsDetected => errors.length > 0; | 418 bool get errorsDetected => errors.length > 0; |
424 | 419 |
425 // Record error message. | 420 // Record error message. |
426 void error(String s) { | 421 void error(String s) { |
427 errors.add(s); | 422 errors.add(s); |
428 } | 423 } |
429 | 424 |
430 void openConnection() { | 425 void openConnection() { |
431 Socket.connect("127.0.0.1", portNumber).then((s) { | 426 Socket.connect("127.0.0.1", portNumber).then((s) { |
kustermann
2013/04/04 11:41:39
Although I really hate putting in sleep's in tests
hausner
2013/04/04 15:12:05
I agree but couldn't figure out how to add a sleep
| |
432 socket = s; | 427 this.socket = s; |
433 var stringStream = socket.transform(new StringDecoder()); | 428 var stringStream = socket.transform(new StringDecoder()); |
434 stringStream.listen( | 429 stringStream.listen((str) { |
435 (str) { | |
436 try { | 430 try { |
437 responses.append(str); | 431 responses.append(str); |
438 handleMessages(); | 432 handleMessages(); |
439 } catch(e, trace) { | 433 } catch(e, trace) { |
440 print("Unexpected exception:\n$e\n$trace"); | 434 print("Unexpected exception:\n$e\n$trace"); |
441 close(killDebugee: true); | 435 close(killDebugee: true); |
442 } | 436 } |
443 }, | 437 }, |
444 onDone: () { | 438 onDone: () { |
445 print("Connection closed by debug target"); | 439 print("Connection closed by debug target"); |
446 close(killDebugee: true); | 440 close(killDebugee: true); |
447 }, | 441 }, |
448 onError: (e) { | 442 onError: (e) { |
449 print("Error '$e' detected in input stream from debug target"); | 443 print("Error '$e' detected in input stream from debug target"); |
450 close(killDebugee: true); | 444 close(killDebugee: true); |
451 }); | 445 }); |
446 }, | |
447 onError: (asyncErr) { | |
448 print("Error while connecting to debugee: $asyncErr"); | |
449 close(killDebugee: true); | |
452 }); | 450 }); |
kustermann
2013/04/04 11:41:39
I think there is a bug here: If we were not able t
hausner
2013/04/04 15:12:05
I had this at one point and then removed it again.
| |
453 } | 451 } |
454 | 452 |
455 void close({killDebugee: false}) { | 453 void close({killDebugee: false}) { |
456 if (errorsDetected) { | 454 if (errorsDetected) { |
457 for (int i = 0; i < errors.length; i++) print(errors[i]); | 455 for (int i = 0; i < errors.length; i++) print(errors[i]); |
458 } | 456 } |
459 socket.close(); | 457 if (socket != null) socket.close(); |
Tom Ball
2013/04/03 21:22:26
Braces surrounding socket.close()? I don't know if
hausner
2013/04/04 15:12:05
I've seen both kinds of formatting in Dart code. (
| |
460 if (killDebugee) { | 458 if (killDebugee) { |
461 targetProcess.kill(); | 459 targetProcess.kill(); |
462 print("Target process killed"); | 460 print("Target process killed"); |
463 } | 461 } |
464 Expect.isTrue(!errorsDetected); | 462 Expect.isTrue(!errorsDetected); |
465 exit(errors.length); | 463 exit(errors.length); |
466 } | 464 } |
467 } | 465 } |
468 | 466 |
469 | 467 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 if (++retries >= 3) { | 501 if (++retries >= 3) { |
504 print('unable to find unused port: $e'); | 502 print('unable to find unused port: $e'); |
505 return -1; | 503 return -1; |
506 } else { | 504 } else { |
507 // Retry with another random port. | 505 // Retry with another random port. |
508 RunScript(script); | 506 RunScript(script); |
509 } | 507 } |
510 }); | 508 }); |
511 return true; | 509 return true; |
512 } | 510 } |
OLD | NEW |