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=--compile-all --error_on_bad_type --error_on_bad_override | 4 // VMOptions=--compile-all --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 |
(...skipping 36 matching lines...) Loading... |
47 normalized.add(coverage[i]); | 47 normalized.add(coverage[i]); |
48 normalized.add(coverage[i+1] == 0 ? 0 : 1); | 48 normalized.add(coverage[i+1] == 0 ? 0 : 1); |
49 } | 49 } |
50 return normalized; | 50 return normalized; |
51 } | 51 } |
52 | 52 |
53 var tests = [ | 53 var tests = [ |
54 | 54 |
55 // Go to breakpoint at line 14. | 55 // Go to breakpoint at line 14. |
56 (Isolate isolate) { | 56 (Isolate isolate) { |
57 return isolate.rootLib.load().then((_) { | 57 return isolate.rootLibrary.load().then((_) { |
58 // Set up a listener to wait for breakpoint events. | 58 // Set up a listener to wait for breakpoint events. |
59 Completer completer = new Completer(); | 59 Completer completer = new Completer(); |
60 isolate.vm.events.stream.listen((ServiceEvent event) { | 60 isolate.vm.events.stream.listen((ServiceEvent event) { |
61 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | 61 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
62 print('Breakpoint reached'); | 62 print('Breakpoint reached'); |
63 completer.complete(); | 63 completer.complete(); |
64 } | 64 } |
65 }); | 65 }); |
66 | 66 |
67 // Create a timer to set a breakpoint with a short delay. | 67 // Create a timer to set a breakpoint with a short delay. |
68 new Timer(new Duration(milliseconds: 2000), () { | 68 new Timer(new Duration(milliseconds: 2000), () { |
69 // Add the breakpoint. | 69 // Add the breakpoint. |
70 print('Setting breakpoint.'); | 70 print('Setting breakpoint.'); |
71 var script = isolate.rootLib.scripts[0]; | 71 var script = isolate.rootLibrary.scripts[0]; |
72 var line = 14; | 72 var line = 14; |
73 isolate.addBreakpoint(script, line); | 73 isolate.addBreakpoint(script, line); |
74 }); | 74 }); |
75 | 75 |
76 return completer.future; | 76 return completer.future; |
77 }); | 77 }); |
78 }, | 78 }, |
79 | 79 |
80 // Get coverage for function, class, library, script, and isolate. | 80 // Get coverage for function, class, library, script, and isolate. |
81 (Isolate isolate) { | 81 (Isolate isolate) { |
82 return isolate.getStack().then((ServiceMap stack) { | 82 return isolate.getStack().then((ServiceMap stack) { |
83 // Make sure we are in the right place. | 83 // Make sure we are in the right place. |
84 expect(stack.type, equals('Stack')); | 84 expect(stack.type, equals('Stack')); |
85 expect(stack['frames'].length, greaterThanOrEqualTo(2)); | 85 expect(stack['frames'].length, greaterThanOrEqualTo(2)); |
86 expect(stack['frames'][0]['function'].name, equals('myFunction')); | 86 expect(stack['frames'][0]['function'].name, equals('myFunction')); |
87 expect(stack['frames'][0]['function'].dartOwner.name, equals('MyClass')); | 87 expect(stack['frames'][0]['function'].dartOwner.name, equals('MyClass')); |
88 | 88 |
89 var lib = isolate.rootLib; | 89 var lib = isolate.rootLibrary; |
90 var func = stack['frames'][0]['function']; | 90 var func = stack['frames'][0]['function']; |
91 expect(func.name, equals('myFunction')); | 91 expect(func.name, equals('myFunction')); |
92 var cls = stack['frames'][0]['function'].dartOwner; | 92 var cls = stack['frames'][0]['function'].dartOwner; |
93 expect(cls.name, equals('MyClass')); | 93 expect(cls.name, equals('MyClass')); |
94 | 94 |
95 List tests = []; | 95 List tests = []; |
96 // Function | 96 // Function |
97 tests.add(isolate.invokeRpcNoUpgrade('getCoverage', | 97 tests.add(isolate.invokeRpcNoUpgrade('getCoverage', |
98 { 'targetId': func.id }) | 98 { 'targetId': func.id }) |
99 .then((Map coverage) { | 99 .then((Map coverage) { |
(...skipping 46 matching lines...) Loading... |
146 expect(coverage['coverage'].length, greaterThan(100)); | 146 expect(coverage['coverage'].length, greaterThan(100)); |
147 }); | 147 }); |
148 })); | 148 })); |
149 return Future.wait(tests); | 149 return Future.wait(tests); |
150 }); | 150 }); |
151 }, | 151 }, |
152 | 152 |
153 ]; | 153 ]; |
154 | 154 |
155 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); | 155 main(args) => runIsolateTests(args, tests, testeeConcurrent: testFunction); |
OLD | NEW |