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

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

Issue 381383010: Add breakpoints and single-stepping to Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix bugs, gen js Created 6 years, 4 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
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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); 118 char* buffer = isolate->current_zone()->Alloc<char>(len + 1);
119 va_list args2; 119 va_list args2;
120 va_start(args2, fmt); 120 va_start(args2, fmt);
121 OS::VSNPrint(buffer, (len + 1), fmt, args2); 121 OS::VSNPrint(buffer, (len + 1), fmt, args2);
122 va_end(args2); 122 va_end(args2);
123 123
124 return Eval(lib, buffer); 124 return Eval(lib, buffer);
125 } 125 }
126 126
127 127
128 // Search for the formatted string in buff. 128 // Search for the formatted string in buffer.
129 // 129 //
130 // TODO(turnidge): This function obscures the line number of failing 130 // TODO(turnidge): This function obscures the line number of failing
131 // EXPECTs. Rework this. 131 // EXPECTs. Rework this.
132 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { 132 static void ExpectSubstringF(const char* buff, const char* fmt, ...) {
133 Isolate* isolate = Isolate::Current(); 133 Isolate* isolate = Isolate::Current();
134 134
135 va_list args; 135 va_list args;
136 va_start(args, fmt); 136 va_start(args, fmt);
137 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); 137 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args);
138 va_end(args); 138 va_end(args);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 TEST_CASE(Service_DebugBreakpoints) { 257 TEST_CASE(Service_DebugBreakpoints) {
258 const char* kScript = 258 const char* kScript =
259 "var port;\n" // Set to our mock port by C++. 259 "var port;\n" // Set to our mock port by C++.
260 "\n" 260 "\n"
261 "main() {\n" // We set breakpoint here. 261 "main() {\n" // We set breakpoint here.
262 "}"; 262 "}";
263 263
264 Isolate* isolate = Isolate::Current(); 264 Isolate* isolate = Isolate::Current();
265 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 265 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
266 EXPECT_VALID(lib); 266 EXPECT_VALID(lib);
267 Library& vmlib = Library::Handle();
268 vmlib ^= Api::UnwrapHandle(lib);
269 EXPECT(!vmlib.IsNull());
267 270
268 // Build a mock message handler and wrap it in a dart port. 271 // Build a mock message handler and wrap it in a dart port.
269 ServiceTestMessageHandler handler; 272 ServiceTestMessageHandler handler;
270 Dart_Port port_id = PortMap::CreatePort(&handler); 273 Dart_Port port_id = PortMap::CreatePort(&handler);
271 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 274 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
272 EXPECT_VALID(port); 275 EXPECT_VALID(port);
273 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 276 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
274 277
275 Array& service_msg = Array::Handle(); 278 Array& service_msg = Array::Handle();
276 279
277 // Add a breakpoint. 280 // Add a breakpoint.
278 const String& url = String::Handle(String::New(TestCase::url())); 281 service_msg = EvalF(lib,
279 isolate->debugger()->SetBreakpointAtLine(url, 3); 282 "[0, port, ['libraries', '%" Pd "', "
283 "'scripts', 'test-lib', 'setBreakpoint'], "
284 "['line'], ['3']]",
285 vmlib.index());
286 Service::HandleIsolateMessage(isolate, service_msg);
287 handler.HandleNextMessage();
288 ExpectSubstringF(
289 handler.msg(),
290 "{\"type\":\"Breakpoint\",\"id\":\"debug\\/breakpoints\\/1\","
291 "\"breakpointNumber\":1,\"enabled\":true,\"resolved\":false,"
292 "\"location\":{\"type\":\"Location\","
293 "\"script\":{\"type\":\"@Script\","
294 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
295 "\"name\":\"test-lib\",\"user_name\":\"test-lib\",\"kind\":\"script\"},"
296 "\"tokenPos\":5}}",
297 vmlib.index());
298
299 // Get the breakpoint list.
300 service_msg = Eval(lib, "[0, port, ['debug', 'breakpoints'], [], []]");
301 Service::HandleIsolateMessage(isolate, service_msg);
302 handler.HandleNextMessage();
303 ExpectSubstringF(
304 handler.msg(),
305 "{\"type\":\"BreakpointList\",\"id\":\"debug\\/breakpoints\","
306 "\"breakpoints\":["
307 "{\"type\":\"Breakpoint\",\"id\":\"debug\\/breakpoints\\/1\","
308 "\"breakpointNumber\":1,\"enabled\":true,\"resolved\":false,"
309 "\"location\":{\"type\":\"Location\","
310 "\"script\":{\"type\":\"@Script\","
311 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
312 "\"name\":\"test-lib\",\"user_name\":\"test-lib\",\"kind\":\"script\"},"
313 "\"tokenPos\":5}}]}",
314 vmlib.index());
315
316 // Lookup individual breakpoint.
317 service_msg = Eval(lib, "[0, port, ['debug', 'breakpoints', '1'], [], []]");
318 Service::HandleIsolateMessage(isolate, service_msg);
319 handler.HandleNextMessage();
320 ExpectSubstringF(
321 handler.msg(),
322 "{\"type\":\"Breakpoint\",\"id\":\"debug\\/breakpoints\\/1\","
323 "\"breakpointNumber\":1,\"enabled\":true,\"resolved\":false,"
324 "\"location\":{\"type\":\"Location\","
325 "\"script\":{\"type\":\"@Script\","
326 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
327 "\"name\":\"test-lib\",\"user_name\":\"test-lib\",\"kind\":\"script\"},"
328 "\"tokenPos\":5}}",
329 vmlib.index());
330
331 // Unrecognized breakpoint subcommand.
332 service_msg =
333 Eval(lib, "[0, port, ['debug', 'breakpoints', '1', 'green'], [], []]");
334 Service::HandleIsolateMessage(isolate, service_msg);
335 handler.HandleNextMessage();
336 EXPECT_STREQ("{\"type\":\"Error\",\"id\":\"\","
337 "\"message\":\"Unrecognized subcommand: green\","
338 "\"request\":{\"arguments\":[\"debug\",\"breakpoints\","
339 "\"1\",\"green\"],"
340 "\"option_keys\":[],\"option_values\":[]}}",
341 handler.msg());
342
343 // Clear breakpoint.
344 service_msg =
345 Eval(lib, "[0, port, ['debug', 'breakpoints', '1', 'clear'], [], []]");
346 Service::HandleIsolateMessage(isolate, service_msg);
347 handler.HandleNextMessage();
348 EXPECT_STREQ("{\"type\":\"Success\",\"id\":\"\"}",
349 handler.msg());
280 350
281 // Get the breakpoint list. 351 // Get the breakpoint list.
282 service_msg = Eval(lib, "[0, port, ['debug', 'breakpoints'], [], []]"); 352 service_msg = Eval(lib, "[0, port, ['debug', 'breakpoints'], [], []]");
283 Service::HandleIsolateMessage(isolate, service_msg); 353 Service::HandleIsolateMessage(isolate, service_msg);
284 handler.HandleNextMessage(); 354 handler.HandleNextMessage();
285 EXPECT_STREQ( 355 EXPECT_STREQ(
286 "{\"type\":\"BreakpointList\",\"breakpoints\":[{" 356 "{\"type\":\"BreakpointList\",\"id\":\"debug\\/breakpoints\","
287 "\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true," 357 "\"breakpoints\":[]}",
288 "\"resolved\":false,"
289 "\"location\":{\"type\":\"Location\","
290 "\"script\":\"test-lib\",\"tokenPos\":5}}]}",
291 handler.msg());
292
293 // Individual breakpoint.
294 service_msg = Eval(lib, "[0, port, ['debug', 'breakpoints', '1'], [], []]");
295 Service::HandleIsolateMessage(isolate, service_msg);
296 handler.HandleNextMessage();
297 EXPECT_STREQ(
298 "{\"type\":\"Breakpoint\",\"id\":1,\"enabled\":true,"
299 "\"resolved\":false,"
300 "\"location\":{\"type\":\"Location\","
301 "\"script\":\"test-lib\",\"tokenPos\":5}}",
302 handler.msg()); 358 handler.msg());
303 359
304 // Missing sub-command. 360 // Missing sub-command.
305 service_msg = Eval(lib, "[0, port, ['debug'], [], []]"); 361 service_msg = Eval(lib, "[0, port, ['debug'], [], []]");
306 Service::HandleIsolateMessage(isolate, service_msg); 362 Service::HandleIsolateMessage(isolate, service_msg);
307 handler.HandleNextMessage(); 363 handler.HandleNextMessage();
308 EXPECT_STREQ( 364 EXPECT_STREQ(
309 "{\"type\":\"Error\",\"id\":\"\"," 365 "{\"type\":\"Error\",\"id\":\"\","
310 "\"message\":\"Must specify a subcommand\"," 366 "\"message\":\"Must specify a subcommand\","
311 "\"request\":{\"arguments\":[\"debug\"],\"option_keys\":[]," 367 "\"request\":{\"arguments\":[\"debug\"],\"option_keys\":[],"
312 "\"option_values\":[]}}", 368 "\"option_values\":[]}}",
313 handler.msg()); 369 handler.msg());
314 370
315 // Unrecognized breakpoint. 371 // Unrecognized breakpoint.
316 service_msg = Eval(lib, 372 service_msg = Eval(lib,
317 "[0, port, ['debug', 'breakpoints', '1111'], [], []]"); 373 "[0, port, ['debug', 'breakpoints', '1111'], [], []]");
318 Service::HandleIsolateMessage(isolate, service_msg); 374 Service::HandleIsolateMessage(isolate, service_msg);
319 handler.HandleNextMessage(); 375 handler.HandleNextMessage();
320 EXPECT_STREQ("{\"type\":\"Error\",\"id\":\"\"," 376 EXPECT_STREQ("{\"type\":\"Error\",\"id\":\"\","
321 "\"message\":\"Unrecognized breakpoint id 1111\"," 377 "\"message\":\"Unrecognized breakpoint id: 1111\","
322 "\"request\":{" 378 "\"request\":{"
323 "\"arguments\":[\"debug\",\"breakpoints\",\"1111\"]," 379 "\"arguments\":[\"debug\",\"breakpoints\",\"1111\"],"
324 "\"option_keys\":[],\"option_values\":[]}}", 380 "\"option_keys\":[],\"option_values\":[]}}",
325 handler.msg()); 381 handler.msg());
326 382
327 // Command too long.
328 service_msg =
329 Eval(lib, "[0, port, ['debug', 'breakpoints', '1111', 'green'], [], []]");
330 Service::HandleIsolateMessage(isolate, service_msg);
331 handler.HandleNextMessage();
332 EXPECT_STREQ("{\"type\":\"Error\",\"id\":\"\","
333 "\"message\":\"Command too long\","
334 "\"request\":{\"arguments\":[\"debug\",\"breakpoints\","
335 "\"1111\",\"green\"],"
336 "\"option_keys\":[],\"option_values\":[]}}",
337 handler.msg());
338
339 // Unrecognized subcommand. 383 // Unrecognized subcommand.
340 service_msg = Eval(lib, "[0, port, ['debug', 'nosferatu'], [], []]"); 384 service_msg = Eval(lib, "[0, port, ['debug', 'nosferatu'], [], []]");
341 Service::HandleIsolateMessage(isolate, service_msg); 385 Service::HandleIsolateMessage(isolate, service_msg);
342 handler.HandleNextMessage(); 386 handler.HandleNextMessage();
343 EXPECT_STREQ("{\"type\":\"Error\",\"id\":\"\"," 387 EXPECT_STREQ("{\"type\":\"Error\",\"id\":\"\","
344 "\"message\":\"Unrecognized subcommand 'nosferatu'\"," 388 "\"message\":\"Unrecognized subcommand 'nosferatu'\","
345 "\"request\":{\"arguments\":[\"debug\",\"nosferatu\"]," 389 "\"request\":{\"arguments\":[\"debug\",\"nosferatu\"],"
346 "\"option_keys\":[],\"option_values\":[]}}", 390 "\"option_keys\":[],\"option_values\":[]}}",
347 handler.msg()); 391 handler.msg());
348 } 392 }
349 393
350 394
395 // Globals used to communicate with HandlerPausedEvent.
396 static intptr_t pause_line_number = 0;
397 static Dart_Handle saved_lib;
398 static ServiceTestMessageHandler* saved_handler = NULL;
399
400 static void HandlePausedEvent(Dart_IsolateId isolate_id,
401 intptr_t bp_id,
402 const Dart_CodeLocation& loc) {
403 Isolate* isolate = Isolate::Current();
404 Debugger* debugger = isolate->debugger();
405
406 // The debugger knows that it is paused, and why.
407 EXPECT(debugger->IsPaused());
408 const DebuggerEvent* event = debugger->PauseEvent();
409 EXPECT(event != NULL);
410 EXPECT(event->type() == DebuggerEvent::kBreakpointReached);
411
412 // Save the last line number seen by this handler.
413 pause_line_number = event->top_frame()->LineNumber();
414
415 // Single step
416 Array& service_msg = Array::Handle();
417 service_msg = Eval(saved_lib,
418 "[0, port, ['debug', 'resume'], "
419 "['step'], ['into']]");
420 Service::HandleIsolateMessage(isolate, service_msg);
421 saved_handler->HandleNextMessage();
422 EXPECT_STREQ("{\"type\":\"Success\",\"id\":\"\"}",
423 saved_handler->msg());
424 }
425
426
427 TEST_CASE(Service_Stepping) {
428 const char* kScript =
429 "var port;\n" // Set to our mock port by C++.
430 "var value = 0;\n"
431 "\n"
432 "main() {\n" // We set breakpoint here.
433 " value++;\n"
434 " value++;\n"
435 " value++;\n"
436 "}"; // We step up to here.
437
438 Isolate* isolate = Isolate::Current();
439 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
440 EXPECT_VALID(lib);
441 Library& vmlib = Library::Handle();
442 vmlib ^= Api::UnwrapHandle(lib);
443 EXPECT(!vmlib.IsNull());
444 saved_lib = lib;
445
446 // Build a mock message handler and wrap it in a dart port.
447 ServiceTestMessageHandler handler;
448 saved_handler = &handler;
449 Dart_Port port_id = PortMap::CreatePort(&handler);
450 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
451 EXPECT_VALID(port);
452 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
453
454 Array& service_msg = Array::Handle();
455
456 // Add a breakpoint.
457 service_msg = EvalF(lib,
458 "[0, port, ['libraries', '%" Pd "', "
459 "'scripts', 'test-lib', 'setBreakpoint'], "
460 "['line'], ['4']]",
461 vmlib.index());
462 Service::HandleIsolateMessage(isolate, service_msg);
463 handler.HandleNextMessage();
464 ExpectSubstringF(
465 handler.msg(),
466 "{\"type\":\"Breakpoint\",\"id\":\"debug\\/breakpoints\\/1\","
467 "\"breakpointNumber\":1,\"enabled\":true,\"resolved\":false,"
468 "\"location\":{\"type\":\"Location\","
469 "\"script\":{\"type\":\"@Script\","
470 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
471 "\"name\":\"test-lib\",\"user_name\":\"test-lib\",\"kind\":\"script\"},"
472 "\"tokenPos\":11}}",
473 vmlib.index());
474
475 pause_line_number = -1;
476 Dart_SetPausedEventHandler(HandlePausedEvent);
477
478 // Run the program.
479 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
480 EXPECT_VALID(result);
481
482 // We were able to step to the last line in main.
483 EXPECT_EQ(8, pause_line_number);
484 }
485
486
351 TEST_CASE(Service_Objects) { 487 TEST_CASE(Service_Objects) {
352 // TODO(turnidge): Extend this test to cover a non-trivial stack trace. 488 // TODO(turnidge): Extend this test to cover a non-trivial stack trace.
353 const char* kScript = 489 const char* kScript =
354 "var port;\n" // Set to our mock port by C++. 490 "var port;\n" // Set to our mock port by C++.
355 "var validId;\n" // Set to a valid object id by C++. 491 "var validId;\n" // Set to a valid object id by C++.
356 "\n" 492 "\n"
357 "main() {\n" 493 "main() {\n"
358 "}"; 494 "}";
359 495
360 Isolate* isolate = Isolate::Current(); 496 Isolate* isolate = Isolate::Current();
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 " String f0;\n" 754 " String f0;\n"
619 " String f1;\n" 755 " String f1;\n"
620 "}\n" 756 "}\n"
621 "Foo foo;\n" 757 "Foo foo;\n"
622 "List<String> lst;\n" 758 "List<String> lst;\n"
623 "main() {\n" 759 "main() {\n"
624 " foo = new Foo();\n" 760 " foo = new Foo();\n"
625 " lst = new List<String>(100);\n" 761 " lst = new List<String>(100);\n"
626 "}\n"; 762 "}\n";
627 Isolate* isolate = Isolate::Current(); 763 Isolate* isolate = Isolate::Current();
628 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 764 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
629 EXPECT_VALID(h_lib); 765 EXPECT_VALID(lib);
630 Library& lib = Library::Handle(); 766 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
631 lib ^= Api::UnwrapHandle(h_lib);
632 EXPECT(!lib.IsNull());
633 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
634 EXPECT_VALID(result); 767 EXPECT_VALID(result);
635 const Class& class_foo = Class::Handle(GetClass(lib, "Foo")); 768 Library& vmlib = Library::Handle();
769 vmlib ^= Api::UnwrapHandle(lib);
770 EXPECT(!vmlib.IsNull());
771 const Class& class_foo = Class::Handle(GetClass(vmlib, "Foo"));
636 EXPECT(!class_foo.IsNull()); 772 EXPECT(!class_foo.IsNull());
637 Dart_Handle foo = Dart_GetField(h_lib, NewString("foo")); 773 Dart_Handle foo = Dart_GetField(lib, NewString("foo"));
638 Dart_Handle lst = Dart_GetField(h_lib, NewString("lst")); 774 Dart_Handle lst = Dart_GetField(lib, NewString("lst"));
639 const intptr_t kElemIndex = 42; 775 const intptr_t kElemIndex = 42;
640 { 776 {
641 Dart_EnterScope(); 777 Dart_EnterScope();
642 ObjectIdRing* ring = isolate->object_id_ring(); 778 ObjectIdRing* ring = isolate->object_id_ring();
643 { 779 {
644 const String& foo0 = String::Handle(String::New("foo0", Heap::kOld)); 780 const String& foo0 = String::Handle(String::New("foo0", Heap::kOld));
645 Dart_Handle h_foo0 = Api::NewHandle(isolate, foo0.raw()); 781 Dart_Handle h_foo0 = Api::NewHandle(isolate, foo0.raw());
646 EXPECT_VALID(Dart_SetField(foo, NewString("f0"), h_foo0)); 782 EXPECT_VALID(Dart_SetField(foo, NewString("f0"), h_foo0));
647 Dart_Handle id0 = Dart_NewInteger(ring->GetIdForObject(foo0.raw())); 783 Dart_Handle id0 = Dart_NewInteger(ring->GetIdForObject(foo0.raw()));
648 EXPECT_VALID(id0); 784 EXPECT_VALID(id0);
649 EXPECT_VALID(Dart_SetField(h_lib, NewString("id0"), id0)); 785 EXPECT_VALID(Dart_SetField(lib, NewString("id0"), id0));
650 } 786 }
651 { 787 {
652 const String& foo1 = String::Handle(String::New("foo1", Heap::kOld)); 788 const String& foo1 = String::Handle(String::New("foo1", Heap::kOld));
653 Dart_Handle h_foo1 = Api::NewHandle(isolate, foo1.raw()); 789 Dart_Handle h_foo1 = Api::NewHandle(isolate, foo1.raw());
654 EXPECT_VALID(Dart_SetField(foo, NewString("f1"), h_foo1)); 790 EXPECT_VALID(Dart_SetField(foo, NewString("f1"), h_foo1));
655 Dart_Handle id1 = Dart_NewInteger(ring->GetIdForObject(foo1.raw())); 791 Dart_Handle id1 = Dart_NewInteger(ring->GetIdForObject(foo1.raw()));
656 EXPECT_VALID(id1); 792 EXPECT_VALID(id1);
657 EXPECT_VALID(Dart_SetField(h_lib, NewString("id1"), id1)); 793 EXPECT_VALID(Dart_SetField(lib, NewString("id1"), id1));
658 } 794 }
659 { 795 {
660 const String& elem = String::Handle(String::New("elem", Heap::kOld)); 796 const String& elem = String::Handle(String::New("elem", Heap::kOld));
661 Dart_Handle h_elem = Api::NewHandle(isolate, elem.raw()); 797 Dart_Handle h_elem = Api::NewHandle(isolate, elem.raw());
662 EXPECT_VALID(Dart_ListSetAt(lst, kElemIndex, h_elem)); 798 EXPECT_VALID(Dart_ListSetAt(lst, kElemIndex, h_elem));
663 Dart_Handle idElem = Dart_NewInteger(ring->GetIdForObject(elem.raw())); 799 Dart_Handle idElem = Dart_NewInteger(ring->GetIdForObject(elem.raw()));
664 EXPECT_VALID(idElem); 800 EXPECT_VALID(idElem);
665 EXPECT_VALID(Dart_SetField(h_lib, NewString("idElem"), idElem)); 801 EXPECT_VALID(Dart_SetField(lib, NewString("idElem"), idElem));
666 } 802 }
667 Dart_ExitScope(); 803 Dart_ExitScope();
668 } 804 }
669 805
670 // Build a mock message handler and wrap it in a dart port. 806 // Build a mock message handler and wrap it in a dart port.
671 ServiceTestMessageHandler handler; 807 ServiceTestMessageHandler handler;
672 Dart_Port port_id = PortMap::CreatePort(&handler); 808 Dart_Port port_id = PortMap::CreatePort(&handler);
673 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 809 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
674 EXPECT_VALID(port); 810 EXPECT_VALID(port);
675 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 811 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
676 Array& service_msg = Array::Handle(); 812 Array& service_msg = Array::Handle();
677 813
678 // Retaining path to 'foo0', limit 2. 814 // Retaining path to 'foo0', limit 2.
679 service_msg = Eval( 815 service_msg = Eval(
680 h_lib, 816 lib,
681 "[0, port, ['objects', '$id0', 'retaining_path'], ['limit'], ['2']]"); 817 "[0, port, ['objects', '$id0', 'retaining_path'], ['limit'], ['2']]");
682 Service::HandleIsolateMessage(isolate, service_msg); 818 Service::HandleIsolateMessage(isolate, service_msg);
683 handler.HandleNextMessage(); 819 handler.HandleNextMessage();
684 ExpectSubstringF( 820 ExpectSubstringF(
685 handler.msg(), 821 handler.msg(),
686 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2," 822 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2,"
687 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); 823 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\"");
688 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\""); 824 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\"");
689 ExpectSubstringF(handler.msg(), "\"name\":\"f0\""); 825 ExpectSubstringF(handler.msg(), "\"name\":\"f0\"");
690 ExpectSubstringF(handler.msg(), 826 ExpectSubstringF(handler.msg(),
691 "{\"index\":1,\"value\":{\"type\":\"@Instance\""); 827 "{\"index\":1,\"value\":{\"type\":\"@Instance\"");
692 828
693 // Retaining path to 'foo1', limit 2. 829 // Retaining path to 'foo1', limit 2.
694 service_msg = Eval( 830 service_msg = Eval(
695 h_lib, 831 lib,
696 "[0, port, ['objects', '$id1', 'retaining_path'], ['limit'], ['2']]"); 832 "[0, port, ['objects', '$id1', 'retaining_path'], ['limit'], ['2']]");
697 Service::HandleIsolateMessage(isolate, service_msg); 833 Service::HandleIsolateMessage(isolate, service_msg);
698 handler.HandleNextMessage(); 834 handler.HandleNextMessage();
699 ExpectSubstringF( 835 ExpectSubstringF(
700 handler.msg(), 836 handler.msg(),
701 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2," 837 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2,"
702 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); 838 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\"");
703 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\""); 839 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\"");
704 ExpectSubstringF(handler.msg(), "\"name\":\"f1\""); 840 ExpectSubstringF(handler.msg(), "\"name\":\"f1\"");
705 ExpectSubstringF(handler.msg(), 841 ExpectSubstringF(handler.msg(),
706 "{\"index\":1,\"value\":{\"type\":\"@Instance\""); 842 "{\"index\":1,\"value\":{\"type\":\"@Instance\"");
707 843
708 // Retaining path to 'elem', limit 2. 844 // Retaining path to 'elem', limit 2.
709 service_msg = Eval( 845 service_msg = Eval(
710 h_lib, 846 lib,
711 "[0, port, ['objects', '$idElem', 'retaining_path'], ['limit'], ['2']]"); 847 "[0, port, ['objects', '$idElem', 'retaining_path'], ['limit'], ['2']]");
712 Service::HandleIsolateMessage(isolate, service_msg); 848 Service::HandleIsolateMessage(isolate, service_msg);
713 handler.HandleNextMessage(); 849 handler.HandleNextMessage();
714 ExpectSubstringF( 850 ExpectSubstringF(
715 handler.msg(), 851 handler.msg(),
716 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2," 852 "{\"type\":\"RetainingPath\",\"id\":\"retaining_path\",\"length\":2,"
717 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); 853 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\"");
718 ExpectSubstringF(handler.msg(), "\"parentListIndex\":%" Pd, kElemIndex); 854 ExpectSubstringF(handler.msg(), "\"parentListIndex\":%" Pd, kElemIndex);
719 ExpectSubstringF(handler.msg(), 855 ExpectSubstringF(handler.msg(),
720 "{\"index\":1,\"value\":{\"type\":\"@Array\""); 856 "{\"index\":1,\"value\":{\"type\":\"@Array\"");
721 } 857 }
722 858
723 859
724 TEST_CASE(Service_Libraries) { 860 TEST_CASE(Service_Libraries) {
725 const char* kScript = 861 const char* kScript =
726 "var port;\n" // Set to our mock port by C++. 862 "var port;\n" // Set to our mock port by C++.
727 "var libVar = 54321;\n" 863 "var libVar = 54321;\n"
728 "\n" 864 "\n"
729 "main() {\n" 865 "main() {\n"
730 "}"; 866 "}";
731 867
732 Isolate* isolate = Isolate::Current(); 868 Isolate* isolate = Isolate::Current();
733 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 869 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
734 EXPECT_VALID(h_lib); 870 EXPECT_VALID(lib);
735 Library& lib = Library::Handle(); 871 Library& vmlib = Library::Handle();
736 lib ^= Api::UnwrapHandle(h_lib); 872 vmlib ^= Api::UnwrapHandle(lib);
737 EXPECT(!lib.IsNull()); 873 EXPECT(!vmlib.IsNull());
738
739 // Find the current library.
740 intptr_t lib_id = -1;
741 const GrowableObjectArray& libs =
742 GrowableObjectArray::Handle(isolate->object_store()->libraries());
743 for (intptr_t i = 0; i < libs.Length(); i++) {
744 if (libs.At(i) == lib.raw()) {
745 lib_id = i;
746 }
747 }
748 ASSERT(lib_id > 0);
749 874
750 // Build a mock message handler and wrap it in a dart port. 875 // Build a mock message handler and wrap it in a dart port.
751 ServiceTestMessageHandler handler; 876 ServiceTestMessageHandler handler;
752 Dart_Port port_id = PortMap::CreatePort(&handler); 877 Dart_Port port_id = PortMap::CreatePort(&handler);
753 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 878 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
754 EXPECT_VALID(port); 879 EXPECT_VALID(port);
755 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 880 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
756 881
757 Array& service_msg = Array::Handle(); 882 Array& service_msg = Array::Handle();
758 883
759 // Request library. 884 // Request library.
760 service_msg = EvalF(h_lib, 885 service_msg = EvalF(lib,
761 "[0, port, ['libraries', '%" Pd "'], [], []]", lib_id); 886 "[0, port, ['libraries', '%" Pd "'], [], []]",
887 vmlib.index());
762 Service::HandleIsolateMessage(isolate, service_msg); 888 Service::HandleIsolateMessage(isolate, service_msg);
763 handler.HandleNextMessage(); 889 handler.HandleNextMessage();
764 EXPECT_SUBSTRING("\"type\":\"Library\"", handler.msg()); 890 EXPECT_SUBSTRING("\"type\":\"Library\"", handler.msg());
765 EXPECT_SUBSTRING("\"url\":\"test-lib\"", handler.msg()); 891 EXPECT_SUBSTRING("\"url\":\"test-lib\"", handler.msg());
766 892
767 // Evaluate an expression from a library. 893 // Evaluate an expression from a library.
768 service_msg = EvalF(h_lib, 894 service_msg = EvalF(lib,
769 "[0, port, ['libraries', '%" Pd "', 'eval'], " 895 "[0, port, ['libraries', '%" Pd "', 'eval'], "
770 "['expr'], ['libVar - 1']]", lib_id); 896 "['expr'], ['libVar - 1']]",
897 vmlib.index());
771 Service::HandleIsolateMessage(isolate, service_msg); 898 Service::HandleIsolateMessage(isolate, service_msg);
772 handler.HandleNextMessage(); 899 handler.HandleNextMessage();
773 handler.filterMsg("name"); 900 handler.filterMsg("name");
774 EXPECT_STREQ( 901 EXPECT_STREQ(
775 "{\"type\":\"@Smi\"," 902 "{\"type\":\"@Smi\","
776 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\"," 903 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\","
777 "\"user_name\":\"_Smi\"},\"id\":\"objects\\/int-54320\"," 904 "\"user_name\":\"_Smi\"},\"id\":\"objects\\/int-54320\","
778 "\"valueAsString\":\"54320\"}", 905 "\"valueAsString\":\"54320\"}",
779 handler.msg()); 906 handler.msg());
780 } 907 }
(...skipping 14 matching lines...) Expand all
795 "}\n" 922 "}\n"
796 "class B { static int i = 42; }\n" 923 "class B { static int i = 42; }\n"
797 "main() {\n" 924 "main() {\n"
798 " var z = new A();\n" 925 " var z = new A();\n"
799 " var x = z.c();\n" 926 " var x = z.c();\n"
800 " x();\n" 927 " x();\n"
801 " ++B.i;\n" 928 " ++B.i;\n"
802 "}"; 929 "}";
803 930
804 Isolate* isolate = Isolate::Current(); 931 Isolate* isolate = Isolate::Current();
805 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 932 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
806 EXPECT_VALID(h_lib); 933 EXPECT_VALID(lib);
807 Library& lib = Library::Handle(); 934 Library& vmlib = Library::Handle();
808 lib ^= Api::UnwrapHandle(h_lib); 935 vmlib ^= Api::UnwrapHandle(lib);
809 EXPECT(!lib.IsNull()); 936 EXPECT(!vmlib.IsNull());
810 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 937 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
811 EXPECT_VALID(result); 938 EXPECT_VALID(result);
812 const Class& class_a = Class::Handle(GetClass(lib, "A")); 939 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
813 EXPECT(!class_a.IsNull()); 940 EXPECT(!class_a.IsNull());
814 intptr_t cid = class_a.id(); 941 intptr_t cid = class_a.id();
815 942
816 // Build a mock message handler and wrap it in a dart port. 943 // Build a mock message handler and wrap it in a dart port.
817 ServiceTestMessageHandler handler; 944 ServiceTestMessageHandler handler;
818 Dart_Port port_id = PortMap::CreatePort(&handler); 945 Dart_Port port_id = PortMap::CreatePort(&handler);
819 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 946 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
820 EXPECT_VALID(port); 947 EXPECT_VALID(port);
821 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 948 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
822 949
823 Array& service_msg = Array::Handle(); 950 Array& service_msg = Array::Handle();
824 951
825 // Request an invalid class id. 952 // Request an invalid class id.
826 service_msg = Eval(h_lib, "[0, port, ['classes', '999999'], [], []]"); 953 service_msg = Eval(lib, "[0, port, ['classes', '999999'], [], []]");
827 Service::HandleIsolateMessage(isolate, service_msg); 954 Service::HandleIsolateMessage(isolate, service_msg);
828 handler.HandleNextMessage(); 955 handler.HandleNextMessage();
829 EXPECT_STREQ( 956 EXPECT_STREQ(
830 "{\"type\":\"Error\",\"id\":\"\"," 957 "{\"type\":\"Error\",\"id\":\"\","
831 "\"message\":\"999999 is not a valid class id.\"," 958 "\"message\":\"999999 is not a valid class id.\","
832 "\"request\":{\"arguments\":[\"classes\",\"999999\"]," 959 "\"request\":{\"arguments\":[\"classes\",\"999999\"],"
833 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); 960 "\"option_keys\":[],\"option_values\":[]}}", handler.msg());
834 961
835 // Request the class A over the service. 962 // Request the class A over the service.
836 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "'], [], []]", cid); 963 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "'], [], []]", cid);
837 Service::HandleIsolateMessage(isolate, service_msg); 964 Service::HandleIsolateMessage(isolate, service_msg);
838 handler.HandleNextMessage(); 965 handler.HandleNextMessage();
839 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); 966 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg());
840 ExpectSubstringF(handler.msg(), 967 ExpectSubstringF(handler.msg(),
841 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid); 968 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid);
842 ExpectSubstringF(handler.msg(), "\"allocationStats\":"); 969 ExpectSubstringF(handler.msg(), "\"allocationStats\":");
843 ExpectSubstringF(handler.msg(), "\"tokenPos\":"); 970 ExpectSubstringF(handler.msg(), "\"tokenPos\":");
844 ExpectSubstringF(handler.msg(), "\"endTokenPos\":"); 971 ExpectSubstringF(handler.msg(), "\"endTokenPos\":");
845 972
846 // Evaluate an expression from class A. 973 // Evaluate an expression from class A.
847 service_msg = EvalF(h_lib, 974 service_msg = EvalF(lib,
848 "[0, port, ['classes', '%" Pd "', 'eval'], " 975 "[0, port, ['classes', '%" Pd "', 'eval'], "
849 "['expr'], ['cobra + 100000']]", cid); 976 "['expr'], ['cobra + 100000']]", cid);
850 Service::HandleIsolateMessage(isolate, service_msg); 977 Service::HandleIsolateMessage(isolate, service_msg);
851 handler.HandleNextMessage(); 978 handler.HandleNextMessage();
852 handler.filterMsg("name"); 979 handler.filterMsg("name");
853 EXPECT_STREQ( 980 EXPECT_STREQ(
854 "{\"type\":\"@Smi\"," 981 "{\"type\":\"@Smi\","
855 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\"," 982 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/42\","
856 "\"user_name\":\"_Smi\"}," 983 "\"user_name\":\"_Smi\"},"
857 "\"id\":\"objects\\/int-111235\"," 984 "\"id\":\"objects\\/int-111235\","
858 "\"valueAsString\":\"111235\"}", 985 "\"valueAsString\":\"111235\"}",
859 handler.msg()); 986 handler.msg());
860 987
861 // Request function 0 from class A. 988 // Request function 0 from class A.
862 service_msg = EvalF(h_lib, 989 service_msg = EvalF(lib,
863 "[0, port, ['classes', '%" Pd "', 'functions', '0']," 990 "[0, port, ['classes', '%" Pd "', 'functions', '0'],"
864 "[], []]", cid); 991 "[], []]", cid);
865 Service::HandleIsolateMessage(isolate, service_msg); 992 Service::HandleIsolateMessage(isolate, service_msg);
866 handler.HandleNextMessage(); 993 handler.HandleNextMessage();
867 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg()); 994 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg());
868 ExpectSubstringF(handler.msg(), 995 ExpectSubstringF(handler.msg(),
869 "\"id\":\"classes\\/%" Pd "\\/functions\\/0\"," 996 "\"id\":\"classes\\/%" Pd "\\/functions\\/0\","
870 "\"name\":\"get:a\",", cid); 997 "\"name\":\"get:a\",", cid);
871 998
872 // Request field 0 from class A. 999 // Request field 0 from class A.
873 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'fields', '0']," 1000 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'fields', '0'],"
874 "[], []]", cid); 1001 "[], []]", cid);
875 Service::HandleIsolateMessage(isolate, service_msg); 1002 Service::HandleIsolateMessage(isolate, service_msg);
876 handler.HandleNextMessage(); 1003 handler.HandleNextMessage();
877 EXPECT_SUBSTRING("\"type\":\"Field\"", handler.msg()); 1004 EXPECT_SUBSTRING("\"type\":\"Field\"", handler.msg());
878 ExpectSubstringF(handler.msg(), 1005 ExpectSubstringF(handler.msg(),
879 "\"id\":\"classes\\/%" Pd "\\/fields\\/0\"," 1006 "\"id\":\"classes\\/%" Pd "\\/fields\\/0\","
880 "\"name\":\"a\",", cid); 1007 "\"name\":\"a\",", cid);
881 1008
882 // Invalid sub command. 1009 // Invalid sub command.
883 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'huh', '0']," 1010 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'huh', '0'],"
884 "[], []]", cid); 1011 "[], []]", cid);
885 Service::HandleIsolateMessage(isolate, service_msg); 1012 Service::HandleIsolateMessage(isolate, service_msg);
886 handler.HandleNextMessage(); 1013 handler.HandleNextMessage();
887 ExpectSubstringF(handler.msg(), 1014 ExpectSubstringF(handler.msg(),
888 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection huh\"" 1015 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection huh\""
889 ",\"request\":" 1016 ",\"request\":"
890 "{\"arguments\":[\"classes\",\"%" Pd "\",\"huh\",\"0\"],\"option_keys\":[]," 1017 "{\"arguments\":[\"classes\",\"%" Pd "\",\"huh\",\"0\"],\"option_keys\":[],"
891 "\"option_values\":[]}}", cid); 1018 "\"option_values\":[]}}", cid);
892 1019
893 // Invalid field request. 1020 // Invalid field request.
894 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'fields', '9']," 1021 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'fields', '9'],"
895 "[], []]", cid); 1022 "[], []]", cid);
896 Service::HandleIsolateMessage(isolate, service_msg); 1023 Service::HandleIsolateMessage(isolate, service_msg);
897 handler.HandleNextMessage(); 1024 handler.HandleNextMessage();
898 ExpectSubstringF(handler.msg(), 1025 ExpectSubstringF(handler.msg(),
899 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Field 9 not found\"," 1026 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Field 9 not found\","
900 "\"request\":{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\"]," 1027 "\"request\":{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\"],"
901 "\"option_keys\":[],\"option_values\":[]}}", cid); 1028 "\"option_keys\":[],\"option_values\":[]}}", cid);
902 1029
903 // Invalid function request. 1030 // Invalid function request.
904 service_msg = EvalF(h_lib, 1031 service_msg = EvalF(lib,
905 "[0, port, ['classes', '%" Pd "', 'functions', '9']," 1032 "[0, port, ['classes', '%" Pd "', 'functions', '9'],"
906 "[], []]", cid); 1033 "[], []]", cid);
907 Service::HandleIsolateMessage(isolate, service_msg); 1034 Service::HandleIsolateMessage(isolate, service_msg);
908 handler.HandleNextMessage(); 1035 handler.HandleNextMessage();
909 ExpectSubstringF(handler.msg(), 1036 ExpectSubstringF(handler.msg(),
910 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Function 9 not found\"," 1037 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Function 9 not found\","
911 "\"request\":{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"9\"]," 1038 "\"request\":{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"9\"],"
912 "\"option_keys\":[],\"option_values\":[]}}", cid); 1039 "\"option_keys\":[],\"option_values\":[]}}", cid);
913 1040
914 1041
915 // Invalid field subcommand. 1042 // Invalid field subcommand.
916 service_msg = EvalF(h_lib, 1043 service_msg = EvalF(lib,
917 "[0, port, ['classes', '%" Pd "', 'fields', '9', 'x']" 1044 "[0, port, ['classes', '%" Pd "', 'fields', '9', 'x']"
918 ",[], []]", cid); 1045 ",[], []]", cid);
919 Service::HandleIsolateMessage(isolate, service_msg); 1046 Service::HandleIsolateMessage(isolate, service_msg);
920 handler.HandleNextMessage(); 1047 handler.HandleNextMessage();
921 ExpectSubstringF(handler.msg(), 1048 ExpectSubstringF(handler.msg(),
922 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," 1049 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\","
923 "\"request\":" 1050 "\"request\":"
924 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"]," 1051 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"],"
925 "\"option_keys\":[],\"option_values\":[]}}", cid); 1052 "\"option_keys\":[],\"option_values\":[]}}", cid);
926 1053
927 // Invalid function command. 1054 // Invalid function command.
928 service_msg = EvalF(h_lib, 1055 service_msg = EvalF(lib,
929 "[0, port, ['classes', '%" Pd "', 'functions', '0'," 1056 "[0, port, ['classes', '%" Pd "', 'functions', '0',"
930 "'x', 'y'], [], []]", cid); 1057 "'x', 'y'], [], []]", cid);
931 Service::HandleIsolateMessage(isolate, service_msg); 1058 Service::HandleIsolateMessage(isolate, service_msg);
932 handler.HandleNextMessage(); 1059 handler.HandleNextMessage();
933 ExpectSubstringF(handler.msg(), 1060 ExpectSubstringF(handler.msg(),
934 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," 1061 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\","
935 "\"request\":" 1062 "\"request\":"
936 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\",\"y\"]," 1063 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\",\"y\"],"
937 "\"option_keys\":[],\"option_values\":[]}}", cid); 1064 "\"option_keys\":[],\"option_values\":[]}}", cid);
938 1065
939 // Invalid function subcommand with valid function id. 1066 // Invalid function subcommand with valid function id.
940 service_msg = EvalF(h_lib, 1067 service_msg = EvalF(lib,
941 "[0, port, ['classes', '%" Pd "', 'functions', '0'," 1068 "[0, port, ['classes', '%" Pd "', 'functions', '0',"
942 "'x'], [], []]", cid); 1069 "'x'], [], []]", cid);
943 Service::HandleIsolateMessage(isolate, service_msg); 1070 Service::HandleIsolateMessage(isolate, service_msg);
944 handler.HandleNextMessage(); 1071 handler.HandleNextMessage();
945 ExpectSubstringF(handler.msg(), 1072 ExpectSubstringF(handler.msg(),
946 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection x\"," 1073 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection x\","
947 "\"request\":" 1074 "\"request\":"
948 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\"]," 1075 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\"],"
949 "\"option_keys\":[],\"option_values\":[]}}", cid); 1076 "\"option_keys\":[],\"option_values\":[]}}", cid);
950 1077
951 // Retained size of all instances of class B. 1078 // Retained size of all instances of class B.
952 const Class& class_b = Class::Handle(GetClass(lib, "B")); 1079 const Class& class_b = Class::Handle(GetClass(vmlib, "B"));
953 EXPECT(!class_b.IsNull()); 1080 EXPECT(!class_b.IsNull());
954 const Instance& b0 = Instance::Handle(Instance::New(class_b)); 1081 const Instance& b0 = Instance::Handle(Instance::New(class_b));
955 const Instance& b1 = Instance::Handle(Instance::New(class_b)); 1082 const Instance& b1 = Instance::Handle(Instance::New(class_b));
956 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'retained']," 1083 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'retained'],"
957 "[], []]", class_b.id()); 1084 "[], []]", class_b.id());
958 Service::HandleIsolateMessage(isolate, service_msg); 1085 Service::HandleIsolateMessage(isolate, service_msg);
959 handler.HandleNextMessage(); 1086 handler.HandleNextMessage();
960 ExpectSubstringF(handler.msg(), 1087 ExpectSubstringF(handler.msg(),
961 "\"id\":\"objects\\/int-%" Pd "\"", 1088 "\"id\":\"objects\\/int-%" Pd "\"",
962 b0.raw()->Size() + b1.raw()->Size()); 1089 b0.raw()->Size() + b1.raw()->Size());
963 // ... and list the instances of class B. 1090 // ... and list the instances of class B.
964 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'instances']," 1091 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'instances'],"
965 "['limit'], ['3']]", class_b.id()); 1092 "['limit'], ['3']]", class_b.id());
966 Service::HandleIsolateMessage(isolate, service_msg); 1093 Service::HandleIsolateMessage(isolate, service_msg);
967 handler.HandleNextMessage(); 1094 handler.HandleNextMessage();
968 ExpectSubstringF(handler.msg(), "\"type\":\"InstanceSet\""); 1095 ExpectSubstringF(handler.msg(), "\"type\":\"InstanceSet\"");
969 ExpectSubstringF(handler.msg(), "\"totalCount\":2"); 1096 ExpectSubstringF(handler.msg(), "\"totalCount\":2");
970 ExpectSubstringF(handler.msg(), "\"sampleCount\":2"); 1097 ExpectSubstringF(handler.msg(), "\"sampleCount\":2");
971 // TODO(koda): Actually parse the response. 1098 // TODO(koda): Actually parse the response.
972 static const intptr_t kInstanceListId = 0; 1099 static const intptr_t kInstanceListId = 0;
973 ExpectSubstringF(handler.msg(), "\"id\":\"objects\\/%" Pd "\",\"length\":2", 1100 ExpectSubstringF(handler.msg(), "\"id\":\"objects\\/%" Pd "\",\"length\":2",
974 kInstanceListId); 1101 kInstanceListId);
975 Array& list = Array::Handle(); 1102 Array& list = Array::Handle();
976 list ^= isolate->object_id_ring()->GetObjectForId(kInstanceListId); 1103 list ^= isolate->object_id_ring()->GetObjectForId(kInstanceListId);
977 EXPECT_EQ(2, list.Length()); 1104 EXPECT_EQ(2, list.Length());
978 // The list should contain {b0, b1}. 1105 // The list should contain {b0, b1}.
979 EXPECT((list.At(0) == b0.raw() && list.At(1) == b1.raw()) || 1106 EXPECT((list.At(0) == b0.raw() && list.At(1) == b1.raw()) ||
980 (list.At(0) == b1.raw() && list.At(1) == b0.raw())); 1107 (list.At(0) == b1.raw() && list.At(1) == b0.raw()));
981 // ... and if limit is 1, we one get one of them. 1108 // ... and if limit is 1, we one get one of them.
982 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'instances']," 1109 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'instances'],"
983 "['limit'], ['1']]", class_b.id()); 1110 "['limit'], ['1']]", class_b.id());
984 Service::HandleIsolateMessage(isolate, service_msg); 1111 Service::HandleIsolateMessage(isolate, service_msg);
985 handler.HandleNextMessage(); 1112 handler.HandleNextMessage();
986 ExpectSubstringF(handler.msg(), "\"totalCount\":2"); 1113 ExpectSubstringF(handler.msg(), "\"totalCount\":2");
987 ExpectSubstringF(handler.msg(), "\"sampleCount\":1"); 1114 ExpectSubstringF(handler.msg(), "\"sampleCount\":1");
988 } 1115 }
989 1116
990 1117
991 TEST_CASE(Service_Types) { 1118 TEST_CASE(Service_Types) {
992 const char* kScript = 1119 const char* kScript =
993 "var port;\n" // Set to our mock port by C++. 1120 "var port;\n" // Set to our mock port by C++.
994 "\n" 1121 "\n"
995 "class A<T> { }\n" 1122 "class A<T> { }\n"
996 "\n" 1123 "\n"
997 "main() {\n" 1124 "main() {\n"
998 " new A<A<bool>>();\n" 1125 " new A<A<bool>>();\n"
999 "}"; 1126 "}";
1000 1127
1001 Isolate* isolate = Isolate::Current(); 1128 Isolate* isolate = Isolate::Current();
1002 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1129 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1003 EXPECT_VALID(h_lib); 1130 EXPECT_VALID(lib);
1004 Library& lib = Library::Handle(); 1131 Library& vmlib = Library::Handle();
1005 lib ^= Api::UnwrapHandle(h_lib); 1132 vmlib ^= Api::UnwrapHandle(lib);
1006 EXPECT(!lib.IsNull()); 1133 EXPECT(!vmlib.IsNull());
1007 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1134 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1008 EXPECT_VALID(result); 1135 EXPECT_VALID(result);
1009 const Class& class_a = Class::Handle(GetClass(lib, "A")); 1136 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
1010 EXPECT(!class_a.IsNull()); 1137 EXPECT(!class_a.IsNull());
1011 intptr_t cid = class_a.id(); 1138 intptr_t cid = class_a.id();
1012 1139
1013 // Build a mock message handler and wrap it in a dart port. 1140 // Build a mock message handler and wrap it in a dart port.
1014 ServiceTestMessageHandler handler; 1141 ServiceTestMessageHandler handler;
1015 Dart_Port port_id = PortMap::CreatePort(&handler); 1142 Dart_Port port_id = PortMap::CreatePort(&handler);
1016 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1143 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1017 EXPECT_VALID(port); 1144 EXPECT_VALID(port);
1018 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1145 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1019 1146
1020 Array& service_msg = Array::Handle(); 1147 Array& service_msg = Array::Handle();
1021 1148
1022 // Request the class A over the service. 1149 // Request the class A over the service.
1023 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "'], [], []]", cid); 1150 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "'], [], []]", cid);
1024 Service::HandleIsolateMessage(isolate, service_msg); 1151 Service::HandleIsolateMessage(isolate, service_msg);
1025 handler.HandleNextMessage(); 1152 handler.HandleNextMessage();
1026 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); 1153 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg());
1027 EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg()); 1154 EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg());
1028 ExpectSubstringF(handler.msg(), 1155 ExpectSubstringF(handler.msg(),
1029 "\"id\":\"classes\\/%" Pd "\"", cid); 1156 "\"id\":\"classes\\/%" Pd "\"", cid);
1030 1157
1031 // Request canonical type 0 from class A. 1158 // Request canonical type 0 from class A.
1032 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'types', '0']," 1159 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'types', '0'],"
1033 "[], []]", cid); 1160 "[], []]", cid);
1034 Service::HandleIsolateMessage(isolate, service_msg); 1161 Service::HandleIsolateMessage(isolate, service_msg);
1035 handler.HandleNextMessage(); 1162 handler.HandleNextMessage();
1036 EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg()); 1163 EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg());
1037 EXPECT_SUBSTRING("\"name\":\"A<bool>\"", handler.msg()); 1164 EXPECT_SUBSTRING("\"name\":\"A<bool>\"", handler.msg());
1038 ExpectSubstringF(handler.msg(), 1165 ExpectSubstringF(handler.msg(),
1039 "\"id\":\"classes\\/%" Pd "\\/types\\/0\"", cid); 1166 "\"id\":\"classes\\/%" Pd "\\/types\\/0\"", cid);
1040 1167
1041 // Request canonical type 1 from class A. 1168 // Request canonical type 1 from class A.
1042 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'types', '1']," 1169 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'types', '1'],"
1043 "[], []]", cid); 1170 "[], []]", cid);
1044 Service::HandleIsolateMessage(isolate, service_msg); 1171 Service::HandleIsolateMessage(isolate, service_msg);
1045 handler.HandleNextMessage(); 1172 handler.HandleNextMessage();
1046 EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg()); 1173 EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg());
1047 EXPECT_SUBSTRING("\"name\":\"A<A<bool>>\"", handler.msg()); 1174 EXPECT_SUBSTRING("\"name\":\"A<A<bool>>\"", handler.msg());
1048 ExpectSubstringF(handler.msg(), 1175 ExpectSubstringF(handler.msg(),
1049 "\"id\":\"classes\\/%" Pd "\\/types\\/1\"", cid); 1176 "\"id\":\"classes\\/%" Pd "\\/types\\/1\"", cid);
1050 1177
1051 // Request for non-existent canonical type from class A. 1178 // Request for non-existent canonical type from class A.
1052 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'types', '42']," 1179 service_msg = EvalF(lib, "[0, port, ['classes', '%" Pd "', 'types', '42'],"
1053 "[], []]", cid); 1180 "[], []]", cid);
1054 Service::HandleIsolateMessage(isolate, service_msg); 1181 Service::HandleIsolateMessage(isolate, service_msg);
1055 handler.HandleNextMessage(); 1182 handler.HandleNextMessage();
1056 ExpectSubstringF(handler.msg(), 1183 ExpectSubstringF(handler.msg(),
1057 "{\"type\":\"Error\",\"id\":\"\"," 1184 "{\"type\":\"Error\",\"id\":\"\","
1058 "\"message\":\"Canonical type 42 not found\"" 1185 "\"message\":\"Canonical type 42 not found\""
1059 ",\"request\":" 1186 ",\"request\":"
1060 "{\"arguments\":[\"classes\",\"%" Pd "\",\"types\",\"42\"]," 1187 "{\"arguments\":[\"classes\",\"%" Pd "\",\"types\",\"42\"],"
1061 "\"option_keys\":[],\"option_values\":[]}}", cid); 1188 "\"option_keys\":[],\"option_values\":[]}}", cid);
1062 1189
1063 // Request canonical type arguments. Expect <A<bool>> to be listed. 1190 // Request canonical type arguments. Expect <A<bool>> to be listed.
1064 service_msg = EvalF(h_lib, "[0, port, ['typearguments']," 1191 service_msg = EvalF(lib, "[0, port, ['typearguments'],"
1065 "[], []]"); 1192 "[], []]");
1066 Service::HandleIsolateMessage(isolate, service_msg); 1193 Service::HandleIsolateMessage(isolate, service_msg);
1067 handler.HandleNextMessage(); 1194 handler.HandleNextMessage();
1068 EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg()); 1195 EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg());
1069 ExpectSubstringF(handler.msg(), "\"name\":\"<A<bool>>\","); 1196 ExpectSubstringF(handler.msg(), "\"name\":\"<A<bool>>\",");
1070 1197
1071 // Request canonical type arguments with instantiations. 1198 // Request canonical type arguments with instantiations.
1072 service_msg = EvalF(h_lib, 1199 service_msg = EvalF(lib,
1073 "[0, port, ['typearguments', 'withinstantiations']," 1200 "[0, port, ['typearguments', 'withinstantiations'],"
1074 "[], []]"); 1201 "[], []]");
1075 Service::HandleIsolateMessage(isolate, service_msg); 1202 Service::HandleIsolateMessage(isolate, service_msg);
1076 handler.HandleNextMessage(); 1203 handler.HandleNextMessage();
1077 EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg()); 1204 EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg());
1078 } 1205 }
1079 1206
1080 1207
1081 TEST_CASE(Service_Code) { 1208 TEST_CASE(Service_Code) {
1082 const char* kScript = 1209 const char* kScript =
1083 "var port;\n" // Set to our mock port by C++. 1210 "var port;\n" // Set to our mock port by C++.
1084 "\n" 1211 "\n"
1085 "class A {\n" 1212 "class A {\n"
1086 " var a;\n" 1213 " var a;\n"
1087 " dynamic b() {}\n" 1214 " dynamic b() {}\n"
1088 " dynamic c() {\n" 1215 " dynamic c() {\n"
1089 " var d = () { b(); };\n" 1216 " var d = () { b(); };\n"
1090 " return d;\n" 1217 " return d;\n"
1091 " }\n" 1218 " }\n"
1092 "}\n" 1219 "}\n"
1093 "main() {\n" 1220 "main() {\n"
1094 " var z = new A();\n" 1221 " var z = new A();\n"
1095 " var x = z.c();\n" 1222 " var x = z.c();\n"
1096 " x();\n" 1223 " x();\n"
1097 "}"; 1224 "}";
1098 1225
1099 Isolate* isolate = Isolate::Current(); 1226 Isolate* isolate = Isolate::Current();
1100 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1227 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1101 EXPECT_VALID(h_lib); 1228 EXPECT_VALID(lib);
1102 Library& lib = Library::Handle(); 1229 Library& vmlib = Library::Handle();
1103 lib ^= Api::UnwrapHandle(h_lib); 1230 vmlib ^= Api::UnwrapHandle(lib);
1104 EXPECT(!lib.IsNull()); 1231 EXPECT(!vmlib.IsNull());
1105 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1232 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1106 EXPECT_VALID(result); 1233 EXPECT_VALID(result);
1107 const Class& class_a = Class::Handle(GetClass(lib, "A")); 1234 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
1108 EXPECT(!class_a.IsNull()); 1235 EXPECT(!class_a.IsNull());
1109 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); 1236 const Function& function_c = Function::Handle(GetFunction(class_a, "c"));
1110 EXPECT(!function_c.IsNull()); 1237 EXPECT(!function_c.IsNull());
1111 const Code& code_c = Code::Handle(function_c.CurrentCode()); 1238 const Code& code_c = Code::Handle(function_c.CurrentCode());
1112 EXPECT(!code_c.IsNull()); 1239 EXPECT(!code_c.IsNull());
1113 // Use the entry of the code object as it's reference. 1240 // Use the entry of the code object as it's reference.
1114 uword entry = code_c.EntryPoint(); 1241 uword entry = code_c.EntryPoint();
1115 int64_t compile_timestamp = code_c.compile_timestamp(); 1242 int64_t compile_timestamp = code_c.compile_timestamp();
1116 EXPECT_GT(code_c.Size(), 16); 1243 EXPECT_GT(code_c.Size(), 16);
1117 uword last = entry + code_c.Size(); 1244 uword last = entry + code_c.Size();
1118 1245
1119 // Build a mock message handler and wrap it in a dart port. 1246 // Build a mock message handler and wrap it in a dart port.
1120 ServiceTestMessageHandler handler; 1247 ServiceTestMessageHandler handler;
1121 Dart_Port port_id = PortMap::CreatePort(&handler); 1248 Dart_Port port_id = PortMap::CreatePort(&handler);
1122 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1249 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1123 EXPECT_VALID(port); 1250 EXPECT_VALID(port);
1124 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1251 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1125 1252
1126 Array& service_msg = Array::Handle(); 1253 Array& service_msg = Array::Handle();
1127 1254
1128 // Request an invalid code object. 1255 // Request an invalid code object.
1129 service_msg = Eval(h_lib, "[0, port, ['code', '0'], [], []]"); 1256 service_msg = Eval(lib, "[0, port, ['code', '0'], [], []]");
1130 Service::HandleIsolateMessage(isolate, service_msg); 1257 Service::HandleIsolateMessage(isolate, service_msg);
1131 handler.HandleNextMessage(); 1258 handler.HandleNextMessage();
1132 EXPECT_STREQ( 1259 EXPECT_STREQ(
1133 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Malformed code id: 0\"," 1260 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Malformed code id: 0\","
1134 "\"request\":{\"arguments\":[\"code\",\"0\"]," 1261 "\"request\":{\"arguments\":[\"code\",\"0\"],"
1135 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); 1262 "\"option_keys\":[],\"option_values\":[]}}", handler.msg());
1136 1263
1137 // The following test checks that a code object can be found only 1264 // The following test checks that a code object can be found only
1138 // at compile_timestamp()-code.EntryPoint(). 1265 // at compile_timestamp()-code.EntryPoint().
1139 service_msg = EvalF(h_lib, "[0, port, ['code', '%" Px64"-%" Px "'], [], []]", 1266 service_msg = EvalF(lib, "[0, port, ['code', '%" Px64"-%" Px "'], [], []]",
1140 compile_timestamp, 1267 compile_timestamp,
1141 entry); 1268 entry);
1142 Service::HandleIsolateMessage(isolate, service_msg); 1269 Service::HandleIsolateMessage(isolate, service_msg);
1143 handler.HandleNextMessage(); 1270 handler.HandleNextMessage();
1144 { 1271 {
1145 // Only perform a partial match. 1272 // Only perform a partial match.
1146 const intptr_t kBufferSize = 512; 1273 const intptr_t kBufferSize = 512;
1147 char buffer[kBufferSize]; 1274 char buffer[kBufferSize];
1148 OS::SNPrint(buffer, kBufferSize-1, 1275 OS::SNPrint(buffer, kBufferSize-1,
1149 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",", 1276 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",",
1150 compile_timestamp, 1277 compile_timestamp,
1151 entry); 1278 entry);
1152 EXPECT_SUBSTRING(buffer, handler.msg()); 1279 EXPECT_SUBSTRING(buffer, handler.msg());
1153 } 1280 }
1154 1281
1155 // Request code object at compile_timestamp-code.EntryPoint() + 16 1282 // Request code object at compile_timestamp-code.EntryPoint() + 16
1156 // Expect this to fail because the address is not the entry point. 1283 // Expect this to fail because the address is not the entry point.
1157 uintptr_t address = entry + 16; 1284 uintptr_t address = entry + 16;
1158 service_msg = EvalF(h_lib, "[0, port, ['code', '%" Px64"-%" Px "'], [], []]", 1285 service_msg = EvalF(lib, "[0, port, ['code', '%" Px64"-%" Px "'], [], []]",
1159 compile_timestamp, 1286 compile_timestamp,
1160 address); 1287 address);
1161 Service::HandleIsolateMessage(isolate, service_msg); 1288 Service::HandleIsolateMessage(isolate, service_msg);
1162 handler.HandleNextMessage(); 1289 handler.HandleNextMessage();
1163 { 1290 {
1164 // Only perform a partial match. 1291 // Only perform a partial match.
1165 const intptr_t kBufferSize = 512; 1292 const intptr_t kBufferSize = 512;
1166 char buffer[kBufferSize]; 1293 char buffer[kBufferSize];
1167 OS::SNPrint(buffer, kBufferSize-1, 1294 OS::SNPrint(buffer, kBufferSize-1,
1168 "Could not find code with id: %" Px64 "-%" Px "", 1295 "Could not find code with id: %" Px64 "-%" Px "",
1169 compile_timestamp, 1296 compile_timestamp,
1170 address); 1297 address);
1171 EXPECT_SUBSTRING(buffer, handler.msg()); 1298 EXPECT_SUBSTRING(buffer, handler.msg());
1172 } 1299 }
1173 1300
1174 // Request code object at (compile_timestamp - 1)-code.EntryPoint() 1301 // Request code object at (compile_timestamp - 1)-code.EntryPoint()
1175 // Expect this to fail because the timestamp is wrong. 1302 // Expect this to fail because the timestamp is wrong.
1176 address = entry; 1303 address = entry;
1177 service_msg = EvalF(h_lib, "[0, port, ['code', '%" Px64"-%" Px "'], [], []]", 1304 service_msg = EvalF(lib, "[0, port, ['code', '%" Px64"-%" Px "'], [], []]",
1178 compile_timestamp - 1, 1305 compile_timestamp - 1,
1179 address); 1306 address);
1180 Service::HandleIsolateMessage(isolate, service_msg); 1307 Service::HandleIsolateMessage(isolate, service_msg);
1181 handler.HandleNextMessage(); 1308 handler.HandleNextMessage();
1182 { 1309 {
1183 // Only perform a partial match. 1310 // Only perform a partial match.
1184 const intptr_t kBufferSize = 512; 1311 const intptr_t kBufferSize = 512;
1185 char buffer[kBufferSize]; 1312 char buffer[kBufferSize];
1186 OS::SNPrint(buffer, kBufferSize-1, 1313 OS::SNPrint(buffer, kBufferSize-1,
1187 "Could not find code with id: %" Px64 "-%" Px "", 1314 "Could not find code with id: %" Px64 "-%" Px "",
1188 compile_timestamp - 1, 1315 compile_timestamp - 1,
1189 address); 1316 address);
1190 EXPECT_SUBSTRING(buffer, handler.msg()); 1317 EXPECT_SUBSTRING(buffer, handler.msg());
1191 } 1318 }
1192 1319
1193 // Request native code at address. Expect the null code object back. 1320 // Request native code at address. Expect the null code object back.
1194 address = last; 1321 address = last;
1195 service_msg = EvalF(h_lib, "[0, port, ['code', 'native-%" Px "'], [], []]", 1322 service_msg = EvalF(lib, "[0, port, ['code', 'native-%" Px "'], [], []]",
1196 address); 1323 address);
1197 Service::HandleIsolateMessage(isolate, service_msg); 1324 Service::HandleIsolateMessage(isolate, service_msg);
1198 handler.HandleNextMessage(); 1325 handler.HandleNextMessage();
1199 EXPECT_STREQ("{\"type\":\"Null\",\"id\":\"objects\\/null\"," 1326 EXPECT_STREQ("{\"type\":\"Null\",\"id\":\"objects\\/null\","
1200 "\"valueAsString\":\"null\"}", 1327 "\"valueAsString\":\"null\"}",
1201 handler.msg()); 1328 handler.msg());
1202 1329
1203 // Request malformed native code. 1330 // Request malformed native code.
1204 service_msg = EvalF(h_lib, "[0, port, ['code', 'native%" Px "'], [], []]", 1331 service_msg = EvalF(lib, "[0, port, ['code', 'native%" Px "'], [], []]",
1205 address); 1332 address);
1206 Service::HandleIsolateMessage(isolate, service_msg); 1333 Service::HandleIsolateMessage(isolate, service_msg);
1207 handler.HandleNextMessage(); 1334 handler.HandleNextMessage();
1208 EXPECT_SUBSTRING("\"message\":\"Malformed code id:", handler.msg()); 1335 EXPECT_SUBSTRING("\"message\":\"Malformed code id:", handler.msg());
1209 } 1336 }
1210 1337
1211 1338
1212 TEST_CASE(Service_VM) { 1339 TEST_CASE(Service_VM) {
1213 const char* kScript = 1340 const char* kScript =
1214 "var port;\n" // Set to our mock port by C++. 1341 "var port;\n" // Set to our mock port by C++.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 1418
1292 1419
1293 TEST_CASE(Service_Scripts) { 1420 TEST_CASE(Service_Scripts) {
1294 const char* kScript = 1421 const char* kScript =
1295 "var port;\n" // Set to our mock port by C++. 1422 "var port;\n" // Set to our mock port by C++.
1296 "\n" 1423 "\n"
1297 "main() {\n" 1424 "main() {\n"
1298 "}"; 1425 "}";
1299 1426
1300 Isolate* isolate = Isolate::Current(); 1427 Isolate* isolate = Isolate::Current();
1301 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1428 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1302 EXPECT_VALID(h_lib); 1429 EXPECT_VALID(lib);
1303 Library& lib = Library::Handle(); 1430 Library& vmlib = Library::Handle();
1304 lib ^= Api::UnwrapHandle(h_lib); 1431 vmlib ^= Api::UnwrapHandle(lib);
1305 EXPECT(!lib.IsNull()); 1432 EXPECT(!vmlib.IsNull());
1306 1433
1307 // Build a mock message handler and wrap it in a dart port. 1434 // Build a mock message handler and wrap it in a dart port.
1308 ServiceTestMessageHandler handler; 1435 ServiceTestMessageHandler handler;
1309 Dart_Port port_id = PortMap::CreatePort(&handler); 1436 Dart_Port port_id = PortMap::CreatePort(&handler);
1310 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1437 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1311 EXPECT_VALID(port); 1438 EXPECT_VALID(port);
1312 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1439 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1313 1440
1314 Array& service_msg = Array::Handle(); 1441 Array& service_msg = Array::Handle();
1315 char buf[1024]; 1442 char buf[1024];
1316 OS::SNPrint(buf, sizeof(buf), 1443 OS::SNPrint(buf, sizeof(buf),
1317 "[0, port, ['libraries', '%" Pd "', 'scripts', 'test-lib'], [], []]", 1444 "[0, port, ['libraries', '%" Pd "', 'scripts', 'test-lib'], [], []]",
1318 lib.index()); 1445 vmlib.index());
1319 1446
1320 service_msg = Eval(h_lib, buf); 1447 service_msg = Eval(lib, buf);
1321 Service::HandleIsolateMessage(isolate, service_msg); 1448 Service::HandleIsolateMessage(isolate, service_msg);
1322 handler.HandleNextMessage(); 1449 handler.HandleNextMessage();
1323 OS::SNPrint(buf, sizeof(buf), 1450 OS::SNPrint(buf, sizeof(buf),
1324 "{\"type\":\"Script\"," 1451 "{\"type\":\"Script\","
1325 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," 1452 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
1326 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1453 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1327 "\"kind\":\"script\"," 1454 "\"kind\":\"script\","
1328 "\"owning_library\":{\"type\":\"@Library\"," 1455 "\"owning_library\":{\"type\":\"@Library\","
1329 "\"id\":\"libraries\\/%" Pd "\",\"user_name\":\"\",\"name\":\"\"," 1456 "\"id\":\"libraries\\/%" Pd "\",\"user_name\":\"\",\"name\":\"\","
1330 "\"url\":\"test-lib\"}," 1457 "\"url\":\"test-lib\"},"
1331 "\"source\":\"var port;\\n\\nmain() {\\n}\"," 1458 "\"source\":\"var port;\\n\\nmain() {\\n}\","
1332 "\"tokenPosTable\":[[1,0,1,1,5,2,9],[3,5,1,6,5,7,6,8,8],[4,10,1]]}", 1459 "\"tokenPosTable\":[[1,0,1,1,5,2,9],[3,5,1,6,5,7,6,8,8],[4,10,1]]}",
1333 lib.index(), lib.index()); 1460 vmlib.index(), vmlib.index());
1334 EXPECT_STREQ(buf, handler.msg()); 1461 EXPECT_STREQ(buf, handler.msg());
1335 } 1462 }
1336 1463
1337 1464
1338 // TODO(zra): Remove when tests are ready to enable. 1465 // TODO(zra): Remove when tests are ready to enable.
1339 #if !defined(TARGET_ARCH_ARM64) 1466 #if !defined(TARGET_ARCH_ARM64)
1340 1467
1341 TEST_CASE(Service_Coverage) { 1468 TEST_CASE(Service_Coverage) {
1342 const char* kScript = 1469 const char* kScript =
1343 "var port;\n" // Set to our mock port by C++. 1470 "var port;\n" // Set to our mock port by C++.
1344 "\n" 1471 "\n"
1345 "var x = 7;\n" 1472 "var x = 7;\n"
1346 "main() {\n" 1473 "main() {\n"
1347 " x = x * x;\n" 1474 " x = x * x;\n"
1348 " x = x / 13;\n" 1475 " x = x / 13;\n"
1349 "}"; 1476 "}";
1350 1477
1351 Isolate* isolate = Isolate::Current(); 1478 Isolate* isolate = Isolate::Current();
1352 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1479 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1353 EXPECT_VALID(h_lib); 1480 EXPECT_VALID(lib);
1354 Library& lib = Library::Handle(); 1481 Library& vmlib = Library::Handle();
1355 lib ^= Api::UnwrapHandle(h_lib); 1482 vmlib ^= Api::UnwrapHandle(lib);
1356 EXPECT(!lib.IsNull()); 1483 EXPECT(!vmlib.IsNull());
1357 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1484 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1358 EXPECT_VALID(result); 1485 EXPECT_VALID(result);
1359 1486
1360 // Build a mock message handler and wrap it in a dart port. 1487 // Build a mock message handler and wrap it in a dart port.
1361 ServiceTestMessageHandler handler; 1488 ServiceTestMessageHandler handler;
1362 Dart_Port port_id = PortMap::CreatePort(&handler); 1489 Dart_Port port_id = PortMap::CreatePort(&handler);
1363 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1490 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1364 EXPECT_VALID(port); 1491 EXPECT_VALID(port);
1365 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1492 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1366 1493
1367 Array& service_msg = Array::Handle(); 1494 Array& service_msg = Array::Handle();
1368 service_msg = Eval(h_lib, "[0, port, ['coverage'], [], []]"); 1495 service_msg = Eval(lib, "[0, port, ['coverage'], [], []]");
1369 Service::HandleIsolateMessage(isolate, service_msg); 1496 Service::HandleIsolateMessage(isolate, service_msg);
1370 handler.HandleNextMessage(); 1497 handler.HandleNextMessage();
1371 1498
1372 // Look up the service id for the library containg the test-lib script.
1373 const GrowableObjectArray& libs =
1374 GrowableObjectArray::Handle(isolate->object_store()->libraries());
1375 intptr_t i;
1376 for (i = 0; i < libs.Length(); i++) {
1377 if (libs.At(i) == lib.raw()) {
1378 break;
1379 }
1380 }
1381 ASSERT(i != libs.Length());
1382
1383 char buf[1024]; 1499 char buf[1024];
1384 OS::SNPrint(buf, sizeof(buf), 1500 OS::SNPrint(buf, sizeof(buf),
1385 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," 1501 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\","
1386 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," 1502 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
1387 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1503 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1388 "\"kind\":\"script\"},\"hits\":" 1504 "\"kind\":\"script\"},\"hits\":"
1389 "[5,1,6,1]}", i); 1505 "[5,1,6,1]}",
1506 vmlib.index());
1390 EXPECT_SUBSTRING(buf, handler.msg()); 1507 EXPECT_SUBSTRING(buf, handler.msg());
1391 } 1508 }
1392 1509
1393 1510
1394 TEST_CASE(Service_LibrariesScriptsCoverage) { 1511 TEST_CASE(Service_LibrariesScriptsCoverage) {
1395 const char* kScript = 1512 const char* kScript =
1396 "var port;\n" // Set to our mock port by C++. 1513 "var port;\n" // Set to our mock port by C++.
1397 "\n" 1514 "\n"
1398 "var x = 7;\n" 1515 "var x = 7;\n"
1399 "main() {\n" 1516 "main() {\n"
1400 " x = x * x;\n" 1517 " x = x * x;\n"
1401 " x = x / 13;\n" 1518 " x = x / 13;\n"
1402 "}"; 1519 "}";
1403 1520
1404 Isolate* isolate = Isolate::Current(); 1521 Isolate* isolate = Isolate::Current();
1405 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1522 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1406 EXPECT_VALID(h_lib); 1523 EXPECT_VALID(lib);
1407 Library& lib = Library::Handle(); 1524 Library& vmlib = Library::Handle();
1408 lib ^= Api::UnwrapHandle(h_lib); 1525 vmlib ^= Api::UnwrapHandle(lib);
1409 EXPECT(!lib.IsNull()); 1526 EXPECT(!vmlib.IsNull());
1410 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1527 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1411 EXPECT_VALID(result); 1528 EXPECT_VALID(result);
1412 1529
1413 // Build a mock message handler and wrap it in a dart port. 1530 // Build a mock message handler and wrap it in a dart port.
1414 ServiceTestMessageHandler handler; 1531 ServiceTestMessageHandler handler;
1415 Dart_Port port_id = PortMap::CreatePort(&handler); 1532 Dart_Port port_id = PortMap::CreatePort(&handler);
1416 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1533 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1417 EXPECT_VALID(port); 1534 EXPECT_VALID(port);
1418 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1535 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1419 1536
1420 Array& service_msg = Array::Handle(); 1537 Array& service_msg = Array::Handle();
1421 char buf[1024]; 1538 char buf[1024];
1422 OS::SNPrint(buf, sizeof(buf), 1539 OS::SNPrint(buf, sizeof(buf),
1423 "[0, port, ['libraries', '%" Pd "', 'scripts', 'test-lib', 'coverage'], " 1540 "[0, port, ['libraries', '%" Pd "', 'scripts', 'test-lib', 'coverage'], "
1424 "[], []]", 1541 "[], []]",
1425 lib.index()); 1542 vmlib.index());
1426 1543
1427 service_msg = Eval(h_lib, buf); 1544 service_msg = Eval(lib, buf);
1428 Service::HandleIsolateMessage(isolate, service_msg); 1545 Service::HandleIsolateMessage(isolate, service_msg);
1429 handler.HandleNextMessage(); 1546 handler.HandleNextMessage();
1430 OS::SNPrint(buf, sizeof(buf), 1547 OS::SNPrint(buf, sizeof(buf),
1431 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" 1548 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1432 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," 1549 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\","
1433 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," 1550 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
1434 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1551 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1435 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", lib.index()); 1552 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", vmlib.index());
1436 EXPECT_STREQ(buf, handler.msg()); 1553 EXPECT_STREQ(buf, handler.msg());
1437 } 1554 }
1438 1555
1439 1556
1440 TEST_CASE(Service_LibrariesCoverage) { 1557 TEST_CASE(Service_LibrariesCoverage) {
1441 const char* kScript = 1558 const char* kScript =
1442 "var port;\n" // Set to our mock port by C++. 1559 "var port;\n" // Set to our mock port by C++.
1443 "\n" 1560 "\n"
1444 "var x = 7;\n" 1561 "var x = 7;\n"
1445 "main() {\n" 1562 "main() {\n"
1446 " x = x * x;\n" 1563 " x = x * x;\n"
1447 " x = x / 13;\n" 1564 " x = x / 13;\n"
1448 "}"; 1565 "}";
1449 1566
1450 Isolate* isolate = Isolate::Current(); 1567 Isolate* isolate = Isolate::Current();
1451 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1568 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1452 EXPECT_VALID(h_lib); 1569 EXPECT_VALID(lib);
1453 Library& lib = Library::Handle(); 1570 Library& vmlib = Library::Handle();
1454 lib ^= Api::UnwrapHandle(h_lib); 1571 vmlib ^= Api::UnwrapHandle(lib);
1455 EXPECT(!lib.IsNull()); 1572 EXPECT(!vmlib.IsNull());
1456 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1573 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1457 EXPECT_VALID(result); 1574 EXPECT_VALID(result);
1458 1575
1459 // Build a mock message handler and wrap it in a dart port. 1576 // Build a mock message handler and wrap it in a dart port.
1460 ServiceTestMessageHandler handler; 1577 ServiceTestMessageHandler handler;
1461 Dart_Port port_id = PortMap::CreatePort(&handler); 1578 Dart_Port port_id = PortMap::CreatePort(&handler);
1462 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1579 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1463 EXPECT_VALID(port); 1580 EXPECT_VALID(port);
1464 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1581 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1465 1582
1466 // Look up the service id for the library containg the test-lib script.
1467 const GrowableObjectArray& libs =
1468 GrowableObjectArray::Handle(isolate->object_store()->libraries());
1469 intptr_t i;
1470 for (i = 0; i < libs.Length(); i++) {
1471 if (libs.At(i) == lib.raw()) {
1472 break;
1473 }
1474 }
1475 ASSERT(i != libs.Length());
1476 char buf[1024]; 1583 char buf[1024];
1477 OS::SNPrint(buf, sizeof(buf), 1584 OS::SNPrint(buf, sizeof(buf),
1478 "[0, port, ['libraries', '%" Pd "', 'coverage'], [], []]", i); 1585 "[0, port, ['libraries', '%" Pd "', 'coverage'], [], []]",
1586 vmlib.index());
1479 1587
1480 Array& service_msg = Array::Handle(); 1588 Array& service_msg = Array::Handle();
1481 service_msg = Eval(h_lib, buf); 1589 service_msg = Eval(lib, buf);
1482 Service::HandleIsolateMessage(isolate, service_msg); 1590 Service::HandleIsolateMessage(isolate, service_msg);
1483 handler.HandleNextMessage(); 1591 handler.HandleNextMessage();
1484 OS::SNPrint(buf, sizeof(buf), 1592 OS::SNPrint(buf, sizeof(buf),
1485 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" 1593 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1486 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," 1594 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\","
1487 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," 1595 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
1488 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1596 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1489 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", lib.index()); 1597 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}",
1598 vmlib.index());
1490 EXPECT_STREQ(buf, handler.msg()); 1599 EXPECT_STREQ(buf, handler.msg());
1491 } 1600 }
1492 1601
1493 1602
1494 TEST_CASE(Service_ClassesCoverage) { 1603 TEST_CASE(Service_ClassesCoverage) {
1495 const char* kScript = 1604 const char* kScript =
1496 "var port;\n" // Set to our mock port by C++. 1605 "var port;\n" // Set to our mock port by C++.
1497 "\n" 1606 "\n"
1498 "class Foo {\n" 1607 "class Foo {\n"
1499 " var x;\n" 1608 " var x;\n"
1500 " Foo(this.x);\n" 1609 " Foo(this.x);\n"
1501 " bar() {\n" 1610 " bar() {\n"
1502 " x = x * x;\n" 1611 " x = x * x;\n"
1503 " x = x / 13;\n" 1612 " x = x / 13;\n"
1504 " }\n" 1613 " }\n"
1505 "}\n" 1614 "}\n"
1506 "main() {\n" 1615 "main() {\n"
1507 " var foo = new Foo(7);\n" 1616 " var foo = new Foo(7);\n"
1508 " foo.bar();\n" 1617 " foo.bar();\n"
1509 "}"; 1618 "}";
1510 1619
1511 Isolate* isolate = Isolate::Current(); 1620 Isolate* isolate = Isolate::Current();
1512 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1621 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1513 EXPECT_VALID(h_lib); 1622 EXPECT_VALID(lib);
1514 Library& lib = Library::Handle(); 1623 Library& vmlib = Library::Handle();
1515 lib ^= Api::UnwrapHandle(h_lib); 1624 vmlib ^= Api::UnwrapHandle(lib);
1516 EXPECT(!lib.IsNull()); 1625 EXPECT(!vmlib.IsNull());
1517 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1626 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1518 EXPECT_VALID(result); 1627 EXPECT_VALID(result);
1519 1628
1520 // Build a mock message handler and wrap it in a dart port. 1629 // Build a mock message handler and wrap it in a dart port.
1521 ServiceTestMessageHandler handler; 1630 ServiceTestMessageHandler handler;
1522 Dart_Port port_id = PortMap::CreatePort(&handler); 1631 Dart_Port port_id = PortMap::CreatePort(&handler);
1523 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1632 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1524 EXPECT_VALID(port); 1633 EXPECT_VALID(port);
1525 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1634 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1526 1635
1527 // Look up the service id of Foo. 1636 // Look up the service id of Foo.
1528 const Class& cls = Class::Handle( 1637 const Class& cls = Class::Handle(
1529 lib.LookupClass(String::Handle(String::New("Foo")))); 1638 vmlib.LookupClass(String::Handle(String::New("Foo"))));
1530 ASSERT(!cls.IsNull()); 1639 ASSERT(!cls.IsNull());
1531 ClassTable* table = isolate->class_table(); 1640 ClassTable* table = isolate->class_table();
1532 intptr_t i; 1641 intptr_t i;
1533 for (i = 1; i < table->NumCids(); i++) { 1642 for (i = 1; i < table->NumCids(); i++) {
1534 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) { 1643 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) {
1535 break; 1644 break;
1536 } 1645 }
1537 } 1646 }
1538 ASSERT(i != table->NumCids()); 1647 ASSERT(i != table->NumCids());
1539 char buf[1024]; 1648 char buf[1024];
1540 OS::SNPrint(buf, sizeof(buf), 1649 OS::SNPrint(buf, sizeof(buf),
1541 "[0, port, ['classes', '%" Pd "', 'coverage'], [], []]", i); 1650 "[0, port, ['classes', '%" Pd "', 'coverage'], [], []]", i);
1542 1651
1543 Array& service_msg = Array::Handle(); 1652 Array& service_msg = Array::Handle();
1544 service_msg = Eval(h_lib, buf); 1653 service_msg = Eval(lib, buf);
1545 Service::HandleIsolateMessage(isolate, service_msg); 1654 Service::HandleIsolateMessage(isolate, service_msg);
1546 handler.HandleNextMessage(); 1655 handler.HandleNextMessage();
1547 OS::SNPrint(buf, sizeof(buf), 1656 OS::SNPrint(buf, sizeof(buf),
1548 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" 1657 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1549 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," 1658 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\","
1550 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," 1659 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
1551 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1660 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1552 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}", lib.index()); 1661 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}",
1662 vmlib.index());
1553 EXPECT_STREQ(buf, handler.msg()); 1663 EXPECT_STREQ(buf, handler.msg());
1554 } 1664 }
1555 1665
1556 1666
1557 TEST_CASE(Service_ClassesFunctionsCoverage) { 1667 TEST_CASE(Service_ClassesFunctionsCoverage) {
1558 const char* kScript = 1668 const char* kScript =
1559 "var port;\n" // Set to our mock port by C++. 1669 "var port;\n" // Set to our mock port by C++.
1560 "\n" 1670 "\n"
1561 "class Foo {\n" 1671 "class Foo {\n"
1562 " var x;\n" 1672 " var x;\n"
1563 " Foo(this.x);\n" 1673 " Foo(this.x);\n"
1564 " bar() {\n" 1674 " bar() {\n"
1565 " x = x * x;\n" 1675 " x = x * x;\n"
1566 " x = x / 13;\n" 1676 " x = x / 13;\n"
1567 " }\n" 1677 " }\n"
1568 " badum(var a) => 4 + a;\n" 1678 " badum(var a) => 4 + a;\n"
1569 "}\n" 1679 "}\n"
1570 "main() {\n" 1680 "main() {\n"
1571 " var foo = new Foo(7);\n" 1681 " var foo = new Foo(7);\n"
1572 " foo.bar();\n" 1682 " foo.bar();\n"
1573 "}"; 1683 "}";
1574 1684
1575 Isolate* isolate = Isolate::Current(); 1685 Isolate* isolate = Isolate::Current();
1576 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1686 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1577 EXPECT_VALID(h_lib); 1687 EXPECT_VALID(lib);
1578 Library& lib = Library::Handle(); 1688 Library& vmlib = Library::Handle();
1579 lib ^= Api::UnwrapHandle(h_lib); 1689 vmlib ^= Api::UnwrapHandle(lib);
1580 EXPECT(!lib.IsNull()); 1690 EXPECT(!vmlib.IsNull());
1581 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); 1691 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1582 EXPECT_VALID(result); 1692 EXPECT_VALID(result);
1583 1693
1584 // Build a mock message handler and wrap it in a dart port. 1694 // Build a mock message handler and wrap it in a dart port.
1585 ServiceTestMessageHandler handler; 1695 ServiceTestMessageHandler handler;
1586 Dart_Port port_id = PortMap::CreatePort(&handler); 1696 Dart_Port port_id = PortMap::CreatePort(&handler);
1587 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1697 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1588 EXPECT_VALID(port); 1698 EXPECT_VALID(port);
1589 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1699 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1590 1700
1591 // Look up the service id of Foo. 1701 // Look up the service id of Foo.
1592 const Class& cls = Class::Handle( 1702 const Class& cls = Class::Handle(
1593 lib.LookupClass(String::Handle(String::New("Foo")))); 1703 vmlib.LookupClass(String::Handle(String::New("Foo"))));
1594 ASSERT(!cls.IsNull()); 1704 ASSERT(!cls.IsNull());
1595 ClassTable* table = isolate->class_table(); 1705 ClassTable* table = isolate->class_table();
1596 intptr_t i; 1706 intptr_t i;
1597 for (i = 1; i < table->NumCids(); i++) { 1707 for (i = 1; i < table->NumCids(); i++) {
1598 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) { 1708 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) {
1599 break; 1709 break;
1600 } 1710 }
1601 } 1711 }
1602 ASSERT(i != table->NumCids()); 1712 ASSERT(i != table->NumCids());
1603 1713
1604 // Look up the service if of the function Foo.bar. 1714 // Look up the service if of the function Foo.bar.
1605 const Function& func = Function::Handle( 1715 const Function& func = Function::Handle(
1606 cls.LookupFunction(String::Handle(String::New("bar")))); 1716 cls.LookupFunction(String::Handle(String::New("bar"))));
1607 ASSERT(!func.IsNull()); 1717 ASSERT(!func.IsNull());
1608 intptr_t function_id = -1; 1718 intptr_t function_id = -1;
1609 function_id = cls.FindFunctionIndex(func); 1719 function_id = cls.FindFunctionIndex(func);
1610 ASSERT(function_id != -1); 1720 ASSERT(function_id != -1);
1611 1721
1612 char buf[1024]; 1722 char buf[1024];
1613 OS::SNPrint(buf, sizeof(buf), 1723 OS::SNPrint(buf, sizeof(buf),
1614 "[0, port, ['classes', '%" Pd "', 'functions'," 1724 "[0, port, ['classes', '%" Pd "', 'functions',"
1615 "'% " Pd "', 'coverage'], [], []]", i, function_id); 1725 "'% " Pd "', 'coverage'], [], []]", i, function_id);
1616 1726
1617 Array& service_msg = Array::Handle(); 1727 Array& service_msg = Array::Handle();
1618 service_msg = Eval(h_lib, buf); 1728 service_msg = Eval(lib, buf);
1619 Service::HandleIsolateMessage(isolate, service_msg); 1729 Service::HandleIsolateMessage(isolate, service_msg);
1620 handler.HandleNextMessage(); 1730 handler.HandleNextMessage();
1621 OS::SNPrint(buf, sizeof(buf), 1731 OS::SNPrint(buf, sizeof(buf),
1622 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" 1732 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1623 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\"," 1733 "{\"source\":\"test-lib\",\"script\":{\"type\":\"@Script\","
1624 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," 1734 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\","
1625 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1735 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1626 "\"kind\":\"script\"},\"hits\":[7,4,8,3]}]}", lib.index()); 1736 "\"kind\":\"script\"},\"hits\":[7,4,8,3]}]}", vmlib.index());
1627 EXPECT_STREQ(buf, handler.msg()); 1737 EXPECT_STREQ(buf, handler.msg());
1628 } 1738 }
1629 1739
1630 #endif 1740 #endif
1631 1741
1632 1742
1633 TEST_CASE(Service_AllocationProfile) { 1743 TEST_CASE(Service_AllocationProfile) {
1634 const char* kScript = 1744 const char* kScript =
1635 "var port;\n" // Set to our mock port by C++. 1745 "var port;\n" // Set to our mock port by C++.
1636 "\n" 1746 "\n"
1637 "var x = 7;\n" 1747 "var x = 7;\n"
1638 "main() {\n" 1748 "main() {\n"
1639 " x = x * x;\n" 1749 " x = x * x;\n"
1640 " x = x / 13;\n" 1750 " x = x / 13;\n"
1641 "}"; 1751 "}";
1642 1752
1643 Isolate* isolate = Isolate::Current(); 1753 Isolate* isolate = Isolate::Current();
1644 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 1754 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1645 EXPECT_VALID(h_lib); 1755 EXPECT_VALID(lib);
1646 Library& lib = Library::Handle(); 1756 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1647 lib ^= Api::UnwrapHandle(h_lib);
1648 EXPECT(!lib.IsNull());
1649 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
1650 EXPECT_VALID(result); 1757 EXPECT_VALID(result);
1651 1758
1652 // Build a mock message handler and wrap it in a dart port. 1759 // Build a mock message handler and wrap it in a dart port.
1653 ServiceTestMessageHandler handler; 1760 ServiceTestMessageHandler handler;
1654 Dart_Port port_id = PortMap::CreatePort(&handler); 1761 Dart_Port port_id = PortMap::CreatePort(&handler);
1655 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 1762 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1656 EXPECT_VALID(port); 1763 EXPECT_VALID(port);
1657 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 1764 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1658 1765
1659 Array& service_msg = Array::Handle(); 1766 Array& service_msg = Array::Handle();
1660 service_msg = Eval(h_lib, "[0, port, ['allocationprofile'], [], []]"); 1767 service_msg = Eval(lib, "[0, port, ['allocationprofile'], [], []]");
1661 Service::HandleIsolateMessage(isolate, service_msg); 1768 Service::HandleIsolateMessage(isolate, service_msg);
1662 handler.HandleNextMessage(); 1769 handler.HandleNextMessage();
1663 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); 1770 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg());
1664 1771
1665 // Too long. 1772 // Too long.
1666 service_msg = Eval(h_lib, "[0, port, ['allocationprofile', 'foo'], [], []]"); 1773 service_msg = Eval(lib, "[0, port, ['allocationprofile', 'foo'], [], []]");
1667 Service::HandleIsolateMessage(isolate, service_msg); 1774 Service::HandleIsolateMessage(isolate, service_msg);
1668 handler.HandleNextMessage(); 1775 handler.HandleNextMessage();
1669 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 1776 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1670 1777
1671 // Bad gc option. 1778 // Bad gc option.
1672 service_msg = Eval(h_lib, 1779 service_msg = Eval(lib,
1673 "[0, port, ['allocationprofile'], ['gc'], ['cat']]"); 1780 "[0, port, ['allocationprofile'], ['gc'], ['cat']]");
1674 Service::HandleIsolateMessage(isolate, service_msg); 1781 Service::HandleIsolateMessage(isolate, service_msg);
1675 handler.HandleNextMessage(); 1782 handler.HandleNextMessage();
1676 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 1783 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1677 1784
1678 // Bad reset option. 1785 // Bad reset option.
1679 service_msg = Eval(h_lib, 1786 service_msg = Eval(lib,
1680 "[0, port, ['allocationprofile'], ['reset'], ['ff']]"); 1787 "[0, port, ['allocationprofile'], ['reset'], ['ff']]");
1681 Service::HandleIsolateMessage(isolate, service_msg); 1788 Service::HandleIsolateMessage(isolate, service_msg);
1682 handler.HandleNextMessage(); 1789 handler.HandleNextMessage();
1683 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 1790 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1684 1791
1685 // Good reset. 1792 // Good reset.
1686 service_msg = 1793 service_msg =
1687 Eval(h_lib, "[0, port, ['allocationprofile'], ['reset'], ['true']]"); 1794 Eval(lib, "[0, port, ['allocationprofile'], ['reset'], ['true']]");
1688 Service::HandleIsolateMessage(isolate, service_msg); 1795 Service::HandleIsolateMessage(isolate, service_msg);
1689 handler.HandleNextMessage(); 1796 handler.HandleNextMessage();
1690 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); 1797 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg());
1691 1798
1692 // Good GC. 1799 // Good GC.
1693 service_msg = 1800 service_msg =
1694 Eval(h_lib, "[0, port, ['allocationprofile'], ['gc'], ['full']]"); 1801 Eval(lib, "[0, port, ['allocationprofile'], ['gc'], ['full']]");
1695 Service::HandleIsolateMessage(isolate, service_msg); 1802 Service::HandleIsolateMessage(isolate, service_msg);
1696 handler.HandleNextMessage(); 1803 handler.HandleNextMessage();
1697 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); 1804 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg());
1698 1805
1699 // Good GC and reset. 1806 // Good GC and reset.
1700 service_msg = Eval(h_lib, 1807 service_msg = Eval(lib,
1701 "[0, port, ['allocationprofile'], ['gc', 'reset'], ['full', 'true']]"); 1808 "[0, port, ['allocationprofile'], ['gc', 'reset'], ['full', 'true']]");
1702 Service::HandleIsolateMessage(isolate, service_msg); 1809 Service::HandleIsolateMessage(isolate, service_msg);
1703 handler.HandleNextMessage(); 1810 handler.HandleNextMessage();
1704 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); 1811 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg());
1705 } 1812 }
1706 1813
1707 1814
1708 TEST_CASE(Service_HeapMap) { 1815 TEST_CASE(Service_HeapMap) {
1709 const char* kScript = 1816 const char* kScript =
1710 "var port;\n" // Set to our mock port by C++. 1817 "var port;\n" // Set to our mock port by C++.
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 const char* kScript = 1991 const char* kScript =
1885 "var port;\n" // Set to our mock port by C++. 1992 "var port;\n" // Set to our mock port by C++.
1886 "\n" 1993 "\n"
1887 "var x = 7;\n" 1994 "var x = 7;\n"
1888 "main() {\n" 1995 "main() {\n"
1889 " x = x * x;\n" 1996 " x = x * x;\n"
1890 " x = x / 13;\n" 1997 " x = x / 13;\n"
1891 "}"; 1998 "}";
1892 1999
1893 Isolate* isolate = Isolate::Current(); 2000 Isolate* isolate = Isolate::Current();
1894 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); 2001 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
1895 EXPECT_VALID(h_lib); 2002 EXPECT_VALID(lib);
1896 Library& lib = Library::Handle(); 2003 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
1897 lib ^= Api::UnwrapHandle(h_lib);
1898 EXPECT(!lib.IsNull());
1899 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
1900 EXPECT_VALID(result); 2004 EXPECT_VALID(result);
1901 2005
1902 // Build a mock message handler and wrap it in a dart port. 2006 // Build a mock message handler and wrap it in a dart port.
1903 ServiceTestMessageHandler handler; 2007 ServiceTestMessageHandler handler;
1904 Dart_Port port_id = PortMap::CreatePort(&handler); 2008 Dart_Port port_id = PortMap::CreatePort(&handler);
1905 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 2009 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1906 EXPECT_VALID(port); 2010 EXPECT_VALID(port);
1907 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); 2011 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
1908 2012
1909 Array& service_msg = Array::Handle(); 2013 Array& service_msg = Array::Handle();
1910 service_msg = Eval(h_lib, "[0, port, ['profile'], [], []]"); 2014 service_msg = Eval(lib, "[0, port, ['profile'], [], []]");
1911 Service::HandleIsolateMessage(isolate, service_msg); 2015 Service::HandleIsolateMessage(isolate, service_msg);
1912 handler.HandleNextMessage(); 2016 handler.HandleNextMessage();
1913 // Expect profile 2017 // Expect profile
1914 EXPECT_SUBSTRING("\"type\":\"Profile\"", handler.msg()); 2018 EXPECT_SUBSTRING("\"type\":\"Profile\"", handler.msg());
1915 2019
1916 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hide']]"); 2020 service_msg = Eval(lib, "[0, port, ['profile'], ['tags'], ['hide']]");
1917 Service::HandleIsolateMessage(isolate, service_msg); 2021 Service::HandleIsolateMessage(isolate, service_msg);
1918 handler.HandleNextMessage(); 2022 handler.HandleNextMessage();
1919 // Expect profile 2023 // Expect profile
1920 EXPECT_SUBSTRING("\"type\":\"Profile\"", handler.msg()); 2024 EXPECT_SUBSTRING("\"type\":\"Profile\"", handler.msg());
1921 2025
1922 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); 2026 service_msg = Eval(lib, "[0, port, ['profile'], ['tags'], ['hidden']]");
1923 Service::HandleIsolateMessage(isolate, service_msg); 2027 Service::HandleIsolateMessage(isolate, service_msg);
1924 handler.HandleNextMessage(); 2028 handler.HandleNextMessage();
1925 // Expect error. 2029 // Expect error.
1926 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 2030 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1927 } 2031 }
1928 2032
1929 #endif // !defined(TARGET_ARCH_ARM64) 2033 #endif // !defined(TARGET_ARCH_ARM64)
1930 2034
1931 } // namespace dart 2035 } // namespace dart
OLDNEW
« runtime/bin/vmservice/client/lib/src/service/object.dart ('K') | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698