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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 CHECK_EQ(ExternalReference::address_of_real_stack_limit().address(), | 167 CHECK_EQ(ExternalReference::address_of_real_stack_limit().address(), |
168 decoder.Decode(make_code(UNCLASSIFIED, 5))); | 168 decoder.Decode(make_code(UNCLASSIFIED, 5))); |
169 CHECK_EQ(ExternalReference::debug_break().address(), | 169 CHECK_EQ(ExternalReference::debug_break().address(), |
170 decoder.Decode(make_code(UNCLASSIFIED, 11))); | 170 decoder.Decode(make_code(UNCLASSIFIED, 11))); |
171 CHECK_EQ(ExternalReference::new_space_start().address(), | 171 CHECK_EQ(ExternalReference::new_space_start().address(), |
172 decoder.Decode(make_code(UNCLASSIFIED, 7))); | 172 decoder.Decode(make_code(UNCLASSIFIED, 7))); |
173 } | 173 } |
174 | 174 |
175 | 175 |
176 static void Serialize() { | 176 static void Serialize() { |
177 #ifdef DEBUG | |
Christian Plesner Hansen
2009/11/13 13:43:36
We have corresponding tests for the new serializer
| |
178 FLAG_debug_serialization = true; | |
179 #endif | |
180 StatsTable::SetCounterFunction(counter_function); | |
181 | |
182 v8::HandleScope scope; | |
183 const int kExtensionCount = 1; | |
184 const char* extension_list[kExtensionCount] = { "v8/gc" }; | |
185 v8::ExtensionConfiguration extensions(kExtensionCount, extension_list); | |
186 Serializer::Enable(); | |
187 v8::Persistent<v8::Context> env = v8::Context::New(&extensions); | |
188 env->Enter(); | |
189 | |
190 Snapshot::WriteToFile(FLAG_testing_serialization_file); | |
191 } | |
192 | |
193 | |
194 static void Serialize2() { | |
195 // We have to create one context. One reason for this is so that the builtins | 177 // We have to create one context. One reason for this is so that the builtins |
196 // can be loaded from v8natives.js and their addresses can be processed. This | 178 // can be loaded from v8natives.js and their addresses can be processed. This |
197 // will clear the pending fixups array, which would otherwise contain GC roots | 179 // will clear the pending fixups array, which would otherwise contain GC roots |
198 // that would confuse the serialization/deserialization process. | 180 // that would confuse the serialization/deserialization process. |
199 v8::Persistent<v8::Context> env = v8::Context::New(); | 181 v8::Persistent<v8::Context> env = v8::Context::New(); |
200 env.Dispose(); | 182 env.Dispose(); |
201 Snapshot::WriteToFile2(FLAG_testing_serialization_file); | 183 Snapshot::WriteToFile(FLAG_testing_serialization_file); |
202 } | |
203 | |
204 | |
205 // Test that the whole heap can be serialized when running from a | |
206 // bootstrapped heap. | |
207 // (Smoke test.) | |
208 TEST(Serialize) { | |
209 if (Snapshot::IsEnabled()) return; | |
210 Serialize(); | |
211 } | 184 } |
212 | 185 |
213 | 186 |
214 // Test that the whole heap can be serialized. | 187 // Test that the whole heap can be serialized. |
215 TEST(Serialize2) { | 188 TEST(Serialize) { |
216 Serializer::Enable(); | 189 Serializer::Enable(); |
217 v8::V8::Initialize(); | 190 v8::V8::Initialize(); |
218 Serialize2(); | 191 Serialize(); |
219 } | 192 } |
220 | 193 |
221 | 194 |
222 // Test that the heap isn't destroyed after a serialization. | |
223 TEST(SerializeNondestructive) { | |
224 if (Snapshot::IsEnabled()) return; | |
225 StatsTable::SetCounterFunction(counter_function); | |
226 v8::HandleScope scope; | |
227 Serializer::Enable(); | |
228 v8::Persistent<v8::Context> env = v8::Context::New(); | |
229 v8::Context::Scope context_scope(env); | |
230 Serializer().Serialize(); | |
231 const char* c_source = "\"abcd\".charAt(2) == 'c'"; | |
232 v8::Local<v8::String> source = v8::String::New(c_source); | |
233 v8::Local<v8::Script> script = v8::Script::Compile(source); | |
234 v8::Local<v8::Value> value = script->Run(); | |
235 CHECK(value->BooleanValue()); | |
236 } | |
237 | |
238 //---------------------------------------------------------------------------- | 195 //---------------------------------------------------------------------------- |
239 // Tests that the heap can be deserialized. | 196 // Tests that the heap can be deserialized. |
240 | 197 |
241 static void Deserialize() { | 198 static void Deserialize() { |
242 #ifdef DEBUG | |
243 FLAG_debug_serialization = true; | |
244 #endif | |
245 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); | 199 CHECK(Snapshot::Initialize(FLAG_testing_serialization_file)); |
246 } | 200 } |
247 | 201 |
248 | 202 |
249 static void Deserialize2() { | |
250 CHECK(Snapshot::Initialize2(FLAG_testing_serialization_file)); | |
251 } | |
252 | |
253 | |
254 static void SanityCheck() { | 203 static void SanityCheck() { |
255 v8::HandleScope scope; | 204 v8::HandleScope scope; |
256 #ifdef DEBUG | 205 #ifdef DEBUG |
257 Heap::Verify(); | 206 Heap::Verify(); |
258 #endif | 207 #endif |
259 CHECK(Top::global()->IsJSObject()); | 208 CHECK(Top::global()->IsJSObject()); |
260 CHECK(Top::global_context()->IsContext()); | 209 CHECK(Top::global_context()->IsContext()); |
261 CHECK(Top::special_function_table()->IsFixedArray()); | 210 CHECK(Top::special_function_table()->IsFixedArray()); |
262 CHECK(Heap::symbol_table()->IsSymbolTable()); | 211 CHECK(Heap::symbol_table()->IsSymbolTable()); |
263 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure()); | 212 CHECK(!Factory::LookupAsciiSymbol("Empty")->IsFailure()); |
264 } | 213 } |
265 | 214 |
266 | 215 |
267 DEPENDENT_TEST(Deserialize, Serialize) { | 216 DEPENDENT_TEST(Deserialize, Serialize) { |
268 v8::HandleScope scope; | 217 v8::HandleScope scope; |
269 | 218 |
270 Deserialize(); | 219 Deserialize(); |
271 | 220 |
272 SanityCheck(); | |
273 } | |
274 | |
275 | |
276 DEPENDENT_TEST(Deserialize2, Serialize2) { | |
277 v8::HandleScope scope; | |
278 | |
279 Deserialize2(); | |
280 | |
281 fflush(stdout); | 221 fflush(stdout); |
282 | 222 |
283 v8::Persistent<v8::Context> env = v8::Context::New(); | 223 v8::Persistent<v8::Context> env = v8::Context::New(); |
284 env->Enter(); | 224 env->Enter(); |
285 | 225 |
286 SanityCheck(); | 226 SanityCheck(); |
287 } | 227 } |
288 | 228 |
289 | 229 |
290 DEPENDENT_TEST(DeserializeAndRunScript, Serialize) { | 230 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) { |
291 v8::HandleScope scope; | 231 v8::HandleScope scope; |
292 | 232 |
293 Deserialize(); | 233 Deserialize(); |
294 | 234 |
295 const char* c_source = "\"1234\".length"; | |
296 v8::Local<v8::String> source = v8::String::New(c_source); | |
297 v8::Local<v8::Script> script = v8::Script::Compile(source); | |
298 CHECK_EQ(4, script->Run()->Int32Value()); | |
299 } | |
300 | |
301 | |
302 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize2) { | |
303 v8::HandleScope scope; | |
304 | |
305 Deserialize2(); | |
306 | |
307 v8::Persistent<v8::Context> env = v8::Context::New(); | 235 v8::Persistent<v8::Context> env = v8::Context::New(); |
308 env->Enter(); | 236 env->Enter(); |
309 | 237 |
310 const char* c_source = "\"1234\".length"; | 238 const char* c_source = "\"1234\".length"; |
311 v8::Local<v8::String> source = v8::String::New(c_source); | 239 v8::Local<v8::String> source = v8::String::New(c_source); |
312 v8::Local<v8::Script> script = v8::Script::Compile(source); | 240 v8::Local<v8::Script> script = v8::Script::Compile(source); |
313 CHECK_EQ(4, script->Run()->Int32Value()); | 241 CHECK_EQ(4, script->Run()->Int32Value()); |
314 } | 242 } |
315 | 243 |
316 | 244 |
317 DEPENDENT_TEST(DeserializeNatives, Serialize) { | |
318 v8::HandleScope scope; | |
319 | |
320 Deserialize(); | |
321 | |
322 const char* c_source = "\"abcd\".charAt(2) == 'c'"; | |
323 v8::Local<v8::String> source = v8::String::New(c_source); | |
324 v8::Local<v8::Script> script = v8::Script::Compile(source); | |
325 v8::Local<v8::Value> value = script->Run(); | |
326 CHECK(value->BooleanValue()); | |
327 } | |
328 | |
329 | |
330 DEPENDENT_TEST(DeserializeExtensions, Serialize) { | |
331 v8::HandleScope scope; | |
332 | |
333 Deserialize(); | |
334 const char* c_source = "gc();"; | |
335 v8::Local<v8::String> source = v8::String::New(c_source); | |
336 v8::Local<v8::Script> script = v8::Script::Compile(source); | |
337 v8::Local<v8::Value> value = script->Run(); | |
338 CHECK(value->IsUndefined()); | |
339 } | |
340 | |
341 | |
342 TEST(TestThatAlwaysSucceeds) { | 245 TEST(TestThatAlwaysSucceeds) { |
343 } | 246 } |
344 | 247 |
345 | 248 |
346 TEST(TestThatAlwaysFails) { | 249 TEST(TestThatAlwaysFails) { |
347 bool ArtificialFailure = false; | 250 bool ArtificialFailure = false; |
348 CHECK(ArtificialFailure); | 251 CHECK(ArtificialFailure); |
349 } | 252 } |
350 | 253 |
351 | 254 |
352 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { | 255 DEPENDENT_TEST(DependentTestThatAlwaysFails, TestThatAlwaysSucceeds) { |
353 bool ArtificialFailure2 = false; | 256 bool ArtificialFailure2 = false; |
354 CHECK(ArtificialFailure2); | 257 CHECK(ArtificialFailure2); |
355 } | 258 } |
OLD | NEW |