Fuzzing: Add test case logging and regression test template
When the test case that causes the failure can successfully be disassembled to
WAT, we get logs like this:
```
[2019-11-26T18:48:46Z INFO wasmtime_fuzzing] Wrote WAT disassembly to: /home/fitzgen/wasmtime/crates/fuzzing/target/scratch/8437-0.wat
[2019-11-26T18:48:46Z INFO wasmtime_fuzzing] If this fuzz test fails, copy `/home/fitzgen/wasmtime/crates/fuzzing/target/scratch/8437-0.wat` to `wasmtime/crates/fuzzing/tests/regressions/my-regression.wat` and add the following test to `wasmtime/crates/fuzzing/tests/regressions.rs`:
```
#[test]
fn my_fuzzing_regression_test() {
let data = wat::parse_str(
include_str!("./regressions/my-regression.wat")
).unwrap();
oracles::instantiate(data, CompilationStrategy::Auto)
}
```
```
If the test case cannot be disassembled to WAT, then we get logs like this:
```
[2019-11-26T18:48:46Z INFO wasmtime_fuzzing] Wrote Wasm test case to: /home/fitzgen/wasmtime/crates/fuzzing/target/scratch/8437-0.wasm
[2019-11-26T18:48:46Z INFO wasmtime_fuzzing] Failed to disassemble Wasm into WAT:
Bad magic number (at offset 0)
Stack backtrace:
Run with RUST_LIB_BACKTRACE=1 env variable to display a backtrace
[2019-11-26T18:48:46Z INFO wasmtime_fuzzing] If this fuzz test fails, copy `/home/fitzgen/wasmtime/crates/fuzzing/target/scratch/8437-0.wasm` to `wasmtime/crates/fuzzing/tests/regressions/my-regression.wasm` and add the following test to `wasmtime/crates/fuzzing/tests/regressions.rs`:
```
#[test]
fn my_fuzzing_regression_test() {
let data = include_bytes!("./regressions/my-regression.wasm");
oracles::instantiate(data, CompilationStrategy::Auto)
}
```
```
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use wasmtime_fuzzing::oracles;
|
||||
use wasmtime_fuzzing::{oracles, with_log_wasm_test_case};
|
||||
use wasmtime_jit::CompilationStrategy;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
oracles::compile(data, CompilationStrategy::Cranelift);
|
||||
with_log_wasm_test_case!(data, |data| oracles::compile(
|
||||
data,
|
||||
CompilationStrategy::Cranelift
|
||||
));
|
||||
});
|
||||
|
||||
#[cfg(feature = "lightbeam")]
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
oracles::compile(data, CompilationStrategy::Lightbeam);
|
||||
with_log_wasm_test_case!(data, |data| oracles::compile(
|
||||
data,
|
||||
CompilationStrategy::Lightbeam
|
||||
));
|
||||
});
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use wasmtime_fuzzing::oracles;
|
||||
use wasmtime_jit::{CompilationStrategy};
|
||||
use wasmtime_fuzzing::{oracles, with_log_wasm_test_case};
|
||||
use wasmtime_jit::CompilationStrategy;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
oracles::instantiate(data, CompilationStrategy::Auto);
|
||||
with_log_wasm_test_case!(data, |data| oracles::instantiate(
|
||||
data,
|
||||
CompilationStrategy::Auto
|
||||
));
|
||||
});
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use wasmtime_fuzzing::{generators, oracles};
|
||||
use wasmtime_fuzzing::{generators, oracles, with_log_wasm_test_case};
|
||||
use wasmtime_jit::CompilationStrategy;
|
||||
|
||||
fuzz_target!(|data: generators::WasmOptTtf| {
|
||||
oracles::instantiate(&data.wasm, CompilationStrategy::Auto);
|
||||
with_log_wasm_test_case!(&data.wasm, |wasm| oracles::instantiate(
|
||||
wasm,
|
||||
CompilationStrategy::Auto
|
||||
));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user