Skip to content

Commit 62dfd35

Browse files
committed
add coverage report generation in CI
adds the coverage report generation in CI . Also make the coverage script more CI friendly.
1 parent b0196f4 commit 62dfd35

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

ci/ci-tests.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,28 @@ RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightnin
158158
RUSTFLAGS="--cfg=simple_close" cargo test --verbose --color always -p lightning
159159
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
160160
RUSTFLAGS="--cfg=lsps1_service" cargo test --verbose --color always -p lightning-liquidity
161+
162+
# Generate fuzz coverage report
163+
echo -e "\n\nGenerating fuzz coverage report"
164+
if [ -n "$CI" ]; then
165+
# In CI, store coverage in a specific directory for artifact collection
166+
COVERAGE_DIR="coverage-report"
167+
mkdir -p "$COVERAGE_DIR"
168+
echo "Installing cargo-llvm-cov..."
169+
# Install cargo-llvm-cov if not already installed
170+
cargo install cargo-llvm-cov --locked
171+
echo "Running fuzz coverage generation..."
172+
./contrib/generate_fuzz_coverage.sh --output-dir "$COVERAGE_DIR"
173+
echo "Coverage generation completed. Checking results..."
174+
if [ -f "fuzz/$COVERAGE_DIR/html/index.html" ]; then
175+
echo "✓ Coverage report successfully generated at fuzz/$COVERAGE_DIR/html/index.html"
176+
ls -la "fuzz/$COVERAGE_DIR/html/"
177+
else
178+
echo "✗ Coverage report not found at expected location"
179+
echo "Checking what was created in fuzz/$COVERAGE_DIR:"
180+
ls -la "fuzz/$COVERAGE_DIR" || echo "Directory does not exist"
181+
fi
182+
else
183+
# Local development
184+
./contrib/generate_fuzz_coverage.sh
185+
fi

contrib/generate_fuzz_coverage.sh

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
set -e
33
set -x
44

5+
# Parse command line arguments
6+
OUTPUT_DIR="target/llvm-cov/html"
7+
while [[ $# -gt 0 ]]; do
8+
case $1 in
9+
--output-dir)
10+
OUTPUT_DIR="$2"
11+
shift 2
12+
;;
13+
*)
14+
echo "Unknown option: $1"
15+
echo "Usage: $0 [--output-dir OUTPUT_DIRECTORY]"
16+
exit 1
17+
;;
18+
esac
19+
done
20+
521
# Check if we're in the root directory, if so change to fuzz
622
if [ -d "fuzz" ]; then
723
cd fuzz
@@ -32,11 +48,28 @@ if [ "$show_corpus_message" = true ]; then
3248
echo ""
3349
fi
3450

51+
# Create output directory if it doesn't exist
52+
mkdir -p "$OUTPUT_DIR"
53+
3554
export RUSTFLAGS="--cfg=fuzzing --cfg=secp256k1_fuzz --cfg=hashes_fuzz"
3655
# ignore anything in fuzz directory since we don't want coverage of targets
37-
cargo llvm-cov --html --ignore-filename-regex "fuzz/"
56+
cargo llvm-cov --html --ignore-filename-regex "fuzz/" --output-dir "$OUTPUT_DIR"
57+
58+
# Check if coverage report was generated successfully
59+
# The report is generated directly in $OUTPUT_DIR/html/index.html
60+
if [ ! -f "$OUTPUT_DIR/html/index.html" ]; then
61+
echo "Error: Failed to generate coverage report at $OUTPUT_DIR/html/index.html"
62+
# Debug: list what was actually created
63+
echo "Contents of $OUTPUT_DIR:"
64+
ls -la "$OUTPUT_DIR" || echo "Directory $OUTPUT_DIR does not exist"
65+
if [ -d "$OUTPUT_DIR/html" ]; then
66+
echo "Contents of $OUTPUT_DIR/html:"
67+
ls -la "$OUTPUT_DIR/html"
68+
fi
69+
exit 1
70+
fi
3871

3972
echo ""
40-
echo "Coverage report generated in target/llvm-cov/html/index.html"
73+
echo "Coverage report generated in $OUTPUT_DIR/html/index.html"
4174

4275

0 commit comments

Comments
 (0)