mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
contrib: deterministic-fuzz-coverage fixups
* Name the fuzz_corpora dir after its real name. * Add missing cargo lock file. * Use git instead of diff command to increase compatibility * Use --help instead of --version to increase compatibility * Use assert consistently for unexpected errors. * Remove redundant Stdio::from. * Fix typos.
This commit is contained in:
parent
faf905b9b6
commit
fa3940b1cb
3 changed files with 21 additions and 17 deletions
|
@ -22,7 +22,7 @@ repository must have been cloned. Finally, a fuzz target has to be picked
|
||||||
before running the tool:
|
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
|
clang-format-diff.py
|
||||||
|
|
7
contrib/devtools/deterministic-fuzz-coverage/Cargo.lock
generated
Normal file
7
contrib/devtools/deterministic-fuzz-coverage/Cargo.lock
generated
Normal file
|
@ -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"
|
|
@ -5,25 +5,25 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{read_dir, File};
|
use std::fs::{read_dir, File};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::{exit, Command, Stdio};
|
use std::process::{exit, Command};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
const LLVM_PROFDATA: &str = "llvm-profdata";
|
const LLVM_PROFDATA: &str = "llvm-profdata";
|
||||||
const LLVM_COV: &str = "llvm-cov";
|
const LLVM_COV: &str = "llvm-cov";
|
||||||
const DIFF: &str = "diff";
|
const GIT: &str = "git";
|
||||||
|
|
||||||
fn exit_help(err: &str) -> ! {
|
fn exit_help(err: &str) -> ! {
|
||||||
eprintln!("Error: {}", err);
|
eprintln!("Error: {}", err);
|
||||||
eprintln!();
|
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!();
|
||||||
eprintln!("Refer to the devtools/README.md for more details.");
|
eprintln!("Refer to the devtools/README.md for more details.");
|
||||||
exit(1)
|
exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sanity_check(corpora_dir: &Path, fuzz_exe: &Path) {
|
fn sanity_check(corpora_dir: &Path, fuzz_exe: &Path) {
|
||||||
for tool in [LLVM_PROFDATA, LLVM_COV, DIFF] {
|
for tool in [LLVM_PROFDATA, LLVM_COV, GIT] {
|
||||||
let output = Command::new(tool).arg("--version").output();
|
let output = Command::new(tool).arg("--help").output();
|
||||||
match output {
|
match output {
|
||||||
Ok(output) if output.status.success() => {}
|
Ok(output) if output.status.success() => {}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -135,7 +135,7 @@ fn deterministic_coverage(
|
||||||
.expect("merge failed")
|
.expect("merge failed")
|
||||||
.success());
|
.success());
|
||||||
let cov_file = File::create(&cov_txt_path).expect("Failed to create coverage txt file");
|
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([
|
.args([
|
||||||
"show",
|
"show",
|
||||||
"--show-line-counts-or-regions",
|
"--show-line-counts-or-regions",
|
||||||
|
@ -144,34 +144,31 @@ fn deterministic_coverage(
|
||||||
&format!("--instr-profile={}", profdata_file.display()),
|
&format!("--instr-profile={}", profdata_file.display()),
|
||||||
])
|
])
|
||||||
.arg(fuzz_exe)
|
.arg(fuzz_exe)
|
||||||
.stdout(Stdio::from(cov_file))
|
.stdout(cov_file)
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Failed to execute llvm-cov")
|
.expect("Failed to execute llvm-cov")
|
||||||
.wait()
|
.wait()
|
||||||
.expect("Failed to execute llvm-cov")
|
.expect("Failed to execute llvm-cov")
|
||||||
.success();
|
.success());
|
||||||
if !passed {
|
|
||||||
panic!("Failed to execute llvm-profdata")
|
|
||||||
}
|
|
||||||
cov_txt_path
|
cov_txt_path
|
||||||
};
|
};
|
||||||
let check_diff = |a: &Path, b: &Path, err: &str| {
|
let check_diff = |a: &Path, b: &Path, err: &str| {
|
||||||
let same = Command::new(DIFF)
|
let same = Command::new(GIT)
|
||||||
.arg("--unified")
|
.args(["--no-pager", "diff", "--no-index"])
|
||||||
.arg(a)
|
.arg(a)
|
||||||
.arg(b)
|
.arg(b)
|
||||||
.status()
|
.status()
|
||||||
.expect("Failed to execute diff command")
|
.expect("Failed to execute git command")
|
||||||
.success();
|
.success();
|
||||||
if !same {
|
if !same {
|
||||||
eprintln!();
|
eprintln!();
|
||||||
eprintln!("The coverage was not determinstic between runs.");
|
eprintln!("The coverage was not deterministic between runs.");
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
eprintln!("Exiting.");
|
eprintln!("Exiting.");
|
||||||
exit(1);
|
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
|
// This can catch issues and isolate where a single fuzz input triggers non-determinism, but
|
||||||
// all other fuzz inputs are deterministic.
|
// all other fuzz inputs are deterministic.
|
||||||
|
|
Loading…
Add table
Reference in a new issue