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

Side by Side Diff: runtime/vm/service_test.cc

Issue 1120133002: Rework error handling in the service protocol and in Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
« runtime/vm/service.cc ('K') | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_entry.h" 9 #include "vm/dart_entry.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 EXPECT_VALID(port); 153 EXPECT_VALID(port);
154 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 154 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
155 155
156 Array& service_msg = Array::Handle(); 156 Array& service_msg = Array::Handle();
157 157
158 // Request an invalid code object. 158 // Request an invalid code object.
159 service_msg = 159 service_msg =
160 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]"); 160 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]");
161 Service::HandleIsolateMessage(isolate, service_msg); 161 Service::HandleIsolateMessage(isolate, service_msg);
162 handler.HandleNextMessage(); 162 handler.HandleNextMessage();
163 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 163 EXPECT_SUBSTRING("\"error\"", handler.msg());
164 164
165 // The following test checks that a code object can be found only 165 // The following test checks that a code object can be found only
166 // at compile_timestamp()-code.EntryPoint(). 166 // at compile_timestamp()-code.EntryPoint().
167 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 167 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
168 "['objectId'], ['code/%" Px64"-%" Px "']]", 168 "['objectId'], ['code/%" Px64"-%" Px "']]",
169 compile_timestamp, 169 compile_timestamp,
170 entry); 170 entry);
171 Service::HandleIsolateMessage(isolate, service_msg); 171 Service::HandleIsolateMessage(isolate, service_msg);
172 handler.HandleNextMessage(); 172 handler.HandleNextMessage();
173 { 173 {
174 // Only perform a partial match. 174 // Only perform a partial match.
175 const intptr_t kBufferSize = 512; 175 const intptr_t kBufferSize = 512;
176 char buffer[kBufferSize]; 176 char buffer[kBufferSize];
177 OS::SNPrint(buffer, kBufferSize-1, 177 OS::SNPrint(buffer, kBufferSize-1,
178 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",", 178 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",",
179 compile_timestamp, 179 compile_timestamp,
180 entry); 180 entry);
181 EXPECT_SUBSTRING(buffer, handler.msg()); 181 EXPECT_SUBSTRING(buffer, handler.msg());
182 } 182 }
183 183
184 // Request code object at compile_timestamp-code.EntryPoint() + 16 184 // Request code object at compile_timestamp-code.EntryPoint() + 16
185 // Expect this to fail because the address is not the entry point. 185 // Expect this to fail because the address is not the entry point.
186 uintptr_t address = entry + 16; 186 uintptr_t address = entry + 16;
187 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 187 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
188 "['objectId'], ['code/%" Px64"-%" Px "']]", 188 "['objectId'], ['code/%" Px64"-%" Px "']]",
189 compile_timestamp, 189 compile_timestamp,
190 address); 190 address);
191 Service::HandleIsolateMessage(isolate, service_msg); 191 Service::HandleIsolateMessage(isolate, service_msg);
192 handler.HandleNextMessage(); 192 handler.HandleNextMessage();
193 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 193 EXPECT_SUBSTRING("\"error\"", handler.msg());
194 194
195 // Request code object at (compile_timestamp - 1)-code.EntryPoint() 195 // Request code object at (compile_timestamp - 1)-code.EntryPoint()
196 // Expect this to fail because the timestamp is wrong. 196 // Expect this to fail because the timestamp is wrong.
197 address = entry; 197 address = entry;
198 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 198 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
199 "['objectId'], ['code/%" Px64"-%" Px "']]", 199 "['objectId'], ['code/%" Px64"-%" Px "']]",
200 compile_timestamp - 1, 200 compile_timestamp - 1,
201 address); 201 address);
202 Service::HandleIsolateMessage(isolate, service_msg); 202 Service::HandleIsolateMessage(isolate, service_msg);
203 handler.HandleNextMessage(); 203 handler.HandleNextMessage();
204 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 204 EXPECT_SUBSTRING("\"error\"", handler.msg());
205 205
206 // Request native code at address. Expect the null code object back. 206 // Request native code at address. Expect the null code object back.
207 address = last; 207 address = last;
208 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 208 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
209 "['objectId'], ['code/native-%" Px "']]", 209 "['objectId'], ['code/native-%" Px "']]",
210 address); 210 address);
211 Service::HandleIsolateMessage(isolate, service_msg); 211 Service::HandleIsolateMessage(isolate, service_msg);
212 handler.HandleNextMessage(); 212 handler.HandleNextMessage();
213 EXPECT_SUBSTRING("{\"type\":\"null\",\"id\":\"objects\\/null\"," 213 EXPECT_SUBSTRING("{\"type\":\"null\",\"id\":\"objects\\/null\","
214 "\"valueAsString\":\"null\"", 214 "\"valueAsString\":\"null\"",
215 handler.msg()); 215 handler.msg());
216 216
217 // Request malformed native code. 217 // Request malformed native code.
218 service_msg = EvalF(lib, "[0, port, '0', 'getObject', ['objectId'], " 218 service_msg = EvalF(lib, "[0, port, '0', 'getObject', ['objectId'], "
219 "['code/native%" Px "']]", 219 "['code/native%" Px "']]",
220 address); 220 address);
221 Service::HandleIsolateMessage(isolate, service_msg); 221 Service::HandleIsolateMessage(isolate, service_msg);
222 handler.HandleNextMessage(); 222 handler.HandleNextMessage();
223 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 223 EXPECT_SUBSTRING("\"error\"", handler.msg());
224 } 224 }
225 225
226 226
227 TEST_CASE(Service_TokenStream) { 227 TEST_CASE(Service_TokenStream) {
228 const char* kScript = 228 const char* kScript =
229 "var port;\n" // Set to our mock port by C++. 229 "var port;\n" // Set to our mock port by C++.
230 "\n" 230 "\n"
231 "main() {\n" 231 "main() {\n"
232 "}"; 232 "}";
233 233
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 Dart_Port port_id = PortMap::CreatePort(&handler); 568 Dart_Port port_id = PortMap::CreatePort(&handler);
569 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 569 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
570 EXPECT_VALID(port); 570 EXPECT_VALID(port);
571 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 571 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
572 572
573 Array& service_msg = Array::Handle(); 573 Array& service_msg = Array::Handle();
574 service_msg = Eval(lib, "[0, port, '0', 'getCpuProfile', [], []]"); 574 service_msg = Eval(lib, "[0, port, '0', 'getCpuProfile', [], []]");
575 Service::HandleIsolateMessage(isolate, service_msg); 575 Service::HandleIsolateMessage(isolate, service_msg);
576 handler.HandleNextMessage(); 576 handler.HandleNextMessage();
577 // Expect error (tags required). 577 // Expect error (tags required).
578 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 578 EXPECT_SUBSTRING("\"error\"", handler.msg());
579 579
580 service_msg = 580 service_msg =
581 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['None']]"); 581 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['None']]");
582 Service::HandleIsolateMessage(isolate, service_msg); 582 Service::HandleIsolateMessage(isolate, service_msg);
583 handler.HandleNextMessage(); 583 handler.HandleNextMessage();
584 // Expect profile 584 // Expect profile
585 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg()); 585 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg());
586 586
587 service_msg = 587 service_msg =
588 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['Bogus']]"); 588 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['Bogus']]");
589 Service::HandleIsolateMessage(isolate, service_msg); 589 Service::HandleIsolateMessage(isolate, service_msg);
590 handler.HandleNextMessage(); 590 handler.HandleNextMessage();
591 // Expect error. 591 // Expect error.
592 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 592 EXPECT_SUBSTRING("\"error\"", handler.msg());
593 } 593 }
594 594
595 #endif // !defined(TARGET_ARCH_ARM64) 595 #endif // !defined(TARGET_ARCH_ARM64)
596 596
597 } // namespace dart 597 } // namespace dart
OLDNEW
« runtime/vm/service.cc ('K') | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698