OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; |
| 9 import 'dart:async'; |
| 10 import 'dart:isolate'; |
| 11 |
| 12 int counter = 0; |
| 13 const stoppedAtLine = 23; |
| 14 var port = new RawReceivePort(msgHandler); |
| 15 |
| 16 // This name is used in a test below. |
| 17 void msgHandler(_) { |
| 18 } |
| 19 |
| 20 void periodicTask(_) { |
| 21 counter++; |
| 22 port.sendPort.send(34); |
| 23 counter++; // Line 23. We set our breakpoint here. |
| 24 counter++; |
| 25 if (counter % 300 == 0) { |
| 26 print('counter = $counter'); |
| 27 } |
| 28 } |
| 29 |
| 30 void startTimer() { |
| 31 new Timer.periodic(const Duration(milliseconds:10), periodicTask); |
| 32 } |
| 33 |
| 34 var tests = [ |
| 35 |
| 36 // Add breakpoint |
| 37 (Isolate isolate) async { |
| 38 await isolate.rootLib.load(); |
| 39 |
| 40 // Set up a listener to wait for breakpoint events. |
| 41 Completer completer = new Completer(); |
| 42 var subscription; |
| 43 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
| 44 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
| 45 print('Breakpoint reached'); |
| 46 subscription.cancel(); |
| 47 completer.complete(); |
| 48 } |
| 49 }); |
| 50 |
| 51 var script = isolate.rootLib.scripts[0]; |
| 52 await script.load(); |
| 53 |
| 54 // Add the breakpoint. |
| 55 var result = await isolate.addBreakpoint(script, stoppedAtLine); |
| 56 expect(result is Breakpoint, isTrue); |
| 57 Breakpoint bpt = result; |
| 58 expect(bpt.type, equals('Breakpoint')); |
| 59 expect(bpt.script.id, equals(script.id)); |
| 60 expect(bpt.script.tokenToLine(bpt.tokenPos), equals(stoppedAtLine)); |
| 61 expect(isolate.breakpoints.length, equals(1)); |
| 62 |
| 63 await completer.future; // Wait for breakpoint events. |
| 64 }, |
| 65 |
| 66 // Get stack |
| 67 (Isolate isolate) async { |
| 68 var stack = await isolate.getStack(); |
| 69 expect(stack.type, equals('Stack')); |
| 70 |
| 71 // Sanity check. |
| 72 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
| 73 Script script = stack['frames'][0]['script']; |
| 74 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), |
| 75 equals(stoppedAtLine)); |
| 76 |
| 77 // Iterate over frames. |
| 78 var frameDepth = 0; |
| 79 for (var frame in stack['frames']) { |
| 80 print('checking frame $frameDepth'); |
| 81 expect(frame.type, equals('Frame')); |
| 82 expect(frame['depth'], equals(frameDepth++)); |
| 83 expect(frame['code'].type, equals('Code')); |
| 84 expect(frame['function'].type, equals('Function')); |
| 85 expect(frame['script'].type, equals('Script')); |
| 86 expect(frame['tokenPos'], isNotNull); |
| 87 } |
| 88 |
| 89 // Sanity check. |
| 90 expect(stack['messages'].length, greaterThanOrEqualTo(1)); |
| 91 |
| 92 // Iterate over messages. |
| 93 var messageDepth = 0; |
| 94 // objectId of message to be handled by msgHandler. |
| 95 var msgHandlerObjectId; |
| 96 for (var message in stack['messages']) { |
| 97 print('checking message $messageDepth'); |
| 98 expect(message.type, equals('Message')); |
| 99 expect(message['_destinationPort'], isNotNull); |
| 100 expect(message['depth'], equals(messageDepth++)); |
| 101 expect(message['name'], isNotNull); |
| 102 expect(message['size'], greaterThanOrEqualTo(1)); |
| 103 expect(message['priority'], isNotNull); |
| 104 expect(message['handlerFunction'].type, equals('Function')); |
| 105 if (message['handlerFunction'].name.contains('msgHandler')) { |
| 106 msgHandlerObjectId = message['messageObjectId']; |
| 107 } |
| 108 } |
| 109 expect(msgHandlerObjectId, isNotNull); |
| 110 |
| 111 // Get object. |
| 112 var object = await isolate.getObject(msgHandlerObjectId); |
| 113 expect(object.valueAsString, equals('34')); |
| 114 } |
| 115 |
| 116 ]; |
| 117 |
| 118 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); |
OLD | NEW |