Skip to content

Commit 129231a

Browse files
Add Code Coverage and Clang-tidy (#11)
1 parent cb7baac commit 129231a

File tree

9 files changed

+359
-164
lines changed

9 files changed

+359
-164
lines changed

.codecov.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
codecov:
2+
require_ci_to_pass: no
3+
4+
coverage:
5+
precision: 2
6+
round: down
7+
range: "70...100"
8+
9+
status:
10+
project:
11+
default:
12+
target: auto # Uses coverage from base commit
13+
threshold: 2 # Allow 2% drop
14+
15+
patch:
16+
default:
17+
target: 85 # New code should have 85% coverage
18+
threshold: 2 # Allow 2% variance
19+
20+
changes: no
21+
22+
parsers:
23+
gcov:
24+
branch_detection:
25+
conditional: yes
26+
loop: yes
27+
method: no
28+
macro: no
29+
30+
comment:
31+
layout: "reach, diff, flags, tree, files"
32+
behavior: default
33+
require_changes: no
34+
35+
ignore:
36+
- "test/**/*"
37+
38+
- "benchmark/**/*"
39+
40+
- "scripts/**/*"
41+
- "**/*.C"
42+
43+
- "Doxyfile"
44+
45+
flags:
46+
ramcore:
47+
paths:
48+
- "src/ramcore/**"
49+
- "inc/ramcore/**"
50+
carryforward: true
51+
52+
rntuple:
53+
paths:
54+
- "src/rntuple/**"
55+
- "inc/rntuple/**"
56+
carryforward: true
57+
58+
ttree:
59+
paths:
60+
- "src/ttree/**"
61+
- "inc/ttree/**"
62+
carryforward: true
63+
64+
tools:
65+
paths:
66+
- "tools/**"
67+
carryforward: true
68+
69+
github_checks:
70+
annotations: true
71+

.github/workflows/ci.yml

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ on:
99
jobs:
1010
build-and-test:
1111
name: Build and Test
12-
runs-on: ubuntu-24.04
12+
runs-on: ubuntu-24.04
1313

1414
steps:
15-
- uses: actions/checkout@v5
15+
- uses: actions/checkout@v5
1616

1717
- name: Install ROOT
1818
run: |
1919
ROOT_URL="https://root.cern/download/root_v6.36.00.Linux-ubuntu24.04-x86_64-gcc13.3.tar.gz"
2020
wget -O root.tar.gz $ROOT_URL
21-
tar -xzf root.tar.gz -C /opt/
21+
tar -xzf root.tar.gz -C /opt/
2222
echo "/opt/root/bin" >> $GITHUB_PATH
2323
2424
- name: Install build dependencies
@@ -29,7 +29,7 @@ jobs:
2929
- name: Configure CMake
3030
run: |
3131
source thisroot.sh
32-
mkdir build
32+
mkdir build
3333
cd build
3434
cmake .. \
3535
-DCMAKE_BUILD_TYPE=Release \
@@ -49,3 +49,59 @@ jobs:
4949
cd build
5050
ctest --output-on-failure --build-config Release
5151
52+
coverage:
53+
name: Code Coverage
54+
runs-on: ubuntu-24.04
55+
needs: build-and-test # Run only if build-and-test succeeds
56+
57+
steps:
58+
- uses: actions/checkout@v5
59+
60+
- name: Install ROOT
61+
run: |
62+
ROOT_URL="https://root.cern/download/root_v6.36.00.Linux-ubuntu24.04-x86_64-gcc13.3.tar.gz"
63+
wget -O root.tar.gz $ROOT_URL
64+
tar -xzf root.tar.gz -C /opt/
65+
echo "/opt/root/bin" >> $GITHUB_PATH
66+
67+
- name: Install build and coverage dependencies
68+
run: |
69+
sudo apt-get update
70+
sudo apt-get install -y libvdt-dev libtbb-dev gcovr lcov
71+
72+
- name: Configure with coverage
73+
run: |
74+
source thisroot.sh
75+
mkdir build
76+
cd build
77+
cmake .. \
78+
-DCMAKE_BUILD_TYPE=Debug \
79+
-DENABLE_COVERAGE=ON \
80+
-DRAMTOOLS_BUILD_TESTS=ON \
81+
-DRAMTOOLS_BUILD_TOOLS=ON \
82+
-DRAMTOOLS_BUILD_BENCHMARKS=OFF
83+
84+
- name: Build
85+
run: |
86+
source thisroot.sh
87+
cd build
88+
cmake --build . --config Debug -j $(nproc)
89+
90+
- name: Run tests
91+
run: |
92+
source thisroot.sh
93+
cd build
94+
ctest --output-on-failure --build-config Debug
95+
96+
- name: Generate coverage report
97+
run: |
98+
cd build
99+
gcovr -r .. --xml-pretty --xml coverage.xml --print-summary
100+
101+
- name: Upload coverage to Codecov
102+
uses: codecov/codecov-action@v4
103+
with:
104+
files: ./build/coverage.xml
105+
flags: unittests
106+
name: codecov-ramtools
107+
fail_ci_if_error: false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Post clang-tidy review comments
2+
3+
on:
4+
workflow_run:
5+
workflows: ["clang-tidy-review"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
checks: write
11+
pull-requests: write
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.event.workflow_run.pull_requests[0].number }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
post-comments:
19+
# Only run if the triggering workflow was from a pull request
20+
if: github.event.workflow_run.event == 'pull_request'
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Post review comments
25+
id: post-review
26+
uses: ZedThree/clang-tidy-review/post@v0.21.0
27+
with:
28+
max_comments: 10
29+
30+
# Fail if there are any clang-tidy warnings
31+
- name: Check for issues
32+
if: steps.post-review.outputs.total_comments > 0
33+
run: |
34+
echo "::error::Found ${{ steps.post-review.outputs.total_comments }} clang-tidy issues"
35+
exit 1
36+

CMakeLists.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1010
option(RAMTOOLS_BUILD_TESTS "Build unit tests" ON)
1111
option(RAMTOOLS_BUILD_BENCHMARKS "Build benchmarks" ON)
1212
option(RAMTOOLS_BUILD_TOOLS "Build tools" ON)
13+
option(ENABLE_COVERAGE "Enable code coverage reporting" OFF)
14+
15+
if(ENABLE_COVERAGE)
16+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
17+
message(STATUS "Code coverage enabled")
18+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
19+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
20+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
21+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
22+
else()
23+
message(WARNING "Code coverage requires GCC or Clang")
24+
endif()
25+
endif()
1326

1427
set(ROOT_MIN_VERSION 6.26)
1528
find_package(ROOT ${ROOT_MIN_VERSION} REQUIRED COMPONENTS Core RIO Tree ROOTNTuple ROOTNTupleUtil)
@@ -20,7 +33,7 @@ include(GNUInstallDirs)
2033
set(CMAKE_INSTALL_LIBDIR lib)
2134
set(CMAKE_INSTALL_INCLUDEDIR include)
2235

23-
ROOT_STANDARD_LIBRARY_PACKAGE(ramcore
36+
ROOT_STANDARD_LIBRARY_PACKAGE(ramcore
2437
HEADERS
2538
inc/ttree/RAMRecord.h
2639
inc/ttree/Utils.h
@@ -61,12 +74,24 @@ if(RAMTOOLS_BUILD_TOOLS)
6174
add_subdirectory(tools)
6275
endif()
6376

64-
if(RAMTOOLS_BUILD_BENCHMARKS)
77+
# Include benchmark directory if benchmarks OR tests are enabled
78+
# (sam_generator is needed by tests)
79+
if(RAMTOOLS_BUILD_BENCHMARKS OR RAMTOOLS_BUILD_TESTS)
6580
add_subdirectory(benchmark)
6681
endif()
6782

6883
if(RAMTOOLS_BUILD_TESTS)
6984
enable_testing()
7085
add_subdirectory(test)
86+
87+
if(ENABLE_COVERAGE)
88+
add_custom_target(coverage
89+
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
90+
COMMAND gcovr -r ${CMAKE_SOURCE_DIR} --html --html-details -o ${CMAKE_BINARY_DIR}/coverage.html
91+
COMMAND gcovr -r ${CMAKE_SOURCE_DIR} --xml-pretty --xml coverage.xml
92+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
93+
COMMENT "Running tests and generating code coverage report..."
94+
)
95+
endif()
7196
endif()
7297

0 commit comments

Comments
 (0)