Skip to content

Commit 4b7e478

Browse files
PetroZarytskyianigamova
authored andcommitted
[CI] Add code coverage testing
1 parent 723a5ee commit 4b7e478

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

.codecov.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
codecov:
2+
require_ci_to_pass: no
3+
4+
coverage:
5+
precision: 2
6+
round: down
7+
range: "5...100"
8+
9+
status:
10+
project:
11+
default:
12+
target: auto # will use the coverage from the base commit
13+
threshold: 2 # Allow to drop by 2%, and posting a success status.
14+
patch:
15+
default:
16+
target: 98 # Force 98% coverage with 2% threshold.
17+
threshold: 2 # Allow to drop by 2%, and posting a success status.
18+
changes: no
19+
20+
parsers:
21+
gcov:
22+
branch_detection:
23+
conditional: yes
24+
loop: yes
25+
method: yes
26+
macro: no
27+
28+
comment:
29+
layout: "reach, diff, flags, tree, files"
30+
behavior: default
31+
require_changes: no
32+
33+
ignore:
34+
- test/*
35+
- test/**/*
36+
37+
github_checks:
38+
annotations: true # Deprecated but very useful

.github/workflows/cvmfs-ci.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
- LCG_RELEASE: "LCG_108"
4141
LCG_ARCH: "x86_64-ubuntu2204-gcc11-opt"
4242
ROOT: "6.36.02"
43+
coverage: true
4344
- LCG_RELEASE: "dev3/latest"
4445
LCG_ARCH: "x86_64-ubuntu2204-gcc11-opt"
4546
ROOT: "LCG master"
@@ -56,6 +57,23 @@ jobs:
5657
with:
5758
cvmfs_repositories: ${{ (env.CMSSW_VERSION != '') && 'cms.cern.ch' || 'sft.cern.ch' }}
5859

60+
- name: Setup compiler
61+
run: |
62+
echo "CC=$(which gcc)" >> $GITHUB_ENV
63+
echo "CXX=$(which g++)" >> $GITHUB_ENV
64+
65+
- name: Setup code coverage
66+
if: ${{ (matrix.coverage == true) }}
67+
run: |
68+
sudo apt install -y lcov
69+
# Workaround ubuntu lcov-1.15-1 package bug
70+
if sudo apt list lcov --installed | grep "1.15-1" ; then
71+
wget https://launchpad.net/ubuntu/+source/lcov/1.15-2/+build/23784466/+files/lcov_1.15-2_all.deb
72+
sudo apt install -y ./lcov_1.15-2_all.deb
73+
fi
74+
echo "COMBINE_CODE_COVERAGE=1" >> $GITHUB_ENV
75+
echo "BUILD_TYPE=Debug" >> $GITHUB_ENV
76+
5977
- name: Build Combine (LCG)
6078
if: ${{ env.CMSSW_VERSION == '' }}
6179
env:
@@ -70,7 +88,8 @@ jobs:
7088
mkdir build;
7189
cd build;
7290
cmake -DCMAKE_INSTALL_PREFIX=../install \
73-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
91+
-DCMAKE_BUILD_TYPE=$([[ -z "$BUILD_TYPE" ]] && echo RelWithDebInfo || echo $BUILD_TYPE) \
92+
-DCOMBINE_CODE_COVERAGE=${{ env.COMBINE_CODE_COVERAGE }} \
7493
-DUSE_VDT=${USE_VDT} \
7594
-DBUILD_TESTS=TRUE \
7695
..;
@@ -245,3 +264,28 @@ jobs:
245264
script: |
246265
cd test
247266
python3 test_interference.py
267+
268+
- name: Prepare code coverage report
269+
if: ${{ success() && (matrix.coverage == true) }}
270+
run: |
271+
# Create lcov report
272+
# capture coverage info
273+
lcov --directory . --capture --output-file coverage.info --gcov-tool $CONDA_PREFIX/bin/gcov --ignore-errors gcov
274+
# filter out system and extra files.
275+
# To also not include test code in coverage add them with full path to the patterns: '*/ci/*'
276+
lcov --remove coverage.info \
277+
'/usr/*' \
278+
"${HOME}/.cache/*" \
279+
'*/ci/*' \
280+
--output-file coverage.info
281+
# output coverage data for debugging (optional)
282+
lcov --list coverage.info
283+
284+
- name: Upload to codecov.io
285+
if: ${{ success() && (matrix.coverage == true) }}
286+
uses: codecov/codecov-action@v5
287+
with:
288+
files: ./coverage.info
289+
fail_ci_if_error: true
290+
verbose: true
291+
token: ${{ secrets.CODECOV_TOKEN }}

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,21 @@ set(LIBNAME HiggsAnalysisCombinedLimit)
5353

5454
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "lib")
5555

56+
## Code Coverage Configuration
57+
option(COMBINE_CODE_COVERAGE "Enable coverage reporting" OFF)
58+
if(COMBINE_CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
59+
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
60+
if(NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
61+
message(FATAL_ERROR "CodeCov enabled on non-debug build!")
62+
endif()
63+
set(GCC_COVERAGE_COMPILE_FLAGS "-fprofile-arcs -ftest-coverage")
64+
set(GCC_COVERAGE_LINK_FLAGS "--coverage")
65+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
66+
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
67+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
68+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
69+
endif()
70+
5671
file(GLOB HEADERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} interface/*.h*)
5772
file(GLOB SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/*.c*)
5873

0 commit comments

Comments
 (0)