Skip to content

Commit d4771f5

Browse files
Add code coverage to CI workflow (#42)
1 parent 7dff612 commit d4771f5

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

.github/workflows/main.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ jobs:
3939
run: cmake --build . -j$(nproc)
4040

4141
# -------------------------------------------------
42-
# 2. FULL BUILD + TEST + SIMPLE DAG RUN + DOCS (RelWithDebInfo + Eigen)
42+
# 2. FULL BUILD + TEST + SIMPLE DAG RUN + COVERAGE + DOCS (RelWithDebInfo + Eigen)
4343
# -------------------------------------------------
4444
test_and_run:
45-
name: Build & Test (RelWithDebInfo + Eigen)
45+
name: Build, Test & Coverage (RelWithDebInfo + Eigen)
4646
runs-on: ubuntu-latest
4747
needs: build_matrix
4848
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
@@ -55,21 +55,42 @@ jobs:
5555
sudo apt-get update
5656
sudo apt-get install -y --no-install-recommends \
5757
make gcc g++ git libboost-all-dev \
58-
doxygen graphviz python3-pip libeigen3-dev
58+
doxygen graphviz python3-pip libeigen3-dev lcov
5959
pip3 install --upgrade pip
6060
pip3 install cmake==3.21.3
6161
6262
- name: Configure
63-
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON
63+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON
6464

6565
- name: Build all targets
6666
working-directory: ${{ github.workspace }}/build
6767
run: cmake --build . -j$(nproc)
6868

69-
- name: Run tests
69+
- name: Run tests with coverage
7070
working-directory: ${{ github.workspace }}/build
71-
run: ctest --output-on-failure --output-junit test_results.xml
72-
continue-on-error: true
71+
run: |
72+
# Run tests
73+
ctest --output-on-failure --output-junit test_results.xml
74+
75+
# Capture coverage ONLY from include/
76+
lcov --capture --directory . \
77+
--output-file coverage.info \
78+
--ignore-errors empty,mismatch \
79+
--include '*/OneStopParallel/include/*'
80+
81+
# Remove unused warnings + ignore tests/apps
82+
lcov --remove coverage.info '*/tests/*' '*/apps/*' \
83+
--ignore-errors unused,empty,mismatch \
84+
--output-file coverage.info
85+
86+
# Generate HTML report
87+
genhtml coverage.info --output-directory coverage_html
88+
89+
- name: Upload coverage artifacts
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: coverage-report
93+
path: build/coverage_html
7394

7495
- name: Upload test results
7596
uses: actions/upload-artifact@v4

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ set(CMAKE_CXX_STANDARD 17)
2525
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2626
set(CMAKE_CXX_EXTENSIONS OFF) # Ensure C++17 standard is strictly enforced
2727

28+
# --- Code Coverage (optional) ---
29+
option(ENABLE_COVERAGE "Enable code coverage flags" OFF)
30+
31+
if(ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
32+
message(STATUS "Code coverage enabled")
33+
add_compile_options(--coverage -g)
34+
add_link_options(--coverage)
35+
endif()
36+
2837
# Configure git hooks
2938
add_subdirectory(.githooks)
3039

@@ -102,7 +111,7 @@ target_compile_options(ProjectExecutableFlags INTERFACE
102111
# Else (not Debug)
103112
$<IF:$<CONFIG:RelWithDebInfo>,
104113
# RelWithDebInfo flags
105-
-O3;-g,
114+
-O3;-g;-DNDEBUG,
106115
# Release and other/custom flags
107116
-O3;-DNDEBUG
108117
>

0 commit comments

Comments
 (0)