Merge bitcoin/bitcoin#32206: doc: Add fuzz based coverage report generation
Some checks are pending
CI / test each commit (push) Waiting to run
CI / macOS 14 native, arm64, no depends, sqlite only, gui (push) Waiting to run
CI / macOS 14 native, arm64, fuzz (push) Waiting to run
CI / Windows native, VS 2022 (push) Waiting to run
CI / Windows native, fuzz, VS 2022 (push) Waiting to run
CI / Linux->Windows cross, no tests (push) Waiting to run
CI / Windows, test cross-built (push) Blocked by required conditions
CI / ASan + LSan + UBSan + integer, no depends, USDT (push) Waiting to run

7677fde4c7 Add fuzz test coverage report generation (Prabhat Verma)

Pull request description:

  Followup from [comment 1 31933](https://github.com/bitcoin/bitcoin/pull/31933#pullrequestreview-2685168897) and [comment 2 31933](https://github.com/bitcoin/bitcoin/pull/31933#pullrequestreview-2683653107) , have added the instructions to generate coverage report for fuzz tests.

ACKs for top commit:
  maflcko:
    lgtm ACK 7677fde4c7
  mabu44:
    Tested ACK 7677fde4c7

Tree-SHA512: b4883ec41e272443fc9fc97dce3fb0f05871ce5ddc07d97f4cf7e1d28506dc892324b42005387a2f5a844b27827785a68d10881067414fe93fd4fbb9645f765d
This commit is contained in:
Ryan Ofsky 2025-04-08 17:26:30 -04:00
commit bb92bb36f2
No known key found for this signature in database
GPG key ID: 46800E30FC748A66

View file

@ -575,6 +575,47 @@ llvm-cov show \
The generated coverage report can be accessed at `build/coverage_report/index.html`. The generated coverage report can be accessed at `build/coverage_report/index.html`.
#### Compiling for Fuzz Coverage
```shell
cmake -B build \
-DCMAKE_C_COMPILER="clang" \
-DCMAKE_CXX_COMPILER="clang++" \
-DCMAKE_C_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
-DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping" \
-DBUILD_FOR_FUZZING=ON
cmake --build build # Use "-j N" here for N parallel jobs.
```
Running fuzz tests with one or more targets
```shell
# For single target run with the target of choice
LLVM_PROFILE_FILE="$(pwd)/build/raw_profile_data/txorphan.profraw" ./build/test/fuzz/test_runner.py ../qa-assets/fuzz_corpora txorphan
# If running for multiple targets
LLVM_PROFILE_FILE="$(pwd)/build/raw_profile_data/%m_%p.profraw" ./build/test/fuzz/test_runner.py ../qa-assets/fuzz_corpora
# Merge profiles
llvm-profdata merge build/raw_profile_data/*.profraw -o build/coverage.profdata
```
Generate report:
```shell
llvm-cov show \
--object=build/bin/fuzz \
-Xdemangler=llvm-cxxfilt \
--instr-profile=build/coverage.profdata \
--ignore-filename-regex="src/crc32c/|src/leveldb/|src/minisketch/|src/secp256k1/|src/test/" \
--format=html \
--show-instantiation-summary \
--show-line-counts-or-regions \
--show-expansions \
--output-dir=build/coverage_report \
--project-title="Bitcoin Core Fuzz Coverage Report"
```
The generated coverage report can be accessed at `build/coverage_report/index.html`.
### Performance profiling with perf ### Performance profiling with perf
Profiling is a good way to get a precise idea of where time is being spent in Profiling is a good way to get a precise idea of where time is being spent in