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 | 9 |
10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 testMethod(Isolate isolate) async { | 70 testMethod(Isolate isolate) async { |
71 // silence analyzer. | 71 // silence analyzer. |
72 expect(math.sqrt(4), equals(2)); | 72 expect(math.sqrt(4), equals(2)); |
73 Library rootLib = await isolate.rootLibrary.load(); | 73 Library rootLib = await isolate.rootLibrary.load(); |
74 ServiceFunction function = | 74 ServiceFunction function = |
75 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | 75 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
76 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | 76 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
77 print("Breakpoint: $bpt"); | 77 print("Breakpoint: $bpt"); |
78 expect(bpt is Breakpoint, isTrue); // I.e, not null. | 78 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
79 | 79 |
80 bool hitBreakpoint = false; | 80 bool hitBreakpoint = false; |
81 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 81 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
82 var sub; | 82 var sub; |
83 sub = stream.listen((ServiceEvent event) async { | 83 sub = stream.listen((ServiceEvent event) async { |
84 print("Event $event"); | 84 print("Event $event"); |
85 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 85 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
86 var frameNumber = 1, r; | 86 var frameNumber = 1, r; |
87 r = await isolate.evalFrame(frameNumber, '123'); /// instance: ok | 87 r = await isolate.evalFrame(frameNumber, '123'); |
88 expect(r.valueAsString, equals('123')); /// instance: continued | 88 |
89 r = await isolate.evalFrame(frameNumber, 'this'); /// scope: ok | 89 /// instance: ok |
90 expect(r.clazz.name, equals('C')); /// scope: continued | 90 expect(r.valueAsString, equals('123')); |
91 r = await isolate.evalFrame(frameNumber, 'instVar'); /// instance: contin
ued | 91 |
92 expect(r.valueAsString, equals('1')); /// instance: continued | 92 /// instance: continued |
93 r = await isolate.evalFrame(frameNumber, 'classVar'); /// instance: contin
ued | 93 r = await isolate.evalFrame(frameNumber, 'this'); |
94 expect(r.valueAsString, equals('2')); /// instance: continued | 94 |
95 r = await isolate.evalFrame(frameNumber, 'methodParam'); /// scope: conti
nued | 95 /// scope: ok |
96 expect(r.valueAsString, equals('3')); /// scope: continued | 96 expect(r.clazz.name, equals('C')); |
97 r = await isolate.evalFrame(frameNumber, 'methodTemp'); /// scope: contin
ued | 97 |
98 expect(r.valueAsString, equals('4')); /// scope: continued | 98 /// scope: continued |
99 r = await isolate.evalFrame(frameNumber, 'outerParam'); /// scope: contin
ued | 99 r = await isolate.evalFrame(frameNumber, 'instVar'); |
100 expect(r.valueAsString, equals('5')); /// scope: continued | 100 |
101 r = await isolate.evalFrame(frameNumber, 'outerTemp'); /// scope: continu
ed | 101 /// instance: continued |
102 expect(r.valueAsString, equals('6')); /// scope: continued | 102 expect(r.valueAsString, equals('1')); |
103 r = await isolate.evalFrame(frameNumber, 'innerParam'); /// instance: con
tinued | 103 |
104 expect(r.valueAsString, equals('7')); /// instance: continued | 104 /// instance: continued |
105 r = await isolate.evalFrame(frameNumber, 'innerTemp'); /// instance: cont
inued | 105 r = await isolate.evalFrame(frameNumber, 'classVar'); |
106 expect(r.valueAsString, equals('8')); /// instance: continued | 106 |
107 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); /// instance: cont
inued | 107 /// instance: continued |
108 expect(r.isClosure, isTrue); /// instance: continued | 108 expect(r.valueAsString, equals('2')); |
| 109 |
| 110 /// instance: continued |
| 111 r = await isolate.evalFrame(frameNumber, 'methodParam'); |
| 112 |
| 113 /// scope: continued |
| 114 expect(r.valueAsString, equals('3')); |
| 115 |
| 116 /// scope: continued |
| 117 r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
| 118 |
| 119 /// scope: continued |
| 120 expect(r.valueAsString, equals('4')); |
| 121 |
| 122 /// scope: continued |
| 123 r = await isolate.evalFrame(frameNumber, 'outerParam'); |
| 124 |
| 125 /// scope: continued |
| 126 expect(r.valueAsString, equals('5')); |
| 127 |
| 128 /// scope: continued |
| 129 r = await isolate.evalFrame(frameNumber, 'outerTemp'); |
| 130 |
| 131 /// scope: continued |
| 132 expect(r.valueAsString, equals('6')); |
| 133 |
| 134 /// scope: continued |
| 135 r = await isolate.evalFrame(frameNumber, 'innerParam'); |
| 136 |
| 137 /// instance: continued |
| 138 expect(r.valueAsString, equals('7')); |
| 139 |
| 140 /// instance: continued |
| 141 r = await isolate.evalFrame(frameNumber, 'innerTemp'); |
| 142 |
| 143 /// instance: continued |
| 144 expect(r.valueAsString, equals('8')); |
| 145 |
| 146 /// instance: continued |
| 147 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
| 148 |
| 149 /// instance: continued |
| 150 expect(r.isClosure, isTrue); |
| 151 |
| 152 /// instance: continued |
109 | 153 |
110 hitBreakpoint = true; | 154 hitBreakpoint = true; |
111 sub.cancel(); // Do not handle events for the other tests. | 155 sub.cancel(); // Do not handle events for the other tests. |
112 isolate.resume(); | 156 isolate.resume(); |
113 } | 157 } |
114 }); | 158 }); |
115 | 159 |
116 var result = await rootLib.evaluate('new C().method(3);'); | 160 var result = await rootLib.evaluate('new C().method(3);'); |
117 print("Result $result"); | 161 print("Result $result"); |
118 expect(hitBreakpoint, isTrue); | 162 expect(hitBreakpoint, isTrue); |
119 } | 163 } |
120 | 164 |
121 testMethod2(Isolate isolate) async { | 165 testMethod2(Isolate isolate) async { |
122 Library rootLib = await isolate.rootLibrary.load(); | 166 Library rootLib = await isolate.rootLibrary.load(); |
123 ServiceFunction function = | 167 ServiceFunction function = |
124 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | 168 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
125 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | 169 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
126 print("Breakpoint: $bpt"); | 170 print("Breakpoint: $bpt"); |
127 expect(bpt is Breakpoint, isTrue); // I.e, not null. | 171 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
128 | 172 |
129 bool hitBreakpoint = false; | 173 bool hitBreakpoint = false; |
130 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 174 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
131 var sub; | 175 var sub; |
132 sub = stream.listen((ServiceEvent event) async { | 176 sub = stream.listen((ServiceEvent event) async { |
133 print("Event $event"); | 177 print("Event $event"); |
134 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 178 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
135 var frameNumber = 1, r; | 179 var frameNumber = 1, r; |
136 r = await isolate.evalFrame(frameNumber, '123'); | 180 r = await isolate.evalFrame(frameNumber, '123'); |
137 expect(r.valueAsString, equals('123')); | 181 expect(r.valueAsString, equals('123')); |
138 r = await isolate.evalFrame(frameNumber, 'this'); | 182 r = await isolate.evalFrame(frameNumber, 'this'); |
139 expect(r is DartError, isTrue); | 183 expect(r is DartError, isTrue); |
140 r = await isolate.evalFrame(frameNumber, 'instVar'); | 184 r = await isolate.evalFrame(frameNumber, 'instVar'); |
141 expect(r is DartError, isTrue); | 185 expect(r is DartError, isTrue); |
142 r = await isolate.evalFrame(frameNumber, 'classVar'); | 186 r = await isolate.evalFrame(frameNumber, 'classVar'); |
143 expect(r.valueAsString, equals('2')); | 187 expect(r.valueAsString, equals('2')); |
144 r = await isolate.evalFrame(frameNumber, 'methodParam'); | 188 r = await isolate.evalFrame(frameNumber, 'methodParam'); |
145 expect(r.valueAsString, equals('3')); /// scope: continued | 189 expect(r.valueAsString, equals('3')); |
| 190 |
| 191 /// scope: continued |
146 r = await isolate.evalFrame(frameNumber, 'methodTemp'); | 192 r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
147 expect(r.valueAsString, equals('4')); /// scope: continued | 193 expect(r.valueAsString, equals('4')); |
| 194 |
| 195 /// scope: continued |
148 r = await isolate.evalFrame(frameNumber, 'outerParam'); | 196 r = await isolate.evalFrame(frameNumber, 'outerParam'); |
149 expect(r.valueAsString, equals('5')); /// scope: continued | 197 expect(r.valueAsString, equals('5')); |
| 198 |
| 199 /// scope: continued |
150 r = await isolate.evalFrame(frameNumber, 'outerTemp'); | 200 r = await isolate.evalFrame(frameNumber, 'outerTemp'); |
151 expect(r.valueAsString, equals('6')); /// scope: continued | 201 expect(r.valueAsString, equals('6')); |
| 202 |
| 203 /// scope: continued |
152 r = await isolate.evalFrame(frameNumber, 'innerParam'); | 204 r = await isolate.evalFrame(frameNumber, 'innerParam'); |
153 expect(r.valueAsString, equals('7')); | 205 expect(r.valueAsString, equals('7')); |
154 r = await isolate.evalFrame(frameNumber, 'innerTemp'); | 206 r = await isolate.evalFrame(frameNumber, 'innerTemp'); |
155 expect(r.valueAsString, equals('8')); | 207 expect(r.valueAsString, equals('8')); |
156 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); | 208 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
157 expect(r.isClosure, isTrue); | 209 expect(r.isClosure, isTrue); |
158 | 210 |
159 hitBreakpoint = true; | 211 hitBreakpoint = true; |
160 sub.cancel(); // Do not handle events for the other tests. | 212 sub.cancel(); // Do not handle events for the other tests. |
161 isolate.resume(); | 213 isolate.resume(); |
162 } | 214 } |
163 }); | 215 }); |
164 | 216 |
165 var result = await rootLib.evaluate('C.method2(3);'); | 217 var result = await rootLib.evaluate('C.method2(3);'); |
166 print("Result $result"); | 218 print("Result $result"); |
167 expect(hitBreakpoint, isTrue); | 219 expect(hitBreakpoint, isTrue); |
168 } | 220 } |
169 | 221 |
170 testMethod3(Isolate isolate) async { | 222 testMethod3(Isolate isolate) async { |
171 Library rootLib = await isolate.rootLibrary.load(); | 223 Library rootLib = await isolate.rootLibrary.load(); |
172 ServiceFunction function = | 224 ServiceFunction function = |
173 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | 225 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
174 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | 226 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
175 print("Breakpoint: $bpt"); | 227 print("Breakpoint: $bpt"); |
176 expect(bpt is Breakpoint, isTrue); // I.e, not null. | 228 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
177 | 229 |
178 bool hitBreakpoint = false; | 230 bool hitBreakpoint = false; |
179 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 231 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
180 var sub; | 232 var sub; |
181 sub = stream.listen((ServiceEvent event) async { | 233 sub = stream.listen((ServiceEvent event) async { |
182 print("Event $event"); | 234 print("Event $event"); |
183 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 235 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
184 var frameNumber = 1, r; | 236 var frameNumber = 1, r; |
185 r = await isolate.evalFrame(frameNumber, '123'); | 237 r = await isolate.evalFrame(frameNumber, '123'); |
186 expect(r.valueAsString, equals('123')); | 238 expect(r.valueAsString, equals('123')); |
187 r = await isolate.evalFrame(frameNumber, 'this'); | 239 r = await isolate.evalFrame(frameNumber, 'this'); |
188 expect(r.clazz.name, equals('C')); | 240 expect(r.clazz.name, equals('C')); |
189 r = await isolate.evalFrame(frameNumber, 'instVar'); | 241 r = await isolate.evalFrame(frameNumber, 'instVar'); |
190 expect(r.valueAsString, equals('1')); | 242 expect(r.valueAsString, equals('1')); |
191 r = await isolate.evalFrame(frameNumber, 'classVar'); | 243 r = await isolate.evalFrame(frameNumber, 'classVar'); |
192 expect(r.valueAsString, equals('2')); | 244 expect(r.valueAsString, equals('2')); |
193 r = await isolate.evalFrame(frameNumber, 'methodParam'); | 245 r = await isolate.evalFrame(frameNumber, 'methodParam'); |
194 expect(r.valueAsString, equals('3')); | 246 expect(r.valueAsString, equals('3')); |
195 r = await isolate.evalFrame(frameNumber, 'methodTemp'); | 247 r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
196 expect(r.valueAsString, equals('4')); | 248 expect(r.valueAsString, equals('4')); |
197 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); | 249 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
198 expect(r.isClosure, isTrue); | 250 expect(r.isClosure, isTrue); |
199 | 251 |
200 hitBreakpoint = true; | 252 hitBreakpoint = true; |
201 sub.cancel(); // Do not handle events for the other tests. | 253 sub.cancel(); // Do not handle events for the other tests. |
202 isolate.resume(); | 254 isolate.resume(); |
203 } | 255 } |
204 }); | 256 }); |
205 | 257 |
206 var result = await rootLib.evaluate('new C().method3(3);'); | 258 var result = await rootLib.evaluate('new C().method3(3);'); |
207 print("Result $result"); | 259 print("Result $result"); |
208 expect(hitBreakpoint, isTrue); | 260 expect(hitBreakpoint, isTrue); |
209 } | 261 } |
210 | 262 |
211 | |
212 testMethod4(Isolate isolate) async { | 263 testMethod4(Isolate isolate) async { |
213 Library rootLib = await isolate.rootLibrary.load(); | 264 Library rootLib = await isolate.rootLibrary.load(); |
214 ServiceFunction function = | 265 ServiceFunction function = |
215 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); | 266 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
216 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); | 267 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
217 print("Breakpoint: $bpt"); | 268 print("Breakpoint: $bpt"); |
218 expect(bpt is Breakpoint, isTrue); // I.e, not null. | 269 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
219 | 270 |
220 bool hitBreakpoint = false; | 271 bool hitBreakpoint = false; |
221 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 272 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
222 var sub; | 273 var sub; |
223 sub = stream.listen((ServiceEvent event) async { | 274 sub = stream.listen((ServiceEvent event) async { |
224 print("Event $event"); | 275 print("Event $event"); |
225 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 276 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
226 var frameNumber = 1, r; | 277 var frameNumber = 1, r; |
227 r = await isolate.evalFrame(frameNumber, '123'); /// instance: continued | 278 r = await isolate.evalFrame(frameNumber, '123'); |
228 expect(r.valueAsString, equals('123')); /// instance: continued | 279 |
229 r = await isolate.evalFrame(frameNumber, 'this'); /// scope: continued | 280 /// instance: continued |
230 expect(r.clazz.name, equals('C')); /// scope: continued | 281 expect(r.valueAsString, equals('123')); |
231 r = await isolate.evalFrame(frameNumber, 'instVar'); /// instance: contin
ued | 282 |
232 expect(r.valueAsString, equals('1')); /// instance: continued | 283 /// instance: continued |
233 r = await isolate.evalFrame(frameNumber, 'classVar'); /// instance: conti
nued | 284 r = await isolate.evalFrame(frameNumber, 'this'); |
234 expect(r.valueAsString, equals('2')); /// instance: continued | 285 |
235 r = await isolate.evalFrame(frameNumber, 'methodParam'); /// scope: conti
nued | 286 /// scope: continued |
236 expect(r.valueAsString, equals('3')); /// scope: continued | 287 expect(r.clazz.name, equals('C')); |
237 r = await isolate.evalFrame(frameNumber, 'methodTemp'); /// scope: contin
ued | 288 |
238 expect(r.valueAsString, equals('4')); /// scope: continued | 289 /// scope: continued |
239 r = await isolate.evalFrame(frameNumber, 'outerParam'); /// scope: contin
ued | 290 r = await isolate.evalFrame(frameNumber, 'instVar'); |
240 expect(r.valueAsString, equals('5')); /// scope: continued | 291 |
241 r = await isolate.evalFrame(frameNumber, 'outerTemp'); /// scope: continu
ed | 292 /// instance: continued |
242 expect(r.valueAsString, equals('6')); /// scope: continued | 293 expect(r.valueAsString, equals('1')); |
243 r = await isolate.evalFrame(frameNumber, 'innerParam'); /// instance: con
tinued | 294 |
244 expect(r.valueAsString, equals('7')); /// instance: continued | 295 /// instance: continued |
245 r = await isolate.evalFrame(frameNumber, 'innerTemp'); /// instance: cont
inued | 296 r = await isolate.evalFrame(frameNumber, 'classVar'); |
246 expect(r.valueAsString, equals('8')); /// instance: continued | 297 |
247 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); /// instance: cont
inued | 298 /// instance: continued |
248 expect(r.isClosure, isTrue); /// instance: continued | 299 expect(r.valueAsString, equals('2')); |
| 300 |
| 301 /// instance: continued |
| 302 r = await isolate.evalFrame(frameNumber, 'methodParam'); |
| 303 |
| 304 /// scope: continued |
| 305 expect(r.valueAsString, equals('3')); |
| 306 |
| 307 /// scope: continued |
| 308 r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
| 309 |
| 310 /// scope: continued |
| 311 expect(r.valueAsString, equals('4')); |
| 312 |
| 313 /// scope: continued |
| 314 r = await isolate.evalFrame(frameNumber, 'outerParam'); |
| 315 |
| 316 /// scope: continued |
| 317 expect(r.valueAsString, equals('5')); |
| 318 |
| 319 /// scope: continued |
| 320 r = await isolate.evalFrame(frameNumber, 'outerTemp'); |
| 321 |
| 322 /// scope: continued |
| 323 expect(r.valueAsString, equals('6')); |
| 324 |
| 325 /// scope: continued |
| 326 r = await isolate.evalFrame(frameNumber, 'innerParam'); |
| 327 |
| 328 /// instance: continued |
| 329 expect(r.valueAsString, equals('7')); |
| 330 |
| 331 /// instance: continued |
| 332 r = await isolate.evalFrame(frameNumber, 'innerTemp'); |
| 333 |
| 334 /// instance: continued |
| 335 expect(r.valueAsString, equals('8')); |
| 336 |
| 337 /// instance: continued |
| 338 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
| 339 |
| 340 /// instance: continued |
| 341 expect(r.isClosure, isTrue); |
| 342 |
| 343 /// instance: continued |
249 | 344 |
250 hitBreakpoint = true; | 345 hitBreakpoint = true; |
251 sub.cancel(); // Do not handle events for the other tests. | 346 sub.cancel(); // Do not handle events for the other tests. |
252 isolate.resume(); | 347 isolate.resume(); |
253 } | 348 } |
254 }); | 349 }); |
255 | 350 |
256 var result = await rootLib.evaluate( | 351 var result = await rootLib |
257 '(){ new C().method4(3); C.closureWithReturnedHome(7); }()'); | 352 .evaluate('(){ new C().method4(3); C.closureWithReturnedHome(7); }()'); |
258 print("Result $result"); | 353 print("Result $result"); |
259 expect(hitBreakpoint, isTrue); | 354 expect(hitBreakpoint, isTrue); |
260 } | 355 } |
261 | 356 |
262 var tests = [ | 357 var tests = [ |
263 testMethod, | 358 testMethod, |
264 testMethod2, | 359 testMethod2, |
265 testMethod3, | 360 testMethod3, |
266 testMethod4, | 361 testMethod4, |
267 ]; | 362 ]; |
268 | 363 |
269 main(args) => runIsolateTests(args, tests); | 364 main(args) => runIsolateTests(args, tests); |
OLD | NEW |