Chromium Code Reviews| 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 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1225 Service::HandleIsolateMessage(isolate, service_msg); | 1225 Service::HandleIsolateMessage(isolate, service_msg); |
| 1226 handler.HandleNextMessage(); | 1226 handler.HandleNextMessage(); |
| 1227 EXPECT_SUBSTRING( | 1227 EXPECT_SUBSTRING( |
| 1228 "{\"source\":\"test-lib\",\"script\":{" | 1228 "{\"source\":\"test-lib\",\"script\":{" |
| 1229 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," | 1229 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 1230 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," | 1230 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 1231 "\"kind\":\"script\"},\"hits\":" | 1231 "\"kind\":\"script\"},\"hits\":" |
| 1232 "[5,1,6,1]}", handler.msg()); | 1232 "[5,1,6,1]}", handler.msg()); |
| 1233 } | 1233 } |
| 1234 | 1234 |
| 1235 | |
| 1236 TEST_CASE(Service_ScriptsCoverage) { | |
| 1237 const char* kScript = | |
| 1238 "var port;\n" // Set to our mock port by C++. | |
| 1239 "\n" | |
| 1240 "var x = 7;\n" | |
| 1241 "main() {\n" | |
| 1242 " x = x * x;\n" | |
| 1243 " x = x / 13;\n" | |
| 1244 "}"; | |
| 1245 | |
| 1246 Isolate* isolate = Isolate::Current(); | |
| 1247 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | |
| 1248 EXPECT_VALID(h_lib); | |
| 1249 Library& lib = Library::Handle(); | |
| 1250 lib ^= Api::UnwrapHandle(h_lib); | |
| 1251 EXPECT(!lib.IsNull()); | |
| 1252 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
| 1253 EXPECT_VALID(result); | |
| 1254 | |
| 1255 // Build a mock message handler and wrap it in a dart port. | |
| 1256 ServiceTestMessageHandler handler; | |
| 1257 Dart_Port port_id = PortMap::CreatePort(&handler); | |
| 1258 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
| 1259 EXPECT_VALID(port); | |
| 1260 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | |
| 1261 | |
| 1262 Instance& service_msg = Instance::Handle(); | |
| 1263 service_msg = Eval( | |
| 1264 h_lib, "[0, port, ['scripts', 'test-lib', 'coverage'], [], []]"); | |
| 1265 Service::HandleIsolateMessage(isolate, service_msg); | |
| 1266 handler.HandleNextMessage(); | |
| 1267 EXPECT_STREQ( | |
| 1268 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" | |
| 1269 "{\"source\":\"test-lib\",\"script\":{" | |
| 1270 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," | |
| 1271 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," | |
|
Cutch
2014/06/23 16:23:11
The result of all of these requests is the same. C
Michael Lippautz (Google)
2014/06/24 17:51:07
The class coverage test now checks against an actu
| |
| 1272 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", handler.msg()); | |
| 1273 } | |
| 1274 | |
| 1275 | |
| 1276 TEST_CASE(Service_LibrariesCoverage) { | |
| 1277 const char* kScript = | |
| 1278 "var port;\n" // Set to our mock port by C++. | |
| 1279 "\n" | |
| 1280 "var x = 7;\n" | |
| 1281 "main() {\n" | |
| 1282 " x = x * x;\n" | |
| 1283 " x = x / 13;\n" | |
| 1284 "}"; | |
| 1285 | |
| 1286 Isolate* isolate = Isolate::Current(); | |
| 1287 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | |
| 1288 EXPECT_VALID(h_lib); | |
| 1289 Library& lib = Library::Handle(); | |
| 1290 lib ^= Api::UnwrapHandle(h_lib); | |
| 1291 EXPECT(!lib.IsNull()); | |
| 1292 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
| 1293 EXPECT_VALID(result); | |
| 1294 | |
| 1295 // Build a mock message handler and wrap it in a dart port. | |
| 1296 ServiceTestMessageHandler handler; | |
| 1297 Dart_Port port_id = PortMap::CreatePort(&handler); | |
| 1298 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
| 1299 EXPECT_VALID(port); | |
| 1300 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | |
| 1301 | |
| 1302 // Look up the service id for the library containg the test-lib script. | |
| 1303 const GrowableObjectArray& libs = | |
| 1304 GrowableObjectArray::Handle(isolate->object_store()->libraries()); | |
| 1305 intptr_t i; | |
| 1306 for (i = 0; i < libs.Length(); i++) { | |
| 1307 if (libs.At(i) == lib.raw()) { | |
| 1308 break; | |
| 1309 } | |
| 1310 } | |
| 1311 ASSERT(i != libs.Length()); | |
| 1312 char buf[1024]; | |
| 1313 OS::SNPrint(buf, sizeof(buf), | |
| 1314 "[0, port, ['libraries', '%" Pd "', 'coverage'], [], []]", i); | |
| 1315 | |
| 1316 Instance& service_msg = Instance::Handle(); | |
| 1317 service_msg = Eval(h_lib, buf); | |
| 1318 Service::HandleIsolateMessage(isolate, service_msg); | |
| 1319 handler.HandleNextMessage(); | |
| 1320 EXPECT_STREQ( | |
| 1321 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" | |
| 1322 "{\"source\":\"test-lib\",\"script\":{" | |
| 1323 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," | |
| 1324 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," | |
| 1325 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", handler.msg()); | |
| 1326 } | |
| 1327 | |
| 1328 | |
| 1329 TEST_CASE(Service_ClassesCoverage) { | |
| 1330 const char* kScript = | |
| 1331 "var port;\n" // Set to our mock port by C++. | |
| 1332 "\n" | |
| 1333 "var x = 7;\n" | |
| 1334 "main() {\n" | |
| 1335 " x = x * x;\n" | |
| 1336 " x = x / 13;\n" | |
| 1337 "}"; | |
| 1338 | |
| 1339 Isolate* isolate = Isolate::Current(); | |
| 1340 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | |
| 1341 EXPECT_VALID(h_lib); | |
| 1342 Library& lib = Library::Handle(); | |
| 1343 lib ^= Api::UnwrapHandle(h_lib); | |
| 1344 EXPECT(!lib.IsNull()); | |
| 1345 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
| 1346 EXPECT_VALID(result); | |
| 1347 | |
| 1348 // Build a mock message handler and wrap it in a dart port. | |
| 1349 ServiceTestMessageHandler handler; | |
| 1350 Dart_Port port_id = PortMap::CreatePort(&handler); | |
| 1351 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
| 1352 EXPECT_VALID(port); | |
| 1353 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | |
| 1354 | |
| 1355 // Look up the service id of the ``class'' containg the test-lib script. | |
| 1356 const Function& main_fn = Function::Handle( | |
| 1357 lib.LookupFunctionAllowPrivate( | |
| 1358 String::Handle(String::New("main")))); | |
| 1359 ASSERT(!main_fn.IsNull()); | |
| 1360 const Class& cls = Class::Handle(main_fn.Owner()); | |
| 1361 ASSERT(!cls.IsNull()); | |
| 1362 ClassTable* table = isolate->class_table(); | |
| 1363 intptr_t i; | |
| 1364 for (i = 1; i < table->NumCids(); i++) { | |
| 1365 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) { | |
| 1366 break; | |
| 1367 } | |
| 1368 } | |
| 1369 ASSERT(i != table->NumCids()); | |
| 1370 char buf[1024]; | |
| 1371 OS::SNPrint(buf, sizeof(buf), | |
| 1372 "[0, port, ['classes', '%" Pd "', 'coverage'], [], []]", i); | |
| 1373 | |
| 1374 Instance& service_msg = Instance::Handle(); | |
| 1375 service_msg = Eval(h_lib, buf); | |
| 1376 Service::HandleIsolateMessage(isolate, service_msg); | |
| 1377 handler.HandleNextMessage(); | |
| 1378 EXPECT_STREQ( | |
| 1379 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" | |
| 1380 "{\"source\":\"test-lib\",\"script\":{" | |
| 1381 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," | |
| 1382 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," | |
| 1383 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", handler.msg()); | |
| 1384 } | |
| 1385 | |
| 1235 #endif | 1386 #endif |
| 1236 | 1387 |
| 1237 | 1388 |
| 1238 TEST_CASE(Service_AllocationProfile) { | 1389 TEST_CASE(Service_AllocationProfile) { |
| 1239 const char* kScript = | 1390 const char* kScript = |
| 1240 "var port;\n" // Set to our mock port by C++. | 1391 "var port;\n" // Set to our mock port by C++. |
| 1241 "\n" | 1392 "\n" |
| 1242 "var x = 7;\n" | 1393 "var x = 7;\n" |
| 1243 "main() {\n" | 1394 "main() {\n" |
| 1244 " x = x * x;\n" | 1395 " x = x * x;\n" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); | 1678 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); |
| 1528 Service::HandleIsolateMessage(isolate, service_msg); | 1679 Service::HandleIsolateMessage(isolate, service_msg); |
| 1529 handler.HandleNextMessage(); | 1680 handler.HandleNextMessage(); |
| 1530 // Expect error. | 1681 // Expect error. |
| 1531 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 1682 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 1532 } | 1683 } |
| 1533 | 1684 |
| 1534 #endif // !defined(TARGET_ARCH_ARM64) | 1685 #endif // !defined(TARGET_ARCH_ARM64) |
| 1535 | 1686 |
| 1536 } // namespace dart | 1687 } // namespace dart |
| OLD | NEW |