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

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

Issue 346003003: vmservice: Add /coverage collection to scripts, classes and libraries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: exclude service_classescoverage from simmips tests Created 6 years, 6 months 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 | Annotate | Revision Log
« runtime/vm/service.cc ('K') | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 Service::HandleIsolateMessage(isolate, service_msg); 1229 Service::HandleIsolateMessage(isolate, service_msg);
1230 handler.HandleNextMessage(); 1230 handler.HandleNextMessage();
1231 EXPECT_SUBSTRING( 1231 EXPECT_SUBSTRING(
1232 "{\"source\":\"test-lib\",\"script\":{" 1232 "{\"source\":\"test-lib\",\"script\":{"
1233 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," 1233 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
1234 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," 1234 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1235 "\"kind\":\"script\"},\"hits\":" 1235 "\"kind\":\"script\"},\"hits\":"
1236 "[5,1,6,1]}", handler.msg()); 1236 "[5,1,6,1]}", handler.msg());
1237 } 1237 }
1238 1238
1239
1240 TEST_CASE(Service_ScriptsCoverage) {
1241 const char* kScript =
1242 "var port;\n" // Set to our mock port by C++.
1243 "\n"
1244 "var x = 7;\n"
1245 "main() {\n"
1246 " x = x * x;\n"
1247 " x = x / 13;\n"
1248 "}";
1249
1250 Isolate* isolate = Isolate::Current();
1251 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
1252 EXPECT_VALID(h_lib);
1253 Library& lib = Library::Handle();
1254 lib ^= Api::UnwrapHandle(h_lib);
1255 EXPECT(!lib.IsNull());
1256 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
1257 EXPECT_VALID(result);
1258
1259 // Build a mock message handler and wrap it in a dart port.
1260 ServiceTestMessageHandler handler;
1261 Dart_Port port_id = PortMap::CreatePort(&handler);
1262 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1263 EXPECT_VALID(port);
1264 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
1265
1266 Instance& service_msg = Instance::Handle();
1267 service_msg = Eval(
1268 h_lib, "[0, port, ['scripts', 'test-lib', 'coverage'], [], []]");
1269 Service::HandleIsolateMessage(isolate, service_msg);
1270 handler.HandleNextMessage();
1271 EXPECT_STREQ(
1272 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1273 "{\"source\":\"test-lib\",\"script\":{"
1274 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
1275 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1276 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", handler.msg());
1277 }
1278
1279
1280 TEST_CASE(Service_LibrariesCoverage) {
1281 const char* kScript =
1282 "var port;\n" // Set to our mock port by C++.
1283 "\n"
1284 "var x = 7;\n"
1285 "main() {\n"
1286 " x = x * x;\n"
1287 " x = x / 13;\n"
1288 "}";
1289
1290 Isolate* isolate = Isolate::Current();
1291 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
1292 EXPECT_VALID(h_lib);
1293 Library& lib = Library::Handle();
1294 lib ^= Api::UnwrapHandle(h_lib);
1295 EXPECT(!lib.IsNull());
1296 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
1297 EXPECT_VALID(result);
1298
1299 // Build a mock message handler and wrap it in a dart port.
1300 ServiceTestMessageHandler handler;
1301 Dart_Port port_id = PortMap::CreatePort(&handler);
1302 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1303 EXPECT_VALID(port);
1304 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
1305
1306 // Look up the service id for the library containg the test-lib script.
1307 const GrowableObjectArray& libs =
1308 GrowableObjectArray::Handle(isolate->object_store()->libraries());
1309 intptr_t i;
1310 for (i = 0; i < libs.Length(); i++) {
1311 if (libs.At(i) == lib.raw()) {
1312 break;
1313 }
1314 }
1315 ASSERT(i != libs.Length());
1316 char buf[1024];
1317 OS::SNPrint(buf, sizeof(buf),
1318 "[0, port, ['libraries', '%" Pd "', 'coverage'], [], []]", i);
1319
1320 Instance& service_msg = Instance::Handle();
1321 service_msg = Eval(h_lib, buf);
1322 Service::HandleIsolateMessage(isolate, service_msg);
1323 handler.HandleNextMessage();
1324 EXPECT_STREQ(
1325 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1326 "{\"source\":\"test-lib\",\"script\":{"
1327 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
1328 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1329 "\"kind\":\"script\"},\"hits\":[5,1,6,1]}]}", handler.msg());
1330 }
1331
1332
1333 TEST_CASE(Service_ClassesCoverage) {
1334 const char* kScript =
1335 "var port;\n" // Set to our mock port by C++.
1336 "\n"
1337 "class Foo {\n"
1338 " var x;\n"
1339 " Foo(this.x);\n"
1340 " bar() {\n"
1341 " x = x * x;\n"
1342 " x = x / 13;\n"
1343 " }\n"
1344 "}\n"
1345 "main() {\n"
1346 " var foo = new Foo(7);\n"
1347 " foo.bar();\n"
1348 "}";
1349
1350 Isolate* isolate = Isolate::Current();
1351 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL);
1352 EXPECT_VALID(h_lib);
1353 Library& lib = Library::Handle();
1354 lib ^= Api::UnwrapHandle(h_lib);
1355 EXPECT(!lib.IsNull());
1356 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL);
1357 EXPECT_VALID(result);
1358
1359 // Build a mock message handler and wrap it in a dart port.
1360 ServiceTestMessageHandler handler;
1361 Dart_Port port_id = PortMap::CreatePort(&handler);
1362 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id));
1363 EXPECT_VALID(port);
1364 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port));
1365
1366 // Look up the service id of Foo.
1367 const Class& cls = Class::Handle(
1368 lib.LookupClass(String::Handle(String::New("Foo"))));
1369 ASSERT(!cls.IsNull());
1370 ClassTable* table = isolate->class_table();
1371 intptr_t i;
1372 for (i = 1; i < table->NumCids(); i++) {
1373 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) {
1374 break;
1375 }
1376 }
1377 ASSERT(i != table->NumCids());
1378 char buf[1024];
1379 OS::SNPrint(buf, sizeof(buf),
1380 "[0, port, ['classes', '%" Pd "', 'coverage'], [], []]", i);
1381
1382 Instance& service_msg = Instance::Handle();
1383 service_msg = Eval(h_lib, buf);
1384 Service::HandleIsolateMessage(isolate, service_msg);
1385 handler.HandleNextMessage();
1386 EXPECT_STREQ(
1387 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":["
1388 "{\"source\":\"test-lib\",\"script\":{"
1389 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\","
1390 "\"name\":\"test-lib\",\"user_name\":\"test-lib\","
1391 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}", handler.msg());
1392 }
1393
1239 #endif 1394 #endif
1240 1395
1241 1396
1242 TEST_CASE(Service_AllocationProfile) { 1397 TEST_CASE(Service_AllocationProfile) {
1243 const char* kScript = 1398 const char* kScript =
1244 "var port;\n" // Set to our mock port by C++. 1399 "var port;\n" // Set to our mock port by C++.
1245 "\n" 1400 "\n"
1246 "var x = 7;\n" 1401 "var x = 7;\n"
1247 "main() {\n" 1402 "main() {\n"
1248 " x = x * x;\n" 1403 " x = x * x;\n"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); 1686 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]");
1532 Service::HandleIsolateMessage(isolate, service_msg); 1687 Service::HandleIsolateMessage(isolate, service_msg);
1533 handler.HandleNextMessage(); 1688 handler.HandleNextMessage();
1534 // Expect error. 1689 // Expect error.
1535 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); 1690 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg());
1536 } 1691 }
1537 1692
1538 #endif // !defined(TARGET_ARCH_ARM64) 1693 #endif // !defined(TARGET_ARCH_ARM64)
1539 1694
1540 } // namespace dart 1695 } // namespace dart
OLDNEW
« runtime/vm/service.cc ('K') | « runtime/vm/service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698