Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tooling/ast_fuzzer/fuzz/src/targets/acir_vs_brillig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ mod tests {
fn fuzz_with_arbtest() {
crate::targets::tests::fuzz_with_arbtest(super::fuzz, 10000);
}

#[test]
fn fuzz_regressions() {
for seed in crate::targets::tests::load_seeds_from_file() {
crate::targets::tests::run_reproduce(super::fuzz, seed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ mod tests {
fn fuzz_with_arbtest() {
crate::targets::tests::fuzz_with_arbtest(super::fuzz, 2500);
}

#[test]
fn fuzz_regressions() {
for seed in crate::targets::tests::load_seeds_from_file() {
crate::targets::tests::run_reproduce(super::fuzz, seed);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ mod tests {
fn fuzz_with_arbtest() {
crate::targets::tests::fuzz_with_arbtest(super::fuzz, 1000);
}

#[test]
fn fuzz_regressions() {
for seed in crate::targets::tests::load_seeds_from_file() {
crate::targets::tests::run_reproduce(super::fuzz, seed);
}
}
}
3 changes: 3 additions & 0 deletions tooling/ast_fuzzer/fuzz/src/targets/fuzzer-regressions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0x37c7908f00100000
0x631f5e9400100000
0x578b445000100000
8 changes: 8 additions & 0 deletions tooling/ast_fuzzer/fuzz/src/targets/min_vs_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn fuzz(u: &mut Unstructured) -> eyre::Result<()> {

#[cfg(test)]
mod tests {

/// ```ignore
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// cargo test -p noir_ast_fuzzer_fuzz min_vs_full
Expand All @@ -61,4 +62,11 @@ mod tests {
fn fuzz_with_arbtest() {
crate::targets::tests::fuzz_with_arbtest(super::fuzz, 10000);
}

#[test]
fn fuzz_regressions() {
for seed in crate::targets::tests::load_seeds_from_file() {
crate::targets::tests::run_reproduce(super::fuzz, seed);
}
}
}
18 changes: 15 additions & 3 deletions tooling/ast_fuzzer/fuzz/src/targets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@ mod tests {
const MIN_SIZE: u32 = 1 << 12;
const MAX_SIZE: u32 = 1 << 20;

use std::time::Duration;
use std::{fs::File, io::BufRead, path::PathBuf, time::Duration};

use arbitrary::Unstructured;
use color_eyre::eyre;
use proptest::prelude::*;

use crate::bool_from_env;

pub(crate) fn load_seeds_from_file() -> impl Iterator<Item = u64> {
let regressions_file =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("./src/targets/fuzzer-regressions.txt");
let file = File::open(regressions_file).unwrap();
let file_reader = std::io::BufReader::new(file).lines();
file_reader.map(|line| {
let line = line.expect("Could not read line");
let seed = line.strip_prefix("0x").unwrap_or(&line);
u64::from_str_radix(seed, 16).expect("Seed should parse as u64")
})
}

fn seed_from_env() -> Option<u64> {
let Ok(seed) = std::env::var("NOIR_AST_FUZZER_SEED") else { return None };
let seed = u64::from_str_radix(seed.trim_start_matches("0x"), 16)
Expand Down Expand Up @@ -74,7 +86,7 @@ mod tests {
///
/// The `cases` determine how many tests to run on CI.
/// Tune this so that we can expect CI to be able to get through all cases in reasonable time.
pub fn fuzz_with_arbtest(f: impl Fn(&mut Unstructured) -> eyre::Result<()>, cases: u32) {
pub(crate) fn fuzz_with_arbtest(f: impl Fn(&mut Unstructured) -> eyre::Result<()>, cases: u32) {
let _ = env_logger::try_init();

if let Some(seed) = seed_from_env() {
Expand All @@ -87,7 +99,7 @@ mod tests {
}

/// Reproduce the result of a single seed.
fn run_reproduce(f: impl Fn(&mut Unstructured) -> eyre::Result<()>, seed: u64) {
pub(crate) fn run_reproduce(f: impl Fn(&mut Unstructured) -> eyre::Result<()>, seed: u64) {
arbtest::arbtest(|u| {
f(u).unwrap();
Ok(())
Expand Down
8 changes: 8 additions & 0 deletions tooling/ast_fuzzer/fuzz/src/targets/orig_vs_morph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ mod helpers {

#[cfg(test)]
mod tests {

/// ```ignore
/// NOIR_AST_FUZZER_SEED=0xb2fb5f0b00100000 \
/// cargo test -p noir_ast_fuzzer_fuzz orig_vs_morph
Expand All @@ -828,4 +829,11 @@ mod tests {
fn fuzz_with_arbtest() {
crate::targets::tests::fuzz_with_arbtest(super::fuzz, 10000);
}

#[test]
fn fuzz_regressions() {
for seed in crate::targets::tests::load_seeds_from_file() {
crate::targets::tests::run_reproduce(super::fuzz, seed);
}
}
}
8 changes: 8 additions & 0 deletions tooling/ast_fuzzer/fuzz/src/targets/pass_vs_prev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn clone_ssa(ssa: &Ssa) -> Ssa {

#[cfg(test)]
mod tests {

/// ```ignore
/// NOIR_AST_FUZZER_SEED=0x6819c61400001000 \
/// RUST_LOG=debug \
Expand All @@ -73,4 +74,11 @@ mod tests {
fn fuzz_with_arbtest() {
crate::targets::tests::fuzz_with_arbtest(super::fuzz, 20000);
}

#[test]
fn fuzz_regressions() {
for seed in crate::targets::tests::load_seeds_from_file() {
crate::targets::tests::run_reproduce(super::fuzz, seed);
}
}
}
Loading