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/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'test_helper.dart'; | 8 import 'test_helper.dart'; |
9 import 'dart:async'; | 9 import 'dart:async'; |
10 | 10 |
11 int counter = 0; | 11 int counter = 0; |
12 | 12 |
13 void funcB() { | 13 void funcB() { |
14 counter++; // line 13 | 14 counter++; // line 13 |
15 if (counter % 100000000 == 0) { | 15 if (counter % 100000000 == 0) { |
16 print(counter); | 16 print(counter); |
17 } | 17 } |
18 } | 18 } |
19 | 19 |
20 void funcA() { | 20 void funcA() { |
21 funcB(); | 21 funcB(); |
22 } | 22 } |
23 | 23 |
24 void testFunction() { | 24 void testFunction() { |
25 while (true) { | 25 while (true) { |
26 funcA(); | 26 funcA(); |
27 } | 27 } |
28 } | 28 } |
29 | 29 |
30 var tests = [ | 30 var tests = [ |
| 31 |
31 // Go to breakpoint at line 13. | 32 // Go to breakpoint at line 13. |
32 (Isolate isolate) { | 33 (Isolate isolate) { |
33 return isolate.rootLibrary.load().then((_) { | 34 return isolate.rootLibrary.load().then((_) { |
34 // Set up a listener to wait for breakpoint events. | 35 // Set up a listener to wait for breakpoint events. |
35 Completer completer = new Completer(); | 36 Completer completer = new Completer(); |
36 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { | 37 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
37 var subscription; | 38 var subscription; |
38 subscription = stream.listen((ServiceEvent event) { | 39 subscription = stream.listen((ServiceEvent event) { |
39 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 40 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
40 print('Breakpoint reached'); | 41 print('Breakpoint reached'); |
41 subscription.cancel(); | 42 subscription.cancel(); |
42 completer.complete(); | 43 completer.complete(); |
43 } | 44 } |
44 }); | 45 }); |
45 }); | 46 }); |
46 | 47 |
47 // Add the breakpoint. | 48 // Add the breakpoint. |
48 var script = isolate.rootLibrary.scripts[0]; | 49 var script = isolate.rootLibrary.scripts[0]; |
49 var line = 13; | 50 var line = 13; |
50 return isolate.addBreakpoint(script, line).then((ServiceObject bpt) { | 51 return isolate.addBreakpoint(script, line).then((ServiceObject bpt) { |
51 return completer.future; // Wait for breakpoint reached. | 52 return completer.future; // Wait for breakpoint reached. |
52 }); | 53 }); |
53 }); | 54 }); |
54 }, | 55 }, |
55 | 56 |
56 // Inspect code objects for top two frames. | 57 // Inspect code objects for top two frames. |
57 (Isolate isolate) { | 58 (Isolate isolate) { |
58 return isolate.getStack().then((ServiceMap stack) { | 59 return isolate.getStack().then((ServiceMap stack) { |
59 // Make sure we are in the right place. | 60 // Make sure we are in the right place. |
60 expect(stack.type, equals('Stack')); | 61 expect(stack.type, equals('Stack')); |
61 expect(stack['frames'].length, greaterThanOrEqualTo(3)); | 62 expect(stack['frames'].length, greaterThanOrEqualTo(3)); |
62 var frame0 = stack['frames'][0]; | 63 var frame0 = stack['frames'][0]; |
63 var frame1 = stack['frames'][1]; | 64 var frame1 = stack['frames'][1]; |
64 print(frame0); | 65 print(frame0); |
65 expect(frame0.function.name, equals('funcB')); | 66 expect(frame0.function.name, equals('funcB')); |
66 expect(frame1.function.name, equals('funcA')); | 67 expect(frame1.function.name, equals('funcA')); |
67 var codeId0 = frame0.code.id; | 68 var codeId0 = frame0.code.id; |
68 var codeId1 = frame1.code.id; | 69 var codeId1 = frame1.code.id; |
69 | 70 |
70 List tests = []; | 71 List tests = []; |
71 // Load code from frame 0. | 72 // Load code from frame 0. |
72 tests.add(isolate.getObject(codeId0) | 73 tests.add(isolate.getObject(codeId0)..then((Code code) { |
73 ..then((Code code) { | 74 expect(code.type, equals('Code')); |
74 expect(code.type, equals('Code')); | 75 expect(code.function.name, equals('funcB')); |
75 expect(code.function.name, equals('funcB')); | 76 expect(code.hasDisassembly, equals(true)); |
76 expect(code.hasDisassembly, equals(true)); | 77 })); |
77 })); | |
78 // Load code from frame 0. | 78 // Load code from frame 0. |
79 tests.add(isolate.getObject(codeId1) | 79 tests.add(isolate.getObject(codeId1)..then((Code code) { |
80 ..then((Code code) { | 80 expect(code.type, equals('Code')); |
81 expect(code.type, equals('Code')); | 81 expect(code.function.name, equals('funcA')); |
82 expect(code.function.name, equals('funcA')); | 82 expect(code.hasDisassembly, equals(true)); |
83 expect(code.hasDisassembly, equals(true)); | 83 })); |
84 })); | |
85 return Future.wait(tests); | 84 return Future.wait(tests); |
86 }); | 85 }); |
87 }, | 86 }, |
| 87 |
88 ]; | 88 ]; |
89 | 89 |
90 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 90 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
OLD | NEW |