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

Side by Side Diff: test/fuzzer/wasm-code.cc

Issue 2321443002: [wasm] Call the wasm interpreter from the wasm-code-fuzzer. (Closed)
Patch Set: Bugfix 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "include/v8.h" 8 #include "include/v8.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "src/wasm/encoder.h" 10 #include "src/wasm/encoder.h"
11 #include "src/wasm/wasm-interpreter.h"
11 #include "src/wasm/wasm-js.h" 12 #include "src/wasm/wasm-js.h"
12 #include "src/wasm/wasm-module.h" 13 #include "src/wasm/wasm-module.h"
13 #include "test/cctest/wasm/test-signatures.h" 14 #include "test/cctest/wasm/test-signatures.h"
14 #include "test/fuzzer/fuzzer-support.h" 15 #include "test/fuzzer/fuzzer-support.h"
15 16
16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); 18 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
18 v8::Isolate* isolate = support->GetIsolate(); 19 v8::Isolate* isolate = support->GetIsolate();
19 v8::internal::Isolate* i_isolate = 20 v8::internal::Isolate* i_isolate =
20 reinterpret_cast<v8::internal::Isolate*>(isolate); 21 reinterpret_cast<v8::internal::Isolate*>(isolate);
(...skipping 20 matching lines...) Expand all
41 f->SetSignature(sigs.i_iii()); 42 f->SetSignature(sigs.i_iii());
42 f->EmitCode(data, static_cast<uint32_t>(size)); 43 f->EmitCode(data, static_cast<uint32_t>(size));
43 f->SetExported(); 44 f->SetExported();
44 f->SetName("main", 4); 45 f->SetName("main", 4);
45 46
46 v8::internal::wasm::ZoneBuffer buffer(&zone); 47 v8::internal::wasm::ZoneBuffer buffer(&zone);
47 builder.WriteTo(buffer); 48 builder.WriteTo(buffer);
48 49
49 v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate, 50 v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate,
50 i_isolate->native_context()); 51 i_isolate->native_context());
51 v8::internal::wasm::testing::CompileAndRunWasmModule( 52
52 i_isolate, buffer.begin(), buffer.end(), false); 53 v8::internal::HandleScope scope(i_isolate);
54
55 v8::internal::wasm::ErrorThrower interpreter_thrower(i_isolate,
56 "Interpreter");
57 std::unique_ptr<const v8::internal::wasm::WasmModule> module(
58 v8::internal::wasm::testing::DecodeWasmModuleForTesting(
59 i_isolate, &zone, interpreter_thrower, buffer.begin(), buffer.end(),
60 v8::internal::wasm::kWasmOrigin));
61
62 if (module == nullptr) {
63 return 0;
64 }
65 int32_t result_interpreted;
66 {
67 v8::internal::wasm::WasmVal args[] = {v8::internal::wasm::WasmVal(1),
68 v8::internal::wasm::WasmVal(2),
69 v8::internal::wasm::WasmVal(3)};
70 result_interpreted = v8::internal::wasm::testing::InterpretWasmModule(
71 i_isolate, interpreter_thrower, module.get(), 0, args);
72 }
73
74 v8::internal::wasm::ErrorThrower compiler_thrower(i_isolate, "Compiler");
75 v8::internal::Handle<v8::internal::JSObject> instance =
76 v8::internal::wasm::testing::InstantiateModuleForTesting(
77 i_isolate, compiler_thrower, module.get());
78
79 if (!interpreter_thrower.error()) {
80 CHECK(!instance.is_null());
81 } else {
82 return 0;
83 }
84 int32_t result_compiled;
85 {
86 v8::internal::Handle<v8::internal::Object> arguments[] = {
87 v8::internal::handle(v8::internal::Smi::FromInt(1), i_isolate)};
88 result_compiled = v8::internal::wasm::testing::CallWasmFunctionForTesting(
89 i_isolate, instance, compiler_thrower, "main", arraysize(arguments),
90 arguments, false);
91 }
92 if (result_interpreted == 0xdeadbeef) {
93 CHECK(i_isolate->has_pending_exception());
94 i_isolate->clear_pending_exception();
95 } else {
96 CHECK_EQ(result_interpreted, result_compiled);
97 }
53 return 0; 98 return 0;
54 } 99 }
OLDNEW
« src/wasm/wasm-module.cc ('K') | « test/cctest/wasm/test-run-wasm-module.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698