Skip to content

Commit b06f6c5

Browse files
committed
Upload CI generated fuzz corpus coverage to codecov
Because each CI job runs on a fresh runner and can't share data between jobs. We rely on Github Actions upload-artifact and download-artifact to share the CI generated fuzz corpus, then replay them in the `contrib/generate_fuzz_coverage.sh` script to generate the coverage report.
1 parent c1bca16 commit b06f6c5

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jobs:
110110
run: CI_ENV=1 CI_MINIMIZE_DISK_USAGE=1 ./ci/ci-tx-sync-tests.sh
111111

112112
coverage:
113+
needs: fuzz
113114
strategy:
114115
fail-fast: false
115116
runs-on: self-hosted
@@ -133,6 +134,11 @@ jobs:
133134
# Maybe if codecov wasn't broken we wouldn't need to do this...
134135
./codecov --verbose upload-process --disable-search --fail-on-error -f target/codecov.json -t "f421b687-4dc2-4387-ac3d-dc3b2528af57" -F 'tests'
135136
cargo clean
137+
- name: Download honggfuzz corpus
138+
uses: actions/download-artifact@v4
139+
with:
140+
name: hfuzz-corpus
141+
path: fuzz/hfuzz_workspace
136142
- name: Run fuzz coverage generation
137143
run: |
138144
./contrib/generate_fuzz_coverage.sh --output-dir `pwd` --output-codecov-json
@@ -268,6 +274,11 @@ jobs:
268274
cargo clean
269275
- name: Run fuzzers
270276
run: cd fuzz && ./ci-fuzz.sh && cd ..
277+
- name: Upload honggfuzz corpus
278+
uses: actions/upload-artifact@v4
279+
with:
280+
name: hfuzz-corpus
281+
path: fuzz/hfuzz_workspace
271282

272283
linting:
273284
runs-on: ubuntu-latest

contrib/generate_fuzz_coverage.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,26 @@ if [ "$OUTPUT_CODECOV_JSON" = "0" ]; then
6262
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"
6363
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
6464
else
65-
cargo llvm-cov -j8 --codecov --ignore-filename-regex "fuzz/" --output-path "$OUTPUT_DIR/fuzz-codecov.json"
66-
echo "Fuzz codecov report available at $OUTPUT_DIR/fuzz-codecov.json"
67-
fi
65+
# Clean previous coverage artifacts to ensure a fresh run.
66+
cargo llvm-cov clean --workspace
6867

68+
# Import honggfuzz corpus if the artifact was downloaded.
69+
if [ -d "hfuzz_workspace" ]; then
70+
echo "Importing corpus from hfuzz_workspace..."
71+
for target_dir in hfuzz_workspace/*; do
72+
[ -d "$target_dir" ] || continue
73+
src_name="$(basename "$target_dir")"
74+
dest="${src_name%_target}"
75+
mkdir -p "test_cases/$dest"
76+
# Copy corpus files into the test_cases directory
77+
find "$target_dir" -maxdepth 2 -type f -path "$target_dir/input/*" \
78+
-print0 | xargs -0 -I{} cp -n {} "test_cases/$dest/"
79+
done
80+
fi
6981

82+
echo "Replaying imported corpus (if found) via tests to generate coverage..."
83+
cargo llvm-cov -j8 --codecov --ignore-filename-regex "fuzz/" \
84+
--output-path "$OUTPUT_DIR/fuzz-codecov.json" --tests
7085

86+
echo "Fuzz codecov report available at $OUTPUT_DIR/fuzz-codecov.json"
87+
fi

0 commit comments

Comments
 (0)