| 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 "[0, port, ['classes', '%" Pd "', 'fields', '9', 'x']" | 917 "[0, port, ['classes', '%" Pd "', 'fields', '9', 'x']" |
| 918 ",[], []]", cid); | 918 ",[], []]", cid); |
| 919 Service::HandleIsolateMessage(isolate, service_msg); | 919 Service::HandleIsolateMessage(isolate, service_msg); |
| 920 handler.HandleNextMessage(); | 920 handler.HandleNextMessage(); |
| 921 ExpectSubstringF(handler.msg(), | 921 ExpectSubstringF(handler.msg(), |
| 922 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," | 922 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," |
| 923 "\"request\":" | 923 "\"request\":" |
| 924 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"]," | 924 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"]," |
| 925 "\"option_keys\":[],\"option_values\":[]}}", cid); | 925 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 926 | 926 |
| 927 // Invalid function request. | 927 // Invalid function request with valid function id. |
| 928 service_msg = EvalF(h_lib, | 928 service_msg = EvalF(h_lib, |
| 929 "[0, port, ['classes', '%" Pd "', 'functions', '9'," | 929 "[0, port, ['classes', '%" Pd "', 'functions', '0'," |
| 930 "'x'], [], []]", cid); | 930 "'x'], [], []]", cid); |
| 931 Service::HandleIsolateMessage(isolate, service_msg); | 931 Service::HandleIsolateMessage(isolate, service_msg); |
| 932 handler.HandleNextMessage(); | 932 handler.HandleNextMessage(); |
| 933 ExpectSubstringF(handler.msg(), | 933 ExpectSubstringF(handler.msg(), |
| 934 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," | 934 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection x\"," |
| 935 "\"request\":" | 935 "\"request\":" |
| 936 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"9\",\"x\"]," | 936 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\"]," |
| 937 "\"option_keys\":[],\"option_values\":[]}}", cid); | 937 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 938 | 938 |
| 939 // Retained size of all instances of class B. | 939 // Retained size of all instances of class B. |
| 940 const Class& class_b = Class::Handle(GetClass(lib, "B")); | 940 const Class& class_b = Class::Handle(GetClass(lib, "B")); |
| 941 EXPECT(!class_b.IsNull()); | 941 EXPECT(!class_b.IsNull()); |
| 942 const Instance& b0 = Instance::Handle(Instance::New(class_b)); | 942 const Instance& b0 = Instance::Handle(Instance::New(class_b)); |
| 943 const Instance& b1 = Instance::Handle(Instance::New(class_b)); | 943 const Instance& b1 = Instance::Handle(Instance::New(class_b)); |
| 944 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'retained']," | 944 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'retained']," |
| 945 "[], []]", class_b.id()); | 945 "[], []]", class_b.id()); |
| 946 Service::HandleIsolateMessage(isolate, service_msg); | 946 Service::HandleIsolateMessage(isolate, service_msg); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 Service::HandleIsolateMessage(isolate, service_msg); | 1499 Service::HandleIsolateMessage(isolate, service_msg); |
| 1500 handler.HandleNextMessage(); | 1500 handler.HandleNextMessage(); |
| 1501 EXPECT_STREQ( | 1501 EXPECT_STREQ( |
| 1502 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" | 1502 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" |
| 1503 "{\"source\":\"test-lib\",\"script\":{" | 1503 "{\"source\":\"test-lib\",\"script\":{" |
| 1504 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," | 1504 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 1505 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," | 1505 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 1506 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}", handler.msg()); | 1506 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}", handler.msg()); |
| 1507 } | 1507 } |
| 1508 | 1508 |
| 1509 |
| 1510 TEST_CASE(Service_ClassesFunctionsCoverage) { |
| 1511 const char* kScript = |
| 1512 "var port;\n" // Set to our mock port by C++. |
| 1513 "\n" |
| 1514 "class Foo {\n" |
| 1515 " var x;\n" |
| 1516 " Foo(this.x);\n" |
| 1517 " bar() {\n" |
| 1518 " x = x * x;\n" |
| 1519 " x = x / 13;\n" |
| 1520 " }\n" |
| 1521 " badum(var a) => 4 + a;\n" |
| 1522 "}\n" |
| 1523 "main() {\n" |
| 1524 " var foo = new Foo(7);\n" |
| 1525 " foo.bar();\n" |
| 1526 "}"; |
| 1527 |
| 1528 Isolate* isolate = Isolate::Current(); |
| 1529 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 1530 EXPECT_VALID(h_lib); |
| 1531 Library& lib = Library::Handle(); |
| 1532 lib ^= Api::UnwrapHandle(h_lib); |
| 1533 EXPECT(!lib.IsNull()); |
| 1534 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 1535 EXPECT_VALID(result); |
| 1536 |
| 1537 // Build a mock message handler and wrap it in a dart port. |
| 1538 ServiceTestMessageHandler handler; |
| 1539 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 1540 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 1541 EXPECT_VALID(port); |
| 1542 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 1543 |
| 1544 // Look up the service id of Foo. |
| 1545 const Class& cls = Class::Handle( |
| 1546 lib.LookupClass(String::Handle(String::New("Foo")))); |
| 1547 ASSERT(!cls.IsNull()); |
| 1548 ClassTable* table = isolate->class_table(); |
| 1549 intptr_t i; |
| 1550 for (i = 1; i < table->NumCids(); i++) { |
| 1551 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) { |
| 1552 break; |
| 1553 } |
| 1554 } |
| 1555 ASSERT(i != table->NumCids()); |
| 1556 |
| 1557 // Look up the service if of the function Foo.bar. |
| 1558 const Function& func = Function::Handle( |
| 1559 cls.LookupFunction(String::Handle(String::New("bar")))); |
| 1560 ASSERT(!func.IsNull()); |
| 1561 intptr_t function_id = -1; |
| 1562 function_id = cls.FindFunctionIndex(func); |
| 1563 ASSERT(function_id != -1); |
| 1564 |
| 1565 char buf[1024]; |
| 1566 OS::SNPrint(buf, sizeof(buf), |
| 1567 "[0, port, ['classes', '%" Pd "', 'functions'," |
| 1568 "'% " Pd "', 'coverage'], [], []]", i, function_id); |
| 1569 |
| 1570 Array& service_msg = Array::Handle(); |
| 1571 service_msg = Eval(h_lib, buf); |
| 1572 Service::HandleIsolateMessage(isolate, service_msg); |
| 1573 handler.HandleNextMessage(); |
| 1574 EXPECT_STREQ( |
| 1575 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" |
| 1576 "{\"source\":\"test-lib\",\"script\":{" |
| 1577 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 1578 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 1579 "\"kind\":\"script\"},\"hits\":[7,4,8,3]}]}", handler.msg()); |
| 1580 } |
| 1581 |
| 1509 #endif | 1582 #endif |
| 1510 | 1583 |
| 1511 | 1584 |
| 1512 TEST_CASE(Service_AllocationProfile) { | 1585 TEST_CASE(Service_AllocationProfile) { |
| 1513 const char* kScript = | 1586 const char* kScript = |
| 1514 "var port;\n" // Set to our mock port by C++. | 1587 "var port;\n" // Set to our mock port by C++. |
| 1515 "\n" | 1588 "\n" |
| 1516 "var x = 7;\n" | 1589 "var x = 7;\n" |
| 1517 "main() {\n" | 1590 "main() {\n" |
| 1518 " x = x * x;\n" | 1591 " x = x * x;\n" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); | 1874 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); |
| 1802 Service::HandleIsolateMessage(isolate, service_msg); | 1875 Service::HandleIsolateMessage(isolate, service_msg); |
| 1803 handler.HandleNextMessage(); | 1876 handler.HandleNextMessage(); |
| 1804 // Expect error. | 1877 // Expect error. |
| 1805 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 1878 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 1806 } | 1879 } |
| 1807 | 1880 |
| 1808 #endif // !defined(TARGET_ARCH_ARM64) | 1881 #endif // !defined(TARGET_ARCH_ARM64) |
| 1809 | 1882 |
| 1810 } // namespace dart | 1883 } // namespace dart |
| OLD | NEW |