Skip to content

Commit fa3940b

Browse files
author
MarcoFalke
committed
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.
1 parent faf905b commit fa3940b

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

contrib/devtools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repository must have been cloned. Finally, a fuzz target has to be picked
2222
before running the tool:
2323

2424
```
25-
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
25+
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
2626
```
2727

2828
clang-format-diff.py

contrib/devtools/deterministic-fuzz-coverage/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/devtools/deterministic-fuzz-coverage/src/main.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
use std::env;
66
use std::fs::{read_dir, File};
77
use std::path::Path;
8-
use std::process::{exit, Command, Stdio};
8+
use std::process::{exit, Command};
99
use std::str;
1010

1111
const LLVM_PROFDATA: &str = "llvm-profdata";
1212
const LLVM_COV: &str = "llvm-cov";
13-
const DIFF: &str = "diff";
13+
const GIT: &str = "git";
1414

1515
fn exit_help(err: &str) -> ! {
1616
eprintln!("Error: {}", err);
1717
eprintln!();
18-
eprintln!("Usage: program ./build_dir ./qa-assets-corpora-dir fuzz_target");
18+
eprintln!("Usage: program ./build_dir ./qa-assets/fuzz_corpora fuzz_target_name");
1919
eprintln!();
2020
eprintln!("Refer to the devtools/README.md for more details.");
2121
exit(1)
2222
}
2323

2424
fn sanity_check(corpora_dir: &Path, fuzz_exe: &Path) {
25-
for tool in [LLVM_PROFDATA, LLVM_COV, DIFF] {
26-
let output = Command::new(tool).arg("--version").output();
25+
for tool in [LLVM_PROFDATA, LLVM_COV, GIT] {
26+
let output = Command::new(tool).arg("--help").output();
2727
match output {
2828
Ok(output) if output.status.success() => {}
2929
_ => {
@@ -135,7 +135,7 @@ fn deterministic_coverage(
135135
.expect("merge failed")
136136
.success());
137137
let cov_file = File::create(&cov_txt_path).expect("Failed to create coverage txt file");
138-
let passed = Command::new(LLVM_COV)
138+
assert!(Command::new(LLVM_COV)
139139
.args([
140140
"show",
141141
"--show-line-counts-or-regions",
@@ -144,34 +144,31 @@ fn deterministic_coverage(
144144
&format!("--instr-profile={}", profdata_file.display()),
145145
])
146146
.arg(fuzz_exe)
147-
.stdout(Stdio::from(cov_file))
147+
.stdout(cov_file)
148148
.spawn()
149149
.expect("Failed to execute llvm-cov")
150150
.wait()
151151
.expect("Failed to execute llvm-cov")
152-
.success();
153-
if !passed {
154-
panic!("Failed to execute llvm-profdata")
155-
}
152+
.success());
156153
cov_txt_path
157154
};
158155
let check_diff = |a: &Path, b: &Path, err: &str| {
159-
let same = Command::new(DIFF)
160-
.arg("--unified")
156+
let same = Command::new(GIT)
157+
.args(["--no-pager", "diff", "--no-index"])
161158
.arg(a)
162159
.arg(b)
163160
.status()
164-
.expect("Failed to execute diff command")
161+
.expect("Failed to execute git command")
165162
.success();
166163
if !same {
167164
eprintln!();
168-
eprintln!("The coverage was not determinstic between runs.");
165+
eprintln!("The coverage was not deterministic between runs.");
169166
eprintln!("{}", err);
170167
eprintln!("Exiting.");
171168
exit(1);
172169
}
173170
};
174-
// First, check that each fuzz input is determinisic running by itself in a process.
171+
// First, check that each fuzz input is deterministic running by itself in a process.
175172
//
176173
// This can catch issues and isolate where a single fuzz input triggers non-determinism, but
177174
// all other fuzz inputs are deterministic.

0 commit comments

Comments
 (0)