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 26 matching lines...) Expand all Loading... |
37 // Parse the message. | 37 // Parse the message. |
38 SnapshotReader reader(message->data(), message->len(), Snapshot::kMessage, | 38 SnapshotReader reader(message->data(), message->len(), Snapshot::kMessage, |
39 Isolate::Current(), Thread::Current()->zone()); | 39 Isolate::Current(), Thread::Current()->zone()); |
40 const Object& response_obj = Object::Handle(reader.ReadObject()); | 40 const Object& response_obj = Object::Handle(reader.ReadObject()); |
41 String& response = String::Handle(); | 41 String& response = String::Handle(); |
42 response ^= response_obj.raw(); | 42 response ^= response_obj.raw(); |
43 _msg = strdup(response.ToCString()); | 43 _msg = strdup(response.ToCString()); |
44 return true; | 44 return true; |
45 } | 45 } |
46 | 46 |
47 // Removes a given json key:value from _msg. | |
48 void filterMsg(const char* key) { | |
49 int key_len = strlen(key); | |
50 int old_len = strlen(_msg); | |
51 char* new_msg = reinterpret_cast<char*>(malloc(old_len + 1)); | |
52 int old_pos = 0; | |
53 int new_pos = 0; | |
54 while (_msg[old_pos] != '\0') { | |
55 if (_msg[old_pos] == '\"') { | |
56 old_pos++; | |
57 if ((old_len - old_pos) > key_len && | |
58 strncmp(&_msg[old_pos], key, key_len) == 0 && | |
59 _msg[old_pos + key_len] == '\"') { | |
60 old_pos += (key_len + 2); | |
61 // Skip until next , or }. | |
62 while (_msg[old_pos] != '\0' && | |
63 _msg[old_pos] != ',' && | |
64 _msg[old_pos] != '}') { | |
65 old_pos++; | |
66 } | |
67 if (_msg[old_pos] == ',') { | |
68 old_pos++; | |
69 } | |
70 } else { | |
71 new_msg[new_pos] = '\"';; | |
72 new_pos++; | |
73 } | |
74 } else { | |
75 new_msg[new_pos] = _msg[old_pos]; | |
76 new_pos++; | |
77 old_pos++; | |
78 } | |
79 } | |
80 new_msg[new_pos] = '\0'; | |
81 free(_msg); | |
82 _msg = new_msg; | |
83 } | |
84 | |
85 const char* msg() const { return _msg; } | 47 const char* msg() const { return _msg; } |
86 | 48 |
87 private: | 49 private: |
88 char* _msg; | 50 char* _msg; |
89 }; | 51 }; |
90 | 52 |
91 | 53 |
92 static RawArray* EvalVM(Dart_Handle lib, const char* expr) { | |
93 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr)); | |
94 EXPECT_VALID(expr_val); | |
95 Isolate* isolate = Isolate::Current(); | |
96 const GrowableObjectArray& value = | |
97 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val); | |
98 const Array& result = Array::Handle(Array::MakeArray(value)); | |
99 GrowableObjectArray& growable = GrowableObjectArray::Handle(); | |
100 growable ^= result.At(3); | |
101 Array& array = Array::Handle(Array::MakeArray(growable)); | |
102 result.SetAt(3, array); | |
103 growable ^= result.At(4); | |
104 array = Array::MakeArray(growable); | |
105 result.SetAt(4, array); | |
106 return result.raw(); | |
107 } | |
108 | |
109 | |
110 static RawArray* Eval(Dart_Handle lib, const char* expr) { | 54 static RawArray* Eval(Dart_Handle lib, const char* expr) { |
111 const String& dummy_isolate_id = String::Handle(String::New("isolateId")); | 55 const String& dummy_isolate_id = String::Handle(String::New("isolateId")); |
112 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr)); | 56 Dart_Handle expr_val = Dart_EvaluateExpr(lib, NewString(expr)); |
113 EXPECT_VALID(expr_val); | 57 EXPECT_VALID(expr_val); |
114 Isolate* isolate = Isolate::Current(); | 58 Isolate* isolate = Isolate::Current(); |
115 const GrowableObjectArray& value = | 59 const GrowableObjectArray& value = |
116 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val); | 60 Api::UnwrapGrowableObjectArrayHandle(isolate, expr_val); |
117 const Array& result = Array::Handle(Array::MakeArray(value)); | 61 const Array& result = Array::Handle(Array::MakeArray(value)); |
118 GrowableObjectArray& growable = GrowableObjectArray::Handle(); | 62 GrowableObjectArray& growable = GrowableObjectArray::Handle(); |
119 growable ^= result.At(3); | 63 growable ^= result.At(3); |
(...skipping 21 matching lines...) Expand all Loading... |
141 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | 85 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
142 va_list args2; | 86 va_list args2; |
143 va_start(args2, fmt); | 87 va_start(args2, fmt); |
144 OS::VSNPrint(buffer, (len + 1), fmt, args2); | 88 OS::VSNPrint(buffer, (len + 1), fmt, args2); |
145 va_end(args2); | 89 va_end(args2); |
146 | 90 |
147 return Eval(lib, buffer); | 91 return Eval(lib, buffer); |
148 } | 92 } |
149 | 93 |
150 | 94 |
151 // Search for the formatted string in buffer. | |
152 // | |
153 // TODO(turnidge): This function obscures the line number of failing | |
154 // EXPECTs. Rework this. | |
155 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { | |
156 Isolate* isolate = Isolate::Current(); | |
157 | |
158 va_list args; | |
159 va_start(args, fmt); | |
160 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); | |
161 va_end(args); | |
162 | |
163 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | |
164 va_list args2; | |
165 va_start(args2, fmt); | |
166 OS::VSNPrint(buffer, (len + 1), fmt, args2); | |
167 va_end(args2); | |
168 | |
169 EXPECT_SUBSTRING(buffer, buff); | |
170 } | |
171 | |
172 | |
173 static RawFunction* GetFunction(const Class& cls, const char* name) { | 95 static RawFunction* GetFunction(const Class& cls, const char* name) { |
174 const Function& result = Function::Handle(cls.LookupDynamicFunction( | 96 const Function& result = Function::Handle(cls.LookupDynamicFunction( |
175 String::Handle(String::New(name)))); | 97 String::Handle(String::New(name)))); |
176 EXPECT(!result.IsNull()); | 98 EXPECT(!result.IsNull()); |
177 return result.raw(); | 99 return result.raw(); |
178 } | 100 } |
179 | 101 |
180 | 102 |
181 static RawClass* GetClass(const Library& lib, const char* name) { | 103 static RawClass* GetClass(const Library& lib, const char* name) { |
182 const Class& cls = Class::Handle( | 104 const Class& cls = Class::Handle( |
183 lib.LookupClass(String::Handle(Symbols::New(name)))); | 105 lib.LookupClass(String::Handle(Symbols::New(name)))); |
184 EXPECT(!cls.IsNull()); // No ambiguity error expected. | 106 EXPECT(!cls.IsNull()); // No ambiguity error expected. |
185 return cls.raw(); | 107 return cls.raw(); |
186 } | 108 } |
187 | 109 |
188 | 110 |
189 TEST_CASE(Service_Isolate) { | |
190 const char* kScript = | |
191 "var port;\n" // Set to our mock port by C++. | |
192 "\n" | |
193 "main() {\n" | |
194 "}"; | |
195 | |
196 Isolate* isolate = Isolate::Current(); | |
197 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
198 EXPECT_VALID(lib); | |
199 | |
200 // Build a mock message handler and wrap it in a dart port. | |
201 ServiceTestMessageHandler handler; | |
202 Dart_Port port_id = PortMap::CreatePort(&handler); | |
203 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
204 EXPECT_VALID(port); | |
205 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
206 | |
207 Array& service_msg = Array::Handle(); | |
208 | |
209 // Get the isolate summary. | |
210 service_msg = Eval(lib, "[0, port, 'getIsolate', [], []]"); | |
211 Service::HandleIsolateMessage(isolate, service_msg); | |
212 handler.HandleNextMessage(); | |
213 | |
214 JSONReader reader(handler.msg()); | |
215 | |
216 const int kBufferSize = 128; | |
217 char buffer[kBufferSize]; | |
218 | |
219 // Check that the response string is somewhat sane. | |
220 | |
221 // type | |
222 EXPECT(reader.Seek("type")); | |
223 EXPECT_EQ(reader.Type(), JSONReader::kString); | |
224 reader.GetDecodedValueChars(buffer, kBufferSize); | |
225 EXPECT_STREQ("Isolate", buffer); | |
226 | |
227 // id | |
228 EXPECT(reader.Seek("id")); | |
229 EXPECT_EQ(reader.Type(), JSONReader::kString); | |
230 reader.GetDecodedValueChars(buffer, kBufferSize); | |
231 EXPECT_SUBSTRING("isolates/", buffer); | |
232 | |
233 // heap | |
234 EXPECT(reader.Seek("heaps")); | |
235 EXPECT_EQ(reader.Type(), JSONReader::kObject); | |
236 } | |
237 | |
238 | |
239 TEST_CASE(Service_Objects) { | |
240 // TODO(turnidge): Extend this test to cover a non-trivial stack trace. | |
241 const char* kScript = | |
242 "var port;\n" // Set to our mock port by C++. | |
243 "var validId;\n" // Set to a valid object id by C++. | |
244 "\n" | |
245 "main() {\n" | |
246 "}"; | |
247 | |
248 Isolate* isolate = Isolate::Current(); | |
249 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
250 EXPECT_VALID(lib); | |
251 | |
252 // Build a mock message handler and wrap it in a dart port. | |
253 ServiceTestMessageHandler handler; | |
254 Dart_Port port_id = PortMap::CreatePort(&handler); | |
255 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
256 EXPECT_VALID(port); | |
257 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
258 | |
259 ObjectIdRing* ring = isolate->object_id_ring(); | |
260 const Array& arr = Array::Handle(Array::New(1, Heap::kOld)); | |
261 { | |
262 HANDLESCOPE(isolate); | |
263 const String& str = String::Handle(String::New("value", Heap::kOld)); | |
264 arr.SetAt(0, str); | |
265 } | |
266 intptr_t arr_id = ring->GetIdForObject(arr.raw()); | |
267 Dart_Handle valid_id = Dart_NewInteger(arr_id); | |
268 EXPECT_VALID(valid_id); | |
269 EXPECT_VALID(Dart_SetField(lib, NewString("validId"), valid_id)); | |
270 | |
271 Array& service_msg = Array::Handle(); | |
272 | |
273 // null | |
274 service_msg = Eval(lib, "[0, port, 'getObject', " | |
275 "['objectId'], ['objects/null']]"); | |
276 Service::HandleIsolateMessage(isolate, service_msg); | |
277 handler.HandleNextMessage(); | |
278 handler.filterMsg("_vmName"); | |
279 EXPECT_SUBSTRING( | |
280 "{\"type\":\"null\",\"id\":\"objects\\/null\"," | |
281 "\"valueAsString\":\"null\",\"class\":", | |
282 handler.msg()); | |
283 | |
284 // bool | |
285 service_msg = Eval(lib, "[0, port, 'getObject', " | |
286 "['objectId'], ['objects/bool-true']]"); | |
287 Service::HandleIsolateMessage(isolate, service_msg); | |
288 handler.HandleNextMessage(); | |
289 handler.filterMsg("_vmName"); | |
290 handler.filterMsg("size"); | |
291 EXPECT_STREQ( | |
292 "{\"type\":\"bool\"," | |
293 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/45\"," | |
294 "\"name\":\"bool\"}," | |
295 "\"fields\":[],\"id\":\"objects\\/bool-true\"," | |
296 "\"valueAsString\":\"true\"}", | |
297 handler.msg()); | |
298 | |
299 // int | |
300 service_msg = Eval(lib, "[0, port, 'getObject', " | |
301 "['objectId'], ['objects/int-123']]"); | |
302 Service::HandleIsolateMessage(isolate, service_msg); | |
303 handler.HandleNextMessage(); | |
304 handler.filterMsg("_vmName"); | |
305 EXPECT_STREQ( | |
306 "{\"type\":\"int\",\"_vmType\":\"Smi\"," | |
307 "\"class\":{\"type\":\"@Class\",\"id\":\"classes\\/41\"," | |
308 "\"name\":\"_Smi\",}," | |
309 "\"fields\":[]," | |
310 "\"id\":\"objects\\/int-123\"," | |
311 "\"valueAsString\":\"123\"}", | |
312 handler.msg()); | |
313 | |
314 // object id ring / valid | |
315 service_msg = Eval(lib, "[0, port, 'getObject', " | |
316 "['objectId'], ['objects/$validId']]"); | |
317 Service::HandleIsolateMessage(isolate, service_msg); | |
318 handler.HandleNextMessage(); | |
319 handler.filterMsg("_vmName"); | |
320 handler.filterMsg("size"); | |
321 handler.filterMsg("id"); | |
322 EXPECT_STREQ( | |
323 "{\"type\":\"List\",\"_vmType\":\"Array\"," | |
324 "\"class\":{\"type\":\"@Class\",\"name\":\"_List\",}," | |
325 "\"fields\":[]," | |
326 "\"length\":1," | |
327 "\"elements\":[{" | |
328 "\"index\":0," | |
329 "\"value\":{\"type\":\"@String\"," | |
330 "\"class\":{\"type\":\"@Class\",\"name\":\"_OneByteString\",}," | |
331 "\"valueAsString\":\"value\"}}]}", | |
332 handler.msg()); | |
333 | |
334 // object id ring / invalid => expired | |
335 service_msg = Eval(lib, "[0, port, 'getObject', " | |
336 "['objectId'], ['objects/99999999']]"); | |
337 Service::HandleIsolateMessage(isolate, service_msg); | |
338 handler.HandleNextMessage(); | |
339 handler.filterMsg("_vmName"); | |
340 EXPECT_STREQ( | |
341 "{\"type\":\"Sentinel\",\"id\":\"objects\\/expired\"," | |
342 "\"valueAsString\":\"<expired>\"}", | |
343 handler.msg()); | |
344 | |
345 // Retained by single instance. | |
346 service_msg = Eval( | |
347 lib, | |
348 "[0, port, 'getRetainedSize', " | |
349 "['targetId'], ['objects/$validId']]"); | |
350 Service::HandleIsolateMessage(isolate, service_msg); | |
351 handler.HandleNextMessage(); | |
352 handler.filterMsg("_vmName"); | |
353 ExpectSubstringF(handler.msg(), | |
354 "\"id\":\"objects\\/int-%" Pd "\"", | |
355 arr.raw()->Size() + arr.At(0)->Size()); | |
356 | |
357 // Retaining path to 'arr', limit 1. | |
358 service_msg = Eval( | |
359 lib, | |
360 "[0, port, 'getRetainingPath', " | |
361 "['targetId', 'limit'], ['objects/$validId', '1']]"); | |
362 Service::HandleIsolateMessage(isolate, service_msg); | |
363 handler.HandleNextMessage(); | |
364 ExpectSubstringF( | |
365 handler.msg(), | |
366 "{\"type\":\"RetainingPath\",\"length\":1," | |
367 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@List\""); | |
368 | |
369 // Retaining path missing limit. | |
370 service_msg = Eval( | |
371 lib, | |
372 "[0, port, 'getRetainingPath', " | |
373 "['targetId'], ['objects/$validId']]"); | |
374 Service::HandleIsolateMessage(isolate, service_msg); | |
375 handler.HandleNextMessage(); | |
376 ExpectSubstringF(handler.msg(), "{\"type\":\"Error\""); | |
377 } | |
378 | |
379 | |
380 TEST_CASE(Service_RetainingPath) { | |
381 const char* kScript = | |
382 "var port;\n" // Set to our mock port by C++. | |
383 "var id0;\n" // Set to an object id by C++. | |
384 "var id1;\n" // Ditto. | |
385 "var idElem;\n" // Ditto. | |
386 "class Foo {\n" | |
387 " String f0;\n" | |
388 " String f1;\n" | |
389 "}\n" | |
390 "Foo foo;\n" | |
391 "List<String> lst;\n" | |
392 "main() {\n" | |
393 " foo = new Foo();\n" | |
394 " lst = new List<String>(100);\n" | |
395 "}\n"; | |
396 Isolate* isolate = Isolate::Current(); | |
397 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
398 EXPECT_VALID(lib); | |
399 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
400 EXPECT_VALID(result); | |
401 Library& vmlib = Library::Handle(); | |
402 vmlib ^= Api::UnwrapHandle(lib); | |
403 EXPECT(!vmlib.IsNull()); | |
404 const Class& class_foo = Class::Handle(GetClass(vmlib, "Foo")); | |
405 EXPECT(!class_foo.IsNull()); | |
406 Dart_Handle foo = Dart_GetField(lib, NewString("foo")); | |
407 Dart_Handle lst = Dart_GetField(lib, NewString("lst")); | |
408 const intptr_t kElemIndex = 42; | |
409 { | |
410 Dart_EnterScope(); | |
411 ObjectIdRing* ring = isolate->object_id_ring(); | |
412 { | |
413 const String& foo0 = String::Handle(String::New("foo0", Heap::kOld)); | |
414 Dart_Handle h_foo0 = Api::NewHandle(isolate, foo0.raw()); | |
415 EXPECT_VALID(Dart_SetField(foo, NewString("f0"), h_foo0)); | |
416 Dart_Handle id0 = Dart_NewInteger(ring->GetIdForObject(foo0.raw())); | |
417 EXPECT_VALID(id0); | |
418 EXPECT_VALID(Dart_SetField(lib, NewString("id0"), id0)); | |
419 } | |
420 { | |
421 const String& foo1 = String::Handle(String::New("foo1", Heap::kOld)); | |
422 Dart_Handle h_foo1 = Api::NewHandle(isolate, foo1.raw()); | |
423 EXPECT_VALID(Dart_SetField(foo, NewString("f1"), h_foo1)); | |
424 Dart_Handle id1 = Dart_NewInteger(ring->GetIdForObject(foo1.raw())); | |
425 EXPECT_VALID(id1); | |
426 EXPECT_VALID(Dart_SetField(lib, NewString("id1"), id1)); | |
427 } | |
428 { | |
429 const String& elem = String::Handle(String::New("elem", Heap::kOld)); | |
430 Dart_Handle h_elem = Api::NewHandle(isolate, elem.raw()); | |
431 EXPECT_VALID(Dart_ListSetAt(lst, kElemIndex, h_elem)); | |
432 Dart_Handle idElem = Dart_NewInteger(ring->GetIdForObject(elem.raw())); | |
433 EXPECT_VALID(idElem); | |
434 EXPECT_VALID(Dart_SetField(lib, NewString("idElem"), idElem)); | |
435 } | |
436 Dart_ExitScope(); | |
437 } | |
438 | |
439 // Build a mock message handler and wrap it in a dart port. | |
440 ServiceTestMessageHandler handler; | |
441 Dart_Port port_id = PortMap::CreatePort(&handler); | |
442 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
443 EXPECT_VALID(port); | |
444 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
445 Array& service_msg = Array::Handle(); | |
446 | |
447 // Retaining path to 'foo0', limit 2. | |
448 service_msg = Eval( | |
449 lib, | |
450 "[0, port, 'getRetainingPath', " | |
451 "['targetId', 'limit'], ['objects/$id0', '2']]"); | |
452 Service::HandleIsolateMessage(isolate, service_msg); | |
453 handler.HandleNextMessage(); | |
454 ExpectSubstringF( | |
455 handler.msg(), | |
456 "{\"type\":\"RetainingPath\",\"length\":2," | |
457 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); | |
458 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\""); | |
459 ExpectSubstringF(handler.msg(), "\"name\":\"f0\""); | |
460 ExpectSubstringF(handler.msg(), | |
461 "{\"index\":1,\"value\":{\"type\":\"@Instance\""); | |
462 | |
463 // Retaining path to 'foo1', limit 2. | |
464 service_msg = Eval( | |
465 lib, | |
466 "[0, port, 'getRetainingPath', " | |
467 "['targetId', 'limit'], ['objects/$id1', '2']]"); | |
468 Service::HandleIsolateMessage(isolate, service_msg); | |
469 handler.HandleNextMessage(); | |
470 ExpectSubstringF( | |
471 handler.msg(), | |
472 "{\"type\":\"RetainingPath\",\"length\":2," | |
473 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); | |
474 ExpectSubstringF(handler.msg(), "\"parentField\":{\"type\":\"@Field\""); | |
475 ExpectSubstringF(handler.msg(), "\"name\":\"f1\""); | |
476 ExpectSubstringF(handler.msg(), | |
477 "{\"index\":1,\"value\":{\"type\":\"@Instance\""); | |
478 | |
479 // Retaining path to 'elem', limit 2. | |
480 service_msg = Eval( | |
481 lib, | |
482 "[0, port, 'getRetainingPath', " | |
483 "['targetId', 'limit'], ['objects/$idElem', '2']]"); | |
484 Service::HandleIsolateMessage(isolate, service_msg); | |
485 handler.HandleNextMessage(); | |
486 ExpectSubstringF( | |
487 handler.msg(), | |
488 "{\"type\":\"RetainingPath\",\"length\":2," | |
489 "\"elements\":[{\"index\":0,\"value\":{\"type\":\"@String\""); | |
490 ExpectSubstringF(handler.msg(), "\"parentListIndex\":%" Pd, kElemIndex); | |
491 ExpectSubstringF(handler.msg(), | |
492 "{\"index\":1,\"value\":{\"type\":\"@List\""); | |
493 } | |
494 | |
495 | |
496 TEST_CASE(Service_Libraries) { | |
497 const char* kScript = | |
498 "var port;\n" // Set to our mock port by C++. | |
499 "var libVar = 54321;\n" | |
500 "\n" | |
501 "main() {\n" | |
502 "}"; | |
503 | |
504 Isolate* isolate = Isolate::Current(); | |
505 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
506 EXPECT_VALID(lib); | |
507 Library& vmlib = Library::Handle(); | |
508 vmlib ^= Api::UnwrapHandle(lib); | |
509 EXPECT(!vmlib.IsNull()); | |
510 | |
511 // Build a mock message handler and wrap it in a dart port. | |
512 ServiceTestMessageHandler handler; | |
513 Dart_Port port_id = PortMap::CreatePort(&handler); | |
514 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
515 EXPECT_VALID(port); | |
516 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
517 | |
518 Array& service_msg = Array::Handle(); | |
519 | |
520 // Request library. | |
521 service_msg = | |
522 EvalF(lib, | |
523 "[0, port, 'getObject', ['objectId'], ['libraries/%" Pd "']]", | |
524 vmlib.index()); | |
525 Service::HandleIsolateMessage(isolate, service_msg); | |
526 handler.HandleNextMessage(); | |
527 EXPECT_SUBSTRING("\"type\":\"Library\"", handler.msg()); | |
528 EXPECT_SUBSTRING("\"url\":\"test-lib\"", handler.msg()); | |
529 } | |
530 | |
531 | |
532 TEST_CASE(Service_Classes) { | |
533 const char* kScript = | |
534 "var port;\n" // Set to our mock port by C++. | |
535 "\n" | |
536 "class A {\n" | |
537 " var a;\n" | |
538 " static var cobra = 11235;\n" | |
539 " dynamic b() {}\n" | |
540 " dynamic c() {\n" | |
541 " var d = () { b(); };\n" | |
542 " return d;\n" | |
543 " }\n" | |
544 "}\n" | |
545 "class B { static int i = 42; }\n" | |
546 "main() {\n" | |
547 " var z = new A();\n" | |
548 " var x = z.c();\n" | |
549 " x();\n" | |
550 " ++B.i;\n" | |
551 "}"; | |
552 | |
553 Isolate* isolate = Isolate::Current(); | |
554 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
555 EXPECT_VALID(lib); | |
556 Library& vmlib = Library::Handle(); | |
557 vmlib ^= Api::UnwrapHandle(lib); | |
558 EXPECT(!vmlib.IsNull()); | |
559 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
560 EXPECT_VALID(result); | |
561 const Class& class_a = Class::Handle(GetClass(vmlib, "A")); | |
562 EXPECT(!class_a.IsNull()); | |
563 intptr_t cid = class_a.id(); | |
564 | |
565 // Build a mock message handler and wrap it in a dart port. | |
566 ServiceTestMessageHandler handler; | |
567 Dart_Port port_id = PortMap::CreatePort(&handler); | |
568 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
569 EXPECT_VALID(port); | |
570 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
571 | |
572 Array& service_msg = Array::Handle(); | |
573 | |
574 // Request an invalid class id. | |
575 service_msg = Eval(lib, "[0, port, 'getObject', " | |
576 "['objectId'], ['classes/999999']]"); | |
577 Service::HandleIsolateMessage(isolate, service_msg); | |
578 handler.HandleNextMessage(); | |
579 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
580 | |
581 // Request the class A over the service. | |
582 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
583 "['objectId'], ['classes/%" Pd "']]", cid); | |
584 Service::HandleIsolateMessage(isolate, service_msg); | |
585 handler.HandleNextMessage(); | |
586 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); | |
587 ExpectSubstringF(handler.msg(), | |
588 "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid); | |
589 ExpectSubstringF(handler.msg(), "\"allocationStats\":"); | |
590 ExpectSubstringF(handler.msg(), "\"tokenPos\":"); | |
591 ExpectSubstringF(handler.msg(), "\"endTokenPos\":"); | |
592 | |
593 // Request function 'b' from class A. | |
594 service_msg = EvalF(lib, | |
595 "[0, port, 'getObject', " | |
596 "['objectId'], ['classes/%" Pd "/functions/b']]", cid); | |
597 Service::HandleIsolateMessage(isolate, service_msg); | |
598 handler.HandleNextMessage(); | |
599 EXPECT_SUBSTRING("\"type\":\"Function\"", handler.msg()); | |
600 ExpectSubstringF(handler.msg(), | |
601 "\"id\":\"classes\\/%" Pd "\\/functions\\/b\"," | |
602 "\"name\":\"b\",", cid); | |
603 | |
604 // Request field 0 from class A. | |
605 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
606 "['objectId'], ['classes/%" Pd "/fields/0']]", cid); | |
607 Service::HandleIsolateMessage(isolate, service_msg); | |
608 handler.HandleNextMessage(); | |
609 EXPECT_SUBSTRING("\"type\":\"Field\"", handler.msg()); | |
610 ExpectSubstringF(handler.msg(), | |
611 "\"id\":\"classes\\/%" Pd "\\/fields\\/0\"," | |
612 "\"name\":\"a\",", cid); | |
613 | |
614 // Invalid sub command. | |
615 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
616 "['objectId'], ['classes/%" Pd "/huh']]", cid); | |
617 Service::HandleIsolateMessage(isolate, service_msg); | |
618 handler.HandleNextMessage(); | |
619 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
620 | |
621 // Invalid field request. | |
622 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
623 "['objectId'], ['classes/%" Pd "/fields/9']]", cid); | |
624 Service::HandleIsolateMessage(isolate, service_msg); | |
625 handler.HandleNextMessage(); | |
626 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
627 | |
628 // Invalid function request. | |
629 service_msg = EvalF(lib, | |
630 "[0, port, 'getObject', " | |
631 "['objectId'], ['classes/%" Pd "/functions/9']]", cid); | |
632 Service::HandleIsolateMessage(isolate, service_msg); | |
633 handler.HandleNextMessage(); | |
634 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
635 | |
636 // Invalid field subcommand. | |
637 service_msg = EvalF(lib, | |
638 "[0, port, 'getObject', " | |
639 "['objectId'], ['classes/%" Pd "/fields/9']]", cid); | |
640 Service::HandleIsolateMessage(isolate, service_msg); | |
641 handler.HandleNextMessage(); | |
642 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
643 | |
644 // Invalid function command. | |
645 service_msg = EvalF(lib, | |
646 "[0, port, 'getObject', " | |
647 "['objectId'], ['classes/%" Pd "/functions/0/x/y']]", | |
648 cid); | |
649 Service::HandleIsolateMessage(isolate, service_msg); | |
650 handler.HandleNextMessage(); | |
651 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
652 | |
653 // Invalid function subcommand with valid function id. | |
654 service_msg = EvalF(lib, | |
655 "[0, port, 'getObject', " | |
656 "['objectId'], ['classes/%" Pd "/functions/b/x']]", cid); | |
657 Service::HandleIsolateMessage(isolate, service_msg); | |
658 handler.HandleNextMessage(); | |
659 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
660 | |
661 // Retained size of all instances of class B. | |
662 const Class& class_b = Class::Handle(GetClass(vmlib, "B")); | |
663 EXPECT(!class_b.IsNull()); | |
664 const Instance& b0 = Instance::Handle(Instance::New(class_b)); | |
665 const Instance& b1 = Instance::Handle(Instance::New(class_b)); | |
666 service_msg = EvalF(lib, "[0, port, 'getRetainedSize', " | |
667 "['targetId'], ['classes/%" Pd "']]", class_b.id()); | |
668 Service::HandleIsolateMessage(isolate, service_msg); | |
669 handler.HandleNextMessage(); | |
670 ExpectSubstringF(handler.msg(), | |
671 "\"id\":\"objects\\/int-%" Pd "\"", | |
672 b0.raw()->Size() + b1.raw()->Size()); | |
673 // ... and list the instances of class B. | |
674 service_msg = EvalF(lib, "[0, port, 'getInstances', " | |
675 "['classId', 'limit'], ['classes/%" Pd "', '3']]", | |
676 class_b.id()); | |
677 Service::HandleIsolateMessage(isolate, service_msg); | |
678 handler.HandleNextMessage(); | |
679 ExpectSubstringF(handler.msg(), "\"type\":\"InstanceSet\""); | |
680 ExpectSubstringF(handler.msg(), "\"totalCount\":2"); | |
681 ExpectSubstringF(handler.msg(), "\"sampleCount\":2"); | |
682 // TODO(koda): Actually parse the response. | |
683 static const intptr_t kInstanceListId = 0; | |
684 ExpectSubstringF(handler.msg(), "\"id\":\"objects\\/%" Pd "\",\"length\":2", | |
685 kInstanceListId); | |
686 Array& list = Array::Handle(); | |
687 ObjectIdRing::LookupResult kind; | |
688 list ^= isolate->object_id_ring()->GetObjectForId(kInstanceListId, &kind); | |
689 EXPECT_EQ(2, list.Length()); | |
690 // The list should contain {b0, b1}. | |
691 EXPECT((list.At(0) == b0.raw() && list.At(1) == b1.raw()) || | |
692 (list.At(0) == b1.raw() && list.At(1) == b0.raw())); | |
693 // ... and if limit is 1, we one get one of them. | |
694 service_msg = EvalF(lib, "[0, port, 'getInstances', " | |
695 "['classId', 'limit'], ['classes/%" Pd "', '1']]", | |
696 class_b.id()); | |
697 Service::HandleIsolateMessage(isolate, service_msg); | |
698 handler.HandleNextMessage(); | |
699 ExpectSubstringF(handler.msg(), "\"totalCount\":2"); | |
700 ExpectSubstringF(handler.msg(), "\"sampleCount\":1"); | |
701 } | |
702 | |
703 | |
704 TEST_CASE(Service_Types) { | |
705 const char* kScript = | |
706 "var port;\n" // Set to our mock port by C++. | |
707 "\n" | |
708 "class A<T> { }\n" | |
709 "\n" | |
710 "main() {\n" | |
711 " new A<A<bool>>();\n" | |
712 "}"; | |
713 | |
714 Isolate* isolate = Isolate::Current(); | |
715 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
716 EXPECT_VALID(lib); | |
717 Library& vmlib = Library::Handle(); | |
718 vmlib ^= Api::UnwrapHandle(lib); | |
719 EXPECT(!vmlib.IsNull()); | |
720 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
721 EXPECT_VALID(result); | |
722 const Class& class_a = Class::Handle(GetClass(vmlib, "A")); | |
723 EXPECT(!class_a.IsNull()); | |
724 intptr_t cid = class_a.id(); | |
725 | |
726 // Build a mock message handler and wrap it in a dart port. | |
727 ServiceTestMessageHandler handler; | |
728 Dart_Port port_id = PortMap::CreatePort(&handler); | |
729 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
730 EXPECT_VALID(port); | |
731 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
732 | |
733 Array& service_msg = Array::Handle(); | |
734 | |
735 // Request the class A over the service. | |
736 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
737 "['objectId'], ['classes/%" Pd "']]]", cid); | |
738 Service::HandleIsolateMessage(isolate, service_msg); | |
739 handler.HandleNextMessage(); | |
740 EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); | |
741 EXPECT_SUBSTRING("\"name\":\"A\"", handler.msg()); | |
742 ExpectSubstringF(handler.msg(), | |
743 "\"id\":\"classes\\/%" Pd "\"", cid); | |
744 | |
745 // Request canonical type 0 from class A. | |
746 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
747 "['objectId'], ['classes/%" Pd "/types/0']]", cid); | |
748 Service::HandleIsolateMessage(isolate, service_msg); | |
749 handler.HandleNextMessage(); | |
750 EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg()); | |
751 EXPECT_SUBSTRING("\"name\":\"A<bool>\"", handler.msg()); | |
752 ExpectSubstringF(handler.msg(), | |
753 "\"id\":\"classes\\/%" Pd "\\/types\\/0\"", cid); | |
754 | |
755 // Request canonical type 1 from class A. | |
756 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
757 "['objectId'], ['classes/%" Pd "/types/1']]", cid); | |
758 Service::HandleIsolateMessage(isolate, service_msg); | |
759 handler.HandleNextMessage(); | |
760 EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg()); | |
761 EXPECT_SUBSTRING("\"name\":\"A<A<bool>>\"", handler.msg()); | |
762 ExpectSubstringF(handler.msg(), | |
763 "\"id\":\"classes\\/%" Pd "\\/types\\/1\"", cid); | |
764 | |
765 // Request for non-existent canonical type from class A. | |
766 service_msg = EvalF(lib, "[0, port, 'getObject', " | |
767 "['objectId'], ['classes/%" Pd "/types/42']]", cid); | |
768 Service::HandleIsolateMessage(isolate, service_msg); | |
769 handler.HandleNextMessage(); | |
770 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
771 } | |
772 | |
773 | |
774 TEST_CASE(Service_Code) { | 111 TEST_CASE(Service_Code) { |
775 const char* kScript = | 112 const char* kScript = |
776 "var port;\n" // Set to our mock port by C++. | 113 "var port;\n" // Set to our mock port by C++. |
777 "\n" | 114 "\n" |
778 "class A {\n" | 115 "class A {\n" |
779 " var a;\n" | 116 " var a;\n" |
780 " dynamic b() {}\n" | 117 " dynamic b() {}\n" |
781 " dynamic c() {\n" | 118 " dynamic c() {\n" |
782 " var d = () { b(); };\n" | 119 " var d = () { b(); };\n" |
783 " return d;\n" | 120 " return d;\n" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 Service::HandleIsolateMessage(isolate, service_msg); | 386 Service::HandleIsolateMessage(isolate, service_msg); |
1050 handler.HandleNextMessage(); | 387 handler.HandleNextMessage(); |
1051 // Check type. | 388 // Check type. |
1052 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); | 389 EXPECT_SUBSTRING("\"type\":\"Object\"", handler.msg()); |
1053 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); | 390 EXPECT_SUBSTRING("\"_vmType\":\"LocalVarDescriptors\"", handler.msg()); |
1054 // Check for members array. | 391 // Check for members array. |
1055 EXPECT_SUBSTRING("\"members\":[", handler.msg()); | 392 EXPECT_SUBSTRING("\"members\":[", handler.msg()); |
1056 } | 393 } |
1057 | 394 |
1058 | 395 |
1059 TEST_CASE(Service_VM) { | |
1060 const char* kScript = | |
1061 "var port;\n" // Set to our mock port by C++. | |
1062 "\n" | |
1063 "main() {\n" | |
1064 "}"; | |
1065 | |
1066 Isolate* isolate = Isolate::Current(); | |
1067 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1068 EXPECT_VALID(lib); | |
1069 | |
1070 // Build a mock message handler and wrap it in a dart port. | |
1071 ServiceTestMessageHandler handler; | |
1072 Dart_Port port_id = PortMap::CreatePort(&handler); | |
1073 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
1074 EXPECT_VALID(port); | |
1075 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
1076 | |
1077 Array& service_msg = Array::Handle(); | |
1078 service_msg = EvalVM(lib, "[0, port, 'getVM', [], []]"); | |
1079 | |
1080 Service::HandleRootMessage(service_msg); | |
1081 handler.HandleNextMessage(); | |
1082 EXPECT_SUBSTRING("\"type\":\"VM\"", handler.msg()); | |
1083 EXPECT_SUBSTRING("\"targetCPU\"", handler.msg()); | |
1084 EXPECT_SUBSTRING("\"hostCPU\"", handler.msg()); | |
1085 EXPECT_SUBSTRING("\"version\"", handler.msg()); | |
1086 EXPECT_SUBSTRING("\"startTime\"", handler.msg()); | |
1087 EXPECT_SUBSTRING("\"isolates\"", handler.msg()); | |
1088 } | |
1089 | |
1090 | |
1091 TEST_CASE(Service_Flags) { | |
1092 const char* kScript = | |
1093 "var port;\n" // Set to our mock port by C++. | |
1094 "\n" | |
1095 "main() {\n" | |
1096 "}"; | |
1097 | |
1098 Isolate* isolate = Isolate::Current(); | |
1099 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1100 EXPECT_VALID(lib); | |
1101 | |
1102 // Build a mock message handler and wrap it in a dart port. | |
1103 ServiceTestMessageHandler handler; | |
1104 Dart_Port port_id = PortMap::CreatePort(&handler); | |
1105 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
1106 EXPECT_VALID(port); | |
1107 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
1108 | |
1109 Array& service_msg = Array::Handle(); | |
1110 service_msg = EvalVM(lib, "[0, port, 'getFlagList', [], []]"); | |
1111 | |
1112 // Make sure we can get the FlagList. | |
1113 Service::HandleRootMessage(service_msg); | |
1114 handler.HandleNextMessage(); | |
1115 EXPECT_SUBSTRING("\"type\":\"FlagList\"", handler.msg()); | |
1116 EXPECT_SUBSTRING( | |
1117 "\"name\":\"service_testing_flag\",\"comment\":\"Comment\"," | |
1118 "\"flagType\":\"bool\",\"valueAsString\":\"false\"", | |
1119 handler.msg()); | |
1120 | |
1121 // Modify a flag through the vm service. | |
1122 service_msg = EvalVM(lib, | |
1123 "[0, port, 'setFlag', " | |
1124 "['name', 'value'], ['service_testing_flag', 'true']]"); | |
1125 Service::HandleRootMessage(service_msg); | |
1126 handler.HandleNextMessage(); | |
1127 EXPECT_SUBSTRING("Success", handler.msg()); | |
1128 | |
1129 // Make sure that the flag changed. | |
1130 service_msg = EvalVM(lib, "[0, port, 'getFlagList', [], []]"); | |
1131 Service::HandleRootMessage(service_msg); | |
1132 handler.HandleNextMessage(); | |
1133 EXPECT_SUBSTRING( | |
1134 "\"name\":\"service_testing_flag\",\"comment\":\"Comment\"," | |
1135 "\"flagType\":\"bool\",\"valueAsString\":\"true\"", | |
1136 handler.msg()); | |
1137 } | |
1138 | |
1139 | |
1140 TEST_CASE(Service_Scripts) { | |
1141 const char* kScript = | |
1142 "var port;\n" // Set to our mock port by C++. | |
1143 "\n" | |
1144 "main() {\n" | |
1145 "}"; | |
1146 | |
1147 Isolate* isolate = Isolate::Current(); | |
1148 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1149 EXPECT_VALID(lib); | |
1150 Library& vmlib = Library::Handle(); | |
1151 vmlib ^= Api::UnwrapHandle(lib); | |
1152 EXPECT(!vmlib.IsNull()); | |
1153 | |
1154 // Build a mock message handler and wrap it in a dart port. | |
1155 ServiceTestMessageHandler handler; | |
1156 Dart_Port port_id = PortMap::CreatePort(&handler); | |
1157 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
1158 EXPECT_VALID(port); | |
1159 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
1160 | |
1161 Array& service_msg = Array::Handle(); | |
1162 char buf[1024]; | |
1163 OS::SNPrint(buf, sizeof(buf), | |
1164 "[0, port, 'getObject', " | |
1165 "['objectId'], ['libraries/%" Pd "/scripts/test-lib']]", | |
1166 vmlib.index()); | |
1167 | |
1168 service_msg = Eval(lib, buf); | |
1169 Service::HandleIsolateMessage(isolate, service_msg); | |
1170 handler.HandleNextMessage(); | |
1171 OS::SNPrint(buf, sizeof(buf), | |
1172 "{\"type\":\"Script\"," | |
1173 "\"id\":\"libraries\\/%" Pd "\\/scripts\\/test-lib\"," | |
1174 "\"name\":\"test-lib\"," | |
1175 "\"kind\":\"script\"," | |
1176 "\"library\":{\"type\":\"@Library\"," | |
1177 "\"id\":\"libraries\\/%" Pd "\",\"name\":\"\"," | |
1178 "\"url\":\"test-lib\"}," | |
1179 "\"source\":\"var port;\\n\\nmain() {\\n}\"," | |
1180 "\"tokenPosTable\":[[1,0,1,1,5,2,9],[3,5,1,6,5,7,6,8,8],[4,10,1]]}", | |
1181 vmlib.index(), vmlib.index()); | |
1182 EXPECT_STREQ(buf, handler.msg()); | |
1183 } | |
1184 | |
1185 | |
1186 TEST_CASE(Service_AllocationProfile) { | |
1187 const char* kScript = | |
1188 "var port;\n" // Set to our mock port by C++. | |
1189 "\n" | |
1190 "var x = 7;\n" | |
1191 "main() {\n" | |
1192 " x = x * x;\n" | |
1193 " x = x / 13;\n" | |
1194 "}"; | |
1195 | |
1196 Isolate* isolate = Isolate::Current(); | |
1197 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1198 EXPECT_VALID(lib); | |
1199 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
1200 EXPECT_VALID(result); | |
1201 | |
1202 // Build a mock message handler and wrap it in a dart port. | |
1203 ServiceTestMessageHandler handler; | |
1204 Dart_Port port_id = PortMap::CreatePort(&handler); | |
1205 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
1206 EXPECT_VALID(port); | |
1207 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
1208 | |
1209 Array& service_msg = Array::Handle(); | |
1210 service_msg = Eval(lib, "[0, port, 'getAllocationProfile', [], []]"); | |
1211 Service::HandleIsolateMessage(isolate, service_msg); | |
1212 handler.HandleNextMessage(); | |
1213 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); | |
1214 | |
1215 // Bad gc option. | |
1216 service_msg = Eval(lib, | |
1217 "[0, port, 'getAllocationProfile', " | |
1218 "['gc'], ['cat']]"); | |
1219 Service::HandleIsolateMessage(isolate, service_msg); | |
1220 handler.HandleNextMessage(); | |
1221 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
1222 | |
1223 // Bad reset option. | |
1224 service_msg = Eval(lib, "[0, port, 'getAllocationProfile', " | |
1225 "['reset'], ['ff']]"); | |
1226 Service::HandleIsolateMessage(isolate, service_msg); | |
1227 handler.HandleNextMessage(); | |
1228 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | |
1229 | |
1230 // Good reset. | |
1231 service_msg = | |
1232 Eval(lib, | |
1233 "[0, port, 'getAllocationProfile', ['reset'], ['true']]"); | |
1234 Service::HandleIsolateMessage(isolate, service_msg); | |
1235 handler.HandleNextMessage(); | |
1236 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); | |
1237 | |
1238 // Good GC. | |
1239 service_msg = | |
1240 Eval(lib, "[0, port, 'getAllocationProfile', ['gc'], ['full']]"); | |
1241 Service::HandleIsolateMessage(isolate, service_msg); | |
1242 handler.HandleNextMessage(); | |
1243 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); | |
1244 | |
1245 // Good GC and reset. | |
1246 service_msg = Eval(lib, "[0, port, 'getAllocationProfile', " | |
1247 "['gc', 'reset'], ['full', 'true']]"); | |
1248 Service::HandleIsolateMessage(isolate, service_msg); | |
1249 handler.HandleNextMessage(); | |
1250 EXPECT_SUBSTRING("\"type\":\"AllocationProfile\"", handler.msg()); | |
1251 } | |
1252 | |
1253 | |
1254 TEST_CASE(Service_HeapMap) { | |
1255 const char* kScript = | |
1256 "var port;\n" // Set to our mock port by C++. | |
1257 "\n" | |
1258 "main() {\n" | |
1259 "}"; | |
1260 | |
1261 Isolate* isolate = Isolate::Current(); | |
1262 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | |
1263 EXPECT_VALID(lib); | |
1264 | |
1265 // Build a mock message handler and wrap it in a dart port. | |
1266 ServiceTestMessageHandler handler; | |
1267 Dart_Port port_id = PortMap::CreatePort(&handler); | |
1268 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
1269 EXPECT_VALID(port); | |
1270 EXPECT_VALID(Dart_SetField(lib, NewString("port"), port)); | |
1271 | |
1272 Array& service_msg = Array::Handle(); | |
1273 service_msg = Eval(lib, "[0, port, 'getHeapMap', [], []]"); | |
1274 Service::HandleIsolateMessage(isolate, service_msg); | |
1275 handler.HandleNextMessage(); | |
1276 EXPECT_SUBSTRING("\"type\":\"HeapMap\"", handler.msg()); | |
1277 EXPECT_SUBSTRING("\"pages\":[", handler.msg()); | |
1278 } | |
1279 | |
1280 | |
1281 TEST_CASE(Service_Address) { | 396 TEST_CASE(Service_Address) { |
1282 const char* kScript = | 397 const char* kScript = |
1283 "var port;\n" // Set to our mock port by C++. | 398 "var port;\n" // Set to our mock port by C++. |
1284 "\n" | 399 "\n" |
1285 "main() {\n" | 400 "main() {\n" |
1286 "}"; | 401 "}"; |
1287 | 402 |
1288 Isolate* isolate = Isolate::Current(); | 403 Isolate* isolate = Isolate::Current(); |
1289 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); | 404 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL); |
1290 EXPECT_VALID(lib); | 405 EXPECT_VALID(lib); |
(...skipping 28 matching lines...) Expand all Loading... |
1319 "\"type\":\"String\"", | 434 "\"type\":\"String\"", |
1320 handler.msg()); | 435 handler.msg()); |
1321 EXPECT_SUBSTRING("foobar", handler.msg()); | 436 EXPECT_SUBSTRING("foobar", handler.msg()); |
1322 } | 437 } |
1323 // Expect null when no object is found. | 438 // Expect null when no object is found. |
1324 service_msg = Eval(lib, "[0, port, 'getObjectByAddress', " | 439 service_msg = Eval(lib, "[0, port, 'getObjectByAddress', " |
1325 "['address'], ['7']]"); | 440 "['address'], ['7']]"); |
1326 Service::HandleIsolateMessage(isolate, service_msg); | 441 Service::HandleIsolateMessage(isolate, service_msg); |
1327 handler.HandleNextMessage(); | 442 handler.HandleNextMessage(); |
1328 // TODO(turnidge): Should this be a ServiceException instead? | 443 // TODO(turnidge): Should this be a ServiceException instead? |
1329 EXPECT_SUBSTRING("{\"type\":\"null\",\"id\":\"objects\\/null\"," | 444 EXPECT_SUBSTRING("{\"type\":\"Sentinel\",\"id\":\"objects\\/free\"," |
1330 "\"valueAsString\":\"null\"", | 445 "\"valueAsString\":\"<free>\"", |
1331 handler.msg()); | 446 handler.msg()); |
1332 } | 447 } |
1333 | 448 |
1334 | 449 |
1335 static const char* alpha_callback( | 450 static const char* alpha_callback( |
1336 const char* name, | 451 const char* name, |
1337 const char** option_keys, | 452 const char** option_keys, |
1338 const char** option_values, | 453 const char** option_values, |
1339 intptr_t num_options, | 454 intptr_t num_options, |
1340 void* user_data) { | 455 void* user_data) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['Bogus']]"); | 587 Eval(lib, "[0, port, 'getCpuProfile', ['tags'], ['Bogus']]"); |
1473 Service::HandleIsolateMessage(isolate, service_msg); | 588 Service::HandleIsolateMessage(isolate, service_msg); |
1474 handler.HandleNextMessage(); | 589 handler.HandleNextMessage(); |
1475 // Expect error. | 590 // Expect error. |
1476 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 591 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
1477 } | 592 } |
1478 | 593 |
1479 #endif // !defined(TARGET_ARCH_ARM64) | 594 #endif // !defined(TARGET_ARCH_ARM64) |
1480 | 595 |
1481 } // namespace dart | 596 } // namespace dart |
OLD | NEW |