OLD | NEW |
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_tools_api.h" | 7 #include "include/dart_tools_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" |
11 #include "vm/globals.h" | 11 #include "vm/globals.h" |
12 #include "vm/message_handler.h" | 12 #include "vm/message_handler.h" |
13 #include "vm/object_id_ring.h" | 13 #include "vm/object_id_ring.h" |
14 #include "vm/os.h" | 14 #include "vm/os.h" |
15 #include "vm/port.h" | 15 #include "vm/port.h" |
| 16 #include "vm/safepoint.h" |
16 #include "vm/service.h" | 17 #include "vm/service.h" |
17 #include "vm/unit_test.h" | 18 #include "vm/unit_test.h" |
18 | 19 |
19 namespace dart { | 20 namespace dart { |
20 | 21 |
21 // This flag is used in the Service_Flags test below. | 22 // This flag is used in the Service_Flags test below. |
22 DEFINE_FLAG(bool, service_testing_flag, false, "Comment"); | 23 DEFINE_FLAG(bool, service_testing_flag, false, "Comment"); |
23 | 24 |
24 #ifndef PRODUCT | 25 #ifndef PRODUCT |
25 | 26 |
26 class ServiceTestMessageHandler : public MessageHandler { | 27 class ServiceTestMessageHandler : public MessageHandler { |
27 public: | 28 public: |
28 ServiceTestMessageHandler() : _msg(NULL) {} | 29 ServiceTestMessageHandler() : _msg(NULL) {} |
29 | 30 |
30 ~ServiceTestMessageHandler() { | 31 ~ServiceTestMessageHandler() { |
31 free(_msg); | 32 free(_msg); |
32 } | 33 } |
33 | 34 |
34 MessageStatus HandleMessage(Message* message) { | 35 MessageStatus HandleMessage(Message* message) { |
35 if (_msg != NULL) { | 36 if (_msg != NULL) { |
36 free(_msg); | 37 free(_msg); |
37 } | 38 } |
38 | 39 |
39 // Parse the message. | 40 // Parse the message. |
40 String& response = String::Handle(); | |
41 Object& response_obj = Object::Handle(); | 41 Object& response_obj = Object::Handle(); |
42 if (message->IsRaw()) { | 42 if (message->IsRaw()) { |
43 response_obj = message->raw_obj(); | 43 response_obj = message->raw_obj(); |
44 } else { | 44 } else { |
45 Thread* thread = Thread::Current(); | 45 Thread* thread = Thread::Current(); |
46 MessageSnapshotReader reader(message->data(), message->len(), thread); | 46 MessageSnapshotReader reader(message->data(), message->len(), thread); |
47 response_obj = reader.ReadObject(); | 47 response_obj = reader.ReadObject(); |
48 } | 48 } |
49 response ^= response_obj.raw(); | 49 if (response_obj.IsString()) { |
50 _msg = strdup(response.ToCString()); | 50 String& response = String::Handle(); |
| 51 response ^= response_obj.raw(); |
| 52 _msg = strdup(response.ToCString()); |
| 53 } else { |
| 54 ASSERT(response_obj.IsArray()); |
| 55 Array& response_array = Array::Handle(); |
| 56 response_array ^= response_obj.raw(); |
| 57 ASSERT(response_array.Length() == 1); |
| 58 ExternalTypedData& response = ExternalTypedData::Handle(); |
| 59 response ^= response_array.At(0); |
| 60 _msg = strdup(reinterpret_cast<char*>(response.DataAddr(0))); |
| 61 } |
| 62 |
51 return kOK; | 63 return kOK; |
52 } | 64 } |
53 | 65 |
54 const char* msg() const { return _msg; } | 66 const char* msg() const { return _msg; } |
55 | 67 |
56 virtual Isolate* isolate() const { return Isolate::Current(); } | 68 virtual Isolate* isolate() const { return Isolate::Current(); } |
57 | 69 |
58 private: | 70 private: |
59 char* _msg; | 71 char* _msg; |
60 }; | 72 }; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 120 |
109 | 121 |
110 static RawClass* GetClass(const Library& lib, const char* name) { | 122 static RawClass* GetClass(const Library& lib, const char* name) { |
111 const Class& cls = Class::Handle( | 123 const Class& cls = Class::Handle( |
112 lib.LookupClass(String::Handle(Symbols::New(Thread::Current(), name)))); | 124 lib.LookupClass(String::Handle(Symbols::New(Thread::Current(), name)))); |
113 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 125 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
114 return cls.raw(); | 126 return cls.raw(); |
115 } | 127 } |
116 | 128 |
117 | 129 |
| 130 static void HandleIsolateMessage(Isolate* isolate, const Array& msg) { |
| 131 TransitionNativeToVM transition(Thread::Current()); |
| 132 Service::HandleIsolateMessage(isolate, msg); |
| 133 } |
| 134 |
| 135 |
| 136 static void HandleRootMessage(const Array& message) { |
| 137 TransitionNativeToVM transition(Thread::Current()); |
| 138 Service::HandleRootMessage(message); |
| 139 } |
| 140 |
| 141 |
118 TEST_CASE(Service_IsolateStickyError) { | 142 TEST_CASE(Service_IsolateStickyError) { |
119 const char* kScript = | 143 const char* kScript = |
120 "main() => throw 'HI THERE STICKY';\n"; | 144 "main() => throw 'HI THERE STICKY';\n"; |
121 | 145 |
122 Isolate* isolate = thread->isolate(); | 146 Isolate* isolate = thread->isolate(); |
123 isolate->set_is_runnable(true); | 147 isolate->set_is_runnable(true); |
124 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 148 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
125 EXPECT_VALID(lib); | 149 EXPECT_VALID(lib); |
126 Library& vmlib = Library::Handle(); | 150 Library& vmlib = Library::Handle(); |
127 vmlib ^= Api::UnwrapHandle(lib); | 151 vmlib ^= Api::UnwrapHandle(lib); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 Dart_Port port_id = PortMap::CreatePort(&handler); | 262 Dart_Port port_id = PortMap::CreatePort(&handler); |
239 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 263 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
240 EXPECT_VALID(port); | 264 EXPECT_VALID(port); |
241 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 265 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
242 | 266 |
243 Array& service_msg = Array::Handle(); | 267 Array& service_msg = Array::Handle(); |
244 | 268 |
245 // Request an invalid code object. | 269 // Request an invalid code object. |
246 service_msg = | 270 service_msg = |
247 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]"); | 271 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]"); |
248 Service::HandleIsolateMessage(isolate, service_msg); | 272 HandleIsolateMessage(isolate, service_msg); |
249 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 273 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
250 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 274 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
251 | 275 |
252 // The following test checks that a code object can be found only | 276 // The following test checks that a code object can be found only |
253 // at compile_timestamp()-code.EntryPoint(). | 277 // at compile_timestamp()-code.EntryPoint(). |
254 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 278 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
255 "['objectId'], ['code/%" Px64"-%" Px "']]", | 279 "['objectId'], ['code/%" Px64"-%" Px "']]", |
256 compile_timestamp, | 280 compile_timestamp, |
257 entry); | 281 entry); |
258 Service::HandleIsolateMessage(isolate, service_msg); | 282 HandleIsolateMessage(isolate, service_msg); |
259 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 283 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
260 EXPECT_SUBSTRING("\"type\":\"Code\"", handler.msg()); | 284 EXPECT_SUBSTRING("\"type\":\"Code\"", handler.msg()); |
261 { | 285 { |
262 // Only perform a partial match. | 286 // Only perform a partial match. |
263 const intptr_t kBufferSize = 512; | 287 const intptr_t kBufferSize = 512; |
264 char buffer[kBufferSize]; | 288 char buffer[kBufferSize]; |
265 OS::SNPrint(buffer, kBufferSize-1, | 289 OS::SNPrint(buffer, kBufferSize-1, |
266 "\"fixedId\":true,\"id\":\"code\\/%" Px64 "-%" Px "\",", | 290 "\"fixedId\":true,\"id\":\"code\\/%" Px64 "-%" Px "\",", |
267 compile_timestamp, | 291 compile_timestamp, |
268 entry); | 292 entry); |
269 EXPECT_SUBSTRING(buffer, handler.msg()); | 293 EXPECT_SUBSTRING(buffer, handler.msg()); |
270 } | 294 } |
271 | 295 |
272 // Request code object at compile_timestamp-code.EntryPoint() + 16 | 296 // Request code object at compile_timestamp-code.EntryPoint() + 16 |
273 // Expect this to fail because the address is not the entry point. | 297 // Expect this to fail because the address is not the entry point. |
274 uintptr_t address = entry + 16; | 298 uintptr_t address = entry + 16; |
275 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 299 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
276 "['objectId'], ['code/%" Px64"-%" Px "']]", | 300 "['objectId'], ['code/%" Px64"-%" Px "']]", |
277 compile_timestamp, | 301 compile_timestamp, |
278 address); | 302 address); |
279 Service::HandleIsolateMessage(isolate, service_msg); | 303 HandleIsolateMessage(isolate, service_msg); |
280 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 304 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
281 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 305 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
282 | 306 |
283 // Request code object at (compile_timestamp - 1)-code.EntryPoint() | 307 // Request code object at (compile_timestamp - 1)-code.EntryPoint() |
284 // Expect this to fail because the timestamp is wrong. | 308 // Expect this to fail because the timestamp is wrong. |
285 address = entry; | 309 address = entry; |
286 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 310 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
287 "['objectId'], ['code/%" Px64"-%" Px "']]", | 311 "['objectId'], ['code/%" Px64"-%" Px "']]", |
288 compile_timestamp - 1, | 312 compile_timestamp - 1, |
289 address); | 313 address); |
290 Service::HandleIsolateMessage(isolate, service_msg); | 314 HandleIsolateMessage(isolate, service_msg); |
291 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 315 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
292 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 316 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
293 | 317 |
294 // Request native code at address. Expect the null code object back. | 318 // Request native code at address. Expect the null code object back. |
295 address = last; | 319 address = last; |
296 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 320 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
297 "['objectId'], ['code/native-%" Px "']]", | 321 "['objectId'], ['code/native-%" Px "']]", |
298 address); | 322 address); |
299 Service::HandleIsolateMessage(isolate, service_msg); | 323 HandleIsolateMessage(isolate, service_msg); |
300 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 324 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
301 // TODO(turnidge): It is pretty broken to return an Instance here. Fix. | 325 // TODO(turnidge): It is pretty broken to return an Instance here. Fix. |
302 EXPECT_SUBSTRING("\"kind\":\"Null\"", | 326 EXPECT_SUBSTRING("\"kind\":\"Null\"", |
303 handler.msg()); | 327 handler.msg()); |
304 | 328 |
305 // Request malformed native code. | 329 // Request malformed native code. |
306 service_msg = EvalF(lib, "[0, port, '0', 'getObject', ['objectId'], " | 330 service_msg = EvalF(lib, "[0, port, '0', 'getObject', ['objectId'], " |
307 "['code/native%" Px "']]", | 331 "['code/native%" Px "']]", |
308 address); | 332 address); |
309 Service::HandleIsolateMessage(isolate, service_msg); | 333 HandleIsolateMessage(isolate, service_msg); |
310 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 334 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
311 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 335 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
312 } | 336 } |
313 | 337 |
314 | 338 |
315 TEST_CASE(Service_TokenStream) { | 339 TEST_CASE(Service_TokenStream) { |
316 const char* kScript = | 340 const char* kScript = |
317 "var port;\n" // Set to our mock port by C++. | 341 "var port;\n" // Set to our mock port by C++. |
318 "\n" | 342 "\n" |
319 "main() {\n" | 343 "main() {\n" |
(...skipping 22 matching lines...) Expand all Loading... |
342 Dart_Port port_id = PortMap::CreatePort(&handler); | 366 Dart_Port port_id = PortMap::CreatePort(&handler); |
343 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 367 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
344 EXPECT_VALID(port); | 368 EXPECT_VALID(port); |
345 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 369 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
346 | 370 |
347 Array& service_msg = Array::Handle(); | 371 Array& service_msg = Array::Handle(); |
348 | 372 |
349 // Fetch object. | 373 // Fetch object. |
350 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 374 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
351 "['objectId'], ['objects/%" Pd "']]", id); | 375 "['objectId'], ['objects/%" Pd "']]", id); |
352 Service::HandleIsolateMessage(isolate, service_msg); | 376 HandleIsolateMessage(isolate, service_msg); |
353 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 377 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
354 | 378 |
355 // Check type. | 379 // Check type. |
356 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 380 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
357 EXPECT_SUBSTRING("\"_vmType\":\"TokenStream\"", handler.msg()); | 381 EXPECT_SUBSTRING("\"_vmType\":\"TokenStream\"", handler.msg()); |
358 // Check for members array. | 382 // Check for members array. |
359 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 383 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
360 } | 384 } |
361 | 385 |
362 | 386 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 Dart_Port port_id = PortMap::CreatePort(&handler); | 429 Dart_Port port_id = PortMap::CreatePort(&handler); |
406 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 430 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
407 EXPECT_VALID(port); | 431 EXPECT_VALID(port); |
408 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 432 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
409 | 433 |
410 Array& service_msg = Array::Handle(); | 434 Array& service_msg = Array::Handle(); |
411 | 435 |
412 // Fetch object. | 436 // Fetch object. |
413 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 437 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
414 "['objectId'], ['objects/%" Pd "']]", id); | 438 "['objectId'], ['objects/%" Pd "']]", id); |
415 Service::HandleIsolateMessage(isolate, service_msg); | 439 HandleIsolateMessage(isolate, service_msg); |
416 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 440 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
417 // Check type. | 441 // Check type. |
418 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 442 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
419 EXPECT_SUBSTRING("\"_vmType\":\"PcDescriptors\"", handler.msg()); | 443 EXPECT_SUBSTRING("\"_vmType\":\"PcDescriptors\"", handler.msg()); |
420 // Check for members array. | 444 // Check for members array. |
421 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 445 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
422 } | 446 } |
423 | 447 |
424 | 448 |
425 TEST_CASE(Service_LocalVarDescriptors) { | 449 TEST_CASE(Service_LocalVarDescriptors) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 Dart_Port port_id = PortMap::CreatePort(&handler); | 491 Dart_Port port_id = PortMap::CreatePort(&handler); |
468 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 492 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
469 EXPECT_VALID(port); | 493 EXPECT_VALID(port); |
470 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 494 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
471 | 495 |
472 Array& service_msg = Array::Handle(); | 496 Array& service_msg = Array::Handle(); |
473 | 497 |
474 // Fetch object. | 498 // Fetch object. |
475 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " | 499 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
476 "['objectId'], ['objects/%" Pd "']]", id); | 500 "['objectId'], ['objects/%" Pd "']]", id); |
477 Service::HandleIsolateMessage(isolate, service_msg); | 501 HandleIsolateMessage(isolate, service_msg); |
478 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 502 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
479 // Check type. | 503 // Check type. |
480 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 504 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
481 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); | 505 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); |
482 // Check for members array. | 506 // Check for members array. |
483 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 507 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
484 } | 508 } |
485 | 509 |
486 | 510 |
487 | 511 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 ServiceTestMessageHandler handler; | 551 ServiceTestMessageHandler handler; |
528 Dart_Port port_id = PortMap::CreatePort(&handler); | 552 Dart_Port port_id = PortMap::CreatePort(&handler); |
529 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 553 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
530 EXPECT_VALID(port); | 554 EXPECT_VALID(port); |
531 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 555 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
532 | 556 |
533 Array& service_msg = Array::Handle(); | 557 Array& service_msg = Array::Handle(); |
534 | 558 |
535 // Get persistent handles. | 559 // Get persistent handles. |
536 service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]"); | 560 service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]"); |
537 Service::HandleIsolateMessage(isolate, service_msg); | 561 HandleIsolateMessage(isolate, service_msg); |
538 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 562 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
539 // Look for a heart beat. | 563 // Look for a heart beat. |
540 EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg()); | 564 EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg()); |
541 EXPECT_SUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg()); | 565 EXPECT_SUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg()); |
542 EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg()); | 566 EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg()); |
543 EXPECT_SUBSTRING("\"externalSize\":\"128\"", handler.msg()); | 567 EXPECT_SUBSTRING("\"externalSize\":\"128\"", handler.msg()); |
544 | 568 |
545 // Delete persistent handles. | 569 // Delete persistent handles. |
546 Dart_DeletePersistentHandle(persistent_handle); | 570 Dart_DeletePersistentHandle(persistent_handle); |
547 Dart_DeleteWeakPersistentHandle(Dart_CurrentIsolate(), | 571 Dart_DeleteWeakPersistentHandle(Dart_CurrentIsolate(), |
548 weak_persistent_handle); | 572 weak_persistent_handle); |
549 | 573 |
550 // Get persistent handles (again). | 574 // Get persistent handles (again). |
551 service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]"); | 575 service_msg = Eval(lib, "[0, port, '0', '_getPersistentHandles', [], []]"); |
552 Service::HandleIsolateMessage(isolate, service_msg); | 576 HandleIsolateMessage(isolate, service_msg); |
553 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 577 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
554 EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg()); | 578 EXPECT_SUBSTRING("\"type\":\"_PersistentHandles\"", handler.msg()); |
555 // Verify that old persistent handles are not present. | 579 // Verify that old persistent handles are not present. |
556 EXPECT_NOTSUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg()); | 580 EXPECT_NOTSUBSTRING("\"peer\":\"0xdeadbeef\"", handler.msg()); |
557 EXPECT_NOTSUBSTRING("\"name\":\"A\"", handler.msg()); | 581 EXPECT_NOTSUBSTRING("\"name\":\"A\"", handler.msg()); |
558 EXPECT_NOTSUBSTRING("\"externalSize\":\"128\"", handler.msg()); | 582 EXPECT_NOTSUBSTRING("\"externalSize\":\"128\"", handler.msg()); |
559 } | 583 } |
560 | 584 |
561 | 585 |
562 TEST_CASE(Service_Address) { | 586 TEST_CASE(Service_Address) { |
(...skipping 25 matching lines...) Expand all Loading... |
588 char buf[1024]; | 612 char buf[1024]; |
589 bool ref = offset % 2 == 0; | 613 bool ref = offset % 2 == 0; |
590 OS::SNPrint(buf, sizeof(buf), | 614 OS::SNPrint(buf, sizeof(buf), |
591 (ref | 615 (ref |
592 ? "[0, port, '0', '_getObjectByAddress', " | 616 ? "[0, port, '0', '_getObjectByAddress', " |
593 "['address', 'ref'], ['%" Px "', 'true']]" | 617 "['address', 'ref'], ['%" Px "', 'true']]" |
594 : "[0, port, '0', '_getObjectByAddress', " | 618 : "[0, port, '0', '_getObjectByAddress', " |
595 "['address'], ['%" Px "']]"), | 619 "['address'], ['%" Px "']]"), |
596 addr); | 620 addr); |
597 service_msg = Eval(lib, buf); | 621 service_msg = Eval(lib, buf); |
598 Service::HandleIsolateMessage(isolate, service_msg); | 622 HandleIsolateMessage(isolate, service_msg); |
599 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 623 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
600 EXPECT_SUBSTRING(ref ? "\"type\":\"@Instance\"" : | 624 EXPECT_SUBSTRING(ref ? "\"type\":\"@Instance\"" : |
601 "\"type\":\"Instance\"", | 625 "\"type\":\"Instance\"", |
602 handler.msg()); | 626 handler.msg()); |
603 EXPECT_SUBSTRING("\"kind\":\"String\"", handler.msg()); | 627 EXPECT_SUBSTRING("\"kind\":\"String\"", handler.msg()); |
604 EXPECT_SUBSTRING("foobar", handler.msg()); | 628 EXPECT_SUBSTRING("foobar", handler.msg()); |
605 } | 629 } |
606 // Expect null when no object is found. | 630 // Expect null when no object is found. |
607 service_msg = Eval(lib, "[0, port, '0', '_getObjectByAddress', " | 631 service_msg = Eval(lib, "[0, port, '0', '_getObjectByAddress', " |
608 "['address'], ['7']]"); | 632 "['address'], ['7']]"); |
609 Service::HandleIsolateMessage(isolate, service_msg); | 633 HandleIsolateMessage(isolate, service_msg); |
610 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 634 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
611 // TODO(turnidge): Should this be a ServiceException instead? | 635 // TODO(turnidge): Should this be a ServiceException instead? |
612 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"kind\":\"Free\"," | 636 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"kind\":\"Free\"," |
613 "\"valueAsString\":\"<free>\"", | 637 "\"valueAsString\":\"<free>\"", |
614 handler.msg()); | 638 handler.msg()); |
615 } | 639 } |
616 | 640 |
617 | 641 |
618 static bool alpha_callback( | 642 static bool alpha_callback( |
619 const char* name, | 643 const char* name, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 // Build a mock message handler and wrap it in a dart port. | 684 // Build a mock message handler and wrap it in a dart port. |
661 ServiceTestMessageHandler handler; | 685 ServiceTestMessageHandler handler; |
662 Dart_Port port_id = PortMap::CreatePort(&handler); | 686 Dart_Port port_id = PortMap::CreatePort(&handler); |
663 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 687 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
664 EXPECT_VALID(port); | 688 EXPECT_VALID(port); |
665 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 689 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
666 | 690 |
667 | 691 |
668 Array& service_msg = Array::Handle(); | 692 Array& service_msg = Array::Handle(); |
669 service_msg = Eval(lib, "[0, port, '\"', 'alpha', [], []]"); | 693 service_msg = Eval(lib, "[0, port, '\"', 'alpha', [], []]"); |
670 Service::HandleRootMessage(service_msg); | 694 HandleRootMessage(service_msg); |
671 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 695 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
672 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"\\\"\"}", | 696 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"\\\"\"}", |
673 handler.msg()); | 697 handler.msg()); |
674 service_msg = Eval(lib, "[0, port, 1, 'beta', [], []]"); | 698 service_msg = Eval(lib, "[0, port, 1, 'beta', [], []]"); |
675 Service::HandleRootMessage(service_msg); | 699 HandleRootMessage(service_msg); |
676 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 700 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
677 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"error\":beta,\"id\":1}", | 701 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"error\":beta,\"id\":1}", |
678 handler.msg()); | 702 handler.msg()); |
679 } | 703 } |
680 | 704 |
681 | 705 |
682 TEST_CASE(Service_EmbedderIsolateHandler) { | 706 TEST_CASE(Service_EmbedderIsolateHandler) { |
683 const char* kScript = | 707 const char* kScript = |
684 "var port;\n" // Set to our mock port by C++. | 708 "var port;\n" // Set to our mock port by C++. |
685 "\n" | 709 "\n" |
(...skipping 14 matching lines...) Expand all Loading... |
700 | 724 |
701 // Build a mock message handler and wrap it in a dart port. | 725 // Build a mock message handler and wrap it in a dart port. |
702 ServiceTestMessageHandler handler; | 726 ServiceTestMessageHandler handler; |
703 Dart_Port port_id = PortMap::CreatePort(&handler); | 727 Dart_Port port_id = PortMap::CreatePort(&handler); |
704 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 728 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
705 EXPECT_VALID(port); | 729 EXPECT_VALID(port); |
706 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 730 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
707 | 731 |
708 Array& service_msg = Array::Handle(); | 732 Array& service_msg = Array::Handle(); |
709 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]"); | 733 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]"); |
710 Service::HandleIsolateMessage(isolate, service_msg); | 734 HandleIsolateMessage(isolate, service_msg); |
711 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 735 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
712 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"0\"}", | 736 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"0\"}", |
713 handler.msg()); | 737 handler.msg()); |
714 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]"); | 738 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]"); |
715 Service::HandleIsolateMessage(isolate, service_msg); | 739 HandleIsolateMessage(isolate, service_msg); |
716 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 740 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
717 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"error\":beta,\"id\":\"0\"}", | 741 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"error\":beta,\"id\":\"0\"}", |
718 handler.msg()); | 742 handler.msg()); |
719 } | 743 } |
720 | 744 |
721 // TODO(zra): Remove when tests are ready to enable. | 745 // TODO(zra): Remove when tests are ready to enable. |
722 #if !defined(TARGET_ARCH_ARM64) | 746 #if !defined(TARGET_ARCH_ARM64) |
723 | 747 |
724 TEST_CASE(Service_Profile) { | 748 TEST_CASE(Service_Profile) { |
725 const char* kScript = | 749 const char* kScript = |
(...skipping 14 matching lines...) Expand all Loading... |
740 | 764 |
741 // Build a mock message handler and wrap it in a dart port. | 765 // Build a mock message handler and wrap it in a dart port. |
742 ServiceTestMessageHandler handler; | 766 ServiceTestMessageHandler handler; |
743 Dart_Port port_id = PortMap::CreatePort(&handler); | 767 Dart_Port port_id = PortMap::CreatePort(&handler); |
744 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); | 768 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id)); |
745 EXPECT_VALID(port); | 769 EXPECT_VALID(port); |
746 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 770 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
747 | 771 |
748 Array& service_msg = Array::Handle(); | 772 Array& service_msg = Array::Handle(); |
749 service_msg = Eval(lib, "[0, port, '0', '_getCpuProfile', [], []]"); | 773 service_msg = Eval(lib, "[0, port, '0', '_getCpuProfile', [], []]"); |
750 Service::HandleIsolateMessage(isolate, service_msg); | 774 HandleIsolateMessage(isolate, service_msg); |
751 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 775 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
752 // Expect error (tags required). | 776 // Expect error (tags required). |
753 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 777 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
754 | 778 |
755 service_msg = | 779 service_msg = |
756 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['None']]"); | 780 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['None']]"); |
757 Service::HandleIsolateMessage(isolate, service_msg); | 781 HandleIsolateMessage(isolate, service_msg); |
758 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 782 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
759 // Expect profile | 783 // Expect profile |
760 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg()); | 784 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg()); |
761 | 785 |
762 service_msg = | 786 service_msg = |
763 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['Bogus']]"); | 787 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['Bogus']]"); |
764 Service::HandleIsolateMessage(isolate, service_msg); | 788 HandleIsolateMessage(isolate, service_msg); |
765 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); | 789 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); |
766 // Expect error. | 790 // Expect error. |
767 EXPECT_SUBSTRING("\"error\"", handler.msg()); | 791 EXPECT_SUBSTRING("\"error\"", handler.msg()); |
768 } | 792 } |
769 | 793 |
770 #endif // !defined(TARGET_ARCH_ARM64) | 794 #endif // !defined(TARGET_ARCH_ARM64) |
771 | 795 |
772 #endif // !PRODUCT | 796 #endif // !PRODUCT |
773 | 797 |
774 } // namespace dart | 798 } // namespace dart |
OLD | NEW |