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

Unified Diff: test/cctest/wasm/test-run-wasm-module.cc

Issue 2420373002: [wasm] Test deserialized module still has bytes, + negative test (Closed)
Patch Set: Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-run-wasm-module.cc
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc
index fb1cbbf1d3eb87b2ac85c46c9f164465efed9163..6700e407a65423255c476d963a7c13fdeb48f3da 100644
--- a/test/cctest/wasm/test-run-wasm-module.cc
+++ b/test/cctest/wasm/test-run-wasm-module.cc
@@ -230,7 +230,7 @@ TEST(Run_WasmModule_Serialization) {
create_params.array_buffer_allocator =
CcTest::InitIsolateOnce()->array_buffer_allocator();
- for (int i = 0; i < 3; ++i) {
+ for (int i = 0; i < 4; ++i) {
bradnelson 2016/10/17 20:38:04 The numeric counting is getting hard to follow her
Mircea Trofin 2016/10/18 04:34:13 Currently, TEST_F isn't available to cctest. I ref
v8::Isolate* v8_isolate = v8::Isolate::New(create_params);
if (i == 1) {
// Invalidate the header by providing a mismatched version
@@ -244,6 +244,11 @@ TEST(Run_WasmModule_Serialization) {
serialized_bytes.first = nullptr;
serialized_bytes.second = 0;
}
+ if (i == 3) {
+ // Not even the wire bytes are valid. Clear half of them.
+ memset(const_cast<uint8_t*>(wire_bytes.first), '\0',
+ wire_bytes.second / 2);
+ }
{
v8::Isolate::Scope isolate_scope(v8_isolate);
v8::HandleScope new_scope(v8_isolate);
@@ -254,20 +259,33 @@ TEST(Run_WasmModule_Serialization) {
v8::MaybeLocal<v8::WasmCompiledModule> deserialized =
v8::WasmCompiledModule::DeserializeOrCompile(
v8_isolate, serialized_bytes, wire_bytes);
- v8::Local<v8::WasmCompiledModule> compiled_module;
- CHECK(deserialized.ToLocal(&compiled_module));
- Handle<JSObject> module_object =
- Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module));
- Handle<JSObject> instance =
- WasmModule::Instantiate(isolate, &thrower, module_object,
- Handle<JSReceiver>::null(),
- Handle<JSArrayBuffer>::null())
- .ToHandleChecked();
- Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)};
- int32_t result = testing::CallWasmFunctionForTesting(
- isolate, instance, &thrower, kFunctionName, 1, params,
- ModuleOrigin::kWasmOrigin);
- CHECK(result == 42);
+ if (i == 3) {
+ CHECK(deserialized.IsEmpty());
+ } else {
+ v8::Local<v8::WasmCompiledModule> deserialized_module;
+ CHECK(deserialized.ToLocal(&deserialized_module));
+ Handle<JSObject> module_object =
+ Handle<JSObject>::cast(v8::Utils::OpenHandle(*deserialized_module));
+ {
+ DisallowHeapAllocation assume_no_gc;
+ Handle<WasmCompiledModule> compiled_part(
+ WasmCompiledModule::cast(module_object->GetInternalField(0)),
+ isolate);
+ CHECK_EQ(memcmp(compiled_part->module_bytes()->GetCharsAddress(),
+ wire_bytes.first, wire_bytes.second),
+ 0);
+ }
+ Handle<JSObject> instance =
+ WasmModule::Instantiate(isolate, &thrower, module_object,
+ Handle<JSReceiver>::null(),
+ Handle<JSArrayBuffer>::null())
+ .ToHandleChecked();
+ Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)};
+ int32_t result = testing::CallWasmFunctionForTesting(
+ isolate, instance, &thrower, kFunctionName, 1, params,
+ ModuleOrigin::kWasmOrigin);
+ CHECK(result == 42);
+ }
new_ctx->Exit();
}
v8_isolate->Dispose();
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698