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

Side by Side Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2736923002: SnapshotCreator: start from existing snapshot if we have one (Closed)
Patch Set: addressed comments Created 3 years, 9 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 | « src/snapshot/snapshot-common.cc ('k') | tools/dev/gm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 #include "src/snapshot/code-serializer.h" 9 #include "src/snapshot/code-serializer.h"
10 #include "src/version.h" 10 #include "src/version.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 230
231 builder->WriteTo(*buffer); 231 builder->WriteTo(*buffer);
232 } 232 }
233 233
234 void ClearSerializedData() { 234 void ClearSerializedData() {
235 serialized_bytes_.first = nullptr; 235 serialized_bytes_.first = nullptr;
236 serialized_bytes_.second = 0; 236 serialized_bytes_.second = 0;
237 } 237 }
238 238
239 void InvalidateVersion() { 239 void InvalidateVersion() {
240 uint32_t* buffer = reinterpret_cast<uint32_t*>( 240 uint32_t* slot = reinterpret_cast<uint32_t*>(
241 const_cast<uint8_t*>(serialized_bytes_.first)); 241 const_cast<uint8_t*>(serialized_bytes_.first) +
242 buffer[SerializedCodeData::kVersionHashOffset] = Version::Hash() + 1; 242 SerializedCodeData::kVersionHashOffset);
243 *slot = Version::Hash() + 1;
243 } 244 }
244 245
245 void InvalidateWireBytes() { 246 void InvalidateWireBytes() {
246 memset(const_cast<uint8_t*>(wire_bytes_.first), '\0', 247 memset(const_cast<uint8_t*>(wire_bytes_.first), '\0',
247 wire_bytes_.second / 2); 248 wire_bytes_.second / 2);
248 } 249 }
249 250
251 void InvalidateLength() {
252 uint32_t* slot = reinterpret_cast<uint32_t*>(
253 const_cast<uint8_t*>(serialized_bytes_.first) +
254 SerializedCodeData::kPayloadLengthOffset);
255 *slot = 0xfefefefeu;
256 }
257
250 v8::MaybeLocal<v8::WasmCompiledModule> Deserialize() { 258 v8::MaybeLocal<v8::WasmCompiledModule> Deserialize() {
251 ErrorThrower thrower(current_isolate(), ""); 259 ErrorThrower thrower(current_isolate(), "");
252 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = 260 v8::MaybeLocal<v8::WasmCompiledModule> deserialized =
253 v8::WasmCompiledModule::DeserializeOrCompile( 261 v8::WasmCompiledModule::DeserializeOrCompile(
254 current_isolate_v8(), serialized_bytes(), wire_bytes()); 262 current_isolate_v8(), serialized_bytes(), wire_bytes());
255 return deserialized; 263 return deserialized;
256 } 264 }
257 265
258 void DeserializeAndRun() { 266 void DeserializeAndRun() {
259 ErrorThrower thrower(current_isolate(), ""); 267 ErrorThrower thrower(current_isolate(), "");
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 WasmSerializationTest test; 407 WasmSerializationTest test;
400 { 408 {
401 HandleScope scope(test.current_isolate()); 409 HandleScope scope(test.current_isolate());
402 test.ClearSerializedData(); 410 test.ClearSerializedData();
403 test.DeserializeAndRun(); 411 test.DeserializeAndRun();
404 } 412 }
405 Cleanup(test.current_isolate()); 413 Cleanup(test.current_isolate());
406 Cleanup(); 414 Cleanup();
407 } 415 }
408 416
417 TEST(DeserializeInvalidLength) {
418 WasmSerializationTest test;
419 {
420 HandleScope scope(test.current_isolate());
421 test.InvalidateLength();
422 test.DeserializeAndRun();
423 }
424 Cleanup(test.current_isolate());
425 Cleanup();
426 }
427
409 TEST(DeserializeWireBytesAndSerializedDataInvalid) { 428 TEST(DeserializeWireBytesAndSerializedDataInvalid) {
410 WasmSerializationTest test; 429 WasmSerializationTest test;
411 { 430 {
412 HandleScope scope(test.current_isolate()); 431 HandleScope scope(test.current_isolate());
413 test.InvalidateVersion(); 432 test.InvalidateVersion();
414 test.InvalidateWireBytes(); 433 test.InvalidateWireBytes();
415 test.Deserialize(); 434 test.Deserialize();
416 } 435 }
417 Cleanup(test.current_isolate()); 436 Cleanup(test.current_isolate());
418 Cleanup(); 437 Cleanup();
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 }; 967 };
949 968
950 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data, 969 testing::CompileInstantiateWasmModuleForTesting(isolate, &thrower, data,
951 data + arraysize(data), 970 data + arraysize(data),
952 ModuleOrigin::kWasmOrigin); 971 ModuleOrigin::kWasmOrigin);
953 // It should not be possible to instantiate this module. 972 // It should not be possible to instantiate this module.
954 CHECK(thrower.error()); 973 CHECK(thrower.error());
955 } 974 }
956 Cleanup(); 975 Cleanup();
957 } 976 }
OLDNEW
« no previous file with comments | « src/snapshot/snapshot-common.cc ('k') | tools/dev/gm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698