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

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

Issue 2038203002: Fix various nefarious problems with the script table used in source reports. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
« no previous file with comments | « runtime/vm/source_report.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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 "vm/source_report.h" 5 #include "vm/source_report.h"
6 #include "vm/dart_api_impl.h" 6 #include "vm/dart_api_impl.h"
7 #include "vm/unit_test.h" 7 #include "vm/unit_test.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 "\"coverage\":{\"hits\":[23],\"misses\":[32]}", 418 "\"coverage\":{\"hits\":[23],\"misses\":[32]}",
419 result); 419 result);
420 420
421 // More than one script is referenced in the report. 421 // More than one script is referenced in the report.
422 EXPECT_SUBSTRING("\"scriptIndex\":0", result); 422 EXPECT_SUBSTRING("\"scriptIndex\":0", result);
423 EXPECT_SUBSTRING("\"scriptIndex\":1", result); 423 EXPECT_SUBSTRING("\"scriptIndex\":1", result);
424 EXPECT_SUBSTRING("\"scriptIndex\":2", result); 424 EXPECT_SUBSTRING("\"scriptIndex\":2", result);
425 } 425 }
426 426
427 427
428 TEST_CASE(SourceReport_Coverage_AllFunctions_ForceCompile) {
429 const char* kScript =
430 "helper0() {}\n"
431 "helper1() {}\n"
432 "main() {\n"
433 " if (true) {\n"
434 " helper0();\n"
435 " } else {\n"
436 " helper1();\n"
437 " }\n"
438 "}";
439
440 Library& lib = Library::Handle();
441 lib ^= ExecuteScript(kScript);
442 ASSERT(!lib.IsNull());
443
444 SourceReport report(SourceReport::kCoverage, SourceReport::kForceCompile);
445 JSONStream js;
446
447 // We generate a report with all functions in the VM.
448 Script& null_script = Script::Handle();
449 {
450 TransitionNativeToVM transition(Thread::Current());
451 report.PrintJSON(&js, null_script);
452 }
453 const char* result = js.ToCString();
454
455 // Sanity check the header.
456 EXPECT_SUBSTRING("{\"type\":\"SourceReport\",\"ranges\":[", result);
457
458 // Make sure that the main function was found.
459 EXPECT_SUBSTRING(
460 "\"startPos\":12,\"endPos\":39,\"compiled\":true,"
461 "\"coverage\":{\"hits\":[23],\"misses\":[32]}",
462 result);
463
464 // More than one script is referenced in the report.
465 EXPECT_SUBSTRING("\"scriptIndex\":0", result);
466 EXPECT_SUBSTRING("\"scriptIndex\":1", result);
467 EXPECT_SUBSTRING("\"scriptIndex\":2", result);
468 }
469
470
428 TEST_CASE(SourceReport_CallSites_SimpleCall) { 471 TEST_CASE(SourceReport_CallSites_SimpleCall) {
429 char buffer[1024]; 472 char buffer[1024];
430 const char* kScript = 473 const char* kScript =
431 "helper0() {}\n" 474 "helper0() {}\n"
432 "helper1() {}\n" 475 "helper1() {}\n"
433 "main() {\n" 476 "main() {\n"
434 " helper0();\n" 477 " helper0();\n"
435 "}"; 478 "}";
436 479
437 Library& lib = Library::Handle(); 480 Library& lib = Library::Handle();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 678
636 // Only one script in the script table. 679 // Only one script in the script table.
637 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\"," 680 "\"scripts\":[{\"type\":\"@Script\",\"fixedId\":true,\"id\":\"\","
638 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}", 681 "\"uri\":\"test-lib\",\"_kind\":\"script\"}]}",
639 buffer); 682 buffer);
640 } 683 }
641 684
642 #endif // !PRODUCT 685 #endif // !PRODUCT
643 686
644 } // namespace dart 687 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/source_report.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698