From 39d2ebb467ca704ce807806dbe6ed315fa5ddb9e Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Fri, 14 Feb 2025 18:32:02 +0100 Subject: [PATCH] fuzzing.yml: Start producing code coverage report --- .github/workflows/fuzzing.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml index 0902eac7..e44b3df4 100644 --- a/.github/workflows/fuzzing.yml +++ b/.github/workflows/fuzzing.yml @@ -87,7 +87,7 @@ jobs: # Tune compilation of fuzzers to use Clang with ASan and UBSan -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - -DCMAKE_{C,CXX}_FLAGS='-Wall -Wextra -pedantic -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common' + -DCMAKE_{C,CXX}_FLAGS='-Wall -Wextra -pedantic -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common -fprofile-instr-generate -fcoverage-mapping' -DCMAKE_{EXE,MODULE,SHARED}_LINKER_FLAGS='-g -fsanitize=address,undefined' -DEXPAT_WARNINGS_AS_ERRORS=ON ) @@ -119,6 +119,9 @@ jobs: set -x -o pipefail cd expat/build/ + mkdir coverage/ + export LLVM_PROFILE_FILE=coverage/expat-%p.profraw + # vvvvv find corpus_UTF-8/ -type f | sort | xargs \ fuzz/xml_parse_fuzzer_UTF-8 "${fuzz_args[@]}" @@ -134,3 +137,25 @@ jobs: name: expat_fuzzing_logs_${{ github.sha }} path: expat/build/fuzz-*.log if-no-files-found: error + + - name: Render coverage report + run: | + fuzzer=xml_parse_fuzzer_UTF-8 # could be any of them + + set -x -o pipefail + cd expat/build/ + + # Merged and convert to a single indexed profile data file + llvm-profdata merge -sparse -o coverage/expat.profdata coverage/expat-*.profraw + + # Render report + llvm-cov show fuzz/${fuzzer} -instr-profile=coverage/expat.profdata -show-branches=count -format=html -output-dir=coverage/html/ + llvm-cov report fuzz/${fuzzer} -instr-profile=coverage/expat.profdata -show-functions -sources ../lib/ | tee coverage/report_functions.txt + llvm-cov report fuzz/${fuzzer} -instr-profile=coverage/expat.profdata -sources ../lib/ | tee coverage/report_files.txt + + - name: Store coverage report + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0 + with: + name: expat_fuzzing_coverage_${{ github.sha }} + path: expat/build/coverage/ + if-no-files-found: error