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 | 4 |
5 import 'package:observatory/service_io.dart'; | 5 import 'package:observatory/service_io.dart'; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'test_helper.dart'; | 7 import 'test_helper.dart'; |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 | 9 |
10 void helper(i) { | 10 void helper(i) { |
11 print(i); | 11 print(i); |
12 } | 12 } |
13 | 13 |
14 void testFunction() { | 14 void testFunction() { |
15 int i = 0; | 15 int i = 0; |
16 while (true) { | 16 while (true) { |
17 if (++i % 100000000 == 0) { | 17 if (++i % 100000000 == 0) { |
18 helper(i); // line 18 | 18 helper(i); // line 18 |
19 } | 19 } |
20 } | 20 } |
21 } | 21 } |
22 | 22 |
23 var tests = [ | 23 var tests = [ |
24 | 24 |
25 // Pause | 25 // Pause |
26 (Isolate isolate) { | 26 (Isolate isolate) { |
27 Completer completer = new Completer(); | 27 Completer completer = new Completer(); |
28 isolate.vm.events.stream.listen((ServiceEvent event) { | 28 isolate.vm.events.stream.listen((ServiceEvent event) { |
29 if (event.eventType == 'IsolateInterrupted') { | 29 if (event.eventType == ServiceEvent.kPauseInterrupted) { |
30 completer.complete(); | 30 completer.complete(); |
31 } | 31 } |
32 }); | 32 }); |
33 isolate.pause(); | 33 isolate.pause(); |
34 return completer.future; | 34 return completer.future; |
35 }, | 35 }, |
36 | 36 |
37 // Resume | 37 // Resume |
38 (Isolate isolate) { | 38 (Isolate isolate) { |
39 return isolate.resume().then((_) { | 39 return isolate.resume().then((_) { |
40 expect(isolate.pauseEvent == null, isTrue); | 40 expect(isolate.pauseEvent.eventType, equals(ServiceEvent.kResume)); |
| 41 expect(isolate.running, isTrue); |
| 42 expect(isolate.paused, isFalse); |
41 }); | 43 }); |
42 }, | 44 }, |
43 | 45 |
44 // Add breakpoint | 46 // Add breakpoint |
45 (Isolate isolate) { | 47 (Isolate isolate) { |
46 return isolate.rootLib.load().then((_) { | 48 return isolate.rootLib.load().then((_) { |
47 // Set up a listener to wait for breakpoint events. | 49 // Set up a listener to wait for breakpoint events. |
48 Completer completer = new Completer(); | 50 Completer completer = new Completer(); |
49 List events = []; | 51 List events = []; |
50 var subscription; | 52 var subscription; |
51 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 53 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
52 if (event.eventType.startsWith('Breakpoint')) { | 54 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
53 events.add(event); | 55 print('Breakpoint reached'); |
54 if (events.length == 2) { | 56 subscription.cancel(); |
55 expect(events[0].eventType, equals('BreakpointResolved')); | 57 completer.complete(); |
56 expect(events[1].eventType, equals('BreakpointReached')); | |
57 print('Breakpoint reached'); | |
58 subscription.cancel(); | |
59 completer.complete(); | |
60 } | |
61 } | 58 } |
62 }); | 59 }); |
63 | 60 |
64 // Add the breakpoint. | 61 // Add the breakpoint. |
65 var script = isolate.rootLib.scripts[0]; | 62 var script = isolate.rootLib.scripts[0]; |
66 return isolate.addBreakpoint(script, 18).then((result) { | 63 return isolate.addBreakpoint(script, 18).then((result) { |
67 expect(result is Breakpoint, isTrue); | 64 expect(result is Breakpoint, isTrue); |
68 Breakpoint bpt = result; | 65 Breakpoint bpt = result; |
69 expect(bpt.type, equals('Breakpoint')); | 66 expect(bpt.type, equals('Breakpoint')); |
70 expect(bpt.script.id, equals(script.id)); | 67 expect(bpt.script.id, equals(script.id)); |
(...skipping 13 matching lines...) Expand all Loading... |
84 }); | 81 }); |
85 }, | 82 }, |
86 | 83 |
87 // Stepping | 84 // Stepping |
88 (Isolate isolate) { | 85 (Isolate isolate) { |
89 // Set up a listener to wait for breakpoint events. | 86 // Set up a listener to wait for breakpoint events. |
90 Completer completer = new Completer(); | 87 Completer completer = new Completer(); |
91 List events = []; | 88 List events = []; |
92 var subscription; | 89 var subscription; |
93 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 90 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
94 if (event.eventType.startsWith('BreakpointReached')) { | 91 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
95 print('Breakpoint reached'); | 92 print('Breakpoint reached'); |
96 subscription.cancel(); | 93 subscription.cancel(); |
97 completer.complete(); | 94 completer.complete(); |
98 } | 95 } |
99 }); | 96 }); |
100 | 97 |
101 return isolate.stepInto().then((isolate) { | 98 return isolate.stepInto().then((isolate) { |
102 return completer.future; // Wait for breakpoint events. | 99 return completer.future; // Wait for breakpoint events. |
103 }); | 100 }); |
104 }, | 101 }, |
105 | 102 |
106 // Get the stack trace again. We are in 'helper'. | 103 // Get the stack trace again. We are in 'helper'. |
107 (Isolate isolate) { | 104 (Isolate isolate) { |
108 return isolate.getStack().then((ServiceMap stack) { | 105 return isolate.getStack().then((ServiceMap stack) { |
109 expect(stack.type, equals('Stack')); | 106 expect(stack.type, equals('Stack')); |
110 expect(stack['frames'].length, greaterThanOrEqualTo(2)); | 107 expect(stack['frames'].length, greaterThanOrEqualTo(2)); |
111 expect(stack['frames'][0]['function'].name, equals('helper')); | 108 expect(stack['frames'][0]['function'].name, equals('helper')); |
112 }); | 109 }); |
113 }, | 110 }, |
114 | 111 |
115 // Remove breakpoint | 112 // Remove breakpoint |
116 (Isolate isolate) { | 113 (Isolate isolate) { |
| 114 // Set up a listener to wait for breakpoint events. |
| 115 Completer completer = new Completer(); |
| 116 List events = []; |
| 117 var subscription; |
| 118 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
| 119 if (event.eventType == ServiceEvent.kBreakpointRemoved) { |
| 120 print('Breakpoint removed'); |
| 121 expect(isolate.breakpoints.length, equals(0)); |
| 122 subscription.cancel(); |
| 123 completer.complete(); |
| 124 } |
| 125 }); |
| 126 |
117 expect(isolate.breakpoints.length, equals(1)); | 127 expect(isolate.breakpoints.length, equals(1)); |
118 var bpt = isolate.breakpoints[0]; | 128 var bpt = isolate.breakpoints.values.first; |
119 return isolate.removeBreakpoint(bpt).then((_) { | 129 return isolate.removeBreakpoint(bpt).then((_) { |
120 expect(isolate.breakpoints.length, equals(0)); | 130 return completer.future; |
121 }); | 131 }); |
122 }, | 132 }, |
123 | 133 |
124 // Resume | 134 // Resume |
125 (Isolate isolate) { | 135 (Isolate isolate) { |
126 return isolate.resume().then((_) { | 136 return isolate.resume().then((_) { |
127 expect(isolate.pauseEvent == null, isTrue); | 137 expect(isolate.pauseEvent.eventType, equals(ServiceEvent.kResume)); |
| 138 expect(isolate.running, isTrue); |
| 139 expect(isolate.paused, isFalse); |
128 }); | 140 }); |
129 }, | 141 }, |
130 | 142 |
131 // Add breakpoint at function entry | 143 // Add breakpoint at function entry |
132 (Isolate isolate) { | 144 (Isolate isolate) { |
133 // Set up a listener to wait for breakpoint events. | 145 // Set up a listener to wait for breakpoint events. |
134 Completer completer = new Completer(); | 146 Completer completer = new Completer(); |
135 List events = []; | 147 List events = []; |
136 var subscription; | 148 var subscription; |
137 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 149 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
138 if (event.eventType.startsWith('BreakpointReached')) { | 150 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
139 print('Breakpoint reached'); | 151 print('Breakpoint reached'); |
140 subscription.cancel(); | 152 subscription.cancel(); |
141 completer.complete(); | 153 completer.complete(); |
142 } | 154 } |
143 }); | 155 }); |
144 | 156 |
145 // Find a specific function. | 157 // Find a specific function. |
146 ServiceFunction function = isolate.rootLib.functions.firstWhere( | 158 ServiceFunction function = isolate.rootLib.functions.firstWhere( |
147 (f) => f.name == 'helper'); | 159 (f) => f.name == 'helper'); |
148 expect(function, isNotNull); | 160 expect(function, isNotNull); |
149 | 161 |
150 // Add the breakpoint at function entry | 162 // Add the breakpoint at function entry |
151 return isolate.addBreakpointAtEntry(function).then((result) { | 163 return isolate.addBreakpointAtEntry(function).then((result) { |
152 expect(result is Breakpoint, isTrue); | 164 expect(result is Breakpoint, isTrue); |
153 Breakpoint bpt = result; | 165 Breakpoint bpt = result; |
154 expect(bpt.type, equals('Breakpoint')); | 166 expect(bpt.type, equals('Breakpoint')); |
155 expect(bpt.script.name, equals('debugging_test.dart')); | 167 expect(bpt.script.name, equals('debugging_test.dart')); |
156 expect(bpt.tokenPos, equals(29)); | 168 expect(bpt.tokenPos, equals(29)); |
157 expect(isolate.breakpoints.length, equals(1)); | 169 expect(isolate.breakpoints.length, equals(1)); |
158 return completer.future; // Wait for breakpoint events. | 170 return completer.future; // Wait for breakpoint events. |
159 }); | 171 }); |
160 }, | 172 }, |
161 | 173 |
162 ]; | 174 ]; |
163 | 175 |
164 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 176 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
OLD | NEW |