Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 const char* extension_list[kExtensionCount] = { "v8/gc" }; | 178 const char* extension_list[kExtensionCount] = { "v8/gc" }; |
| 179 v8::ExtensionConfiguration extensions(kExtensionCount, extension_list); | 179 v8::ExtensionConfiguration extensions(kExtensionCount, extension_list); |
| 180 Serializer::Enable(); | 180 Serializer::Enable(); |
| 181 v8::Persistent<v8::Context> env = v8::Context::New(&extensions); | 181 v8::Persistent<v8::Context> env = v8::Context::New(&extensions); |
| 182 env->Enter(); | 182 env->Enter(); |
| 183 | 183 |
| 184 Snapshot::WriteToFile(FLAG_testing_serialization_file); | 184 Snapshot::WriteToFile(FLAG_testing_serialization_file); |
| 185 } | 185 } |
| 186 | 186 |
| 187 | 187 |
| 188 static void Serialize2() { | |
| 189 Serializer::Enable(); | |
| 190 // We have to create one context. One reason for this is that the | |
|
Mads Ager (chromium)
2009/10/26 11:14:05
One reason for this is so that the builtins ...
| |
| 191 // so that the builtins can be loaded from v8natives.js and their | |
| 192 // addresses can be processed. This will clear the pending fixups | |
| 193 // array, which would otherwise contain GC roots that would confuse | |
| 194 // the serialization/deserialization process. | |
| 195 v8::Persistent<v8::Context> env = v8::Context::New(); | |
| 196 env.Dispose(); | |
| 197 Snapshot::WriteToFile2(FLAG_testing_serialization_file); | |
| 198 } | |
| 199 | |
| 200 | |
| 188 // Test that the whole heap can be serialized when running from the | 201 // Test that the whole heap can be serialized when running from the |
| 189 // internal snapshot. | 202 // internal snapshot. |
| 190 // (Smoke test.) | 203 // (Smoke test.) |
| 191 TEST(SerializeInternal) { | 204 TEST(SerializeInternal) { |
| 192 Snapshot::Initialize(NULL); | 205 Snapshot::Initialize(NULL); |
| 193 Serialize(); | 206 Serialize(); |
| 194 } | 207 } |
| 195 | 208 |
| 196 | 209 |
| 197 // Test that the whole heap can be serialized when running from a | 210 // Test that the whole heap can be serialized when running from a |
| 198 // bootstrapped heap. | 211 // bootstrapped heap. |
| 199 // (Smoke test.) | 212 // (Smoke test.) |
| 200 TEST(Serialize) { | 213 TEST(Serialize) { |
| 201 if (Snapshot::IsEnabled()) return; | 214 if (Snapshot::IsEnabled()) return; |
| 202 Serialize(); | 215 Serialize(); |
| 203 } | 216 } |
| 204 | 217 |
| 205 | 218 |
| 219 // Test that the whole heap can be serialized. | |
| 220 TEST(Serialize2) { | |
| 221 v8::V8::Initialize(); | |
| 222 Serialize2(); | |
| 223 } | |
| 224 | |
| 225 | |
| 206 // Test that the heap isn't destroyed after a serialization. | 226 // Test that the heap isn't destroyed after a serialization. |
| 207 TEST(SerializeNondestructive) { | 227 TEST(SerializeNondestructive) { |
| 208 if (Snapshot::IsEnabled()) return; | 228 if (Snapshot::IsEnabled()) return; |
| 209 StatsTable::SetCounterFunction(counter_function); | 229 StatsTable::SetCounterFunction(counter_function); |
| 210 v8::HandleScope scope; | 230 v8::HandleScope scope; |
| 211 Serializer::Enable(); | 231 Serializer::Enable(); |
| 212 v8::Persistent<v8::Context> env = v8::Context::New(); | 232 v8::Persistent<v8::Context> env = v8::Context::New(); |
| 213 v8::Context::Scope context_scope(env); | 233 v8::Context::Scope context_scope(env); |
| 214 Serializer().Serialize(); | 234 Serializer().Serialize(); |
| 215 const char* c_source = "\"abcd\".charAt(2) == 'c'"; | 235 const char* c_source = "\"abcd\".charAt(2) == 'c'"; |
| 216 v8::Local<v8::String> source = v8::String::New(c_source); | 236 v8::Local<v8::String> source = v8::String::New(c_source); |
| 217 v8::Local<v8::Script> script = v8::Script::Compile(source); | 237 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 218 v8::Local<v8::Value> value = script->Run(); | 238 v8::Local<v8::Value> value = script->Run(); |
| 219 CHECK(value->BooleanValue()); | 239 CHECK(value->BooleanValue()); |
| 220 } | 240 } |
| 221 | 241 |
| 222 //---------------------------------------------------------------------------- | 242 //---------------------------------------------------------------------------- |
| 223 // Tests that the heap can be deserialized. | 243 // Tests that the heap can be deserialized. |
| 224 | 244 |
| 225 static void Deserialize() { | 245 static void Deserialize() { |
| 226 #ifdef DEBUG | 246 #ifdef DEBUG |
| 227 FLAG_debug_serialization = true; | 247 FLAG_debug_serialization = true; |
| 228 #endif | 248 #endif |
| 229 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); | 249 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); |
| 230 } | 250 } |
| 231 | 251 |
| 232 | 252 |
| 253 static void Deserialize2() { | |
| 254 CHECK(Snapshot::Initialize2(FLAG_testing_serialization_file)); | |
| 255 } | |
| 256 | |
| 257 | |
| 233 static void SanityCheck() { | 258 static void SanityCheck() { |
| 234 v8::HandleScope scope; | 259 v8::HandleScope scope; |
| 235 #ifdef DEBUG | 260 #ifdef DEBUG |
| 236 Heap::Verify(); | 261 Heap::Verify(); |
| 237 #endif | 262 #endif |
| 238 CHECK(Top::global()->IsJSObject()); | 263 CHECK(Top::global()->IsJSObject()); |
| 239 CHECK(Top::global_context()->IsContext()); | 264 CHECK(Top::global_context()->IsContext()); |
| 240 CHECK(Top::special_function_table()->IsFixedArray()); | 265 CHECK(Top::special_function_table()->IsFixedArray()); |
| 241 CHECK(Heap::symbol_table()->IsSymbolTable()); | 266 CHECK(Heap::symbol_table()->IsSymbolTable()); |
| 242 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure()); | 267 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure()); |
| 243 } | 268 } |
| 244 | 269 |
| 245 | 270 |
| 246 DEPENDENT_TEST(Deserialize, Serialize) { | 271 DEPENDENT_TEST(Deserialize, Serialize) { |
| 247 v8::HandleScope scope; | 272 v8::HandleScope scope; |
| 248 | 273 |
| 249 Deserialize(); | 274 Deserialize(); |
| 250 | 275 |
| 251 SanityCheck(); | 276 SanityCheck(); |
| 252 } | 277 } |
| 253 | 278 |
| 279 | |
| 280 DEPENDENT_TEST(Deserialize2, Serialize2) { | |
| 281 v8::HandleScope scope; | |
| 282 | |
| 283 Deserialize2(); | |
| 284 | |
| 285 fflush(stdout); | |
| 286 | |
| 287 v8::Persistent<v8::Context> env = v8::Context::New(); | |
| 288 env->Enter(); | |
| 289 | |
| 290 SanityCheck(); | |
| 291 } | |
| 292 | |
| 293 | |
| 254 DEPENDENT_TEST(DeserializeAndRunScript, Serialize) { | 294 DEPENDENT_TEST(DeserializeAndRunScript, Serialize) { |
| 255 v8::HandleScope scope; | 295 v8::HandleScope scope; |
| 256 | 296 |
| 257 Deserialize(); | 297 Deserialize(); |
| 258 | 298 |
| 259 const char* c_source = "\"1234\".length"; | 299 const char* c_source = "\"1234\".length"; |
| 260 v8::Local<v8::String> source = v8::String::New(c_source); | 300 v8::Local<v8::String> source = v8::String::New(c_source); |
| 261 v8::Local<v8::Script> script = v8::Script::Compile(source); | 301 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 262 CHECK_EQ(4, script->Run()->Int32Value()); | 302 CHECK_EQ(4, script->Run()->Int32Value()); |
| 263 } | 303 } |
| 264 | 304 |
| 265 | 305 |
| 306 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize2) { | |
| 307 v8::HandleScope scope; | |
| 308 | |
| 309 Deserialize2(); | |
| 310 | |
| 311 v8::Persistent<v8::Context> env = v8::Context::New(); | |
| 312 env->Enter(); | |
| 313 | |
| 314 const char* c_source = "\"1234\".length"; | |
| 315 v8::Local<v8::String> source = v8::String::New(c_source); | |
| 316 v8::Local<v8::Script> script = v8::Script::Compile(source); | |
| 317 CHECK_EQ(4, script->Run()->Int32Value()); | |
| 318 } | |
| 319 | |
| 320 | |
| 266 DEPENDENT_TEST(DeserializeNatives, Serialize) { | 321 DEPENDENT_TEST(DeserializeNatives, Serialize) { |
| 267 v8::HandleScope scope; | 322 v8::HandleScope scope; |
| 268 | 323 |
| 269 Deserialize(); | 324 Deserialize(); |
| 270 | 325 |
| 271 const char* c_source = "\"abcd\".charAt(2) == 'c'"; | 326 const char* c_source = "\"abcd\".charAt(2) == 'c'"; |
| 272 v8::Local<v8::String> source = v8::String::New(c_source); | 327 v8::Local<v8::String> source = v8::String::New(c_source); |
| 273 v8::Local<v8::Script> script = v8::Script::Compile(source); | 328 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 274 v8::Local<v8::Value> value = script->Run(); | 329 v8::Local<v8::Value> value = script->Run(); |
| 275 CHECK(value->BooleanValue()); | 330 CHECK(value->BooleanValue()); |
| 276 } | 331 } |
| 277 | 332 |
| 278 | 333 |
| 279 DEPENDENT_TEST(DeserializeExtensions, Serialize) { | 334 DEPENDENT_TEST(DeserializeExtensions, Serialize) { |
| 280 v8::HandleScope scope; | 335 v8::HandleScope scope; |
| 281 | 336 |
| 282 Deserialize(); | 337 Deserialize(); |
| 283 const char* c_source = "gc();"; | 338 const char* c_source = "gc();"; |
| 284 v8::Local<v8::String> source = v8::String::New(c_source); | 339 v8::Local<v8::String> source = v8::String::New(c_source); |
| 285 v8::Local<v8::Script> script = v8::Script::Compile(source); | 340 v8::Local<v8::Script> script = v8::Script::Compile(source); |
| 286 v8::Local<v8::Value> value = script->Run(); | 341 v8::Local<v8::Value> value = script->Run(); |
| 287 CHECK(value->IsUndefined()); | 342 CHECK(value->IsUndefined()); |
| 288 } | 343 } |
| 289 | 344 |
| 290 | 345 |
| 291 extern "C" void V8_Fatal(const char* file, int line, const char* format, ...); | |
| 292 | |
| 293 | |
| 294 TEST(TestThatAlwaysSucceeds) { | 346 TEST(TestThatAlwaysSucceeds) { |
| 295 } | 347 } |
| 296 | 348 |
| 297 | 349 |
| 298 TEST(TestThatAlwaysFails) { | 350 TEST(TestThatAlwaysFails) { |
| 299 bool ArtificialFailure = false; | 351 bool ArtificialFailure = false; |
| 300 CHECK(ArtificialFailure); | 352 CHECK(ArtificialFailure); |
| 301 } | 353 } |
| 302 | 354 |
| 303 | 355 |
| 304 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 356 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
| 305 bool ArtificialFailure2 = false; | 357 bool ArtificialFailure2 = false; |
| 306 CHECK(ArtificialFailure2); | 358 CHECK(ArtificialFailure2); |
| 307 } | 359 } |
| OLD | NEW |