diff --git a/Cargo.lock b/Cargo.lock index 10fd8fea64..924a41bcd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -112,9 +112,9 @@ checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" [[package]] name = "arbitrary" -version = "0.4.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db55d72333851e17d572bec876e390cd3b11eb1ef53ae821dd9f3b653d2b4569" +checksum = "698b65a961a9d730fb45b6b0327e20207810c9f61ee421b082b27ba003f49e2b" dependencies = [ "derive_arbitrary", ] @@ -863,9 +863,9 @@ dependencies = [ [[package]] name = "derive_arbitrary" -version = "0.4.7" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a012b5e473dc912f0db0546a1c9c6a194ce8494feb66fa0237160926f9e0e6" +checksum = "df89dd0d075dea5cc5fdd6d5df6b8a61172a710b3efac1d6bdb9dd8b78f82c1a" dependencies = [ "proc-macro2", "quote", @@ -1442,9 +1442,9 @@ checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3" [[package]] name = "libfuzzer-sys" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcf184a4b6b274f82a5df6b357da6055d3e82272327bba281c28bbba6f1664ef" +checksum = "86c975d637bc2a2f99440932b731491fc34c7f785d239e38af3addd3c2fd0e46" dependencies = [ "arbitrary", "cc", @@ -3058,9 +3058,9 @@ dependencies = [ [[package]] name = "wasm-smith" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5af0d70f17515b1bc412b7727b01304ba2484bc416da72f325d6bf4ab58f4213" +checksum = "f9a5c40555e0fd974d984d9a1186cf2aa7092450912bef9943a581941dd61bfa" dependencies = [ "arbitrary", "indexmap", diff --git a/cranelift/peepmatic/crates/fuzzing/Cargo.toml b/cranelift/peepmatic/crates/fuzzing/Cargo.toml index 81b5c44597..7949451bc9 100644 --- a/cranelift/peepmatic/crates/fuzzing/Cargo.toml +++ b/cranelift/peepmatic/crates/fuzzing/Cargo.toml @@ -8,7 +8,7 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -arbitrary = { version = "0.4.1", features = ["derive"] } +arbitrary = { version = "1.0.0", features = ["derive"] } bincode = "1.2.1" env_logger = "0.8.1" fst = "0.4.1" diff --git a/cranelift/peepmatic/crates/fuzzing/src/lib.rs b/cranelift/peepmatic/crates/fuzzing/src/lib.rs index 82661d8b7d..0fa128c539 100644 --- a/cranelift/peepmatic/crates/fuzzing/src/lib.rs +++ b/cranelift/peepmatic/crates/fuzzing/src/lib.rs @@ -9,7 +9,6 @@ use arbitrary::{Arbitrary, Unstructured}; use rand::prelude::*; use std::fmt::Debug; -use std::panic; use std::time; pub mod automata; @@ -24,7 +23,7 @@ pub mod parser; /// for use with `cargo test` and CI. pub fn check(mut f: impl FnMut(A)) where - A: Clone + Debug + Arbitrary, + A: Clone + Debug + for<'a> Arbitrary<'a>, { let seed = rand::thread_rng().gen(); let mut rng = rand::rngs::SmallRng::seed_from_u64(seed); @@ -38,7 +37,7 @@ where let time_budget = time::Duration::from_secs(2); let then = time::Instant::now(); - let (failing_input, panic_info) = loop { + loop { if num_checked > 0 && time::Instant::now().duration_since(then) > time_budget { eprintln!("Checked {} random inputs.", num_checked); return; @@ -48,9 +47,7 @@ where Ok(input) => { num_checked += 1; eprintln!("Checking input: {:#?}", input); - if let Err(p) = panic::catch_unwind(panic::AssertUnwindSafe(|| f(input.clone()))) { - break (input, p); - } + f(input.clone()); } Err(e @ arbitrary::Error::NotEnoughData) => { eprintln!("warning: {}", e); @@ -97,23 +94,5 @@ where for i in 0..buf.len() { buf[i] = rng.gen(); } - }; - - // Shrink the failing input. - let mut smallest_failing_input = failing_input; - let mut panic_info = panic_info; - 'shrinking: loop { - eprintln!("Smallest failing input: {:#?}", smallest_failing_input); - for input in smallest_failing_input.shrink() { - if let Err(p) = panic::catch_unwind(panic::AssertUnwindSafe(|| f(input.clone()))) { - smallest_failing_input = input; - panic_info = p; - continue 'shrinking; - } - } - break; } - - // Resume the panic for the smallest input. - panic::resume_unwind(panic_info); } diff --git a/crates/fuzzing/Cargo.toml b/crates/fuzzing/Cargo.toml index 5b579f9b76..ef721fc392 100644 --- a/crates/fuzzing/Cargo.toml +++ b/crates/fuzzing/Cargo.toml @@ -9,7 +9,7 @@ license = "Apache-2.0 WITH LLVM-exception" [dependencies] anyhow = "1.0.22" -arbitrary = { version = "0.4.1", features = ["derive"] } +arbitrary = { version = "1.0.0", features = ["derive"] } env_logger = "0.8.1" log = "0.4.8" rayon = "1.2.1" @@ -18,7 +18,7 @@ wasmprinter = "0.2.23" wasmtime = { path = "../wasmtime" } wasmtime-wast = { path = "../wast" } wasm-encoder = "0.4" -wasm-smith = "0.3.1" +wasm-smith = "0.4.0" wasmi = "0.7.0" [dev-dependencies] diff --git a/crates/fuzzing/src/generators.rs b/crates/fuzzing/src/generators.rs index b44af8daf5..764f6a3b38 100644 --- a/crates/fuzzing/src/generators.rs +++ b/crates/fuzzing/src/generators.rs @@ -102,8 +102,8 @@ pub struct SpecTest { pub contents: &'static str, } -impl Arbitrary for SpecTest { - fn arbitrary(u: &mut Unstructured) -> arbitrary::Result { +impl<'a> Arbitrary<'a> for SpecTest { + fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { // NB: this does get a uniform value in the provided range. let i = u.int_in_range(0..=FILES.len() - 1)?; let (file, contents) = FILES[i]; diff --git a/crates/fuzzing/src/generators/api.rs b/crates/fuzzing/src/generators/api.rs index 2605b058ef..bfcaccb0c9 100644 --- a/crates/fuzzing/src/generators/api.rs +++ b/crates/fuzzing/src/generators/api.rs @@ -79,8 +79,8 @@ pub struct ApiCalls { pub calls: Vec, } -impl Arbitrary for ApiCalls { - fn arbitrary(input: &mut Unstructured) -> arbitrary::Result { +impl<'a> Arbitrary<'a> for ApiCalls { + fn arbitrary(input: &mut Unstructured<'a>) -> arbitrary::Result { crate::init_fuzzing(); let swarm = Swarm::arbitrary(input)?; diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index df6905a23f..d90052e769 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -12,12 +12,12 @@ cargo-fuzz = true cranelift-codegen = { path = "../cranelift/codegen" } cranelift-reader = { path = "../cranelift/reader" } cranelift-wasm = { path = "../cranelift/wasm" } -libfuzzer-sys = "0.3.3" +libfuzzer-sys = "0.4.0" target-lexicon = "0.11" peepmatic-fuzzing = { path = "../cranelift/peepmatic/crates/fuzzing", optional = true } wasmtime = { path = "../crates/wasmtime" } wasmtime-fuzzing = { path = "../crates/fuzzing" } -wasm-smith = "0.3.1" +wasm-smith = "0.4.0" [features] experimental_x64 = ["wasmtime-fuzzing/experimental_x64"]