Skip to content

fix(migtd): fix code coverage collection for fuzzing tests#839

Merged
sgrams merged 1 commit into
intel:mainfrom
MichalTarnacki:issue463
May 21, 2026
Merged

fix(migtd): fix code coverage collection for fuzzing tests#839
sgrams merged 1 commit into
intel:mainfrom
MichalTarnacki:issue463

Conversation

@MichalTarnacki
Copy link
Copy Markdown
Contributor

Coverage collection via the -c flag was broken due to multiple issues:

  • AFL: RUSTFLAGS="-C instrument-coverage" was applied during cargo afl build/fuzz, conflicting with AFL's own instrumentation and fork server. Coverage profraw files were either corrupt or missing. Fix by building a separate non-AFL instrumented binary (without --features fuzz) after fuzzing, and replaying the AFL queue through it to generate valid coverage data.

  • AFL: grcov searched from "." which could pick up stale profdata files from other runs. Fix by writing profraw to a dedicated cov_profraw/ directory and pointing grcov only there.

  • AFL: the queue replay glob (queue/*) included the .state directory, causing panics. Fix by using find -type f to iterate only regular files.

  • Libfuzzer: grcov --binary-path pointed to fuzz/target/x86_64-unknown-linux-gnu/release/ (a file) but should be the release/ directory. Additionally, grcov searched from "." picking up incompatible profdata. Fix by pointing grcov to the specific fuzz/coverage//raw directory where cargo fuzz coverage writes profraw files.

  • Libfuzzer run_all_case: inverted conditional (if [ ! -d ... ]) meant the old coverage directory was never cleaned up. Fix the logic.

Fixes #463

@jyao1
Copy link
Copy Markdown
Contributor

jyao1 commented May 21, 2026

what is current coverage data?

Coverage collection via the -c flag was broken due to multiple issues:

- AFL: RUSTFLAGS="-C instrument-coverage" was applied during cargo afl
  build/fuzz, conflicting with AFL's own instrumentation and fork
  server. Coverage profraw files were either corrupt or missing. Fix by
  building a separate non-AFL instrumented binary (without --features
  fuzz) after fuzzing, and replaying the AFL queue through it to
  generate valid coverage data.

- AFL: grcov searched from "." which could pick up stale profdata files
  from other runs. Fix by writing profraw to a dedicated cov_profraw/
  directory and pointing grcov only there.

- AFL: the queue replay glob (queue/*) included the .state directory,
  causing panics. Fix by using find -type f to iterate only regular
  files.

- Libfuzzer: grcov --binary-path pointed to
  fuzz/target/x86_64-unknown-linux-gnu/release/<target> (a file) but
  should be the release/ directory. Additionally, grcov searched from
  "." picking up incompatible profdata. Fix by pointing grcov to the
  specific fuzz/coverage/<target>/raw directory where cargo fuzz
  coverage writes profraw files.

- Libfuzzer run_all_case: inverted conditional (if [ ! -d ... ]) meant
  the old coverage directory was never cleaned up. Fix the logic.

Signed-off-by: Michal Tarnacki <michal.tarnacki@intel.com>
Co-authored-by: GitHub Copilot <noreply@github.com>
@MichalTarnacki
Copy link
Copy Markdown
Contributor Author

image

@sgrams sgrams merged commit c30bf72 into intel:main May 21, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code coverage collection for fuzzing test is not workable

3 participants