Skip to content

Commit f55ac48

Browse files
bors[bot]nlewycky
andauthored
Merge #2202
2202: Include fuzzers in fmt and clippy. r=nlewycky a=nlewycky Co-authored-by: Nick Lewycky <[email protected]>
2 parents 14669d3 + 0193b72 commit f55ac48

File tree

6 files changed

+51
-25
lines changed

6 files changed

+51
-25
lines changed

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ test-packages:
515515
cargo test -p wasmer-cache --release
516516
cargo test -p wasmer-engine --release
517517
cargo test -p wasmer-derive --release
518+
cargo check --manifest-path fuzz/Cargo.toml $(compiler_features) --release
518519

519520

520521
# We want to run all the tests for all available compilers. The C API
@@ -739,9 +740,11 @@ lint-packages:
739740
RUSTFLAGS=${RUSTFLAGS} cargo clippy --manifest-path lib/cli/Cargo.toml $(compiler_features)
740741
RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-cache
741742
RUSTFLAGS=${RUSTFLAGS} cargo clippy -p wasmer-engine
743+
RUSTFLAGS=${RUSTFLAGS} cargo clippy --manifest-path fuzz/Cargo.toml $(compiler_features)
742744

743745
lint-formatting:
744746
cargo fmt --all -- --check
747+
cargo fmt --manifest-path fuzz/Cargo.toml -- --check
745748

746749
lint: lint-formatting lint-packages
747750

fuzz/Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fuzz/Cargo.toml

+21-14
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ cargo-fuzz = true
1212
anyhow = "1"
1313
wasm-smith = { git = "https://github.com/bytecodealliance/wasm-tools" }
1414
libfuzzer-sys = "0.4.0"
15-
[dependencies.wasmer]
16-
path = "../lib/api"
17-
[dependencies.wasmer-compiler-cranelift]
18-
path = "../lib/compiler-cranelift"
19-
[dependencies.wasmer-compiler-llvm]
20-
path = "../lib/compiler-llvm"
21-
[dependencies.wasmer-compiler-singlepass]
22-
path = "../lib/compiler-singlepass"
23-
[dependencies.wasmer-engine-jit]
24-
path = "../lib/engine-jit"
25-
[dependencies.wasmer-engine-native]
26-
path = "../lib/engine-native"
27-
[dependencies.wasmer-middlewares]
28-
path = "../lib/middlewares"
15+
wasmer = { path = "../lib/api" }
16+
wasmer-compiler-cranelift = { path = "../lib/compiler-cranelift", optional = true }
17+
wasmer-compiler-llvm = { path = "../lib/compiler-llvm", optional = true }
18+
wasmer-compiler-singlepass = { path = "../lib/compiler-singlepass", optional = true }
19+
wasmer-engine-jit = { path = "../lib/engine-jit", optional = true }
20+
wasmer-engine-native = { path = "../lib/engine-native", optional = true }
21+
wasmer-middlewares = { path = "../lib/middlewares" }
22+
23+
[features]
24+
cranelift = [ "wasmer-compiler-cranelift" ]
25+
llvm = [ "wasmer-compiler-llvm" ]
26+
singlepass = [ "wasmer-compiler-singlepass" ]
27+
jit = [ "wasmer-engine-jit" ]
28+
native = [ "wasmer-engine-native" ]
2929

3030
# Prevent this from interfering with workspaces
3131
[workspace]
@@ -34,27 +34,34 @@ members = ["."]
3434
[[bin]]
3535
name = "equivalence_jit"
3636
path = "fuzz_targets/equivalence_jit.rs"
37+
required-features = ["jit"]
3738

3839
[[bin]]
3940
name = "jit_cranelift"
4041
path = "fuzz_targets/jit_cranelift.rs"
42+
required-features = ["jit", "cranelift"]
4143

4244
[[bin]]
4345
name = "jit_llvm"
4446
path = "fuzz_targets/jit_llvm.rs"
47+
required-features = ["jit", "llvm"]
4548

4649
[[bin]]
4750
name = "jit_singlepass"
4851
path = "fuzz_targets/jit_singlepass.rs"
52+
required-features = ["jit", "singlepass"]
4953

5054
[[bin]]
5155
name = "metering"
5256
path = "fuzz_targets/metering.rs"
57+
required-features = ["jit", "cranelift"]
5358

5459
[[bin]]
5560
name = "native_cranelift"
5661
path = "fuzz_targets/native_cranelift.rs"
62+
required-features = ["native", "cranelift"]
5763

5864
[[bin]]
5965
name = "validate"
6066
path = "fuzz_targets/validate.rs"
67+
required-features = ["jit", "cranelift"]

fuzz/fuzz_targets/equivalence_jit.rs

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#![no_main]
2+
#![deny(unused_variables)]
23

34
use anyhow::Result;
45
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
56
use wasm_smith::{Config, ConfiguredModule};
67
use wasmer::{imports, CompilerConfig, Instance, Module, Store, Val};
8+
#[cfg(feature = "cranelift")]
79
use wasmer_compiler_cranelift::Cranelift;
10+
#[cfg(feature = "llvm")]
811
use wasmer_compiler_llvm::LLVM;
12+
#[cfg(feature = "singlepass")]
913
use wasmer_compiler_singlepass::Singlepass;
1014
use wasmer_engine_jit::JIT;
1115

@@ -27,6 +31,7 @@ impl Config for ExportedFunctionConfig {
2731
}
2832
}
2933

34+
#[cfg(feature = "singlepass")]
3035
fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
3136
let compiler = Singlepass::default();
3237
let store = Store::new(&JIT::new(compiler).engine());
@@ -45,6 +50,7 @@ fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
4550
Ok(Some(instance))
4651
}
4752

53+
#[cfg(feature = "cranelift")]
4854
fn maybe_instantiate_cranelift(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
4955
let mut compiler = Cranelift::default();
5056
compiler.canonicalize_nans(true);
@@ -55,6 +61,7 @@ fn maybe_instantiate_cranelift(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
5561
Ok(Some(instance))
5662
}
5763

64+
#[cfg(feature = "llvm")]
5865
fn maybe_instantiate_llvm(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
5966
let mut compiler = LLVM::default();
6067
compiler.canonicalize_nans(true);
@@ -78,15 +85,14 @@ impl PartialEq for InstanceResult {
7885
if let InstanceResult::Error(other_message) = other {
7986
return self_message == other_message;
8087
}
81-
return false;
8288
}
8389
InstanceResult::Values(self_values) => {
8490
if let InstanceResult::Values(other_values) = other {
8591
return self_values == other_values;
8692
}
87-
return false;
8893
}
8994
}
95+
false
9096
}
9197
}
9298

@@ -109,8 +115,7 @@ fn evaluate_instance(instance: Result<Instance>) -> Vec<InstanceResult> {
109115
// TODO: support functions which take params.
110116
if f.ty().params().is_empty() {
111117
let result = f.call(&[]);
112-
let result = if result.is_ok() {
113-
let values = result.unwrap();
118+
let result = if let Ok(values) = result {
114119
InstanceResult::Values(values.into())
115120
} else {
116121
let err = result.unwrap_err();
@@ -129,16 +134,28 @@ fuzz_target!(|module: ConfiguredModule<ExportedFunctionConfig>| {
129134
module.ensure_termination(100000);
130135
let wasm_bytes = module.to_bytes();
131136

132-
let singlepass = maybe_instantiate_singlepass(&wasm_bytes).transpose().map(evaluate_instance);
133-
let cranelift = maybe_instantiate_cranelift(&wasm_bytes).transpose().map(evaluate_instance);
134-
let llvm = maybe_instantiate_llvm(&wasm_bytes).transpose().map(evaluate_instance);
137+
#[cfg(feature = "singlepass")]
138+
let singlepass = maybe_instantiate_singlepass(&wasm_bytes)
139+
.transpose()
140+
.map(evaluate_instance);
141+
#[cfg(feature = "cranelift")]
142+
let cranelift = maybe_instantiate_cranelift(&wasm_bytes)
143+
.transpose()
144+
.map(evaluate_instance);
145+
#[cfg(feature = "llvm")]
146+
let llvm = maybe_instantiate_llvm(&wasm_bytes)
147+
.transpose()
148+
.map(evaluate_instance);
135149

150+
#[cfg(all(feature = "singlepass", feature = "cranelift"))]
136151
if singlepass.is_some() && cranelift.is_some() {
137152
assert_eq!(singlepass.as_ref().unwrap(), cranelift.as_ref().unwrap());
138153
}
154+
#[cfg(all(feature = "singlepass", feature = "llvm"))]
139155
if singlepass.is_some() && llvm.is_some() {
140156
assert_eq!(singlepass.as_ref().unwrap(), llvm.as_ref().unwrap());
141157
}
158+
#[cfg(all(feature = "cranelift", feature = "llvm"))]
142159
if cranelift.is_some() && llvm.is_some() {
143160
assert_eq!(cranelift.as_ref().unwrap(), llvm.as_ref().unwrap());
144161
}

fuzz/fuzz_targets/jit_singlepass.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ fuzz_target!(|module: ConfiguredModule<NoImportsConfig>| {
4040
Ok(_) => {}
4141
Err(e) => {
4242
let error_message = format!("{}", e);
43-
if
44-
error_message
43+
if error_message
4544
.contains("RuntimeError: memory out of bounds: data segment does not fit")
4645
|| error_message
4746
.contains("RuntimeError: table out of bounds: elements segment does not fit")

fuzz/fuzz_targets/metering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use libfuzzer_sys::{arbitrary, arbitrary::Arbitrary, fuzz_target};
44
use std::sync::Arc;
55
use wasm_smith::{Config, ConfiguredModule};
6-
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
76
use wasmer::wasmparser::Operator;
7+
use wasmer::{imports, CompilerConfig, Instance, Module, Store};
88
use wasmer_compiler_cranelift::Cranelift;
99
use wasmer_engine_jit::JIT;
1010
use wasmer_middlewares::Metering;

0 commit comments

Comments
 (0)