| 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 'dart:async'; |
| 7 import 'dart:developer'; |
| 6 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
| 9 import 'dart:async'; | |
| 10 | 11 |
| 11 int globalVar = 100; | 12 int globalVar = 100; |
| 12 | 13 |
| 13 class MyClass { | 14 class MyClass { |
| 14 static int staticVar = 1000; | 15 static int staticVar = 1000; |
| 15 | 16 |
| 16 static void printValue(int value) { | 17 static void method(int value) { |
| 17 print(value); // line 17 | 18 debugger(); |
| 18 } | 19 } |
| 19 } | 20 } |
| 20 | 21 |
| 21 void testFunction() { | 22 void testFunction() { |
| 22 int i = 0; | 23 int i = 0; |
| 23 while (true) { | 24 while (true) { |
| 24 if (++i % 100000000 == 0) { | 25 if (++i % 100000000 == 0) { |
| 25 MyClass.printValue(10000); | 26 MyClass.method(10000); |
| 26 } | 27 } |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 | 30 |
| 30 var tests = [ | 31 var tests = [ |
| 31 | 32 |
| 32 // Go to breakpoint at line 16. | 33 hasStoppedAtBreakpoint, |
| 33 (Isolate isolate) { | |
| 34 return isolate.rootLibrary.load().then((_) { | |
| 35 // Set up a listener to wait for breakpoint events. | |
| 36 Completer completer = new Completer(); | |
| 37 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { | |
| 38 var subscription; | |
| 39 subscription = stream.listen((ServiceEvent event) { | |
| 40 if (event.kind == ServiceEvent.kPauseBreakpoint) { | |
| 41 print('Breakpoint reached'); | |
| 42 subscription.cancel(); | |
| 43 completer.complete(); | |
| 44 } | |
| 45 }); | |
| 46 }); | |
| 47 | |
| 48 // Add the breakpoint. | |
| 49 var script = isolate.rootLibrary.scripts[0]; | |
| 50 var line = 17; | |
| 51 return isolate.addBreakpoint(script, line).then((ServiceObject bpt) { | |
| 52 return completer.future; // Wait for breakpoint reached. | |
| 53 }); | |
| 54 }); | |
| 55 }, | |
| 56 | 34 |
| 57 // Evaluate against library, class, and instance. | 35 // Evaluate against library, class, and instance. |
| 58 (Isolate isolate) { | 36 (Isolate isolate) { |
| 59 return isolate.getStack().then((ServiceMap stack) { | 37 return isolate.getStack().then((ServiceMap stack) { |
| 60 // Make sure we are in the right place. | 38 // Make sure we are in the right place. |
| 61 expect(stack.type, equals('Stack')); | 39 expect(stack.type, equals('Stack')); |
| 62 expect(stack['frames'].length, greaterThanOrEqualTo(2)); | 40 expect(stack['frames'].length, greaterThanOrEqualTo(2)); |
| 63 expect(stack['frames'][0].function.name, equals('printValue')); | 41 expect(stack['frames'][0].function.name, equals('method')); |
| 64 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass')); | 42 expect(stack['frames'][0].function.dartOwner.name, equals('MyClass')); |
| 65 | 43 |
| 66 var lib = isolate.rootLibrary; | 44 var lib = isolate.rootLibrary; |
| 67 var cls = stack['frames'][0].function.dartOwner; | 45 var cls = stack['frames'][0].function.dartOwner; |
| 68 var instance = stack['frames'][0].variables[0]['value']; | 46 var instance = stack['frames'][0].variables[0]['value']; |
| 69 | 47 |
| 70 List evals = []; | 48 List evals = []; |
| 71 evals.add(lib.evaluate('globalVar + 5').then((result) { | 49 evals.add(lib.evaluate('globalVar + 5').then((result) { |
| 72 print(result); | 50 print(result); |
| 73 expect(result.valueAsString, equals('105')); | 51 expect(result.valueAsString, equals('105')); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 evals.add(instance.evaluate('this + frog').then((result) { | 67 evals.add(instance.evaluate('this + frog').then((result) { |
| 90 expect(result.type, equals('Error')); | 68 expect(result.type, equals('Error')); |
| 91 })); | 69 })); |
| 92 return Future.wait(evals); | 70 return Future.wait(evals); |
| 93 }); | 71 }); |
| 94 }, | 72 }, |
| 95 | 73 |
| 96 ]; | 74 ]; |
| 97 | 75 |
| 98 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 76 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
| OLD | NEW |