diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 24363c8f39c..6ef84e7af58 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -22,7 +22,7 @@ repository must have been cloned. Finally, a fuzz target has to be picked before running the tool: ``` -RUST_BACKTRACE=1 cargo run --manifest-path ./contrib/devtools/deterministic-fuzz-coverage/Cargo.toml -- $PWD/build_dir $PWD/qa-assets/corpora-dir fuzz_target_name +RUST_BACKTRACE=1 cargo run --manifest-path ./contrib/devtools/deterministic-fuzz-coverage/Cargo.toml -- $PWD/build_dir $PWD/qa-assets/fuzz_corpora fuzz_target_name ``` clang-format-diff.py diff --git a/contrib/devtools/deterministic-fuzz-coverage/Cargo.lock b/contrib/devtools/deterministic-fuzz-coverage/Cargo.lock new file mode 100644 index 00000000000..319e7bfa6de --- /dev/null +++ b/contrib/devtools/deterministic-fuzz-coverage/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "deterministic-fuzz-coverage" +version = "0.1.0" diff --git a/contrib/devtools/deterministic-fuzz-coverage/src/main.rs b/contrib/devtools/deterministic-fuzz-coverage/src/main.rs index adf6333324b..3e2d0ec4a60 100644 --- a/contrib/devtools/deterministic-fuzz-coverage/src/main.rs +++ b/contrib/devtools/deterministic-fuzz-coverage/src/main.rs @@ -5,25 +5,25 @@ use std::env; use std::fs::{read_dir, File}; use std::path::Path; -use std::process::{exit, Command, Stdio}; +use std::process::{exit, Command}; use std::str; const LLVM_PROFDATA: &str = "llvm-profdata"; const LLVM_COV: &str = "llvm-cov"; -const DIFF: &str = "diff"; +const GIT: &str = "git"; fn exit_help(err: &str) -> ! { eprintln!("Error: {}", err); eprintln!(); - eprintln!("Usage: program ./build_dir ./qa-assets-corpora-dir fuzz_target"); + eprintln!("Usage: program ./build_dir ./qa-assets/fuzz_corpora fuzz_target_name"); eprintln!(); eprintln!("Refer to the devtools/README.md for more details."); exit(1) } fn sanity_check(corpora_dir: &Path, fuzz_exe: &Path) { - for tool in [LLVM_PROFDATA, LLVM_COV, DIFF] { - let output = Command::new(tool).arg("--version").output(); + for tool in [LLVM_PROFDATA, LLVM_COV, GIT] { + let output = Command::new(tool).arg("--help").output(); match output { Ok(output) if output.status.success() => {} _ => { @@ -135,7 +135,7 @@ fn deterministic_coverage( .expect("merge failed") .success()); let cov_file = File::create(&cov_txt_path).expect("Failed to create coverage txt file"); - let passed = Command::new(LLVM_COV) + assert!(Command::new(LLVM_COV) .args([ "show", "--show-line-counts-or-regions", @@ -144,34 +144,31 @@ fn deterministic_coverage( &format!("--instr-profile={}", profdata_file.display()), ]) .arg(fuzz_exe) - .stdout(Stdio::from(cov_file)) + .stdout(cov_file) .spawn() .expect("Failed to execute llvm-cov") .wait() .expect("Failed to execute llvm-cov") - .success(); - if !passed { - panic!("Failed to execute llvm-profdata") - } + .success()); cov_txt_path }; let check_diff = |a: &Path, b: &Path, err: &str| { - let same = Command::new(DIFF) - .arg("--unified") + let same = Command::new(GIT) + .args(["--no-pager", "diff", "--no-index"]) .arg(a) .arg(b) .status() - .expect("Failed to execute diff command") + .expect("Failed to execute git command") .success(); if !same { eprintln!(); - eprintln!("The coverage was not determinstic between runs."); + eprintln!("The coverage was not deterministic between runs."); eprintln!("{}", err); eprintln!("Exiting."); exit(1); } }; - // First, check that each fuzz input is determinisic running by itself in a process. + // First, check that each fuzz input is deterministic running by itself in a process. // // This can catch issues and isolate where a single fuzz input triggers non-determinism, but // all other fuzz inputs are deterministic.