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

Unified Diff: test/fuzzer/wasm-code.cc

Issue 2321443002: [wasm] Call the wasm interpreter from the wasm-code-fuzzer. (Closed)
Patch Set: Address comments Created 4 years, 3 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 | « test/fuzzer/wasm-asmjs.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/fuzzer/wasm-code.cc
diff --git a/test/fuzzer/wasm-code.cc b/test/fuzzer/wasm-code.cc
index ae1ec4a0deb7e92cf943d793ea95573a161dbae6..4743e82691601e90477f00975bd456a5435f4724 100644
--- a/test/fuzzer/wasm-code.cc
+++ b/test/fuzzer/wasm-code.cc
@@ -8,11 +8,15 @@
#include "include/v8.h"
#include "src/isolate.h"
#include "src/wasm/encoder.h"
+#include "src/wasm/wasm-interpreter.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "test/cctest/wasm/test-signatures.h"
+#include "test/cctest/wasm/wasm-module-runner.h"
#include "test/fuzzer/fuzzer-support.h"
+using namespace v8::internal::wasm;
+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
v8::Isolate* isolate = support->GetIsolate();
@@ -32,23 +36,63 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::base::AccountingAllocator allocator;
v8::internal::Zone zone(&allocator);
- v8::internal::wasm::TestSignatures sigs;
+ TestSignatures sigs;
- v8::internal::wasm::WasmModuleBuilder builder(&zone);
+ WasmModuleBuilder builder(&zone);
uint16_t f1_index = builder.AddFunction();
- v8::internal::wasm::WasmFunctionBuilder* f = builder.FunctionAt(f1_index);
+ WasmFunctionBuilder* f = builder.FunctionAt(f1_index);
f->SetSignature(sigs.i_iii());
f->EmitCode(data, static_cast<uint32_t>(size));
f->SetExported();
f->SetName("main", 4);
- v8::internal::wasm::ZoneBuffer buffer(&zone);
+ ZoneBuffer buffer(&zone);
builder.WriteTo(buffer);
v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate,
i_isolate->native_context());
- v8::internal::wasm::testing::CompileAndRunWasmModule(
- i_isolate, buffer.begin(), buffer.end(), false);
+
+ v8::internal::HandleScope scope(i_isolate);
+
+ ErrorThrower interpreter_thrower(i_isolate, "Interpreter");
+ std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting(
+ i_isolate, &zone, interpreter_thrower, buffer.begin(), buffer.end(),
+ kWasmOrigin));
+
+ if (module == nullptr) {
+ return 0;
+ }
+ int32_t result_interpreted;
+ {
+ WasmVal args[] = {WasmVal(1), WasmVal(2), WasmVal(3)};
+ result_interpreted = testing::InterpretWasmModule(
+ i_isolate, interpreter_thrower, module.get(), 0, args);
+ }
+
+ ErrorThrower compiler_thrower(i_isolate, "Compiler");
+ v8::internal::Handle<v8::internal::JSObject> instance =
+ testing::InstantiateModuleForTesting(i_isolate, compiler_thrower,
+ module.get());
+
+ if (!interpreter_thrower.error()) {
+ CHECK(!instance.is_null());
+ } else {
+ return 0;
+ }
+ int32_t result_compiled;
+ {
+ v8::internal::Handle<v8::internal::Object> arguments[] = {
+ v8::internal::handle(v8::internal::Smi::FromInt(1), i_isolate)};
+ result_compiled = testing::CallWasmFunctionForTesting(
+ i_isolate, instance, compiler_thrower, "main", arraysize(arguments),
+ arguments, false);
+ }
+ if (result_interpreted == 0xdeadbeef) {
+ CHECK(i_isolate->has_pending_exception());
+ i_isolate->clear_pending_exception();
+ } else {
+ CHECK_EQ(result_interpreted, result_compiled);
+ }
return 0;
}
« no previous file with comments | « test/fuzzer/wasm-asmjs.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698