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 periodicTask(_) { | 13 void periodicTask(_) { |
14 counter++; | 14 counter++; |
15 counter++; // Line 15. We set our breakpoint here. | 15 counter++; // Line 15. We set our breakpoint here. |
16 counter++; | 16 counter++; |
17 if (counter % 300 == 0) { | 17 if (counter % 300 == 0) { |
18 print('counter = $counter'); | 18 print('counter = $counter'); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 void startTimer() { | 22 void startTimer() { |
23 new Timer.periodic(const Duration(milliseconds: 10), periodicTask); | 23 new Timer.periodic(const Duration(milliseconds:10), periodicTask); |
24 } | 24 } |
25 | 25 |
26 var tests = [ | 26 var tests = [ |
| 27 |
27 // Pause | 28 // Pause |
28 (Isolate isolate) async { | 29 (Isolate isolate) async { |
29 Completer completer = new Completer(); | 30 Completer completer = new Completer(); |
30 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 31 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
31 var subscription; | 32 var subscription; |
32 subscription = stream.listen((ServiceEvent event) { | 33 subscription = stream.listen((ServiceEvent event) { |
33 if (event.kind == ServiceEvent.kPauseInterrupted) { | 34 if (event.kind == ServiceEvent.kPauseInterrupted) { |
34 subscription.cancel(); | 35 subscription.cancel(); |
35 completer.complete(); | 36 completer.complete(); |
36 } | 37 } |
37 }); | 38 }); |
38 isolate.pause(); | 39 isolate.pause(); |
39 await completer.future; | 40 await completer.future; |
40 }, | 41 }, |
41 | 42 |
42 // Resume | 43 // Resume |
43 (Isolate isolate) async { | 44 (Isolate isolate) async { |
44 Completer completer = new Completer(); | 45 Completer completer = new Completer(); |
45 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 46 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
46 var subscription; | 47 var subscription; |
47 subscription = stream.listen((ServiceEvent event) { | 48 subscription = stream.listen((ServiceEvent event) { |
48 if (event.kind == ServiceEvent.kResume) { | 49 if (event.kind == ServiceEvent.kResume) { |
49 subscription.cancel(); | 50 subscription.cancel(); |
50 completer.complete(); | 51 completer.complete(); |
51 } | 52 } |
52 }); | 53 }); |
53 isolate.resume(); | 54 isolate.resume(); |
54 await completer.future; | 55 await completer.future; |
55 }, | 56 }, |
56 | 57 |
57 // Add breakpoint | 58 // Add breakpoint |
58 (Isolate isolate) async { | 59 (Isolate isolate) async { |
59 await isolate.rootLibrary.load(); | 60 await isolate.rootLibrary.load(); |
60 | 61 |
61 // Set up a listener to wait for breakpoint events. | 62 // Set up a listener to wait for breakpoint events. |
62 Completer completer = new Completer(); | 63 Completer completer = new Completer(); |
63 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 64 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
64 var subscription; | 65 var subscription; |
65 subscription = stream.listen((ServiceEvent event) { | 66 subscription = stream.listen((ServiceEvent event) { |
66 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 67 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
67 print('Breakpoint reached'); | 68 print('Breakpoint reached'); |
68 subscription.cancel(); | 69 subscription.cancel(); |
69 completer.complete(); | 70 completer.complete(); |
70 } | 71 } |
71 }); | 72 }); |
72 | 73 |
73 var script = isolate.rootLibrary.scripts[0]; | 74 var script = isolate.rootLibrary.scripts[0]; |
74 await script.load(); | 75 await script.load(); |
75 | 76 |
76 // Add the breakpoint. | 77 // Add the breakpoint. |
77 var result = await isolate.addBreakpoint(script, 15); | 78 var result = await isolate.addBreakpoint(script, 15); |
78 expect(result is Breakpoint, isTrue); | 79 expect(result is Breakpoint, isTrue); |
79 Breakpoint bpt = result; | 80 Breakpoint bpt = result; |
80 expect(bpt.type, equals('Breakpoint')); | 81 expect(bpt.type, equals('Breakpoint')); |
81 expect(bpt.location.script.id, equals(script.id)); | 82 expect(bpt.location.script.id, equals(script.id)); |
82 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(15)); | 83 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(15)); |
83 expect(isolate.breakpoints.length, equals(1)); | 84 expect(isolate.breakpoints.length, equals(1)); |
84 | 85 |
85 await completer.future; // Wait for breakpoint events. | 86 await completer.future; // Wait for breakpoint events. |
86 }, | 87 }, |
87 | 88 |
88 // We are at the breakpoint on line 15. | 89 // We are at the breakpoint on line 15. |
89 (Isolate isolate) async { | 90 (Isolate isolate) async { |
90 ServiceMap stack = await isolate.getStack(); | 91 ServiceMap stack = await isolate.getStack(); |
91 expect(stack.type, equals('Stack')); | 92 expect(stack.type, equals('Stack')); |
92 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 93 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
93 | 94 |
94 Script script = stack['frames'][0].location.script; | 95 Script script = stack['frames'][0].location.script; |
95 expect(script.name, endsWith('debugging_test.dart')); | 96 expect(script.name,endsWith('debugging_test.dart')); |
96 expect( | 97 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(15)); |
97 script.tokenToLine(stack['frames'][0].location.tokenPos), equals(15)); | 98 }, |
98 }, | |
99 | 99 |
100 // Stepping | 100 // Stepping |
101 (Isolate isolate) async { | 101 (Isolate isolate) async { |
102 // Set up a listener to wait for breakpoint events. | 102 // Set up a listener to wait for breakpoint events. |
103 Completer completer = new Completer(); | 103 Completer completer = new Completer(); |
104 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 104 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
105 var subscription; | 105 var subscription; |
106 subscription = stream.listen((ServiceEvent event) { | 106 subscription = stream.listen((ServiceEvent event) { |
107 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 107 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
108 print('Breakpoint reached'); | 108 print('Breakpoint reached'); |
109 subscription.cancel(); | 109 subscription.cancel(); |
110 completer.complete(); | 110 completer.complete(); |
111 } | 111 } |
112 }); | 112 }); |
113 | 113 |
114 await isolate.stepOver(); | 114 await isolate.stepOver(); |
115 await completer.future; // Wait for breakpoint events. | 115 await completer.future; // Wait for breakpoint events. |
116 }, | 116 }, |
117 | 117 |
118 // We are now at line 16. | 118 // We are now at line 16. |
119 (Isolate isolate) async { | 119 (Isolate isolate) async { |
120 ServiceMap stack = await isolate.getStack(); | 120 ServiceMap stack = await isolate.getStack(); |
121 expect(stack.type, equals('Stack')); | 121 expect(stack.type, equals('Stack')); |
122 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 122 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
123 | 123 |
124 Script script = stack['frames'][0].location.script; | 124 Script script = stack['frames'][0].location.script; |
125 expect(script.name, endsWith('debugging_test.dart')); | 125 expect(script.name,endsWith('debugging_test.dart')); |
126 expect( | 126 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(16)); |
127 script.tokenToLine(stack['frames'][0].location.tokenPos), equals(16)); | 127 }, |
128 }, | |
129 | 128 |
130 // Remove breakpoint | 129 // Remove breakpoint |
131 (Isolate isolate) async { | 130 (Isolate isolate) async { |
132 // Set up a listener to wait for breakpoint events. | 131 // Set up a listener to wait for breakpoint events. |
133 Completer completer = new Completer(); | 132 Completer completer = new Completer(); |
134 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 133 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
135 var subscription; | 134 var subscription; |
136 subscription = stream.listen((ServiceEvent event) { | 135 subscription = stream.listen((ServiceEvent event) { |
137 if (event.kind == ServiceEvent.kBreakpointRemoved) { | 136 if (event.kind == ServiceEvent.kBreakpointRemoved) { |
138 print('Breakpoint removed'); | 137 print('Breakpoint removed'); |
139 expect(isolate.breakpoints.length, equals(0)); | 138 expect(isolate.breakpoints.length, equals(0)); |
140 subscription.cancel(); | 139 subscription.cancel(); |
141 completer.complete(); | 140 completer.complete(); |
142 } | 141 } |
143 }); | 142 }); |
144 | 143 |
145 expect(isolate.breakpoints.length, equals(1)); | 144 expect(isolate.breakpoints.length, equals(1)); |
146 var bpt = isolate.breakpoints.values.first; | 145 var bpt = isolate.breakpoints.values.first; |
147 await isolate.removeBreakpoint(bpt); | 146 await isolate.removeBreakpoint(bpt); |
148 await completer.future; | 147 await completer.future; |
149 }, | 148 }, |
150 | 149 |
151 // Resume | 150 // Resume |
152 (Isolate isolate) async { | 151 (Isolate isolate) async { |
153 Completer completer = new Completer(); | 152 Completer completer = new Completer(); |
154 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 153 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
155 var subscription; | 154 var subscription; |
156 subscription = stream.listen((ServiceEvent event) { | 155 subscription = stream.listen((ServiceEvent event) { |
157 if (event.kind == ServiceEvent.kResume) { | 156 if (event.kind == ServiceEvent.kResume) { |
158 subscription.cancel(); | 157 subscription.cancel(); |
159 completer.complete(); | 158 completer.complete(); |
160 } | 159 } |
161 }); | 160 }); |
162 isolate.resume(); | 161 isolate.resume(); |
163 await completer.future; | 162 await completer.future; |
164 }, | 163 }, |
165 | 164 |
166 // Add breakpoint at function entry | 165 // Add breakpoint at function entry |
167 (Isolate isolate) async { | 166 (Isolate isolate) async { |
168 // Set up a listener to wait for breakpoint events. | 167 // Set up a listener to wait for breakpoint events. |
169 Completer completer = new Completer(); | 168 Completer completer = new Completer(); |
170 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 169 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
171 var subscription; | 170 var subscription; |
172 subscription = stream.listen((ServiceEvent event) { | 171 subscription = stream.listen((ServiceEvent event) { |
173 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 172 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
174 print('Breakpoint reached'); | 173 print('Breakpoint reached'); |
175 subscription.cancel(); | 174 subscription.cancel(); |
176 completer.complete(); | 175 completer.complete(); |
177 } | 176 } |
178 }); | 177 }); |
179 | 178 |
180 // Find a specific function. | 179 // Find a specific function. |
181 ServiceFunction function = isolate.rootLibrary.functions | 180 ServiceFunction function = isolate.rootLibrary.functions.firstWhere( |
182 .firstWhere((f) => f.name == 'periodicTask'); | 181 (f) => f.name == 'periodicTask'); |
183 expect(function, isNotNull); | 182 expect(function, isNotNull); |
184 | 183 |
185 // Add the breakpoint at function entry | 184 // Add the breakpoint at function entry |
186 var result = await isolate.addBreakpointAtEntry(function); | 185 var result = await isolate.addBreakpointAtEntry(function); |
187 expect(result is Breakpoint, isTrue); | 186 expect(result is Breakpoint, isTrue); |
188 Breakpoint bpt = result; | 187 Breakpoint bpt = result; |
189 expect(bpt.type, equals('Breakpoint')); | 188 expect(bpt.type, equals('Breakpoint')); |
190 expect(bpt.location.script.name, equals('debugging_test.dart')); | 189 expect(bpt.location.script.name, equals('debugging_test.dart')); |
191 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(13)); | 190 expect(bpt.location.script.tokenToLine(bpt.location.tokenPos), equals(13)); |
192 expect(isolate.breakpoints.length, equals(1)); | 191 expect(isolate.breakpoints.length, equals(1)); |
193 | 192 |
194 await completer.future; // Wait for breakpoint events. | 193 await completer.future; // Wait for breakpoint events. |
195 }, | 194 }, |
196 | 195 |
197 // We are now at line 13. | 196 // We are now at line 13. |
198 (Isolate isolate) async { | 197 (Isolate isolate) async { |
199 ServiceMap stack = await isolate.getStack(); | 198 ServiceMap stack = await isolate.getStack(); |
200 expect(stack.type, equals('Stack')); | 199 expect(stack.type, equals('Stack')); |
201 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 200 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
202 | 201 |
203 Script script = stack['frames'][0].location.script; | 202 Script script = stack['frames'][0].location.script; |
204 expect(script.name, endsWith('debugging_test.dart')); | 203 expect(script.name,endsWith('debugging_test.dart')); |
205 expect( | 204 expect(script.tokenToLine(stack['frames'][0].location.tokenPos), equals(13)); |
206 script.tokenToLine(stack['frames'][0].location.tokenPos), equals(13)); | 205 }, |
207 }, | 206 |
208 ]; | 207 ]; |
209 | 208 |
210 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); | 209 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); |
OLD | NEW |