OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 // VMOptions=--error_on_bad_type --error_on_bad_override | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'package:observatory/models.dart' as M; | 6 import 'package:observatory/models.dart' as M; |
7 import 'package:observatory/service_io.dart'; | 7 import 'package:observatory/service_io.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'service_test_common.dart'; | 9 import 'service_test_common.dart'; |
10 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
11 import 'dart:async'; | 11 import 'dart:async'; |
12 import 'dart:isolate' as isolate; | 12 import 'dart:isolate' as isolate; |
13 import 'dart:developer' as developer; | 13 import 'dart:developer' as developer; |
14 | 14 |
15 int counter = 0; | 15 int counter = 0; |
16 const stoppedAtLine = 25; | 16 const stoppedAtLine = 25; |
17 var port = new isolate.RawReceivePort(msgHandler); | 17 var port = new isolate.RawReceivePort(msgHandler); |
18 | 18 |
19 // This name is used in a test below. | 19 // This name is used in a test below. |
20 void msgHandler(_) { } | 20 void msgHandler(_) {} |
21 | 21 |
22 void periodicTask(_) { | 22 void periodicTask(_) { |
23 port.sendPort.send(34); | 23 port.sendPort.send(34); |
24 developer.debugger(message: "fo", when: true); // We will be at the next line. | 24 developer.debugger(message: "fo", when: true); // We will be at the next line. |
25 counter++; | 25 counter++; |
26 if (counter % 300 == 0) { | 26 if (counter % 300 == 0) { |
27 print('counter = $counter'); | 27 print('counter = $counter'); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 void startTimer() { | 31 void startTimer() { |
32 new Timer.periodic(const Duration(milliseconds:10), periodicTask); | 32 new Timer.periodic(const Duration(milliseconds: 10), periodicTask); |
33 } | 33 } |
34 | 34 |
35 var tests = [ | 35 var tests = [ |
36 | |
37 // Initial data fetch and verify we've hit the breakpoint. | 36 // Initial data fetch and verify we've hit the breakpoint. |
38 (Isolate isolate) async { | 37 (Isolate isolate) async { |
39 await isolate.rootLibrary.load(); | 38 await isolate.rootLibrary.load(); |
40 var script = isolate.rootLibrary.scripts[0]; | 39 var script = isolate.rootLibrary.scripts[0]; |
41 await script.load(); | 40 await script.load(); |
42 await hasStoppedAtBreakpoint(isolate); | 41 await hasStoppedAtBreakpoint(isolate); |
43 // Sanity check. | 42 // Sanity check. |
44 expect(isolate.pauseEvent is M.PauseBreakpointEvent, isTrue); | 43 expect(isolate.pauseEvent is M.PauseBreakpointEvent, isTrue); |
45 }, | 44 }, |
46 | 45 |
47 // Get stack | 46 // Get stack |
48 (Isolate isolate) async { | 47 (Isolate isolate) async { |
49 var stack = await isolate.getStack(); | 48 var stack = await isolate.getStack(); |
50 expect(stack.type, equals('Stack')); | 49 expect(stack.type, equals('Stack')); |
51 | 50 |
52 // Sanity check. | 51 // Sanity check. |
53 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 52 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
54 Script script = stack['frames'][0].location.script; | 53 Script script = stack['frames'][0].location.script; |
55 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), | 54 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), |
56 equals(stoppedAtLine)); | 55 equals(stoppedAtLine)); |
57 | 56 |
58 // Iterate over frames. | 57 // Iterate over frames. |
59 var frameDepth = 0; | 58 var frameDepth = 0; |
60 for (var frame in stack['frames']) { | 59 for (var frame in stack['frames']) { |
61 print('checking frame $frameDepth'); | 60 print('checking frame $frameDepth'); |
62 expect(frame.type, equals('Frame')); | 61 expect(frame.type, equals('Frame')); |
63 expect(frame.index, equals(frameDepth++)); | 62 expect(frame.index, equals(frameDepth++)); |
64 expect(frame.code.type, equals('Code')); | 63 expect(frame.code.type, equals('Code')); |
65 expect(frame.function.type, equals('Function')); | 64 expect(frame.function.type, equals('Function')); |
66 expect(frame.location.type, equals('SourceLocation')); | 65 expect(frame.location.type, equals('SourceLocation')); |
| 66 } |
| 67 |
| 68 // Sanity check. |
| 69 expect(stack['messages'].length, greaterThanOrEqualTo(1)); |
| 70 |
| 71 // Iterate over messages. |
| 72 var messageDepth = 0; |
| 73 // objectId of message to be handled by msgHandler. |
| 74 var msgHandlerObjectId; |
| 75 for (var message in stack['messages']) { |
| 76 print('checking message $messageDepth'); |
| 77 expect(message.index, equals(messageDepth++)); |
| 78 expect(message.size, greaterThanOrEqualTo(0)); |
| 79 expect(message.handler.type, equals('Function')); |
| 80 expect(message.location.type, equals('SourceLocation')); |
| 81 if (message.handler.name.contains('msgHandler')) { |
| 82 msgHandlerObjectId = message.messageObjectId; |
| 83 } |
| 84 } |
| 85 expect(msgHandlerObjectId, isNotNull); |
| 86 |
| 87 // Get object. |
| 88 var object = await isolate.getObject(msgHandlerObjectId); |
| 89 expect(object.valueAsString, equals('34')); |
67 } | 90 } |
68 | |
69 // Sanity check. | |
70 expect(stack['messages'].length, greaterThanOrEqualTo(1)); | |
71 | |
72 // Iterate over messages. | |
73 var messageDepth = 0; | |
74 // objectId of message to be handled by msgHandler. | |
75 var msgHandlerObjectId; | |
76 for (var message in stack['messages']) { | |
77 print('checking message $messageDepth'); | |
78 expect(message.index, equals(messageDepth++)); | |
79 expect(message.size, greaterThanOrEqualTo(0)); | |
80 expect(message.handler.type, equals('Function')); | |
81 expect(message.location.type, equals('SourceLocation')); | |
82 if (message.handler.name.contains('msgHandler')) { | |
83 msgHandlerObjectId = message.messageObjectId; | |
84 } | |
85 } | |
86 expect(msgHandlerObjectId, isNotNull); | |
87 | |
88 // Get object. | |
89 var object = await isolate.getObject(msgHandlerObjectId); | |
90 expect(object.valueAsString, equals('34')); | |
91 } | |
92 | |
93 ]; | 91 ]; |
94 | 92 |
95 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); | 93 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); |
OLD | NEW |