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 12 matching lines...) Expand all Loading... |
23 new Timer.periodic(const Duration(milliseconds:10), periodicTask); | 23 new Timer.periodic(const Duration(milliseconds:10), periodicTask); |
24 } | 24 } |
25 | 25 |
26 var tests = [ | 26 var tests = [ |
27 | 27 |
28 // Pause | 28 // Pause |
29 (Isolate isolate) async { | 29 (Isolate isolate) async { |
30 Completer completer = new Completer(); | 30 Completer completer = new Completer(); |
31 var subscription; | 31 var subscription; |
32 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 32 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
33 if (event.eventType == ServiceEvent.kPauseInterrupted) { | 33 if (event.kind == ServiceEvent.kPauseInterrupted) { |
34 subscription.cancel(); | 34 subscription.cancel(); |
35 completer.complete(); | 35 completer.complete(); |
36 } | 36 } |
37 }); | 37 }); |
38 isolate.pause(); | 38 isolate.pause(); |
39 await completer.future; | 39 await completer.future; |
40 }, | 40 }, |
41 | 41 |
42 // Resume | 42 // Resume |
43 (Isolate isolate) async { | 43 (Isolate isolate) async { |
44 Completer completer = new Completer(); | 44 Completer completer = new Completer(); |
45 var subscription; | 45 var subscription; |
46 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 46 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
47 if (event.eventType == ServiceEvent.kResume) { | 47 if (event.kind == ServiceEvent.kResume) { |
48 subscription.cancel(); | 48 subscription.cancel(); |
49 completer.complete(); | 49 completer.complete(); |
50 } | 50 } |
51 }); | 51 }); |
52 isolate.resume(); | 52 isolate.resume(); |
53 await completer.future; | 53 await completer.future; |
54 }, | 54 }, |
55 | 55 |
56 // Add breakpoint | 56 // Add breakpoint |
57 (Isolate isolate) async { | 57 (Isolate isolate) async { |
58 await isolate.rootLibrary.load(); | 58 await isolate.rootLibrary.load(); |
59 | 59 |
60 // Set up a listener to wait for breakpoint events. | 60 // Set up a listener to wait for breakpoint events. |
61 Completer completer = new Completer(); | 61 Completer completer = new Completer(); |
62 var subscription; | 62 var subscription; |
63 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 63 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
64 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | 64 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
65 print('Breakpoint reached'); | 65 print('Breakpoint reached'); |
66 subscription.cancel(); | 66 subscription.cancel(); |
67 completer.complete(); | 67 completer.complete(); |
68 } | 68 } |
69 }); | 69 }); |
70 | 70 |
71 var script = isolate.rootLibrary.scripts[0]; | 71 var script = isolate.rootLibrary.scripts[0]; |
72 await script.load(); | 72 await script.load(); |
73 | 73 |
74 // Add the breakpoint. | 74 // Add the breakpoint. |
(...skipping 18 matching lines...) Expand all Loading... |
93 expect(script.name,endsWith('debugging_test.dart')); | 93 expect(script.name,endsWith('debugging_test.dart')); |
94 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), equals(15)); | 94 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), equals(15)); |
95 }, | 95 }, |
96 | 96 |
97 // Stepping | 97 // Stepping |
98 (Isolate isolate) async { | 98 (Isolate isolate) async { |
99 // Set up a listener to wait for breakpoint events. | 99 // Set up a listener to wait for breakpoint events. |
100 Completer completer = new Completer(); | 100 Completer completer = new Completer(); |
101 var subscription; | 101 var subscription; |
102 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 102 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
103 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | 103 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
104 print('Breakpoint reached'); | 104 print('Breakpoint reached'); |
105 subscription.cancel(); | 105 subscription.cancel(); |
106 completer.complete(); | 106 completer.complete(); |
107 } | 107 } |
108 }); | 108 }); |
109 | 109 |
110 await isolate.stepOver(); | 110 await isolate.stepOver(); |
111 await completer.future; // Wait for breakpoint events. | 111 await completer.future; // Wait for breakpoint events. |
112 }, | 112 }, |
113 | 113 |
114 // We are now at line 16. | 114 // We are now at line 16. |
115 (Isolate isolate) async { | 115 (Isolate isolate) async { |
116 ServiceMap stack = await isolate.getStack(); | 116 ServiceMap stack = await isolate.getStack(); |
117 expect(stack.type, equals('Stack')); | 117 expect(stack.type, equals('Stack')); |
118 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 118 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
119 | 119 |
120 Script script = stack['frames'][0]['script']; | 120 Script script = stack['frames'][0]['script']; |
121 expect(script.name,endsWith('debugging_test.dart')); | 121 expect(script.name,endsWith('debugging_test.dart')); |
122 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), equals(16)); | 122 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), equals(16)); |
123 }, | 123 }, |
124 | 124 |
125 // Remove breakpoint | 125 // Remove breakpoint |
126 (Isolate isolate) async { | 126 (Isolate isolate) async { |
127 // Set up a listener to wait for breakpoint events. | 127 // Set up a listener to wait for breakpoint events. |
128 Completer completer = new Completer(); | 128 Completer completer = new Completer(); |
129 var subscription; | 129 var subscription; |
130 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 130 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
131 if (event.eventType == ServiceEvent.kBreakpointRemoved) { | 131 if (event.kind == ServiceEvent.kBreakpointRemoved) { |
132 print('Breakpoint removed'); | 132 print('Breakpoint removed'); |
133 expect(isolate.breakpoints.length, equals(0)); | 133 expect(isolate.breakpoints.length, equals(0)); |
134 subscription.cancel(); | 134 subscription.cancel(); |
135 completer.complete(); | 135 completer.complete(); |
136 } | 136 } |
137 }); | 137 }); |
138 | 138 |
139 expect(isolate.breakpoints.length, equals(1)); | 139 expect(isolate.breakpoints.length, equals(1)); |
140 var bpt = isolate.breakpoints.values.first; | 140 var bpt = isolate.breakpoints.values.first; |
141 await isolate.removeBreakpoint(bpt); | 141 await isolate.removeBreakpoint(bpt); |
142 await completer.future; | 142 await completer.future; |
143 }, | 143 }, |
144 | 144 |
145 // Resume | 145 // Resume |
146 (Isolate isolate) async { | 146 (Isolate isolate) async { |
147 Completer completer = new Completer(); | 147 Completer completer = new Completer(); |
148 var subscription; | 148 var subscription; |
149 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 149 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
150 if (event.eventType == ServiceEvent.kResume) { | 150 if (event.kind == ServiceEvent.kResume) { |
151 subscription.cancel(); | 151 subscription.cancel(); |
152 completer.complete(); | 152 completer.complete(); |
153 } | 153 } |
154 }); | 154 }); |
155 isolate.resume(); | 155 isolate.resume(); |
156 await completer.future; | 156 await completer.future; |
157 }, | 157 }, |
158 | 158 |
159 // Add breakpoint at function entry | 159 // Add breakpoint at function entry |
160 (Isolate isolate) async { | 160 (Isolate isolate) async { |
161 // Set up a listener to wait for breakpoint events. | 161 // Set up a listener to wait for breakpoint events. |
162 Completer completer = new Completer(); | 162 Completer completer = new Completer(); |
163 var subscription; | 163 var subscription; |
164 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { | 164 subscription = isolate.vm.events.stream.listen((ServiceEvent event) { |
165 if (event.eventType == ServiceEvent.kPauseBreakpoint) { | 165 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
166 print('Breakpoint reached'); | 166 print('Breakpoint reached'); |
167 subscription.cancel(); | 167 subscription.cancel(); |
168 completer.complete(); | 168 completer.complete(); |
169 } | 169 } |
170 }); | 170 }); |
171 | 171 |
172 // Find a specific function. | 172 // Find a specific function. |
173 ServiceFunction function = isolate.rootLibrary.functions.firstWhere( | 173 ServiceFunction function = isolate.rootLibrary.functions.firstWhere( |
174 (f) => f.name == 'periodicTask'); | 174 (f) => f.name == 'periodicTask'); |
175 expect(function, isNotNull); | 175 expect(function, isNotNull); |
(...skipping 17 matching lines...) Expand all Loading... |
193 expect(stack['frames'].length, greaterThanOrEqualTo(1)); | 193 expect(stack['frames'].length, greaterThanOrEqualTo(1)); |
194 | 194 |
195 Script script = stack['frames'][0]['script']; | 195 Script script = stack['frames'][0]['script']; |
196 expect(script.name,endsWith('debugging_test.dart')); | 196 expect(script.name,endsWith('debugging_test.dart')); |
197 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), equals(14)); | 197 expect(script.tokenToLine(stack['frames'][0]['tokenPos']), equals(14)); |
198 }, | 198 }, |
199 | 199 |
200 ]; | 200 ]; |
201 | 201 |
202 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); | 202 main(args) => runIsolateTests(args, tests, testeeBefore: startTimer); |
OLD | NEW |