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

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

Issue 23094003: Make sure type information is not lost in snapshots created in production mode, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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 | « runtime/vm/parser.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 "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_api_message.h" 10 #include "vm/dart_api_message.h"
11 #include "vm/dart_api_state.h" 11 #include "vm/dart_api_state.h"
12 #include "vm/flags.h"
12 #include "vm/snapshot.h" 13 #include "vm/snapshot.h"
13 #include "vm/symbols.h" 14 #include "vm/symbols.h"
14 #include "vm/unicode.h" 15 #include "vm/unicode.h"
15 #include "vm/unit_test.h" 16 #include "vm/unit_test.h"
16 17
17 namespace dart { 18 namespace dart {
18 19
20 DECLARE_FLAG(bool, enable_type_checks);
21
19 // Check if serialized and deserialized objects are equal. 22 // Check if serialized and deserialized objects are equal.
20 static bool Equals(const Object& expected, const Object& actual) { 23 static bool Equals(const Object& expected, const Object& actual) {
21 if (expected.IsNull()) { 24 if (expected.IsNull()) {
22 return actual.IsNull(); 25 return actual.IsNull();
23 } 26 }
24 if (expected.IsSmi()) { 27 if (expected.IsSmi()) {
25 if (actual.IsSmi()) { 28 if (actual.IsSmi()) {
26 return expected.raw() == actual.raw(); 29 return expected.raw() == actual.raw();
27 } 30 }
28 return false; 31 return false;
(...skipping 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 EXPECT(script_snapshot != NULL); 1223 EXPECT(script_snapshot != NULL);
1221 result = Dart_LoadScriptFromSnapshot(script_snapshot, size); 1224 result = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1222 EXPECT_VALID(result); 1225 EXPECT_VALID(result);
1223 } 1226 }
1224 Dart_ShutdownIsolate(); 1227 Dart_ShutdownIsolate();
1225 free(full_snapshot); 1228 free(full_snapshot);
1226 free(script_snapshot); 1229 free(script_snapshot);
1227 } 1230 }
1228 1231
1229 1232
1233 UNIT_TEST_CASE(ScriptSnapshot2) {
1234 // The snapshot of this library is always created in production mode, but
1235 // loaded and executed in both production and checked modes.
1236 // This test verifies that type information is still contained in the snapshot
1237 // although it was created in production mode and that type errors and
1238 // compilation errors (for const fields) are correctly reported according to
1239 // the execution mode.
1240 const char* kLibScriptChars =
1241 "library dart_import_lib;"
1242 "const String s = 1.0;"
1243 "final int i = true;"
1244 "bool b;";
1245 const char* kScriptChars =
1246 "test_s() {"
1247 " s;"
1248 "}"
1249 "test_i() {"
1250 " i;"
1251 "}"
1252 "test_b() {"
1253 " b = 0;"
1254 "}";
1255 Dart_Handle result;
1256
1257 uint8_t* buffer;
1258 intptr_t size;
1259 uint8_t* full_snapshot = NULL;
1260 uint8_t* script_snapshot = NULL;
1261
1262 // Force creation of snapshot in production mode.
1263 bool saved_mode = FLAG_enable_type_checks;
1264 FLAG_enable_type_checks = false;
1265
1266 {
1267 // Start an Isolate, and create a full snapshot of it.
1268 TestIsolateScope __test_isolate__;
1269 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1270
1271 // Write out the script snapshot.
1272 result = Dart_CreateSnapshot(&buffer, &size);
1273 EXPECT_VALID(result);
1274 full_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1275 memmove(full_snapshot, buffer, size);
1276 Dart_ExitScope();
1277 }
1278
1279 {
1280 // Create an Isolate using the full snapshot, load a script and create
1281 // a script snapshot of the script.
1282 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1283 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1284
1285 // Load the library.
1286 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart_import_lib"),
1287 NewString(kLibScriptChars));
1288 EXPECT_VALID(import_lib);
1289
1290 // Create a test library and Load up a test script in it.
1291 TestCase::LoadTestScript(kScriptChars, NULL);
1292
1293 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(),
1294 import_lib,
1295 Dart_Null()));
1296 EXPECT_VALID(Api::CheckIsolateState(Isolate::Current()));
1297
1298 // Write out the script snapshot.
1299 result = Dart_CreateScriptSnapshot(&buffer, &size);
1300 EXPECT_VALID(result);
1301 script_snapshot = reinterpret_cast<uint8_t*>(malloc(size));
1302 memmove(script_snapshot, buffer, size);
1303 Dart_ExitScope();
1304 Dart_ShutdownIsolate();
1305 }
1306
1307 // Continue in originally saved mode.
1308 FLAG_enable_type_checks = saved_mode;
1309
1310 {
1311 // Now Create an Isolate using the full snapshot and load the
1312 // script snapshot created above and execute it.
1313 TestCase::CreateTestIsolateFromSnapshot(full_snapshot);
1314 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1315
1316 // Load the test library from the snapshot.
1317 EXPECT(script_snapshot != NULL);
1318 Dart_Handle lib = Dart_LoadScriptFromSnapshot(script_snapshot, size);
1319 EXPECT_VALID(lib);
1320
1321 // Invoke the test_s function.
1322 result = Dart_Invoke(lib, NewString("test_s"), 0, NULL);
1323 EXPECT(Dart_IsError(result) == saved_mode);
1324
1325 // Invoke the test_i function.
1326 result = Dart_Invoke(lib, NewString("test_i"), 0, NULL);
1327 EXPECT(Dart_IsError(result) == saved_mode);
1328
1329 // Invoke the test_b function.
1330 result = Dart_Invoke(lib, NewString("test_b"), 0, NULL);
1331 EXPECT(Dart_IsError(result) == saved_mode);
1332 }
1333 Dart_ShutdownIsolate();
1334 free(full_snapshot);
1335 free(script_snapshot);
1336 }
1337
1338
1230 TEST_CASE(IntArrayMessage) { 1339 TEST_CASE(IntArrayMessage) {
1231 StackZone zone(Isolate::Current()); 1340 StackZone zone(Isolate::Current());
1232 uint8_t* buffer = NULL; 1341 uint8_t* buffer = NULL;
1233 ApiMessageWriter writer(&buffer, &zone_allocator); 1342 ApiMessageWriter writer(&buffer, &zone_allocator);
1234 1343
1235 static const int kArrayLength = 2; 1344 static const int kArrayLength = 2;
1236 intptr_t data[kArrayLength] = {1, 2}; 1345 intptr_t data[kArrayLength] = {1, 2};
1237 int len = kArrayLength; 1346 int len = kArrayLength;
1238 writer.WriteMessage(len, data); 1347 writer.WriteMessage(len, data);
1239 1348
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 result = Dart_RunLoop(); 2599 result = Dart_RunLoop();
2491 EXPECT(Dart_IsError(result)); 2600 EXPECT(Dart_IsError(result));
2492 EXPECT(Dart_ErrorHasException(result)); 2601 EXPECT(Dart_ErrorHasException(result));
2493 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", 2602 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n",
2494 Dart_GetError(result)); 2603 Dart_GetError(result));
2495 2604
2496 Dart_ExitScope(); 2605 Dart_ExitScope();
2497 } 2606 }
2498 2607
2499 } // namespace dart 2608 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698