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

Side by Side Diff: vm/snapshot_test.cc

Issue 9314048: Fix for issue 1456 - register libraries read from a partial snapshot (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 10 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
« no previous file with comments | « vm/raw_object_snapshot.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "include/dart_debugger_api.h"
5 #include "platform/assert.h" 6 #include "platform/assert.h"
6 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
7 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
8 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 10 #include "vm/dart_api_state.h"
10 #include "vm/snapshot.h" 11 #include "vm/snapshot.h"
11 #include "vm/unit_test.h" 12 #include "vm/unit_test.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 } 538 }
538 EXPECT_VALID(result); 539 EXPECT_VALID(result);
539 Dart_ExitScope(); 540 Dart_ExitScope();
540 } 541 }
541 Dart_ShutdownIsolate(); 542 Dart_ShutdownIsolate();
542 free(buffer); 543 free(buffer);
543 } 544 }
544 545
545 546
546 UNIT_TEST_CASE(ScriptSnapshot) { 547 UNIT_TEST_CASE(ScriptSnapshot) {
548 const char* kLibScriptChars =
549 "#library('dart:import-lib');"
550 "class LibFields {"
551 " LibFields(int i, int j) : fld1 = i, fld2 = j {}"
552 " int fld1;"
553 " final int fld2;"
554 "}";
547 const char* kScriptChars = 555 const char* kScriptChars =
548 "class Fields {" 556 "class Fields {"
549 " Fields(int i, int j) : fld1 = i, fld2 = j {}" 557 " Fields(int i, int j) : fld1 = i, fld2 = j {}"
550 " int fld1;" 558 " int fld1;"
551 " final int fld2;" 559 " final int fld2;"
552 " static int fld3;" 560 " static int fld3;"
553 " static final int fld4 = 10;" 561 " static final int fld4 = 10;"
554 "}" 562 "}"
555 "class FieldsTest {" 563 "class FieldsTest {"
556 " static Fields testMain() {" 564 " static Fields testMain() {"
(...skipping 16 matching lines...) Expand all
573 " }" 581 " }"
574 " return obj;" 582 " return obj;"
575 " }" 583 " }"
576 "}"; 584 "}";
577 Dart_Handle result; 585 Dart_Handle result;
578 586
579 uint8_t* buffer; 587 uint8_t* buffer;
580 intptr_t size; 588 intptr_t size;
581 uint8_t* full_snapshot = NULL; 589 uint8_t* full_snapshot = NULL;
582 uint8_t* script_snapshot = NULL; 590 uint8_t* script_snapshot = NULL;
591 intptr_t expected_num_libs;
592 intptr_t actual_num_libs;
583 593
584 { 594 {
585 // Start an Isolate, and create a full snapshot of it. 595 // Start an Isolate, and create a full snapshot of it.
586 TestIsolateScope __test_isolate__; 596 TestIsolateScope __test_isolate__;
587 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 597 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
588 598
589 // Write out the script snapshot. 599 // Write out the script snapshot.
590 result = Dart_CreateSnapshot(&buffer, &size); 600 result = Dart_CreateSnapshot(&buffer, &size);
591 EXPECT_VALID(result); 601 EXPECT_VALID(result);
592 full_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 602 full_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
593 memmove(full_snapshot, buffer, size); 603 memmove(full_snapshot, buffer, size);
594 Dart_ExitScope(); 604 Dart_ExitScope();
595 } 605 }
596 606
597 { 607 {
598 // Create an Isolate using the full snapshot, load a script and create 608 // Create an Isolate using the full snapshot, load a script and create
599 // a script snapshot of the script. 609 // a script snapshot of the script.
600 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 610 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
601 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 611 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
602 612
613 // Load the library.
614 Dart_Handle import_lib = Dart_LoadLibrary(Dart_NewString("dart:import-lib"),
615 Dart_NewString(kLibScriptChars));
616 EXPECT_VALID(import_lib);
617
603 // Create a test library and Load up a test script in it. 618 // Create a test library and Load up a test script in it.
604 TestCase::LoadTestScript(kScriptChars, NULL); 619 TestCase::LoadTestScript(kScriptChars, NULL);
605 620
621 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), import_lib));
622
623 // Get list of library URLs loaded and save the count.
624 Dart_Handle libs = Dart_GetLibraryURLs();
625 EXPECT(Dart_IsList(libs));
626 Dart_ListLength(libs, &expected_num_libs);
627
606 // Write out the script snapshot. 628 // Write out the script snapshot.
607 result = Dart_CreateScriptSnapshot(&buffer, &size); 629 result = Dart_CreateScriptSnapshot(&buffer, &size);
608 EXPECT_VALID(result); 630 EXPECT_VALID(result);
609 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size)); 631 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
610 memmove(script_snapshot, buffer, size); 632 memmove(script_snapshot, buffer, size);
611 Dart_ExitScope(); 633 Dart_ExitScope();
612 Dart_ShutdownIsolate(); 634 Dart_ShutdownIsolate();
613 } 635 }
614 636
615 { 637 {
616 // Now Create an Isolate using the full snapshot and load the 638 // Now Create an Isolate using the full snapshot and load the
617 // script snapshot created above and execute it. 639 // script snapshot created above and execute it.
618 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 640 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
619 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 641 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
620 642
621 // Load the test library from the snapshot. 643 // Load the test library from the snapshot.
622 EXPECT(script_snapshot != NULL); 644 EXPECT(script_snapshot != NULL);
623 result = Dart_LoadScriptFromSnapshot(script_snapshot); 645 result = Dart_LoadScriptFromSnapshot(script_snapshot);
624 EXPECT_VALID(result); 646 EXPECT_VALID(result);
625 647
648 // Get list of library URLs loaded and compare with expected count.
649 Dart_Handle libs = Dart_GetLibraryURLs();
650 EXPECT(Dart_IsList(libs));
651 Dart_ListLength(libs, &actual_num_libs);
652
653 EXPECT_EQ(expected_num_libs, actual_num_libs);
654
626 // Invoke a function which returns an object. 655 // Invoke a function which returns an object.
627 result = Dart_InvokeStatic(result, 656 result = Dart_InvokeStatic(result,
628 Dart_NewString("FieldsTest"), 657 Dart_NewString("FieldsTest"),
629 Dart_NewString("testMain"), 658 Dart_NewString("testMain"),
630 0, 659 0,
631 NULL); 660 NULL);
632 EXPECT_VALID(result); 661 EXPECT_VALID(result);
633 Dart_ExitScope(); 662 Dart_ExitScope();
634 } 663 }
635 Dart_ShutdownIsolate(); 664 Dart_ShutdownIsolate();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 free(buffer); 789 free(buffer);
761 } 790 }
762 } 791 }
763 Dart_ExitScope(); 792 Dart_ExitScope();
764 Dart_ShutdownIsolate(); 793 Dart_ShutdownIsolate();
765 } 794 }
766 795
767 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 796 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
768 797
769 } // namespace dart 798 } // namespace dart
OLDNEW
« no previous file with comments | « vm/raw_object_snapshot.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698