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

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

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

Powered by Google App Engine
This is Rietveld 408576698