Skip to content
Merged
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
15 changes: 11 additions & 4 deletions src/bin/cargo-ziggy/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ impl Fuzz {
let profile_bin = cx
.target_dir
.join(format!("coverage/debug/{}", cx.bin_target));
let profile_base = cx.target_dir.join("coverage/debug/deps/coverage-");
let profile_base = cx
.target_dir
.join("coverage/debug/deps/coverage-worker.profraw");
Some(crate::coverage::Cfg::new(profile_bin, profile_base)?)
} else {
None
Expand Down Expand Up @@ -225,6 +227,7 @@ impl Fuzz {
let coverage_now_running = Arc::clone(&coverage_now_running);
let cx = cx.clone();
let cfg = coverage_cfg.clone().unwrap();
let terminate = Arc::clone(&common.terminate);
thread::spawn(move || {
let mut seen_new_entry = false;
let prev_start_time =
Expand All @@ -233,7 +236,7 @@ impl Fuzz {
let profile_bin = cx.target_dir.join(format!("coverage/debug/{target}"));
let profile_base = cx
.target_dir
.join("coverage/debug/deps/coverage-")
.join("coverage/debug/deps")
Comment thread
chris-srlabs marked this conversation as resolved.
.as_std_path()
.to_path_buf();
let entries = std::fs::read_dir(&main_corpus).unwrap();
Expand All @@ -250,7 +253,8 @@ impl Fuzz {
});
if potentially_new && let Some(hash) = entry.file_name() {
let profile_file = {
let mut name = hash.to_os_string();
let mut name = std::ffi::OsString::from("coverage-");
Comment thread
chris-srlabs marked this conversation as resolved.
name.push(hash);
name.push(".profraw");
profile_base.join(name)
};
Expand Down Expand Up @@ -282,8 +286,11 @@ impl Fuzz {
};

{
// poison mutex on failure
let mut guard = coverage_now_running.lock().unwrap();
res.unwrap();
if !terminate.load(std::sync::atomic::Ordering::Acquire) {
res.unwrap();
}
*guard = false;
}
*cov_end_time.lock().unwrap() = Instant::now();
Expand Down
44 changes: 44 additions & 0 deletions tests/url_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,47 @@ fn clean() {
assert!(!hfuzz_build_path.exists(), "honggfuzz harness not cleaned");
}
}

#[allow(clippy::zombie_processes)]
#[test]
fn coverage_worker() {
let _guard = exclusive_guard();
let temp_dir = tempfile::tempdir().unwrap();
let output_dir = temp_dir.path().join("output");
let target_dir = temp_dir.path().join("target");
let metadata = cargo_metadata::MetadataCommand::new().exec().unwrap();
let workspace_root: PathBuf = metadata.workspace_root.into();
let cargo_ziggy = metadata.target_directory.join("debug/cargo-ziggy");
let fuzzer_directory = workspace_root.join("examples/url");

// cargo ziggy build
let build_status = process::Command::new(&cargo_ziggy)
.arg("ziggy")
.arg("build")
.env("CARGO_TARGET_DIR", &target_dir)
.current_dir(&fuzzer_directory)
.status()
.expect("failed to run `cargo ziggy build`");
assert!(build_status.success(), "`cargo ziggy build` failed");

// cargo ziggy fuzz -j 2 -t 5 -o temp_dir
let mut fuzzer = process::Command::new(&cargo_ziggy)
.arg("ziggy")
.arg("fuzz")
.arg("-j2")
.arg("-t5")
.arg("-G100")
.arg("--coverage-worker")
.arg("--coverage-interval=0")
.arg("--corpus-sync-interval=0")
.env("CARGO_TARGET_DIR", &target_dir)
.env("ZIGGY_OUTPUT", output_dir)
.env("AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES", "1")
.env("AFL_SKIP_CPUFREQ", "1")
.current_dir(&fuzzer_directory)
.spawn()
.expect("failed to run `cargo ziggy fuzz`");
thread::sleep(Duration::from_secs(30));
assert!(matches!(fuzzer.try_wait(), Ok(None)));
kill_subprocesses_recursively(&format!("{}", fuzzer.id()));
}