Add support for LLVM source-based code coverage instrumentation, enabling developers and CI to generate coverage reports for the Core Lightning codebase. Build System: - Add coverage-clang-collect and coverage-clang-report Makefile targets - Fix missing endif for PYTEST_TESTS conditional - Respect CARGO_TARGET_DIR environment variable for Rust builds Coverage Scripts (contrib/coverage/): - collect-coverage.sh: Merges .profraw files with validation and batching - generate-coverage-report.sh: Generates HTML reports using llvm-cov CI Workflow: - coverage.yaml: Daily workflow for building, testing, and publishing reports Usage: ./configure --enable-coverage CC=clang make -j$(nproc) CLN_COVERAGE_DIR=/tmp/cln-coverage make pytest make coverage-clang Changelog-Changed: Added LLVM source-based code coverage support with CI integration
1.3 KiB
Test Coverage
Coverage isn't everything, but it can tell you were you missed a thing.
We use LLVM's Source-Based Code Coverage support to instrument
the code at compile time. This instrumentation then emits coverage
files (profraw), which can then be aggregated via llvm-profdata
into a single profdata file, and from there a variety of tools can
be used to inspect coverage.
The most common use is to generate an HTML report for all binaries
under test. CLN being a multi-process system has a number of binaries,
sharing some source code. To simplify the aggregation of data and
generation of the report split per source file, we use the
prepare-code-coverage-artifact.py (pcca.py) script from
the LLVM project.
Conventions
The tests/fixtures.py sets the LLVM_PROFILE_FILE environment
variable, indicating that the profraw files ought to be stores in
coverage/raw. Processing the file then uses pcca.py to
aggregate the raw files, into a data file, and then generate a
per-source-file coverage report.
This report is then published here