//! Every input a fuzzer once broke a target with, replayed on every push //! (src/fuzzing.rs, fuzz/). A crash the nightly fuzzing finds goes into //! `tests/fuzz_cases//` with its fix, so it can never come back. use std::fs; use std::path::Path; #[test] fn the_inputs_the_fuzzers_found_stay_harmless() { let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fuzz_cases"); let mut tried = 0; for (name, target) in visa::fuzzing::TARGETS { let dir = root.join(name); let Ok(entries) = fs::read_dir(&dir) else { continue; }; for e in entries { let path = e.unwrap().path(); if path.extension().is_some_and(|x| x == "md") { continue; } let data = fs::read(&path).unwrap(); let caught = std::panic::catch_unwind(|| target(&data)); assert!(caught.is_ok(), "{name}: {} breaks it again", path.display()); tried += 1; } } // the folder of every target exists, so a renamed one is noticed for (name, _) in visa::fuzzing::TARGETS { assert!( root.join(name).is_dir(), "tests/fuzz_cases/{name} is missing" ); } eprintln!("{tried} fuzz cases replayed"); } #[test] fn every_target_takes_its_seeds() { // the seeds the nightly run starts from (fuzz/seeds/) go through too let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("fuzz/seeds"); for (name, target) in visa::fuzzing::TARGETS { let dir = root.join(name); let files: Vec<_> = fs::read_dir(&dir) .unwrap_or_else(|_| panic!("fuzz/seeds/{name} is missing")) .map(|e| e.unwrap().path()) .collect(); assert!(!files.is_empty(), "fuzz/seeds/{name} is empty"); for f in files { target(&fs::read(&f).unwrap()); } } }