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

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

Issue 1168223002: Fix for issue 23598, add a Dart_CreateLibrarySnapshot entrypoint to the API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address code review comments Created 5 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/dart_api_impl.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 "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 "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 &vm_isolate_snapshot_size, 1246 &vm_isolate_snapshot_size,
1247 &isolate_snapshot, 1247 &isolate_snapshot,
1248 &isolate_snapshot_size); 1248 &isolate_snapshot_size);
1249 EXPECT_VALID(result); 1249 EXPECT_VALID(result);
1250 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size)); 1250 full_snapshot = reinterpret_cast<uint8_t*>(malloc(isolate_snapshot_size));
1251 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size); 1251 memmove(full_snapshot, isolate_snapshot, isolate_snapshot_size);
1252 Dart_ExitScope(); 1252 Dart_ExitScope();
1253 } 1253 }
1254 1254
1255 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode; 1255 FLAG_load_deferred_eagerly = saved_load_deferred_eagerly_mode;
1256
1257 // Test for Dart_CreateScriptSnapshot.
1256 { 1258 {
1257 // Create an Isolate using the full snapshot, load a script and create 1259 // Create an Isolate using the full snapshot, load a script and create
1258 // a script snapshot of the script. 1260 // a script snapshot of the script.
1259 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); 1261 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1260 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1262 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1261 1263
1262 // Load the library. 1264 // Load the library.
1263 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"), 1265 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"),
1264 NewString(kLibScriptChars), 1266 NewString(kLibScriptChars),
1265 0, 0); 1267 0, 0);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 EXPECT(Dart_IsList(libs)); 1305 EXPECT(Dart_IsList(libs));
1304 Dart_ListLength(libs, &actual_num_libs); 1306 Dart_ListLength(libs, &actual_num_libs);
1305 1307
1306 EXPECT_EQ(expected_num_libs, actual_num_libs); 1308 EXPECT_EQ(expected_num_libs, actual_num_libs);
1307 1309
1308 // Invoke a function which returns an object. 1310 // Invoke a function which returns an object.
1309 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); 1311 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest"));
1310 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 1312 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1311 EXPECT_VALID(result); 1313 EXPECT_VALID(result);
1312 Dart_ExitScope(); 1314 Dart_ExitScope();
1315 Dart_ShutdownIsolate();
1313 } 1316 }
1314 Dart_ShutdownIsolate(); 1317 free(script_snapshot);
1318
1319 // Test for Dart_CreateLibrarySnapshot.
1320 {
1321 // Create an Isolate using the full snapshot, load a script and create
1322 // a script snapshot of the script.
1323 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1324 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1325
1326 // Load the library.
1327 Dart_Handle lib = Dart_LoadLibrary(NewString("dart_lib"),
1328 NewString(kScriptChars),
1329 0, 0);
1330 EXPECT_VALID(lib);
1331
1332 // Write out the script snapshot.
1333 result = Dart_CreateLibrarySnapshot(lib, &buffer, &size);
1334 EXPECT_VALID(result);
1335 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1336 memmove(script_snapshot, buffer, size);
1337 Dart_ExitScope();
1338 Dart_ShutdownIsolate();
1339 }
1340
1341 {
1342 // Now Create an Isolate using the full snapshot and load the
1343 // script snapshot created above and execute it.
1344 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1345 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1346
1347 // Load the test library from the snapshot.
1348 EXPECT(script_snapshot != NULL);
1349 result = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1350 EXPECT_VALID(result);
1351
1352 // Invoke a function which returns an object.
1353 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest"));
1354 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL);
1355 EXPECT_VALID(result);
1356 Dart_ExitScope();
1357 Dart_ShutdownIsolate();
1358 }
1315 free(full_snapshot); 1359 free(full_snapshot);
1316 free(script_snapshot); 1360 free(script_snapshot);
1317 } 1361 }
1318 1362
1319 1363
1320 UNIT_TEST_CASE(ScriptSnapshot1) { 1364 UNIT_TEST_CASE(ScriptSnapshot1) {
1321 const char* kScriptChars = 1365 const char* kScriptChars =
1322 "class _SimpleNumEnumerable<T extends num> {" 1366 "class _SimpleNumEnumerable<T extends num> {"
1323 "final Iterable<T> _source;" 1367 "final Iterable<T> _source;"
1324 "const _SimpleNumEnumerable(this._source) : super();" 1368 "const _SimpleNumEnumerable(this._source) : super();"
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after
2805 StackZone zone(Isolate::Current()); 2849 StackZone zone(Isolate::Current());
2806 uint8_t* buffer; 2850 uint8_t* buffer;
2807 MessageWriter writer(&buffer, &zone_allocator, true); 2851 MessageWriter writer(&buffer, &zone_allocator, true);
2808 writer.WriteInlinedObjectHeader(kOmittedObjectId); 2852 writer.WriteInlinedObjectHeader(kOmittedObjectId);
2809 // For performance, we'd like single-byte headers when ids are omitted. 2853 // For performance, we'd like single-byte headers when ids are omitted.
2810 // If this starts failing, consider renumbering the snapshot ids. 2854 // If this starts failing, consider renumbering the snapshot ids.
2811 EXPECT_EQ(1, writer.BytesWritten()); 2855 EXPECT_EQ(1, writer.BytesWritten());
2812 } 2856 }
2813 2857
2814 } // namespace dart 2858 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698