fix(migtd): fix code coverage collection for fuzzing tests#839
Merged
Conversation
jyao1
approved these changes
May 21, 2026
Contributor
|
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>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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