Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 107 additions & 16 deletions .github/workflows/coverage-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
workflow_dispatch:
# Allow being called from other workflows
workflow_call:
# Run on pull requests for testing
pull_request:

concurrency:
group: coverage-${{ github.ref }}
Expand All @@ -32,9 +34,17 @@ jobs:
- name: Install dependencies
run: bash -x .github/scripts/setup.sh

- name: Install Clang 18 for coverage
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo ln -sf /usr/bin/clang-18 /usr/bin/clang
sudo ln -sf /usr/bin/clang++-18 /usr/bin/clang++

- name: Build with coverage instrumentation
run: |
./configure --enable-debugbuild --enable-coverage CC=clang
./configure --enable-debugbuild --enable-coverage CC=clang-18
uv run make -j $(nproc) testpack.tar.bz2

- name: Upload build artifact
Expand All @@ -51,12 +61,26 @@ jobs:
fail-fast: false
matrix:
include:
- name: sqlite
- name: sqlite-1
db: sqlite3
pytest_par: 10
test_group: 1
test_group_count: 2
- name: sqlite-2
db: sqlite3
pytest_par: 10
- name: postgres
test_group: 2
test_group_count: 2
- name: postgres-1
db: postgres
pytest_par: 10
test_group: 1
test_group_count: 2
- name: postgres-2
db: postgres
pytest_par: 10
test_group: 2
test_group_count: 2

steps:
- name: Checkout
Expand Down Expand Up @@ -84,24 +108,83 @@ jobs:
- name: Unpack build
run: tar -xaf testpack.tar.bz2

- name: Verify coverage instrumentation
run: |
echo "Checking if binaries are instrumented for coverage..."
if nm lightningd/lightningd | grep -q '__llvm_profile'; then
echo "✓ Binaries appear to be instrumented for coverage"
else
echo "⚠ WARNING: Binaries may not be properly instrumented"
echo "Checking build flags in config.vars:"
grep -E "COVERAGE|CFLAGS" config.vars || echo "No coverage flags found"
fi

- name: Run tests with coverage
env:
CLN_COVERAGE_DIR: ${{ github.workspace }}/coverage-raw
TEST_DB_PROVIDER: ${{ matrix.db }}
PYTEST_PAR: ${{ matrix.pytest_par }}
SLOW_MACHINE: 1
TIMEOUT: 900
VALGRIND: 0
run: |
export CLN_COVERAGE_DIR="${{ github.workspace }}/coverage-raw"
mkdir -p "$CLN_COVERAGE_DIR"
uv run eatmydata pytest tests/ -n ${PYTEST_PAR} -vvv
echo "CLN_COVERAGE_DIR=$CLN_COVERAGE_DIR"
echo "Running test group ${{ matrix.test_group }} of ${{ matrix.test_group_count }}"
echo "Current directory: $(pwd)"
ls -la
VALGRIND=0 uv run eatmydata pytest tests/ -n ${PYTEST_PAR} -vvv \
--test-group-count ${{ matrix.test_group_count }} \
--test-group ${{ matrix.test_group }}

- name: Check coverage files generated
if: always()
run: |
echo "Checking for profraw files in coverage-raw"
find "${{ github.workspace }}/coverage-raw" -name "*.profraw" -ls || echo "No profraw files found"
COUNT=$(find "${{ github.workspace }}/coverage-raw" -name "*.profraw" 2>/dev/null | wc -l)
echo "Total profraw files: $COUNT"
if [ "$COUNT" -eq 0 ]; then
echo "WARNING: No coverage data was generated!"
echo "This might indicate:"
echo " 1. Tests didn't run successfully"
echo " 2. Binaries aren't instrumented"
echo " 3. LLVM_PROFILE_FILE environment variable not set correctly"
fi

- name: Install LLVM tools for merging
if: always()
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo ln -sf /usr/bin/llvm-profdata-18 /usr/bin/llvm-profdata

- name: Merge coverage data locally
if: always()
run: |
cd ${{ github.workspace }}
echo "Current directory: $(pwd)"
ls -la contrib/coverage/ || echo "contrib/coverage directory not found"
chmod +x contrib/coverage/collect-coverage.sh
mkdir -p coverage
CLN_COVERAGE_DIR="${{ github.workspace }}/coverage-raw" \
./contrib/coverage/collect-coverage.sh \
coverage-raw \
coverage/${{ matrix.name }}.profdata
echo "Merged profdata size:"
ls -lh coverage/${{ matrix.name }}.profdata || echo "No profdata file created"
# Clean up raw files to save disk space
rm -rf coverage-raw/*.profraw
echo "Cleaned up raw profraw files"

- name: Upload coverage data
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-raw-${{ matrix.name }}
path: coverage-raw/*.profraw
if-no-files-found: error
name: coverage-merged-${{ matrix.name }}
path: coverage/${{ matrix.name }}.profdata
if-no-files-found: warn

report:
name: Generate Coverage Report
Expand Down Expand Up @@ -132,24 +215,32 @@ jobs:
- name: Download all coverage artifacts
uses: actions/download-artifact@v4
with:
pattern: coverage-raw-*
pattern: coverage-merged-*
path: coverage-artifacts

- name: Merge coverage data
run: |
mkdir -p coverage-raw coverage
find coverage-artifacts -name "*.profraw" -exec cp {} coverage-raw/ \;
PROFRAW_COUNT=$(ls -1 coverage-raw/*.profraw 2>/dev/null | wc -l)
echo "Found $PROFRAW_COUNT profile files"
if [ "$PROFRAW_COUNT" -eq 0 ]; then
mkdir -p coverage
# Find all .profdata files from test jobs
PROFDATA_FILES=($(find coverage-artifacts -name "*.profdata"))
echo "Found ${#PROFDATA_FILES[@]} profdata files from test jobs:"
printf '%s\n' "${PROFDATA_FILES[@]}"

if [ ${#PROFDATA_FILES[@]} -eq 0 ]; then
echo "ERROR: No coverage data found"
exit 1
fi
chmod +x contrib/coverage/collect-coverage.sh
CLN_COVERAGE_DIR=coverage-raw ./contrib/coverage/collect-coverage.sh

# Merge all pre-aggregated profdata files into final merged.profdata
echo "Merging ${#PROFDATA_FILES[@]} profdata files..."
llvm-profdata merge -sparse "${PROFDATA_FILES[@]}" -o coverage/merged.profdata

echo "Final merged profdata size:"
ls -lh coverage/merged.profdata

- name: Generate HTML report
run: |
cd ${{ github.workspace }}
chmod +x contrib/coverage/generate-coverage-report.sh
./contrib/coverage/generate-coverage-report.sh

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gen_*.c
gen_*.h
wire/gen_*_csv
cli/lightning-cli
coverage
/coverage
# Coverage profiling data files
*.profraw
*.profdata
Expand Down
Loading
Loading