Skip to content

Commit fa900bb

Browse files
MarcoFalkehodlinator
andcommitted
contrib: Only print fuzz output on failure
This makes it humanly possible to track progress as only "[N/M]"-lines are printed as long as we succeed. Also, use char (a, b) to indicate run_id instead of u8 (0, 1). Also, use emojis to indicate final success or error. Co-Authored-By: Hodlinator <[email protected]>
1 parent fa82fe2 commit fa900bb

File tree

2 files changed

+26
-22
lines changed
  • contrib/devtools
    • deterministic-fuzz-coverage/src
    • deterministic-unittest-coverage/src

2 files changed

+26
-22
lines changed

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ fn deterministic_coverage(
120120
.map(|entry| entry.expect("IO error"))
121121
.collect::<Vec<_>>();
122122
entries.sort_by_key(|entry| entry.file_name());
123-
let run_single = |run_id: u8, entry: &Path, thread_id: usize| -> Result<PathBuf, AppError> {
124-
let cov_txt_path = build_dir.join(format!("fuzz_det_cov.show.t{thread_id}.r{run_id}.txt"));
125-
let profraw_file = build_dir.join(format!("fuzz_det_cov.t{thread_id}.r{run_id}.profraw"));
126-
let profdata_file = build_dir.join(format!("fuzz_det_cov.t{thread_id}.r{run_id}.profdata"));
127-
if !{
128-
{
123+
let run_single = |run_id: char, entry: &Path, thread_id: usize| -> Result<PathBuf, AppError> {
124+
let cov_txt_path = build_dir.join(format!("fuzz_det_cov.show.t{thread_id}.{run_id}.txt"));
125+
let profraw_file = build_dir.join(format!("fuzz_det_cov.t{thread_id}.{run_id}.profraw"));
126+
let profdata_file = build_dir.join(format!("fuzz_det_cov.t{thread_id}.{run_id}.profdata"));
127+
{
128+
let output = {
129129
let mut cmd = Command::new(fuzz_exe);
130130
if using_libfuzzer {
131131
cmd.arg("-runs=1");
@@ -135,11 +135,15 @@ fn deterministic_coverage(
135135
.env("LLVM_PROFILE_FILE", &profraw_file)
136136
.env("FUZZ", fuzz_target)
137137
.arg(entry)
138-
.status()
139-
.map_err(|e| format!("fuzz failed with {e}"))?
140-
.success()
141-
} {
142-
Err("fuzz failed".to_string())?;
138+
.output()
139+
.map_err(|e| format!("fuzz failed: {e}"))?;
140+
if !output.status.success() {
141+
Err(format!(
142+
"fuzz failed!\nstdout:\n{}\nstderr:\n{}\n",
143+
String::from_utf8_lossy(&output.stdout),
144+
String::from_utf8_lossy(&output.stderr)
145+
))?;
146+
}
143147
}
144148
if !Command::new(LLVM_PROFDATA)
145149
.arg("merge")
@@ -210,8 +214,8 @@ The coverage was not deterministic between runs.
210214
if !entry.is_file() {
211215
Err(format!("{} should be a file", entry.display()))?;
212216
}
213-
let cov_txt_base = run_single(0, &entry, thread_id)?;
214-
let cov_txt_repeat = run_single(1, &entry, thread_id)?;
217+
let cov_txt_base = run_single('a', &entry, thread_id)?;
218+
let cov_txt_repeat = run_single('b', &entry, thread_id)?;
215219
check_diff(
216220
&cov_txt_base,
217221
&cov_txt_repeat,
@@ -249,23 +253,23 @@ The coverage was not deterministic between runs.
249253
if !corpus_dir.is_dir() {
250254
Err(format!("{} should be a folder", corpus_dir.display()))?;
251255
}
252-
let cov_txt_base = run_single(0, &corpus_dir, 0)?;
253-
let cov_txt_repeat = run_single(1, &corpus_dir, 0)?;
256+
let cov_txt_base = run_single('a', &corpus_dir, 0)?;
257+
let cov_txt_repeat = run_single('b', &corpus_dir, 0)?;
254258
check_diff(
255259
&cov_txt_base,
256260
&cov_txt_repeat,
257261
&format!("All fuzz inputs in {} were used.", corpus_dir.display()),
258262
)?;
259263
}
260-
println!("Coverage test passed for {fuzz_target}.");
264+
println!("Coverage test passed for {fuzz_target}.");
261265
Ok(())
262266
}
263267

264268
fn main() -> ExitCode {
265269
match app() {
266270
Ok(()) => ExitCode::SUCCESS,
267271
Err(err) => {
268-
eprintln!("{}", err);
272+
eprintln!("⚠️\n{}", err);
269273
ExitCode::FAILURE
270274
}
271275
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn app() -> AppResult {
7171
fn deterministic_coverage(build_dir: &Path, test_exe: &Path, filter: &str) -> AppResult {
7272
let profraw_file = build_dir.join("test_det_cov.profraw");
7373
let profdata_file = build_dir.join("test_det_cov.profdata");
74-
let run_single = |run_id: u8| -> Result<PathBuf, AppError> {
74+
let run_single = |run_id: char| -> Result<PathBuf, AppError> {
7575
println!("Run with id {run_id}");
7676
let cov_txt_path = build_dir.join(format!("test_det_cov.show.{run_id}.txt"));
7777
if !Command::new(test_exe)
@@ -131,18 +131,18 @@ fn deterministic_coverage(build_dir: &Path, test_exe: &Path, filter: &str) -> Ap
131131
}
132132
Ok(())
133133
};
134-
let r0 = run_single(0)?;
135-
let r1 = run_single(1)?;
134+
let r0 = run_single('a')?;
135+
let r1 = run_single('b')?;
136136
check_diff(&r0, &r1)?;
137-
println!("The coverage was deterministic across two runs.");
137+
println!("The coverage was deterministic across two runs.");
138138
Ok(())
139139
}
140140

141141
fn main() -> ExitCode {
142142
match app() {
143143
Ok(()) => ExitCode::SUCCESS,
144144
Err(err) => {
145-
eprintln!("{}", err);
145+
eprintln!("⚠️\n{}", err);
146146
ExitCode::FAILURE
147147
}
148148
}

0 commit comments

Comments
 (0)