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

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

Issue 1473403003: Move ApiLocalScope out of class ApiState into class Thread so that the API local handles and zone e… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 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"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 " var d = () { b(); };\n" 154 " var d = () { b(); };\n"
155 " return d;\n" 155 " return d;\n"
156 " }\n" 156 " }\n"
157 "}\n" 157 "}\n"
158 "main() {\n" 158 "main() {\n"
159 " var z = new A();\n" 159 " var z = new A();\n"
160 " var x = z.c();\n" 160 " var x = z.c();\n"
161 " x();\n" 161 " x();\n"
162 "}"; 162 "}";
163 163
164 Isolate* isolate = Isolate::Current(); 164 Isolate* isolate = thread->isolate();
165 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 165 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
166 EXPECT_VALID(lib); 166 EXPECT_VALID(lib);
167 Library& vmlib = Library::Handle(); 167 Library& vmlib = Library::Handle();
168 vmlib ^= Api::UnwrapHandle(lib); 168 vmlib ^= Api::UnwrapHandle(lib);
169 EXPECT(!vmlib.IsNull()); 169 EXPECT(!vmlib.IsNull());
170 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 170 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
171 EXPECT_VALID(result); 171 EXPECT_VALID(result);
172 const Class& class_a = Class::Handle(GetClass(vmlib, "A")); 172 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
173 EXPECT(!class_a.IsNull()); 173 EXPECT(!class_a.IsNull());
174 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); 174 const Function& function_c = Function::Handle(GetFunction(class_a, "c"));
175 EXPECT(!function_c.IsNull()); 175 EXPECT(!function_c.IsNull());
176 const Code& code_c = Code::Handle(function_c.CurrentCode()); 176 const Code& code_c = Code::Handle(function_c.CurrentCode());
177 EXPECT(!code_c.IsNull()); 177 EXPECT(!code_c.IsNull());
178 // Use the entry of the code object as it's reference. 178 // Use the entry of the code object as it's reference.
179 uword entry = code_c.EntryPoint(); 179 uword entry = code_c.EntryPoint();
180 int64_t compile_timestamp = code_c.compile_timestamp(); 180 int64_t compile_timestamp = code_c.compile_timestamp();
181 EXPECT_GT(code_c.Size(), 16); 181 EXPECT_GT(code_c.Size(), 16);
182 uword last = entry + code_c.Size(); 182 uword last = entry + code_c.Size();
183 183
184 // Build a mock message handler and wrap it in a dart port. 184 // Build a mock message handler and wrap it in a dart port.
185 ServiceTestMessageHandler handler; 185 ServiceTestMessageHandler handler;
186 Dart_Port port_id = PortMap::CreatePort(&handler); 186 Dart_Port port_id = PortMap::CreatePort(&handler);
187 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 187 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
188 EXPECT_VALID(port); 188 EXPECT_VALID(port);
189 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 189 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
190 190
191 Array& service_msg = Array::Handle(); 191 Array& service_msg = Array::Handle();
192 192
193 // Request an invalid code object. 193 // Request an invalid code object.
194 service_msg = 194 service_msg =
195 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]"); 195 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]");
196 Service::HandleIsolateMessage(isolate, service_msg); 196 Service::HandleIsolateMessage(isolate, service_msg);
197 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 197 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 260 }
261 261
262 262
263 TEST_CASE(Service_TokenStream) { 263 TEST_CASE(Service_TokenStream) {
264 const char* kScript = 264 const char* kScript =
265 "var port;\n" // Set to our mock port by C++. 265 "var port;\n" // Set to our mock port by C++.
266 "\n" 266 "\n"
267 "main() {\n" 267 "main() {\n"
268 "}"; 268 "}";
269 269
270 Isolate* isolate = Isolate::Current(); 270 Isolate* isolate = thread->isolate();
271 271
272 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 272 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
273 EXPECT_VALID(lib); 273 EXPECT_VALID(lib);
274 Library& vmlib = Library::Handle(); 274 Library& vmlib = Library::Handle();
275 vmlib ^= Api::UnwrapHandle(lib); 275 vmlib ^= Api::UnwrapHandle(lib);
276 EXPECT(!vmlib.IsNull()); 276 EXPECT(!vmlib.IsNull());
277 277
278 const String& script_name = String::Handle(String::New("test-lib")); 278 const String& script_name = String::Handle(String::New("test-lib"));
279 EXPECT(!script_name.IsNull()); 279 EXPECT(!script_name.IsNull());
280 const Script& script = Script::Handle(vmlib.LookupScript(script_name)); 280 const Script& script = Script::Handle(vmlib.LookupScript(script_name));
281 EXPECT(!script.IsNull()); 281 EXPECT(!script.IsNull());
282 282
283 const TokenStream& token_stream = TokenStream::Handle(script.tokens()); 283 const TokenStream& token_stream = TokenStream::Handle(script.tokens());
284 EXPECT(!token_stream.IsNull()); 284 EXPECT(!token_stream.IsNull());
285 ObjectIdRing* ring = isolate->object_id_ring(); 285 ObjectIdRing* ring = isolate->object_id_ring();
286 intptr_t id = ring->GetIdForObject(token_stream.raw()); 286 intptr_t id = ring->GetIdForObject(token_stream.raw());
287 287
288 // Build a mock message handler and wrap it in a dart port. 288 // Build a mock message handler and wrap it in a dart port.
289 ServiceTestMessageHandler handler; 289 ServiceTestMessageHandler handler;
290 Dart_Port port_id = PortMap::CreatePort(&handler); 290 Dart_Port port_id = PortMap::CreatePort(&handler);
291 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 291 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
292 EXPECT_VALID(port); 292 EXPECT_VALID(port);
293 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 293 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
294 294
295 Array& service_msg = Array::Handle(); 295 Array& service_msg = Array::Handle();
296 296
297 // Fetch object. 297 // Fetch object.
298 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 298 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
299 "['objectId'], ['objects/%" Pd "']]", id); 299 "['objectId'], ['objects/%" Pd "']]", id);
300 Service::HandleIsolateMessage(isolate, service_msg); 300 Service::HandleIsolateMessage(isolate, service_msg);
301 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 301 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
(...skipping 17 matching lines...) Expand all
319 " var d = () { b(); };\n" 319 " var d = () { b(); };\n"
320 " return d;\n" 320 " return d;\n"
321 " }\n" 321 " }\n"
322 "}\n" 322 "}\n"
323 "main() {\n" 323 "main() {\n"
324 " var z = new A();\n" 324 " var z = new A();\n"
325 " var x = z.c();\n" 325 " var x = z.c();\n"
326 " x();\n" 326 " x();\n"
327 "}"; 327 "}";
328 328
329 Isolate* isolate = Isolate::Current(); 329 Isolate* isolate = thread->isolate();
330 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 330 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
331 EXPECT_VALID(lib); 331 EXPECT_VALID(lib);
332 Library& vmlib = Library::Handle(); 332 Library& vmlib = Library::Handle();
333 vmlib ^= Api::UnwrapHandle(lib); 333 vmlib ^= Api::UnwrapHandle(lib);
334 EXPECT(!vmlib.IsNull()); 334 EXPECT(!vmlib.IsNull());
335 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 335 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
336 EXPECT_VALID(result); 336 EXPECT_VALID(result);
337 const Class& class_a = Class::Handle(GetClass(vmlib, "A")); 337 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
338 EXPECT(!class_a.IsNull()); 338 EXPECT(!class_a.IsNull());
339 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); 339 const Function& function_c = Function::Handle(GetFunction(class_a, "c"));
340 EXPECT(!function_c.IsNull()); 340 EXPECT(!function_c.IsNull());
341 const Code& code_c = Code::Handle(function_c.CurrentCode()); 341 const Code& code_c = Code::Handle(function_c.CurrentCode());
342 EXPECT(!code_c.IsNull()); 342 EXPECT(!code_c.IsNull());
343 343
344 const PcDescriptors& descriptors = 344 const PcDescriptors& descriptors =
345 PcDescriptors::Handle(code_c.pc_descriptors()); 345 PcDescriptors::Handle(code_c.pc_descriptors());
346 EXPECT(!descriptors.IsNull()); 346 EXPECT(!descriptors.IsNull());
347 ObjectIdRing* ring = isolate->object_id_ring(); 347 ObjectIdRing* ring = isolate->object_id_ring();
348 intptr_t id = ring->GetIdForObject(descriptors.raw()); 348 intptr_t id = ring->GetIdForObject(descriptors.raw());
349 349
350 // Build a mock message handler and wrap it in a dart port. 350 // Build a mock message handler and wrap it in a dart port.
351 ServiceTestMessageHandler handler; 351 ServiceTestMessageHandler handler;
352 Dart_Port port_id = PortMap::CreatePort(&handler); 352 Dart_Port port_id = PortMap::CreatePort(&handler);
353 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 353 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
354 EXPECT_VALID(port); 354 EXPECT_VALID(port);
355 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 355 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
356 356
357 Array& service_msg = Array::Handle(); 357 Array& service_msg = Array::Handle();
358 358
359 // Fetch object. 359 // Fetch object.
360 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 360 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
361 "['objectId'], ['objects/%" Pd "']]", id); 361 "['objectId'], ['objects/%" Pd "']]", id);
362 Service::HandleIsolateMessage(isolate, service_msg); 362 Service::HandleIsolateMessage(isolate, service_msg);
363 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 363 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
(...skipping 16 matching lines...) Expand all
380 " var d = () { b(); };\n" 380 " var d = () { b(); };\n"
381 " return d;\n" 381 " return d;\n"
382 " }\n" 382 " }\n"
383 "}\n" 383 "}\n"
384 "main() {\n" 384 "main() {\n"
385 " var z = new A();\n" 385 " var z = new A();\n"
386 " var x = z.c();\n" 386 " var x = z.c();\n"
387 " x();\n" 387 " x();\n"
388 "}"; 388 "}";
389 389
390 Isolate* isolate = Isolate::Current(); 390 Isolate* isolate = thread->isolate();
391 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 391 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
392 EXPECT_VALID(lib); 392 EXPECT_VALID(lib);
393 Library& vmlib = Library::Handle(); 393 Library& vmlib = Library::Handle();
394 vmlib ^= Api::UnwrapHandle(lib); 394 vmlib ^= Api::UnwrapHandle(lib);
395 EXPECT(!vmlib.IsNull()); 395 EXPECT(!vmlib.IsNull());
396 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 396 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
397 EXPECT_VALID(result); 397 EXPECT_VALID(result);
398 const Class& class_a = Class::Handle(GetClass(vmlib, "A")); 398 const Class& class_a = Class::Handle(GetClass(vmlib, "A"));
399 EXPECT(!class_a.IsNull()); 399 EXPECT(!class_a.IsNull());
400 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); 400 const Function& function_c = Function::Handle(GetFunction(class_a, "c"));
401 EXPECT(!function_c.IsNull()); 401 EXPECT(!function_c.IsNull());
402 const Code& code_c = Code::Handle(function_c.CurrentCode()); 402 const Code& code_c = Code::Handle(function_c.CurrentCode());
403 EXPECT(!code_c.IsNull()); 403 EXPECT(!code_c.IsNull());
404 404
405 const LocalVarDescriptors& descriptors = 405 const LocalVarDescriptors& descriptors =
406 LocalVarDescriptors::Handle(code_c.GetLocalVarDescriptors()); 406 LocalVarDescriptors::Handle(code_c.GetLocalVarDescriptors());
407 // Generate an ID for this object. 407 // Generate an ID for this object.
408 ObjectIdRing* ring = isolate->object_id_ring(); 408 ObjectIdRing* ring = isolate->object_id_ring();
409 intptr_t id = ring->GetIdForObject(descriptors.raw()); 409 intptr_t id = ring->GetIdForObject(descriptors.raw());
410 410
411 // Build a mock message handler and wrap it in a dart port. 411 // Build a mock message handler and wrap it in a dart port.
412 ServiceTestMessageHandler handler; 412 ServiceTestMessageHandler handler;
413 Dart_Port port_id = PortMap::CreatePort(&handler); 413 Dart_Port port_id = PortMap::CreatePort(&handler);
414 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 414 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
415 EXPECT_VALID(port); 415 EXPECT_VALID(port);
416 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 416 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
417 417
418 Array& service_msg = Array::Handle(); 418 Array& service_msg = Array::Handle();
419 419
420 // Fetch object. 420 // Fetch object.
421 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " 421 service_msg = EvalF(lib, "[0, port, '0', 'getObject', "
422 "['objectId'], ['objects/%" Pd "']]", id); 422 "['objectId'], ['objects/%" Pd "']]", id);
423 Service::HandleIsolateMessage(isolate, service_msg); 423 Service::HandleIsolateMessage(isolate, service_msg);
424 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 424 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
425 // Check type. 425 // Check type.
426 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); 426 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg());
427 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); 427 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg());
428 // Check for members array. 428 // Check for members array.
429 EXPECT_SUBSTRING("\"members\":[", handler.msg()); 429 EXPECT_SUBSTRING("\"members\":[", handler.msg());
430 } 430 }
431 431
432 432
433 TEST_CASE(Service_Address) { 433 TEST_CASE(Service_Address) {
434 const char* kScript = 434 const char* kScript =
435 "var port;\n" // Set to our mock port by C++. 435 "var port;\n" // Set to our mock port by C++.
436 "\n" 436 "\n"
437 "main() {\n" 437 "main() {\n"
438 "}"; 438 "}";
439 439
440 Isolate* isolate = Isolate::Current(); 440 Isolate* isolate = thread->isolate();
441 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 441 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
442 EXPECT_VALID(lib); 442 EXPECT_VALID(lib);
443 443
444 // Build a mock message handler and wrap it in a dart port. 444 // Build a mock message handler and wrap it in a dart port.
445 ServiceTestMessageHandler handler; 445 ServiceTestMessageHandler handler;
446 Dart_Port port_id = PortMap::CreatePort(&handler); 446 Dart_Port port_id = PortMap::CreatePort(&handler);
447 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 447 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
448 EXPECT_VALID(port); 448 EXPECT_VALID(port);
449 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 449 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
450 450
451 const String& str = String::Handle(String::New("foobar", Heap::kOld)); 451 const String& str = String::Handle(String::New("foobar", Heap::kOld));
452 Array& service_msg = Array::Handle(); 452 Array& service_msg = Array::Handle();
453 // Note: If we ever introduce old space compaction, this test might fail. 453 // Note: If we ever introduce old space compaction, this test might fail.
454 uword start_addr = RawObject::ToAddr(str.raw()); 454 uword start_addr = RawObject::ToAddr(str.raw());
455 // Expect to find 'str', also from internal addresses. 455 // Expect to find 'str', also from internal addresses.
456 for (int offset = 0; offset < kObjectAlignment; ++offset) { 456 for (int offset = 0; offset < kObjectAlignment; ++offset) {
457 uword addr = start_addr + offset; 457 uword addr = start_addr + offset;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 "\n" 511 "\n"
512 "var x = 7;\n" 512 "var x = 7;\n"
513 "main() {\n" 513 "main() {\n"
514 " x = x * x;\n" 514 " x = x * x;\n"
515 " x = x / 13;\n" 515 " x = x / 13;\n"
516 "}"; 516 "}";
517 517
518 Dart_RegisterRootServiceRequestCallback("alpha", alpha_callback, NULL); 518 Dart_RegisterRootServiceRequestCallback("alpha", alpha_callback, NULL);
519 Dart_RegisterRootServiceRequestCallback("beta", beta_callback, NULL); 519 Dart_RegisterRootServiceRequestCallback("beta", beta_callback, NULL);
520 520
521 Isolate* isolate = Isolate::Current();
522 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 521 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
523 EXPECT_VALID(lib); 522 EXPECT_VALID(lib);
524 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 523 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
525 EXPECT_VALID(result); 524 EXPECT_VALID(result);
526 525
527 // Build a mock message handler and wrap it in a dart port. 526 // Build a mock message handler and wrap it in a dart port.
528 ServiceTestMessageHandler handler; 527 ServiceTestMessageHandler handler;
529 Dart_Port port_id = PortMap::CreatePort(&handler); 528 Dart_Port port_id = PortMap::CreatePort(&handler);
530 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 529 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
531 EXPECT_VALID(port); 530 EXPECT_VALID(port);
532 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 531 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
533 532
534 533
535 Array& service_msg = Array::Handle(); 534 Array& service_msg = Array::Handle();
536 service_msg = Eval(lib, "[0, port, '\"', 'alpha', [], []]"); 535 service_msg = Eval(lib, "[0, port, '\"', 'alpha', [], []]");
537 Service::HandleRootMessage(service_msg); 536 Service::HandleRootMessage(service_msg);
538 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 537 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
539 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"\\\"\"}", 538 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"\\\"\"}",
540 handler.msg()); 539 handler.msg());
(...skipping 11 matching lines...) Expand all
552 "\n" 551 "\n"
553 "var x = 7;\n" 552 "var x = 7;\n"
554 "main() {\n" 553 "main() {\n"
555 " x = x * x;\n" 554 " x = x * x;\n"
556 " x = x / 13;\n" 555 " x = x / 13;\n"
557 "}"; 556 "}";
558 557
559 Dart_RegisterIsolateServiceRequestCallback("alpha", alpha_callback, NULL); 558 Dart_RegisterIsolateServiceRequestCallback("alpha", alpha_callback, NULL);
560 Dart_RegisterIsolateServiceRequestCallback("beta", beta_callback, NULL); 559 Dart_RegisterIsolateServiceRequestCallback("beta", beta_callback, NULL);
561 560
562 Isolate* isolate = Isolate::Current(); 561 Isolate* isolate = thread->isolate();
563 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 562 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
564 EXPECT_VALID(lib); 563 EXPECT_VALID(lib);
565 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 564 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
566 EXPECT_VALID(result); 565 EXPECT_VALID(result);
567 566
568 // Build a mock message handler and wrap it in a dart port. 567 // Build a mock message handler and wrap it in a dart port.
569 ServiceTestMessageHandler handler; 568 ServiceTestMessageHandler handler;
570 Dart_Port port_id = PortMap::CreatePort(&handler); 569 Dart_Port port_id = PortMap::CreatePort(&handler);
571 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 570 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
572 EXPECT_VALID(port); 571 EXPECT_VALID(port);
573 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 572 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
574 573
575 Array& service_msg = Array::Handle(); 574 Array& service_msg = Array::Handle();
576 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]"); 575 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]");
577 Service::HandleIsolateMessage(isolate, service_msg); 576 Service::HandleIsolateMessage(isolate, service_msg);
578 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 577 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
579 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"0\"}", 578 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":alpha,\"id\":\"0\"}",
580 handler.msg()); 579 handler.msg());
581 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]"); 580 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]");
582 Service::HandleIsolateMessage(isolate, service_msg); 581 Service::HandleIsolateMessage(isolate, service_msg);
583 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 582 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
584 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":beta,\"id\":\"0\"}", 583 EXPECT_STREQ("{\"jsonrpc\":\"2.0\", \"result\":beta,\"id\":\"0\"}",
585 handler.msg()); 584 handler.msg());
586 } 585 }
587 586
588 // TODO(zra): Remove when tests are ready to enable. 587 // TODO(zra): Remove when tests are ready to enable.
589 #if !defined(TARGET_ARCH_ARM64) 588 #if !defined(TARGET_ARCH_ARM64)
590 589
591 TEST_CASE(Service_Profile) { 590 TEST_CASE(Service_Profile) {
592 const char* kScript = 591 const char* kScript =
593 "var port;\n" // Set to our mock port by C++. 592 "var port;\n" // Set to our mock port by C++.
594 "\n" 593 "\n"
595 "var x = 7;\n" 594 "var x = 7;\n"
596 "main() {\n" 595 "main() {\n"
597 " x = x * x;\n" 596 " x = x * x;\n"
598 " x = x / 13;\n" 597 " x = x / 13;\n"
599 "}"; 598 "}";
600 599
601 Isolate* isolate = Isolate::Current(); 600 Isolate* isolate = thread->isolate();
602 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); 601 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
603 EXPECT_VALID(lib); 602 EXPECT_VALID(lib);
604 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 603 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
605 EXPECT_VALID(result); 604 EXPECT_VALID(result);
606 605
607 // Build a mock message handler and wrap it in a dart port. 606 // Build a mock message handler and wrap it in a dart port.
608 ServiceTestMessageHandler handler; 607 ServiceTestMessageHandler handler;
609 Dart_Port port_id = PortMap::CreatePort(&handler); 608 Dart_Port port_id = PortMap::CreatePort(&handler);
610 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); 609 Dart_Handle port = Api::NewHandle(thread, SendPort::New(port_id));
611 EXPECT_VALID(port); 610 EXPECT_VALID(port);
612 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); 611 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port));
613 612
614 Array& service_msg = Array::Handle(); 613 Array& service_msg = Array::Handle();
615 service_msg = Eval(lib, "[0, port, '0', '_getCpuProfile', [], []]"); 614 service_msg = Eval(lib, "[0, port, '0', '_getCpuProfile', [], []]");
616 Service::HandleIsolateMessage(isolate, service_msg); 615 Service::HandleIsolateMessage(isolate, service_msg);
617 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 616 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
618 // Expect error (tags required). 617 // Expect error (tags required).
619 EXPECT_SUBSTRING("\"error\"", handler.msg()); 618 EXPECT_SUBSTRING("\"error\"", handler.msg());
620 619
621 service_msg = 620 service_msg =
622 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['None']]"); 621 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['None']]");
623 Service::HandleIsolateMessage(isolate, service_msg); 622 Service::HandleIsolateMessage(isolate, service_msg);
624 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 623 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
625 // Expect profile 624 // Expect profile
626 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg()); 625 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg());
627 626
628 service_msg = 627 service_msg =
629 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['Bogus']]"); 628 Eval(lib, "[0, port, '0', '_getCpuProfile', ['tags'], ['Bogus']]");
630 Service::HandleIsolateMessage(isolate, service_msg); 629 Service::HandleIsolateMessage(isolate, service_msg);
631 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage()); 630 EXPECT_EQ(MessageHandler::kOK, handler.HandleNextMessage());
632 // Expect error. 631 // Expect error.
633 EXPECT_SUBSTRING("\"error\"", handler.msg()); 632 EXPECT_SUBSTRING("\"error\"", handler.msg());
634 } 633 }
635 634
636 #endif // !defined(TARGET_ARCH_ARM64) 635 #endif // !defined(TARGET_ARCH_ARM64)
637 636
638 } // namespace dart 637 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698