Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsNo conflicts as of last run. |
f0bf343 to
87ecdf2
Compare
|
tACK 87ecdf2 Ran both versions on qa-assets with the coverage build left over from my #35809 review with par=4. |
maflcko
left a comment
There was a problem hiding this comment.
lgtm, left a nit to slim this down a bit
| let profdata_base = run_profile('a', &corpus_dir, 0)?; | ||
| let profdata_repeat = run_profile('b', &corpus_dir, 0)?; | ||
| if !profdata_eq(&profdata_base, &profdata_repeat)? { | ||
| let cov_txt_base = render_cov(&profdata_base, 'a', 0)?; | ||
| let cov_txt_repeat = render_cov(&profdata_repeat, 'b', 0)?; |
There was a problem hiding this comment.
Nit: There's now a lot of 'a' and 'b'. Maybe check_diff can just accept the &Path and then do everything itself. This would de-dupl a bunch of code. Something like this (untested):
contrib/devtools/deterministic-fuzz-coverage/src/main.rs | 48 +++++++++++++++++++++---------------------------
1 file changed, 21 insertions(+), 27 deletions(-)
diff --git a/contrib/devtools/deterministic-fuzz-coverage/src/main.rs b/contrib/devtools/deterministic-fuzz-coverage/src/main.rs
index d536cf1..5859d7e 100644
--- a/contrib/devtools/deterministic-fuzz-coverage/src/main.rs
+++ b/contrib/devtools/deterministic-fuzz-coverage/src/main.rs
@@ -216,7 +216,18 @@ fn deterministic_coverage(
};
- let check_diff = |a: &Path, b: &Path, err: &str| -> AppResult {
+ let check_diff = |entry: &Path, thread_id: usize, err: &str| -> AppResult {
+ let profdata_base = run_profile('a', entry, thread_id)?;
+ let profdata_repeat = run_profile('b', entry, thread_id)?;
+ // Fast path: identical counters mean the coverage is deterministic, so
+ // skip the expensive llvm-cov rendering entirely.
+ if profdata_eq(&profdata_base, &profdata_repeat)? {
+ return Ok(());
+ }
+ // Slow path: the profiles differ, so render both into human-readable
+ // reports and diff them to confirm and locate the difference.
+ let cov_txt_base = render_cov(&profdata_base, 'a', thread_id)?;
+ let cov_txt_repeat = render_cov(&profdata_repeat, 'b', thread_id)?;
let same = Command::new(GIT)
.args(["--no-pager", "diff", "--no-index"])
- .arg(a)
- .arg(b)
+ .arg(&cov_txt_base)
+ .arg(&cov_txt_repeat)
.status()
@@ -249,16 +260,5 @@ The coverage was not deterministic between runs.
}
- let profdata_base = run_profile('a', &entry, thread_id)?;
- let profdata_repeat = run_profile('b', &entry, thread_id)?;
- // Fast path: identical counters mean the coverage is deterministic, so
- // skip the expensive llvm-cov rendering entirely.
- if profdata_eq(&profdata_base, &profdata_repeat)? {
- return Ok(());
- }
- // Slow path: the profiles differ, so render both into human-readable
- // reports and diff them to confirm and locate the difference.
- let cov_txt_base = render_cov(&profdata_base, 'a', thread_id)?;
- let cov_txt_repeat = render_cov(&profdata_repeat, 'b', thread_id)?;
check_diff(
- &cov_txt_base,
- &cov_txt_repeat,
+ &entry,
+ thread_id,
&format!("The fuzz target input was {}.", entry.display()),
@@ -297,13 +297,7 @@ The coverage was not deterministic between runs.
}
- let profdata_base = run_profile('a', &corpus_dir, 0)?;
- let profdata_repeat = run_profile('b', &corpus_dir, 0)?;
- if !profdata_eq(&profdata_base, &profdata_repeat)? {
- let cov_txt_base = render_cov(&profdata_base, 'a', 0)?;
- let cov_txt_repeat = render_cov(&profdata_repeat, 'b', 0)?;
- check_diff(
- &cov_txt_base,
- &cov_txt_repeat,
- &format!("All fuzz inputs in {} were used.", corpus_dir.display()),
- )?;
- }
+ check_diff(
+ &corpus_dir,
+ 0,
+ &format!("All fuzz inputs in {} were used.", corpus_dir.display()),
+ )?;
}Possibly could also inline profdata_eq and only keep a small comment as it is only called once, to save some more lines?
There was a problem hiding this comment.
Small nit: A build with -fprofile-instr-generate but no -fcoverage-mapping now prints Coverage test passed where master dies with llvm-cov show failed. Determinism is still checked either way, only the broken build slips by. Under your version, worth one run_profile and render_cov before the loop?
There was a problem hiding this comment.
This is a dev-only script. If there is a "broken build" (because the dev ignored the docs), I think it is fine to not hold their hands with extra logic here. If needed, the error message can be adjusted, but other than that, I'd say the logic shouldn't be modified.
There was a problem hiding this comment.
Updated, thanks. Kept the profdata_eq, since I feel it is very good for beginners (like me) to understand the code logic.
87ecdf2 to
c237c9f
Compare
There was a problem hiding this comment.
nit: Needs rebase anyway, and while touching this, could make it a proper named arg in a new commit:
diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md
index 2fb3ba1..35d749d 100644
--- a/contrib/devtools/README.md
+++ b/contrib/devtools/README.md
@@ -25 +25 @@ before running the tool:
-cargo run --manifest-path ./contrib/devtools/deterministic-fuzz-coverage/Cargo.toml -- $PWD/build_dir $PWD/qa-assets/fuzz_corpora fuzz_target_name [parallelism] [--mode=<both|single|combined>]
+cargo run --manifest-path ./contrib/devtools/deterministic-fuzz-coverage/Cargo.toml -- $PWD/build_dir $PWD/qa-assets/fuzz_corpora fuzz_target_name [--parallelism=<parallelism>] [--mode=<both|single|combined>]
diff --git a/contrib/devtools/deterministic-fuzz-coverage/src/main.rs b/contrib/devtools/deterministic-fuzz-coverage/src/main.rs
index 9d06364..5685334 100644
--- a/contrib/devtools/deterministic-fuzz-coverage/src/main.rs
+++ b/contrib/devtools/deterministic-fuzz-coverage/src/main.rs
@@ -28 +28 @@ Error: {err}
-Usage: program ./build_dir ./qa-assets/fuzz_corpora fuzz_target_name [parallelism={DEFAULT_PAR}] [--mode=both]
+Usage: program ./build_dir ./qa-assets/fuzz_corpora fuzz_target_name [--parallelism={DEFAULT_PAR}] [--mode=both]
@@ -75,7 +75 @@ fn app() -> AppResult {
- let par = match args.get(4) {
- Some(s) => s
- .parse::<usize>()
- .map_err(|e| exit_help(&format!("Could not parse parallelism as usize ({s}): {e}")))?,
- None => DEFAULT_PAR,
- }
- .max(1);
+ let mut par = DEFAULT_PAR;
@@ -85,2 +79,11 @@ fn app() -> AppResult {
- for arg in args.iter().skip(5) {
- if let Some(value) = arg.strip_prefix("--mode=") {
+ for arg in args.iter().skip(4) {
+ if let Some(value) = arg.strip_prefix("--parallelism=") {
+ par = value
+ .parse::<usize>()
+ .map_err(|e| {
+ exit_help(&format!(
+ "Could not parse parallelism as usize ({value}): {e}"
+ ))
+ })?
+ .max(1);
+ } else if let Some(value) = arg.strip_prefix("--mode=") {|
@HowHsu are you still working on this? |
deterministic-fuzz-coverage rendered a full `llvm-cov show` report for every input on both runs and diffed the two reports. `llvm-cov show` is by far the most expensive step, so almost all of that work produced two identical reports that were immediately thrown away. Compare the merged profdata first instead: identical counters are a sufficient condition for deterministic coverage, so when the two profdata files match we skip rendering entirely. Only when they differ do we fall back to rendering and diffing the `llvm-cov show` reports to render and locate the difference. Co-authored-by: maflcko <[email protected]>
c237c9f to
02275f6
Compare
Sorry for delay, it's updated. |

Summary
deterministic-fuzz-coveragerendered a fullllvm-cov showreport for everyfuzz input on both runs and diffed the two reports, even though almost all
inputs are deterministic.
llvm-cov showis by far the most expensive step, sothe vast majority of that work produced two identical reports that were
immediately discarded.
Compare the merged
.profdatafirst: identical counters are a sufficientcondition for deterministic coverage, so when the two profdata files match the
llvm-cov showrendering is skipped entirely. Only when they differ does itfall back to rendering and diffing the reports to confirm and locate the
difference.
The pass/fail result is unchanged: identical profdata implies identical
counters, which implies identical
llvm-cov showoutput (the report is adeterministic function of the profdata and the binary). Any profdata difference
falls back to the exact same
llvm-covdiff as before.Benchmark
standalone coverage build (
-DBUILD_FOR_FUZZING=ON+-fprofile-instr-generate -fcoverage-mapping, no sanitizer), par=4,qa-assets corpora:
On
process_messageevery input is deterministic, so all 2386 take theprofdata fast path and zero
llvm-cov showreports are rendered, down from2*2386 + 2 = 4774.