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

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

Issue 1312763010: Support column-based breakpoints in the VM and Observatory. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: hausner review Created 5 years, 3 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
(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=--error_on_bad_type --error_on_bad_override
5
6 import 'package:observatory/service_io.dart';
7 import 'package:unittest/unittest.dart';
8 import 'test_helper.dart';
9 import 'deferred_library.dart' deferred as deferredLib;
10 import 'dart:async';
11 import 'dart:developer' as developer;
12
13 int value = 0;
14
15 int incValue(int amount) {
16 value += amount;
17 return amount;
18 }
19
20 Future testMain() async {
21 incValue(incValue(1)); // line 21
22
23 incValue(incValue(1)); // line 23
24
25 await deferredLib.loadLibrary();
26 deferredLib.deferredTest();
27 }
28
29 var tests = [
30 hasPausedAtStart,
31
32 // Test future breakpoints.
33 (Isolate isolate) async {
34 var rootLib = isolate.rootLibrary;
35 await rootLib.load();
36 var script = rootLib.scripts[0];
37
38 // Future breakpoint.
39 var futureBpt1 = await isolate.addBreakpoint(script, 21);
40 expect(futureBpt1.number, equals(1));
41 expect(futureBpt1.resolved, isFalse);
42 expect(await futureBpt1.location.getLine(), equals(21));
43 expect(await futureBpt1.location.getColumn(), equals(null));
44
45 // Future breakpoint with specific column.
46 var futureBpt2 = await isolate.addBreakpoint(script, 21, 3);
47 expect(futureBpt2.number, equals(2));
48 expect(futureBpt2.resolved, isFalse);
49 expect(await futureBpt2.location.getLine(), equals(21));
50 expect(await futureBpt2.location.getColumn(), equals(3));
51
52 var stream = await isolate.vm.getEventStream(VM.kDebugStream);
53 Completer completer = new Completer();
54 var subscription;
55 var resolvedCount = 0;
56 subscription = stream.listen((ServiceEvent event) async {
57 if (event.kind == ServiceEvent.kBreakpointResolved) {
58 resolvedCount++;
59 }
60 if (event.kind == ServiceEvent.kPauseBreakpoint) {
61 subscription.cancel();
62 completer.complete(null);
63 }
64 });
65 await isolate.resume();
66 await completer.future;
67
68 // After resolution the breakpoints have assigned line & column.
69 expect(resolvedCount, equals(2));
70 expect(futureBpt1.resolved, isTrue);
71 expect(await futureBpt1.location.getLine(), equals(21));
72 expect(await futureBpt1.location.getColumn(), equals(12));
73 expect(futureBpt2.resolved, isTrue);
74 expect(await futureBpt2.location.getLine(), equals(21));
75 expect(await futureBpt2.location.getColumn(), equals(3));
76
77 // The first breakpoint hits before value is modified.
78 expect((await rootLib.evaluate('value')).valueAsString, equals('0'));
79
80 stream = await isolate.vm.getEventStream(VM.kDebugStream);
81 completer = new Completer();
82 subscription = stream.listen((ServiceEvent event) async {
83 if (event.kind == ServiceEvent.kPauseBreakpoint) {
84 subscription.cancel();
85 completer.complete(null);
86 }
87 });
88 await isolate.resume();
89 await completer.future;
90
91 // The second breakpoint hits after value has been modified once.
92 expect((await rootLib.evaluate('value')).valueAsString, equals('1'));
93
94 // Remove the breakpoints.
95 expect((await isolate.removeBreakpoint(futureBpt1)).type,
96 equals('Success'));
97 expect((await isolate.removeBreakpoint(futureBpt2)).type,
98 equals('Success'));
99 },
100
101 // Test breakpoints in deferred libraries (latent breakpoints).
102 (Isolate isolate) async {
103 var rootLib = isolate.rootLibrary;
104 var uri = rootLib.scripts[0].uri;
105 var lastSlashPos = uri.lastIndexOf('/');
106 var deferredUri =uri.substring(0, lastSlashPos) + '/deferred_library.dart';
107
108 // Latent breakpoint.
109 var latentBpt1 = await isolate.addBreakpointByScriptUri(deferredUri, 15);
110 expect(latentBpt1.number, equals(3));
111 expect(latentBpt1.resolved, isFalse);
112 expect(await latentBpt1.location.getLine(), equals(15));
113 expect(await latentBpt1.location.getColumn(), equals(null));
114
115 // Latent breakpoint with specific column.
116 var latentBpt2 =
117 await isolate.addBreakpointByScriptUri(deferredUri, 15, 3);
118 expect(latentBpt2.number, equals(4));
119 expect(latentBpt2.resolved, isFalse);
120 expect(await latentBpt2.location.getLine(), equals(15));
121 expect(await latentBpt2.location.getColumn(), equals(3));
122
123 var stream = await isolate.vm.getEventStream(VM.kDebugStream);
124 Completer completer = new Completer();
125 var subscription;
126 var resolvedCount = 0;
127 subscription = stream.listen((ServiceEvent event) async {
128 if (event.kind == ServiceEvent.kBreakpointResolved) {
129 resolvedCount++;
130 }
131 if (event.kind == ServiceEvent.kPauseBreakpoint) {
132 subscription.cancel();
133 completer.complete(null);
134 }
135 });
136 await isolate.resume();
137 await completer.future;
138
139 // After resolution the breakpoints have assigned line & column.
140 expect(resolvedCount, equals(2));
141 expect(latentBpt1.resolved, isTrue);
142 expect(await latentBpt1.location.getLine(), equals(15));
143 expect(await latentBpt1.location.getColumn(), equals(12));
144 expect(latentBpt2.resolved, isTrue);
145 expect(await latentBpt2.location.getLine(), equals(15));
146 expect(await latentBpt2.location.getColumn(), equals(3));
147
148 // The first breakpoint hits before value is modified.
149 expect((await rootLib.evaluate('deferredLib.value')).valueAsString,
150 equals('0'));
151
152 stream = await isolate.vm.getEventStream(VM.kDebugStream);
153 completer = new Completer();
154 subscription = stream.listen((ServiceEvent event) async {
155 if (event.kind == ServiceEvent.kPauseBreakpoint) {
156 subscription.cancel();
157 completer.complete(null);
158 }
159 });
160 await isolate.resume();
161 await completer.future;
162
163 // The second breakpoint hits after value has been modified once.
164 expect((await rootLib.evaluate('deferredLib.value')).valueAsString,
165 equals('-1'));
166
167 // Remove the breakpoints.
168 expect((await isolate.removeBreakpoint(latentBpt1)).type,
169 equals('Success'));
170 expect((await isolate.removeBreakpoint(latentBpt2)).type,
171 equals('Success'));
172 },
173
174
175 // Test resolution of column breakpoints.
176 (Isolate isolate) async {
177 var script = isolate.rootLibrary.scripts[0];
178 // Try all columns, including some columns that are too big.
179 for (int col = 1; col <= 50; col++) {
180 var bpt = await isolate.addBreakpoint(script, 21, col);
181 expect(bpt.resolved, isTrue);
182 int resolvedLine = await bpt.location.getLine();
183 int resolvedCol = await bpt.location.getColumn();
184 print('21:${col} -> ${resolvedLine}:${resolvedCol}');
185 if (col <= 10) {
186 expect(resolvedLine, equals(21));
187 expect(resolvedCol, equals(3));
188 } else if (col <= 19) {
189 expect(resolvedLine, equals(21));
190 expect(resolvedCol, equals(12));
191 } else {
192 expect(resolvedLine, equals(23));
193 expect(resolvedCol, equals(12));
194 }
195 expect((await isolate.removeBreakpoint(bpt)).type, equals('Success'));
196 }
197
198 // Make sure that a zero column is an error.
199 var caughtException = false;
200 try {
201 await isolate.addBreakpoint(script, 21, 0);
202 expect(false, isTrue, reason:'Unreachable');
203 } on ServerRpcException catch(e) {
204 caughtException = true;
205 expect(e.code, equals(ServerRpcException.kInvalidParams));
206 expect(e.message,
207 "addBreakpoint: invalid 'column' parameter: 0");
208 }
209 expect(caughtException, isTrue);
210 },
211 ];
212
213 main(args) => runIsolateTests(args, tests,
214 testeeConcurrent: testMain,
215 pause_on_start: true);
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/service/object.dart ('k') | runtime/observatory/tests/service/debugger_location_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698