feat: Add LCOV coverage support for Jenkins CI
- Add ENABLE_COVERAGE CMake option with gcov flags - Create collect-coverage.sh script for LCOV workflow - Add Qt6 test files with QTest framework - Update Jenkinsfile with Coverage stage (main/master/coverage.*) - Update CI Docker image with lcov and genhtml packages - Add .gitignore entries for coverage artifacts - Add COVERAGE.md documentation Coverage workflow: 1. Configure with -DENABLE_COVERAGE=ON 2. Build and run tests to generate .gcda/.gcno files 3. Collect coverage with lcov 4. Filter out Qt/system libraries 5. Generate HTML report and lcov.info for Jenkins Jenkins publishes coverage/lcov.info using Coverage Plugin. Coverage stage only runs on protected branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Entire-Checkpoint: 7783c7698334 Entire-Checkpoint: 70341e29996b Signed-off-by: twi-devel <torsten.wierschin@life-maps.com>
This commit is contained in:
19 files changed
+734
-235
No files matched your search
@@ -0,0 +1,103 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# collect-coverage.sh - Generate LCOV coverage report for Qt6 project
|
||||
#
|
||||
# Usage: ./collect-coverage.sh [build_dir]
|
||||
#
|
||||
# This script:
|
||||
# 1. Cleans previous coverage data
|
||||
# 2. Runs tests with coverage enabled
|
||||
# 3. Collects coverage data using lcov
|
||||
# 4. Generates HTML report using genhtml
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
BUILD_DIR="${1:-${PROJECT_ROOT}/build-coverage}"
|
||||
COVERAGE_DIR="${PROJECT_ROOT}/coverage"
|
||||
|
||||
echo "=== LCOV Coverage Collection ==="
|
||||
echo "Project root: ${PROJECT_ROOT}"
|
||||
echo "Build directory: ${BUILD_DIR}"
|
||||
echo "Coverage output: ${COVERAGE_DIR}"
|
||||
|
||||
# Clean previous coverage data
|
||||
echo ""
|
||||
echo "Step 1: Cleaning previous coverage data..."
|
||||
find "${BUILD_DIR}" -name "*.gcda" -delete 2>/dev/null || true
|
||||
find "${BUILD_DIR}" -name "*.gcno" -delete 2>/dev/null || true
|
||||
rm -rf "${COVERAGE_DIR}"
|
||||
mkdir -p "${COVERAGE_DIR}"
|
||||
|
||||
# Configure with coverage enabled (if not already configured)
|
||||
if [ ! -f "${BUILD_DIR}/CMakeCache.txt" ]; then
|
||||
echo ""
|
||||
echo "Step 2: Configuring project with coverage enabled..."
|
||||
cmake -S "${PROJECT_ROOT}" -B "${BUILD_DIR}" -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DENABLE_COVERAGE=ON \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||
else
|
||||
echo ""
|
||||
echo "Step 2: Build directory already configured"
|
||||
fi
|
||||
|
||||
# Build the project
|
||||
echo ""
|
||||
echo "Step 3: Building project..."
|
||||
cmake --build "${BUILD_DIR}" --target all
|
||||
|
||||
# Run tests to generate coverage data
|
||||
echo ""
|
||||
echo "Step 4: Running tests to generate coverage data..."
|
||||
ctest --test-dir "${BUILD_DIR}" --output-on-failure
|
||||
|
||||
# Collect coverage data
|
||||
echo ""
|
||||
echo "Step 5: Collecting coverage data with lcov..."
|
||||
lcov --directory "${BUILD_DIR}" \
|
||||
--capture \
|
||||
--output-file "${COVERAGE_DIR}/coverage.info" \
|
||||
--ignore-errors mismatch \
|
||||
--no-external \
|
||||
--rc lcov_branch_coverage=1
|
||||
|
||||
# Remove Qt and system libraries from coverage report
|
||||
echo "Step 6: Filtering coverage data..."
|
||||
lcov --remove "${COVERAGE_DIR}/coverage.info" \
|
||||
'/usr/*' \
|
||||
'/opt/*' \
|
||||
'*/Qt6/*' \
|
||||
'*/qt6-migrated-benchmark/tests/*' \
|
||||
--output-file "${COVERAGE_DIR}/coverage.filtered.info" \
|
||||
--ignore-errors mismatch \
|
||||
--rc lcov_branch_coverage=1
|
||||
|
||||
# Generate HTML report
|
||||
echo ""
|
||||
echo "Step 7: Generating HTML report with genhtml..."
|
||||
genhtml "${COVERAGE_DIR}/coverage.filtered.info" \
|
||||
--output-directory "${COVERAGE_DIR}/html" \
|
||||
--branch-coverage \
|
||||
--ignore-errors mismatch \
|
||||
--title "Qt6 Migration Benchmark Coverage" \
|
||||
--prefix "${PROJECT_ROOT}"
|
||||
|
||||
# Generate summary
|
||||
echo ""
|
||||
echo "=== Coverage Summary ==="
|
||||
lcov --list "${COVERAGE_DIR}/coverage.filtered.info" \
|
||||
--ignore-errors mismatch \
|
||||
--rc lcov_branch_coverage=1
|
||||
|
||||
# Copy to expected Jenkins location
|
||||
cp "${COVERAGE_DIR}/coverage.filtered.info" "${COVERAGE_DIR}/lcov.info"
|
||||
|
||||
echo ""
|
||||
echo "=== Coverage Report Generated ==="
|
||||
echo "HTML report: ${COVERAGE_DIR}/html/index.html"
|
||||
echo "LCOV data: ${COVERAGE_DIR}/lcov.info (for Jenkins)"
|
||||
echo ""
|
||||
echo "To view the HTML report, open: ${COVERAGE_DIR}/html/index.html"
|
||||
Reference in new issue
Block a user