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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/fuzzer/wasm-asmjs.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
15 #include "test/cctest/wasm/wasm-module-runner.h"
14 #include "test/fuzzer/fuzzer-support.h" 16 #include "test/fuzzer/fuzzer-support.h"
15 17
18 using namespace v8::internal::wasm;
19
16 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 20 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
17 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get(); 21 v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
18 v8::Isolate* isolate = support->GetIsolate(); 22 v8::Isolate* isolate = support->GetIsolate();
19 v8::internal::Isolate* i_isolate = 23 v8::internal::Isolate* i_isolate =
20 reinterpret_cast<v8::internal::Isolate*>(isolate); 24 reinterpret_cast<v8::internal::Isolate*>(isolate);
21 25
22 // Clear any pending exceptions from a prior run. 26 // Clear any pending exceptions from a prior run.
23 if (i_isolate->has_pending_exception()) { 27 if (i_isolate->has_pending_exception()) {
24 i_isolate->clear_pending_exception(); 28 i_isolate->clear_pending_exception();
25 } 29 }
26 30
27 v8::Isolate::Scope isolate_scope(isolate); 31 v8::Isolate::Scope isolate_scope(isolate);
28 v8::HandleScope handle_scope(isolate); 32 v8::HandleScope handle_scope(isolate);
29 v8::Context::Scope context_scope(support->GetContext()); 33 v8::Context::Scope context_scope(support->GetContext());
30 v8::TryCatch try_catch(isolate); 34 v8::TryCatch try_catch(isolate);
31 35
32 v8::base::AccountingAllocator allocator; 36 v8::base::AccountingAllocator allocator;
33 v8::internal::Zone zone(&allocator); 37 v8::internal::Zone zone(&allocator);
34 38
35 v8::internal::wasm::TestSignatures sigs; 39 TestSignatures sigs;
36 40
37 v8::internal::wasm::WasmModuleBuilder builder(&zone); 41 WasmModuleBuilder builder(&zone);
38 42
39 uint16_t f1_index = builder.AddFunction(); 43 uint16_t f1_index = builder.AddFunction();
40 v8::internal::wasm::WasmFunctionBuilder* f = builder.FunctionAt(f1_index); 44 WasmFunctionBuilder* f = builder.FunctionAt(f1_index);
41 f->SetSignature(sigs.i_iii()); 45 f->SetSignature(sigs.i_iii());
42 f->EmitCode(data, static_cast<uint32_t>(size)); 46 f->EmitCode(data, static_cast<uint32_t>(size));
43 f->SetExported(); 47 f->SetExported();
44 f->SetName("main", 4); 48 f->SetName("main", 4);
45 49
46 v8::internal::wasm::ZoneBuffer buffer(&zone); 50 ZoneBuffer buffer(&zone);
47 builder.WriteTo(buffer); 51 builder.WriteTo(buffer);
48 52
49 v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate, 53 v8::internal::WasmJs::InstallWasmFunctionMap(i_isolate,
50 i_isolate->native_context()); 54 i_isolate->native_context());
51 v8::internal::wasm::testing::CompileAndRunWasmModule( 55
52 i_isolate, buffer.begin(), buffer.end(), false); 56 v8::internal::HandleScope scope(i_isolate);
57
58 ErrorThrower interpreter_thrower(i_isolate, "Interpreter");
59 std::unique_ptr<const WasmModule> module(testing::DecodeWasmModuleForTesting(
60 i_isolate, &zone, interpreter_thrower, buffer.begin(), buffer.end(),
61 kWasmOrigin));
62
63 if (module == nullptr) {
64 return 0;
65 }
66 int32_t result_interpreted;
67 {
68 WasmVal args[] = {WasmVal(1), WasmVal(2), WasmVal(3)};
69 result_interpreted = testing::InterpretWasmModule(
70 i_isolate, interpreter_thrower, module.get(), 0, args);
71 }
72
73 ErrorThrower compiler_thrower(i_isolate, "Compiler");
74 v8::internal::Handle<v8::internal::JSObject> instance =
75 testing::InstantiateModuleForTesting(i_isolate, compiler_thrower,
76 module.get());
77
78 if (!interpreter_thrower.error()) {
79 CHECK(!instance.is_null());
80 } else {
81 return 0;
82 }
83 int32_t result_compiled;
84 {
85 v8::internal::Handle<v8::internal::Object> arguments[] = {
86 v8::internal::handle(v8::internal::Smi::FromInt(1), i_isolate)};
87 result_compiled = testing::CallWasmFunctionForTesting(
88 i_isolate, instance, compiler_thrower, "main", arraysize(arguments),
89 arguments, false);
90 }
91 if (result_interpreted == 0xdeadbeef) {
92 CHECK(i_isolate->has_pending_exception());
93 i_isolate->clear_pending_exception();
94 } else {
95 CHECK_EQ(result_interpreted, result_compiled);
96 }
53 return 0; 97 return 0;
54 } 98 }
OLDNEW
« 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