Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: runtime/observatory/tests/service/service_test_common.dart

Issue 2680303002: Kernel debugging; service tests (Closed)
Patch Set: New failing test Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 library service_test_common; 5 library service_test_common;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'package:observatory/models.dart' as M; 8 import 'package:observatory/models.dart' as M;
9 import 'package:observatory/service_common.dart'; 9 import 'package:observatory/service_common.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 sb.write(" $f [${await f.location.getLine()}]\n"); 255 sb.write(" $f [${await f.location.getLine()}]\n");
256 } 256 }
257 throw sb.toString(); 257 throw sb.toString();
258 } else { 258 } else {
259 print('Program is stopped at line: $line'); 259 print('Program is stopped at line: $line');
260 } 260 }
261 }; 261 };
262 } 262 }
263 263
264 264
265 IsolateTest stoppedInFunction(String functionName, {bool contains: false}) { 265 IsolateTest stoppedInFunction(String functionName,
266 {bool contains: false, bool includeOwner: false}) {
266 return (Isolate isolate) async { 267 return (Isolate isolate) async {
267 print("Checking we are in function: $functionName"); 268 print("Checking we are in function: $functionName");
268 269
269 ServiceMap stack = await isolate.getStack(); 270 ServiceMap stack = await isolate.getStack();
270 expect(stack.type, equals('Stack')); 271 expect(stack.type, equals('Stack'));
271 272
272 List<Frame> frames = stack['frames']; 273 List<Frame> frames = stack['frames'];
273 expect(frames.length, greaterThanOrEqualTo(1)); 274 expect(frames.length, greaterThanOrEqualTo(1));
274 275
275 Frame topFrame = stack['frames'][0]; 276 Frame topFrame = stack['frames'][0];
276 ServiceFunction function = await topFrame.function.load(); 277 ServiceFunction function = await topFrame.function.load();
277 final bool matches = 278 String foundFunctionName = function.name;
278 contains ? function.name.contains(functionName) : 279 if (includeOwner) {
279 function.name == functionName; 280 await (function.dartOwner as ServiceObject).load();
281 String ownerName = (function.dartOwner as ServiceObject).name;
282 foundFunctionName = "$ownerName.$foundFunctionName";
283 }
284 final bool matches = contains
285 ? foundFunctionName.contains(functionName)
286 : foundFunctionName == functionName;
280 if (!matches) { 287 if (!matches) {
281 StringBuffer sb = new StringBuffer(); 288 StringBuffer sb = new StringBuffer();
282 sb.write("Expected to be in function $functionName but " 289 sb.write("Expected to be in function $functionName but "
283 "actually in function ${function.name}"); 290 "actually in function ${function.name}");
284 sb.write("\nFull stack trace:\n"); 291 sb.write("\nFull stack trace:\n");
285 for (Frame f in stack['frames']) { 292 for (Frame f in stack['frames']) {
286 await f.function.load(); 293 await f.function.load();
287 await (f.function.dartOwner as ServiceObject).load(); 294 await (f.function.dartOwner as ServiceObject).load();
288 String name = f.function.name; 295 String name = f.function.name;
289 String ownerName = (f.function.dartOwner as ServiceObject).name; 296 String ownerName = (f.function.dartOwner as ServiceObject).name;
290 sb.write(" $f [$name] [$ownerName]\n"); 297 sb.write(" $f [$name] [$ownerName]\n");
291 } 298 }
292 throw sb.toString(); 299 throw sb.toString();
293 } else { 300 } else {
294 print('Program is stopped in function: $functionName'); 301 print('Program is stopped in function: $functionName');
295 } 302 }
296 }; 303 };
297 } 304 }
298 305
299
300 Future<Isolate> resumeIsolate(Isolate isolate) { 306 Future<Isolate> resumeIsolate(Isolate isolate) {
301 Completer completer = new Completer(); 307 Completer completer = new Completer();
302 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { 308 isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
303 var subscription; 309 var subscription;
304 subscription = stream.listen((ServiceEvent event) { 310 subscription = stream.listen((ServiceEvent event) {
305 if (event.kind == ServiceEvent.kResume) { 311 if (event.kind == ServiceEvent.kResume) {
306 subscription.cancel(); 312 subscription.cancel();
307 completer.complete(); 313 completer.complete();
308 } 314 }
309 }); 315 });
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 378
373 Future<Instance> rootLibraryFieldValue(Isolate isolate, 379 Future<Instance> rootLibraryFieldValue(Isolate isolate,
374 String fieldName) async { 380 String fieldName) async {
375 Library rootLib = await isolate.rootLibrary.load(); 381 Library rootLib = await isolate.rootLibrary.load();
376 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName); 382 Field field = rootLib.variables.singleWhere((v) => v.name == fieldName);
377 await field.load(); 383 await field.load();
378 Instance value = field.staticValue; 384 Instance value = field.staticValue;
379 await value.load(); 385 await value.load();
380 return value; 386 return value;
381 } 387 }
388
389 IsolateTest runStepThroughProgramRecordingStops(List<String> recordStops) {
390 return (Isolate isolate) async {
391 Completer completer = new Completer();
392
393 await subscribeToStream(isolate.vm, VM.kDebugStream,
394 (ServiceEvent event) async {
395 if (event.kind == ServiceEvent.kPauseBreakpoint) {
396 await isolate.reload();
397 // We are paused: Step further.
398 Frame frame = isolate.topFrame;
399 recordStops.add(await frame.location.toUserString());
400 if (event.atAsyncSuspension) {
401 isolate.stepOverAsyncSuspension();
402 } else {
403 isolate.stepOver();
404 }
405 } else if (event.kind == ServiceEvent.kPauseExit) {
406 // We are at the exit: The test is done.
407 await cancelStreamSubscription(VM.kDebugStream);
408 completer.complete();
409 }
410 });
411 isolate.resume();
412 return completer.future;
413 };
414 }
415
416 IsolateTest checkRecordedStops(
417 List<String> recordStops, List<String> expectedStops) {
418 return (Isolate isolate) async {
419 int end = recordStops.length < expectedStops.length
420 ? recordStops.length
421 : expectedStops.length;
422 for (int i = 0; i < end; ++i) {
423 expect(recordStops[i], expectedStops[i]);
424 }
425
426 expect(recordStops.length >= expectedStops.length, true,
427 reason: "Expects at least ${expectedStops.length} breaks.");
428 };
429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698