| Index: vm/snapshot_test.cc
|
| ===================================================================
|
| --- vm/snapshot_test.cc (revision 2103)
|
| +++ vm/snapshot_test.cc (working copy)
|
| @@ -44,7 +44,7 @@
|
| TEST_CASE(SerializeNull) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const Object& null_object = Object::Handle();
|
| writer.WriteObject(null_object.raw());
|
| writer.FinalizeBuffer();
|
| @@ -63,7 +63,7 @@
|
| TEST_CASE(SerializeSmi1) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const Smi& smi = Smi::Handle(Smi::New(124));
|
| writer.WriteObject(smi.raw());
|
| writer.FinalizeBuffer();
|
| @@ -82,7 +82,7 @@
|
| TEST_CASE(SerializeSmi2) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const Smi& smi = Smi::Handle(Smi::New(-1));
|
| writer.WriteObject(smi.raw());
|
| writer.FinalizeBuffer();
|
| @@ -101,7 +101,7 @@
|
| TEST_CASE(SerializeDouble) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const Double& dbl = Double::Handle(Double::New(101.29));
|
| writer.WriteObject(dbl.raw());
|
| writer.FinalizeBuffer();
|
| @@ -120,7 +120,7 @@
|
| TEST_CASE(SerializeBool) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const Bool& bool1 = Bool::Handle(Bool::True());
|
| const Bool& bool2 = Bool::Handle(Bool::False());
|
| writer.WriteObject(bool1.raw());
|
| @@ -141,7 +141,7 @@
|
| TEST_CASE(SerializeBigint) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const Bigint& bigint = Bigint::Handle(Bigint::New(0xfffffffffLL));
|
| writer.WriteObject(bigint.raw());
|
| writer.FinalizeBuffer();
|
| @@ -162,7 +162,7 @@
|
| TEST_CASE(SerializeSingletons) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| writer.WriteObject(Object::class_class());
|
| writer.WriteObject(Object::null_class());
|
| writer.WriteObject(Object::type_class());
|
| @@ -215,7 +215,7 @@
|
| TEST_CASE(SerializeString) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| String& str = String::Handle(String::New("This string shall be serialized"));
|
| writer.WriteObject(str.raw());
|
| writer.FinalizeBuffer();
|
| @@ -235,7 +235,7 @@
|
| TEST_CASE(SerializeArray) {
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| const int kArrayLength = 10;
|
| Array& array = Array::Handle(Array::New(kArrayLength));
|
| Smi& smi = Smi::Handle();
|
| @@ -275,7 +275,7 @@
|
|
|
| // Write snapshot with object content.
|
| uint8_t* buffer;
|
| - SnapshotWriter writer(false, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kMessage, &buffer, &allocator);
|
| writer.WriteObject(script.raw());
|
| writer.FinalizeBuffer();
|
|
|
| @@ -344,7 +344,7 @@
|
| Isolate* isolate = Isolate::Current();
|
| Zone zone(isolate);
|
| HandleScope scope(isolate);
|
| - SnapshotWriter writer(true, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kFull, &buffer, &allocator);
|
| writer.WriteFullSnapshot();
|
| }
|
|
|
| @@ -400,7 +400,7 @@
|
| OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime());
|
|
|
| // Write snapshot with object content.
|
| - SnapshotWriter writer(true, &buffer, &allocator);
|
| + SnapshotWriter writer(Snapshot::kFull, &buffer, &allocator);
|
| writer.WriteFullSnapshot();
|
|
|
| // Invoke a function which returns an object.
|
| @@ -438,6 +438,65 @@
|
| Dart_ShutdownIsolate();
|
| free(buffer);
|
| }
|
| +
|
| +
|
| +UNIT_TEST_CASE(ScriptSnapshot) {
|
| + const char* kScriptChars =
|
| + "class Fields {\n"
|
| + " Fields(int i, int j) : fld1 = i, fld2 = j {}\n"
|
| + " int fld1;\n"
|
| + " final int fld2;\n"
|
| + " static int fld3;\n"
|
| + " static final int fld4 = 10;\n"
|
| + "}\n"
|
| + "class FieldsTest {\n"
|
| + " static Fields testMain() {\n"
|
| + " Fields obj = new Fields(10, 20);\n"
|
| + " return obj;\n"
|
| + " }\n"
|
| + "}\n";
|
| + Dart_Handle result;
|
| +
|
| + uint8_t* buffer;
|
| + intptr_t size;
|
| +
|
| + // Start an Isolate, load a script and create a script snapshot.
|
| + {
|
| + TestIsolateScope __test_isolate__;
|
| + Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
|
| +
|
| + // Create a test library and Load up a test script in it.
|
| + TestCase::LoadTestScript(kScriptChars, NULL);
|
| +
|
| + // Write out the script snapshot.
|
| + result = Dart_CreateScriptSnapshot(TestCase::lib(), &buffer, &size);
|
| + EXPECT_VALID(result);
|
| + Dart_ExitScope();
|
| + }
|
| +
|
| + // Now Create another isolate and load the application snapshot and
|
| + // execute it.
|
| + {
|
| + TestIsolateScope __test_isolate__;
|
| + Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
|
| +
|
| + // Load the test library from the snapshot.
|
| + result = Dart_LoadScriptFromSnapshot(buffer);
|
| + EXPECT_VALID(result);
|
| +
|
| + // Invoke a function which returns an object.
|
| + result = Dart_InvokeStatic(result,
|
| + Dart_NewString("FieldsTest"),
|
| + Dart_NewString("testMain"),
|
| + 0,
|
| + NULL);
|
| + EXPECT_VALID(result);
|
| + Dart_ExitScope();
|
| + }
|
| + Dart_ShutdownIsolate();
|
| + free(buffer);
|
| +}
|
| +
|
| #endif // TARGET_ARCH_IA32.
|
|
|
| } // namespace dart
|
|
|