| 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_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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 static RawArray* Eval(Dart_Handle lib, const char* expr) { | 54 static RawArray* Eval(Dart_Handle lib, const char* expr) { |
| 55 const String& dummy_isolate_id = String::Handle(String::New("isolateId")); | 55 const String& dummy_isolate_id = String::Handle(String::New("isolateId")); |
| 56 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr)); | 56 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr)); |
| 57 EXPECT_VALID(expr_val); | 57 EXPECT_VALID(expr_val); |
| 58 Isolate* isolate = Isolate::Current(); | 58 Isolate* isolate = Isolate::Current(); |
| 59 const GrowableObjectArray& value = | 59 const GrowableObjectArray& value = |
| 60 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val); | 60 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val); |
| 61 const Array& result = Array::Handle(Array::MakeArray(value)); | 61 const Array& result = Array::Handle(Array::MakeArray(value)); |
| 62 GrowableObjectArray& growable = GrowableObjectArray::Handle(); | 62 GrowableObjectArray& growable = GrowableObjectArray::Handle(); |
| 63 growable ^= result.At(3); | 63 growable ^= result.At(4); |
| 64 // Append dummy isolate id to parameter values. | 64 // Append dummy isolate id to parameter values. |
| 65 growable.Add(dummy_isolate_id); | 65 growable.Add(dummy_isolate_id); |
| 66 Array& array = Array::Handle(Array::MakeArray(growable)); | 66 Array& array = Array::Handle(Array::MakeArray(growable)); |
| 67 result.SetAt(3, array); | 67 result.SetAt(4, array); |
| 68 growable ^= result.At(4); | 68 growable ^= result.At(5); |
| 69 // Append dummy isolate id to parameter values. | 69 // Append dummy isolate id to parameter values. |
| 70 growable.Add(dummy_isolate_id); | 70 growable.Add(dummy_isolate_id); |
| 71 array = Array::MakeArray(growable); | 71 array = Array::MakeArray(growable); |
| 72 result.SetAt(4, array); | 72 result.SetAt(5, array); |
| 73 return result.raw(); | 73 return result.raw(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 static RawArray* EvalF(Dart_Handle lib, const char* fmt, ...) { | 77 static RawArray* EvalF(Dart_Handle lib, const char* fmt, ...) { |
| 78 Isolate* isolate = Isolate::Current(); | 78 Isolate* isolate = Isolate::Current(); |
| 79 | 79 |
| 80 va_list args; | 80 va_list args; |
| 81 va_start(args, fmt); | 81 va_start(args, fmt); |
| 82 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); | 82 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Build a mock message handler and wrap it in a dart port. | 149 // Build a mock message handler and wrap it in a dart port. |
| 150 ServiceTestMessageHandler handler; | 150 ServiceTestMessageHandler handler; |
| 151 Dart_Port port_id = PortMap::CreatePort(&handler); | 151 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 152 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 152 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 153 EXPECT_VALID(port); | 153 EXPECT_VALID(port); |
| 154 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 154 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 155 | 155 |
| 156 Array& service_msg = Array::Handle(); | 156 Array& service_msg = Array::Handle(); |
| 157 | 157 |
| 158 // Request an invalid code object. | 158 // Request an invalid code object. |
| 159 service_msg = Eval(lib, "[0, port, 'getObject', ['objectId'], ['code/0']]"); | 159 service_msg = |
| 160 Eval(lib, "[0, port, '0', 'getObject', ['objectId'], ['code/0']]"); |
| 160 Service::HandleIsolateMessage(isolate, service_msg); | 161 Service::HandleIsolateMessage(isolate, service_msg); |
| 161 handler.HandleNextMessage(); | 162 handler.HandleNextMessage(); |
| 162 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 163 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 163 | 164 |
| 164 // The following test checks that a code object can be found only | 165 // The following test checks that a code object can be found only |
| 165 // at compile_timestamp()-code.EntryPoint(). | 166 // at compile_timestamp()-code.EntryPoint(). |
| 166 service_msg = EvalF(lib, "[0, port, 'getObject', " | 167 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 167 "['objectId'], ['code/%" Px64"-%" Px "']]", | 168 "['objectId'], ['code/%" Px64"-%" Px "']]", |
| 168 compile_timestamp, | 169 compile_timestamp, |
| 169 entry); | 170 entry); |
| 170 Service::HandleIsolateMessage(isolate, service_msg); | 171 Service::HandleIsolateMessage(isolate, service_msg); |
| 171 handler.HandleNextMessage(); | 172 handler.HandleNextMessage(); |
| 172 { | 173 { |
| 173 // Only perform a partial match. | 174 // Only perform a partial match. |
| 174 const intptr_t kBufferSize = 512; | 175 const intptr_t kBufferSize = 512; |
| 175 char buffer[kBufferSize]; | 176 char buffer[kBufferSize]; |
| 176 OS::SNPrint(buffer, kBufferSize-1, | 177 OS::SNPrint(buffer, kBufferSize-1, |
| 177 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",", | 178 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",", |
| 178 compile_timestamp, | 179 compile_timestamp, |
| 179 entry); | 180 entry); |
| 180 EXPECT_SUBSTRING(buffer, handler.msg()); | 181 EXPECT_SUBSTRING(buffer, handler.msg()); |
| 181 } | 182 } |
| 182 | 183 |
| 183 // Request code object at compile_timestamp-code.EntryPoint() + 16 | 184 // Request code object at compile_timestamp-code.EntryPoint() + 16 |
| 184 // Expect this to fail because the address is not the entry point. | 185 // Expect this to fail because the address is not the entry point. |
| 185 uintptr_t address = entry + 16; | 186 uintptr_t address = entry + 16; |
| 186 service_msg = EvalF(lib, "[0, port, 'getObject', " | 187 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 187 "['objectId'], ['code/%" Px64"-%" Px "']]", | 188 "['objectId'], ['code/%" Px64"-%" Px "']]", |
| 188 compile_timestamp, | 189 compile_timestamp, |
| 189 address); | 190 address); |
| 190 Service::HandleIsolateMessage(isolate, service_msg); | 191 Service::HandleIsolateMessage(isolate, service_msg); |
| 191 handler.HandleNextMessage(); | 192 handler.HandleNextMessage(); |
| 192 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 193 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 193 | 194 |
| 194 // Request code object at (compile_timestamp - 1)-code.EntryPoint() | 195 // Request code object at (compile_timestamp - 1)-code.EntryPoint() |
| 195 // Expect this to fail because the timestamp is wrong. | 196 // Expect this to fail because the timestamp is wrong. |
| 196 address = entry; | 197 address = entry; |
| 197 service_msg = EvalF(lib, "[0, port, 'getObject', " | 198 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 198 "['objectId'], ['code/%" Px64"-%" Px "']]", | 199 "['objectId'], ['code/%" Px64"-%" Px "']]", |
| 199 compile_timestamp - 1, | 200 compile_timestamp - 1, |
| 200 address); | 201 address); |
| 201 Service::HandleIsolateMessage(isolate, service_msg); | 202 Service::HandleIsolateMessage(isolate, service_msg); |
| 202 handler.HandleNextMessage(); | 203 handler.HandleNextMessage(); |
| 203 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 204 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 204 | 205 |
| 205 // Request native code at address. Expect the null code object back. | 206 // Request native code at address. Expect the null code object back. |
| 206 address = last; | 207 address = last; |
| 207 service_msg = EvalF(lib, "[0, port, 'getObject', " | 208 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 208 "['objectId'], ['code/native-%" Px "']]", | 209 "['objectId'], ['code/native-%" Px "']]", |
| 209 address); | 210 address); |
| 210 Service::HandleIsolateMessage(isolate, service_msg); | 211 Service::HandleIsolateMessage(isolate, service_msg); |
| 211 handler.HandleNextMessage(); | 212 handler.HandleNextMessage(); |
| 212 EXPECT_SUBSTRING("{\"type\":\"null\",\"id\":\"objects\\/null\"," | 213 EXPECT_SUBSTRING("{\"type\":\"null\",\"id\":\"objects\\/null\"," |
| 213 "\"valueAsString\":\"null\"", | 214 "\"valueAsString\":\"null\"", |
| 214 handler.msg()); | 215 handler.msg()); |
| 215 | 216 |
| 216 // Request malformed native code. | 217 // Request malformed native code. |
| 217 service_msg = EvalF(lib, "[0, port, 'getObject', ['objectId'], " | 218 service_msg = EvalF(lib, "[0, port, '0', 'getObject', ['objectId'], " |
| 218 "['code/native%" Px "']]", | 219 "['code/native%" Px "']]", |
| 219 address); | 220 address); |
| 220 Service::HandleIsolateMessage(isolate, service_msg); | 221 Service::HandleIsolateMessage(isolate, service_msg); |
| 221 handler.HandleNextMessage(); | 222 handler.HandleNextMessage(); |
| 222 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 223 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 223 } | 224 } |
| 224 | 225 |
| 225 | 226 |
| 226 TEST_CASE(Service_TokenStream) { | 227 TEST_CASE(Service_TokenStream) { |
| 227 const char* kScript = | 228 const char* kScript = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 251 // Build a mock message handler and wrap it in a dart port. | 252 // Build a mock message handler and wrap it in a dart port. |
| 252 ServiceTestMessageHandler handler; | 253 ServiceTestMessageHandler handler; |
| 253 Dart_Port port_id = PortMap::CreatePort(&handler); | 254 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 254 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 255 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 255 EXPECT_VALID(port); | 256 EXPECT_VALID(port); |
| 256 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 257 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 257 | 258 |
| 258 Array& service_msg = Array::Handle(); | 259 Array& service_msg = Array::Handle(); |
| 259 | 260 |
| 260 // Fetch object. | 261 // Fetch object. |
| 261 service_msg = EvalF(lib, "[0, port, 'getObject', " | 262 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 262 "['objectId'], ['objects/%" Pd "']]", id); | 263 "['objectId'], ['objects/%" Pd "']]", id); |
| 263 Service::HandleIsolateMessage(isolate, service_msg); | 264 Service::HandleIsolateMessage(isolate, service_msg); |
| 264 handler.HandleNextMessage(); | 265 handler.HandleNextMessage(); |
| 265 | 266 |
| 266 // Check type. | 267 // Check type. |
| 267 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 268 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
| 268 EXPECT_SUBSTRING("\"_vmType\":\"TokenStream\"", handler.msg()); | 269 EXPECT_SUBSTRING("\"_vmType\":\"TokenStream\"", handler.msg()); |
| 269 // Check for members array. | 270 // Check for members array. |
| 270 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 271 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
| 271 } | 272 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 // Build a mock message handler and wrap it in a dart port. | 314 // Build a mock message handler and wrap it in a dart port. |
| 314 ServiceTestMessageHandler handler; | 315 ServiceTestMessageHandler handler; |
| 315 Dart_Port port_id = PortMap::CreatePort(&handler); | 316 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 316 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 317 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 317 EXPECT_VALID(port); | 318 EXPECT_VALID(port); |
| 318 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 319 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 319 | 320 |
| 320 Array& service_msg = Array::Handle(); | 321 Array& service_msg = Array::Handle(); |
| 321 | 322 |
| 322 // Fetch object. | 323 // Fetch object. |
| 323 service_msg = EvalF(lib, "[0, port, 'getObject', " | 324 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 324 "['objectId'], ['objects/%" Pd "']]", id); | 325 "['objectId'], ['objects/%" Pd "']]", id); |
| 325 Service::HandleIsolateMessage(isolate, service_msg); | 326 Service::HandleIsolateMessage(isolate, service_msg); |
| 326 handler.HandleNextMessage(); | 327 handler.HandleNextMessage(); |
| 327 // Check type. | 328 // Check type. |
| 328 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 329 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
| 329 EXPECT_SUBSTRING("\"_vmType\":\"PcDescriptors\"", handler.msg()); | 330 EXPECT_SUBSTRING("\"_vmType\":\"PcDescriptors\"", handler.msg()); |
| 330 // Check for members array. | 331 // Check for members array. |
| 331 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 332 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
| 332 } | 333 } |
| 333 | 334 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 // Build a mock message handler and wrap it in a dart port. | 375 // Build a mock message handler and wrap it in a dart port. |
| 375 ServiceTestMessageHandler handler; | 376 ServiceTestMessageHandler handler; |
| 376 Dart_Port port_id = PortMap::CreatePort(&handler); | 377 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 377 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 378 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 378 EXPECT_VALID(port); | 379 EXPECT_VALID(port); |
| 379 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 380 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 380 | 381 |
| 381 Array& service_msg = Array::Handle(); | 382 Array& service_msg = Array::Handle(); |
| 382 | 383 |
| 383 // Fetch object. | 384 // Fetch object. |
| 384 service_msg = EvalF(lib, "[0, port, 'getObject', " | 385 service_msg = EvalF(lib, "[0, port, '0', 'getObject', " |
| 385 "['objectId'], ['objects/%" Pd "']]", id); | 386 "['objectId'], ['objects/%" Pd "']]", id); |
| 386 Service::HandleIsolateMessage(isolate, service_msg); | 387 Service::HandleIsolateMessage(isolate, service_msg); |
| 387 handler.HandleNextMessage(); | 388 handler.HandleNextMessage(); |
| 388 // Check type. | 389 // Check type. |
| 389 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 390 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
| 390 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); | 391 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); |
| 391 // Check for members array. | 392 // Check for members array. |
| 392 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 393 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
| 393 } | 394 } |
| 394 | 395 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 415 Array& service_msg = Array::Handle(); | 416 Array& service_msg = Array::Handle(); |
| 416 // Note: If we ever introduce old space compaction, this test might fail. | 417 // Note: If we ever introduce old space compaction, this test might fail. |
| 417 uword start_addr = RawObject::ToAddr(str.raw()); | 418 uword start_addr = RawObject::ToAddr(str.raw()); |
| 418 // Expect to find 'str', also from internal addresses. | 419 // Expect to find 'str', also from internal addresses. |
| 419 for (int offset = 0; offset < kObjectAlignment; ++offset) { | 420 for (int offset = 0; offset < kObjectAlignment; ++offset) { |
| 420 uword addr = start_addr + offset; | 421 uword addr = start_addr + offset; |
| 421 char buf[1024]; | 422 char buf[1024]; |
| 422 bool ref = offset % 2 == 0; | 423 bool ref = offset % 2 == 0; |
| 423 OS::SNPrint(buf, sizeof(buf), | 424 OS::SNPrint(buf, sizeof(buf), |
| 424 (ref | 425 (ref |
| 425 ? "[0, port, 'getObjectByAddress', " | 426 ? "[0, port, '0', 'getObjectByAddress', " |
| 426 "['address', 'ref'], ['%" Px "', 'true']]" | 427 "['address', 'ref'], ['%" Px "', 'true']]" |
| 427 : "[0, port, 'getObjectByAddress', " | 428 : "[0, port, '0', 'getObjectByAddress', " |
| 428 "['address'], ['%" Px "']]"), | 429 "['address'], ['%" Px "']]"), |
| 429 addr); | 430 addr); |
| 430 service_msg = Eval(lib, buf); | 431 service_msg = Eval(lib, buf); |
| 431 Service::HandleIsolateMessage(isolate, service_msg); | 432 Service::HandleIsolateMessage(isolate, service_msg); |
| 432 handler.HandleNextMessage(); | 433 handler.HandleNextMessage(); |
| 433 EXPECT_SUBSTRING(ref ? "\"type\":\"@String\"" : | 434 EXPECT_SUBSTRING(ref ? "\"type\":\"@String\"" : |
| 434 "\"type\":\"String\"", | 435 "\"type\":\"String\"", |
| 435 handler.msg()); | 436 handler.msg()); |
| 436 EXPECT_SUBSTRING("foobar", handler.msg()); | 437 EXPECT_SUBSTRING("foobar", handler.msg()); |
| 437 } | 438 } |
| 438 // Expect null when no object is found. | 439 // Expect null when no object is found. |
| 439 service_msg = Eval(lib, "[0, port, 'getObjectByAddress', " | 440 service_msg = Eval(lib, "[0, port, '0', 'getObjectByAddress', " |
| 440 "['address'], ['7']]"); | 441 "['address'], ['7']]"); |
| 441 Service::HandleIsolateMessage(isolate, service_msg); | 442 Service::HandleIsolateMessage(isolate, service_msg); |
| 442 handler.HandleNextMessage(); | 443 handler.HandleNextMessage(); |
| 443 // TODO(turnidge): Should this be a ServiceException instead? | 444 // TODO(turnidge): Should this be a ServiceException instead? |
| 444 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"id\":\"objects\\/free\"," | 445 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"id\":\"objects\\/free\"," |
| 445 "\"valueAsString\":\"<free>\"", | 446 "\"valueAsString\":\"<free>\"", |
| 446 handler.msg()); | 447 handler.msg()); |
| 447 } | 448 } |
| 448 | 449 |
| 449 | 450 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 | 489 |
| 489 // Build a mock message handler and wrap it in a dart port. | 490 // Build a mock message handler and wrap it in a dart port. |
| 490 ServiceTestMessageHandler handler; | 491 ServiceTestMessageHandler handler; |
| 491 Dart_Port port_id = PortMap::CreatePort(&handler); | 492 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 492 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 493 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 493 EXPECT_VALID(port); | 494 EXPECT_VALID(port); |
| 494 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 495 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 495 | 496 |
| 496 | 497 |
| 497 Array& service_msg = Array::Handle(); | 498 Array& service_msg = Array::Handle(); |
| 498 service_msg = Eval(lib, "[0, port, 'alpha', [], []]"); | 499 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]"); |
| 499 Service::HandleRootMessage(service_msg); | 500 Service::HandleRootMessage(service_msg); |
| 500 handler.HandleNextMessage(); | 501 handler.HandleNextMessage(); |
| 501 EXPECT_STREQ("alpha", handler.msg()); | 502 EXPECT_STREQ("{\"result\":alpha, \"id\":\"0\"}", handler.msg()); |
| 502 service_msg = Eval(lib, "[0, port, 'beta', [], []]"); | 503 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]"); |
| 503 Service::HandleRootMessage(service_msg); | 504 Service::HandleRootMessage(service_msg); |
| 504 handler.HandleNextMessage(); | 505 handler.HandleNextMessage(); |
| 505 EXPECT_STREQ("beta", handler.msg()); | 506 EXPECT_STREQ("{\"result\":beta, \"id\":\"0\"}", handler.msg()); |
| 506 } | 507 } |
| 507 | 508 |
| 508 TEST_CASE(Service_EmbedderIsolateHandler) { | 509 TEST_CASE(Service_EmbedderIsolateHandler) { |
| 509 const char* kScript = | 510 const char* kScript = |
| 510 "var port;\n" // Set to our mock port by C++. | 511 "var port;\n" // Set to our mock port by C++. |
| 511 "\n" | 512 "\n" |
| 512 "var x = 7;\n" | 513 "var x = 7;\n" |
| 513 "main() {\n" | 514 "main() {\n" |
| 514 " x = x * x;\n" | 515 " x = x * x;\n" |
| 515 " x = x / 13;\n" | 516 " x = x / 13;\n" |
| 516 "}"; | 517 "}"; |
| 517 | 518 |
| 518 Dart_RegisterIsolateServiceRequestCallback("alpha", alpha_callback, NULL); | 519 Dart_RegisterIsolateServiceRequestCallback("alpha", alpha_callback, NULL); |
| 519 Dart_RegisterIsolateServiceRequestCallback("beta", beta_callback, NULL); | 520 Dart_RegisterIsolateServiceRequestCallback("beta", beta_callback, NULL); |
| 520 | 521 |
| 521 Isolate* isolate = Isolate::Current(); | 522 Isolate* isolate = Isolate::Current(); |
| 522 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 523 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
| 523 EXPECT_VALID(lib); | 524 EXPECT_VALID(lib); |
| 524 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | 525 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); |
| 525 EXPECT_VALID(result); | 526 EXPECT_VALID(result); |
| 526 | 527 |
| 527 // Build a mock message handler and wrap it in a dart port. | 528 // Build a mock message handler and wrap it in a dart port. |
| 528 ServiceTestMessageHandler handler; | 529 ServiceTestMessageHandler handler; |
| 529 Dart_Port port_id = PortMap::CreatePort(&handler); | 530 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 530 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 531 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 531 EXPECT_VALID(port); | 532 EXPECT_VALID(port); |
| 532 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 533 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 533 | 534 |
| 534 Array& service_msg = Array::Handle(); | 535 Array& service_msg = Array::Handle(); |
| 535 service_msg = Eval(lib, "[0, port, 'alpha', [], []]"); | 536 service_msg = Eval(lib, "[0, port, '0', 'alpha', [], []]"); |
| 536 Service::HandleIsolateMessage(isolate, service_msg); | 537 Service::HandleIsolateMessage(isolate, service_msg); |
| 537 handler.HandleNextMessage(); | 538 handler.HandleNextMessage(); |
| 538 EXPECT_STREQ("alpha", handler.msg()); | 539 EXPECT_STREQ("{\"result\":alpha, \"id\":\"0\"}", handler.msg()); |
| 539 service_msg = Eval(lib, "[0, port, 'beta', [], []]"); | 540 service_msg = Eval(lib, "[0, port, '0', 'beta', [], []]"); |
| 540 Service::HandleIsolateMessage(isolate, service_msg); | 541 Service::HandleIsolateMessage(isolate, service_msg); |
| 541 handler.HandleNextMessage(); | 542 handler.HandleNextMessage(); |
| 542 EXPECT_STREQ("beta", handler.msg()); | 543 EXPECT_STREQ("{\"result\":beta, \"id\":\"0\"}", handler.msg()); |
| 543 } | 544 } |
| 544 | 545 |
| 545 | 546 |
| 546 // TODO(zra): Remove when tests are ready to enable. | 547 // TODO(zra): Remove when tests are ready to enable. |
| 547 #if !defined(TARGET_ARCH_ARM64) | 548 #if !defined(TARGET_ARCH_ARM64) |
| 548 | 549 |
| 549 TEST_CASE(Service_Profile) { | 550 TEST_CASE(Service_Profile) { |
| 550 const char* kScript = | 551 const char* kScript = |
| 551 "var port;\n" // Set to our mock port by C++. | 552 "var port;\n" // Set to our mock port by C++. |
| 552 "\n" | 553 "\n" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 563 EXPECT_VALID(result); | 564 EXPECT_VALID(result); |
| 564 | 565 |
| 565 // Build a mock message handler and wrap it in a dart port. | 566 // Build a mock message handler and wrap it in a dart port. |
| 566 ServiceTestMessageHandler handler; | 567 ServiceTestMessageHandler handler; |
| 567 Dart_Port port_id = PortMap::CreatePort(&handler); | 568 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 568 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | 569 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 569 EXPECT_VALID(port); | 570 EXPECT_VALID(port); |
| 570 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | 571 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); |
| 571 | 572 |
| 572 Array& service_msg = Array::Handle(); | 573 Array& service_msg = Array::Handle(); |
| 573 service_msg = Eval(lib, "[0, port, 'getCpuProfile', [], []]"); | 574 service_msg = Eval(lib, "[0, port, '0', 'getCpuProfile', [], []]"); |
| 574 Service::HandleIsolateMessage(isolate, service_msg); | 575 Service::HandleIsolateMessage(isolate, service_msg); |
| 575 handler.HandleNextMessage(); | 576 handler.HandleNextMessage(); |
| 576 // Expect error (tags required). | 577 // Expect error (tags required). |
| 577 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 578 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 578 | 579 |
| 579 service_msg = | 580 service_msg = |
| 580 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['None']]"); | 581 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['None']]"); |
| 581 Service::HandleIsolateMessage(isolate, service_msg); | 582 Service::HandleIsolateMessage(isolate, service_msg); |
| 582 handler.HandleNextMessage(); | 583 handler.HandleNextMessage(); |
| 583 // Expect profile | 584 // Expect profile |
| 584 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg()); | 585 EXPECT_SUBSTRING("\"type\":\"_CpuProfile\"", handler.msg()); |
| 585 | 586 |
| 586 service_msg = | 587 service_msg = |
| 587 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['Bogus']]"); | 588 Eval(lib, "[0, port, '0', 'getCpuProfile', ['tags'], ['Bogus']]"); |
| 588 Service::HandleIsolateMessage(isolate, service_msg); | 589 Service::HandleIsolateMessage(isolate, service_msg); |
| 589 handler.HandleNextMessage(); | 590 handler.HandleNextMessage(); |
| 590 // Expect error. | 591 // Expect error. |
| 591 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 592 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 592 } | 593 } |
| 593 | 594 |
| 594 #endif // !defined(TARGET_ARCH_ARM64) | 595 #endif // !defined(TARGET_ARCH_ARM64) |
| 595 | 596 |
| 596 } // namespace dart | 597 } // namespace dart |
| OLD | NEW |