Skip to content

dev: LLVM source-based code coverage support#8885

Open
cdecker wants to merge 1 commit intomasterfrom
20240102-coverage
Open

dev: LLVM source-based code coverage support#8885
cdecker wants to merge 1 commit intomasterfrom
20240102-coverage

Conversation

@cdecker
Copy link
Member

@cdecker cdecker commented Feb 5, 2026

Summary

Add support for LLVM source-based code coverage instrumentation, enabling developers and CI to generate coverage reports for the Core Lightning codebase.

Changes

Build System

  • Makefile: Add coverage-clang-collect and coverage-clang-report targets for collecting and generating coverage reports
  • Makefile: Fix missing endif for PYTEST_TESTS conditional
  • Makefile: Respect CARGO_TARGET_DIR environment variable for Rust builds

Coverage Scripts (contrib/coverage/)

  • collect-coverage.sh: Merges .profraw files into a single .profdata file with validation, parallel processing, and batch handling for large file counts
  • generate-coverage-report.sh: Generates HTML reports using llvm-cov show for all instrumented binaries

CI Workflow

  • coverage.yaml: Daily workflow that builds with coverage instrumentation, runs tests, and publishes HTML reports to GitHub Pages

Usage

# Configure with coverage enabled
./configure --enable-coverage CC=clang

# Build
make -j$(nproc)

# Run tests with coverage collection
CLN_COVERAGE_DIR=/tmp/cln-coverage make pytest

# Generate coverage report
make coverage-clang
# Report available at coverage/html/index.html

Notes

  • Uses LLVM's source-based coverage instrumentation (-fprofile-instr-generate -fcoverage-mapping)
  • Handles CLN's multi-process architecture by collecting per-test .profraw files
  • Coverage scripts validate and filter corrupt/incomplete profile files before merging

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
@cdecker
Copy link
Member Author

cdecker commented Feb 5, 2026

@rustyrussell sorry for forgetting the script files in the coverage PR. It was being covered by .gitignore so I didn't see them when staging the content.

make distclean coverage-clean
./configure --enable-coverage --disable-valgrind CC=clang
make -j $(nproc)
PYTEST_PAR=$(nproc) make pytest || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do unit tests too? Some of this stuff (like block parsing) is best done as a unit test?

Comment on lines +32 to +33
- name: Rebase locally
run: git rebase master 20240102-coverage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? I don't think this is needed once we merge?


- name: Generate coverage report
run: |
make distclean coverage-clean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be unnecessary...

Comment on lines +46 to +47
mv coverage/html site/coverage

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sooo... pretty....


[sbcc]: https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
[pcca]: https://github.com/ElementsProject/lightning/tree/master/contrib/prepare-code-coverage-artifact.py
[report]: https://cdecker.github.io/lightning/coverage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, will it appear there or will it appear on the ElementProject pages?

@@ -0,0 +1,30 @@
# Test Coverage

> Coverage isn't everything, but it can tell you were you missed a thing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*where

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants