gitlab-ci: add support for running gcov-based coverage

This commit is contained in:
Ben Boeckel
2025-09-24 23:32:47 -04:00
parent 61aed5e5f2
commit da4a1ec2ff
3 changed files with 71 additions and 0 deletions

View File

@@ -62,6 +62,12 @@
- ${CMAKE_CI_BUILD_DIR}/DartConfiguration.tcl
- ${CMAKE_CI_BUILD_DIR}/CTestCustom.cmake
- ${CMAKE_CI_BUILD_DIR}/cdash-build-id
# CTest coverage files.
- ${CMAKE_CI_BUILD_DIR}/CMakeFiles/TargetDirectories.txt
- ${CMAKE_CI_BUILD_DIR}/**/*.gcno
- ${CMAKE_CI_BUILD_DIR}/Source/QtDialog/moc_*.cpp
- ${CMAKE_CI_BUILD_DIR}/Source/QtDialog/ui_*.h
reports:
annotations:
- ${CMAKE_CI_BUILD_DIR}/annotations.json
@@ -167,6 +173,32 @@
# Take the install tree.
- ${CMAKE_CI_BUILD_DIR}/install/
.cmake_coverage_artifacts:
artifacts:
expire_in: 1d
# External testing can be useful even if test jobs fail.
when: always
reports:
junit:
- ${CMAKE_CI_BUILD_DIR}/junit.xml
annotations:
- ${CMAKE_CI_BUILD_DIR}/annotations.json
paths:
# Generated sources.
- ${CMAKE_CI_BUILD_DIR}/Source/QtDialog/moc_*.cpp
- ${CMAKE_CI_BUILD_DIR}/Source/QtDialog/ui_*.h
# CTest coverage files.
- ${CMAKE_CI_BUILD_DIR}/CMakeFiles/TargetDirectories.txt
- ${CMAKE_CI_BUILD_DIR}/**/*.gcno
- ${CMAKE_CI_BUILD_DIR}/**/*.gcda
# CTest/CDash information.
- ${CMAKE_CI_BUILD_DIR}/Testing/
- ${CMAKE_CI_BUILD_DIR}/DartConfiguration.tcl
- ${CMAKE_CI_BUILD_DIR}/CTestCustom.cmake
- ${CMAKE_CI_BUILD_DIR}/cdash-build-id
.cmake_doc_artifacts:
artifacts:
expire_in: 1d

View File

@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.29)
include("${CMAKE_CURRENT_LIST_DIR}/gitlab_ci.cmake")
# Read the files from the build directory.
ctest_read_custom_files("${CTEST_BINARY_DIRECTORY}")
# Pick up from where the configure left off.
ctest_start(APPEND)
find_program(GCOV NAMES gcov)
set(CTEST_COVERAGE_COMMAND "${GCOV}")
set(CTEST_COVERAGE_EXTRA_FLAGS
--hash-filenames
--long-file-names)
string(REPLACE ";" " " CTEST_COVERAGE_EXTRA_FLAGS "${CTEST_COVERAGE_EXTRA_FLAGS}")
ctest_coverage(
RETURN_VALUE coverage_result)
ctest_submit(PARTS Coverage)
include("${CMAKE_CURRENT_LIST_DIR}/ctest_annotation.cmake")
ctest_annotation_report("${CTEST_BINARY_DIRECTORY}/annotations.json"
"Coverage Report" "https://open.cdash.org/viewCoverage.php?buildid=${build_id}"
)
if (coverage_result)
message(FATAL_ERROR
"Failed to gather coverage")
endif ()

View File

@@ -727,6 +727,16 @@
interruptible: true
.cmake_coverage_linux:
stage: test
script:
- *before_script_linux
- "$LAUNCHER ctest --output-on-failure -V -S .gitlab/ci/ctest_coverage.cmake"
coverage: '/Percentage Coverage: \d+.\d+%/'
interruptible: true
.cmake_build_linux_release:
stage: build