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