Skip to content

Commit 17c3b26

Browse files
committed
Add code coverage
1 parent 14aaf77 commit 17c3b26

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

.github/workflows/ci-linux.yml

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ jobs:
1212
CTEST_OUTPUT_ON_FAILURE: ON
1313
CTEST_PARALLEL_LEVEL: 1
1414
CMAKE_BUILD_TYPE: ${{ matrix.build_type }}
15-
VERBOSE: 1 # to show all cmake scripts debug info
15+
VERBOSE: 1 # to show all cmake scripts debug info
1616

1717
strategy:
1818
fail-fast: false
1919
matrix:
2020
# Github Actions requires a single row to be added to the build matrix.
2121
# See https://help.github.com/en/articles/workflow-syntax-for-github-actions.
22-
name: [
23-
ubuntu-22.04-gcc,
24-
ubuntu-22.04-clang,
25-
ubuntu-24.04-gcc,
26-
ubuntu-24.04-clang,
27-
]
28-
29-
build_type: [ Release ]
22+
name:
23+
[
24+
ubuntu-22.04-gcc,
25+
ubuntu-22.04-clang,
26+
ubuntu-24.04-gcc,
27+
ubuntu-24.04-clang,
28+
]
29+
30+
build_type: [Release]
3031
include:
3132
- name: ubuntu-22.04-gcc
3233
os: ubuntu-22.04
@@ -44,6 +45,11 @@ jobs:
4445
os: ubuntu-24.04
4546
compiler: gcc
4647

48+
- name: ubuntu-24.04-coverage
49+
os: ubuntu-24.04
50+
compiler: gcc
51+
build_type: Coverage
52+
4753
steps:
4854
- name: Checkout
4955
uses: actions/checkout@master
@@ -79,7 +85,38 @@ jobs:
7985
- name: Build
8086
run: |
8187
make -C build
82-
88+
8389
- name: Run tests
8490
run: |
8591
ctest --verbose --test-dir build
92+
93+
- name: Install lcov
94+
if: matrix.build_type == 'Coverage'
95+
run: sudo apt-get -y install lcov
96+
97+
- name: Generate coverage report
98+
if: matrix.build_type == 'Coverage'
99+
run: |
100+
# 1. Capture coverage data from the build directory
101+
# lcov finds all the .gcno and .gcda files
102+
lcov --capture --directory build/ --output-file coverage.info
103+
104+
# 2. Filter to *only* include the main header file
105+
# This fulfills your request to not include examples/tests
106+
lcov --extract coverage.info "*/include/nanoflann.hpp" --output-file coverage_filtered.info
107+
108+
# 3. Print a summary to the console log for easy debugging
109+
echo "--- Coverage Summary for nanoflann.hpp ---"
110+
lcov --list coverage_filtered.info
111+
echo "------------------------------------------"
112+
113+
- name: Upload coverage to Codecov
114+
if: matrix.build_type == 'Coverage'
115+
uses: codecov/codecov-action@v4
116+
with:
117+
# The token is required for private repos, but recommended for all
118+
token: ${{ secrets.CODECOV_TOKEN }}
119+
# Path to the filtered report
120+
files: ./coverage_filtered.info
121+
# Optional name for this upload in the Codecov UI
122+
name: codecov-ubuntu-24.04

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ if (CMAKE_COMPILER_IS_GNUCXX)
2525
# The -Wno-long-long is required in 64bit systems when including sytem headers.
2626
# The -Wno-variadic-macros was needed for Eigen3, StdVector.h
2727
add_compile_options(-Wall -Wshadow -Wno-long-long -Wno-variadic-macros)
28-
if (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
28+
29+
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage")
30+
message(STATUS "Coverage build enabled. Adding gcov flags.")
31+
# Add gcov flags, ensure no optimization (-O0), and include debug symbols (-g)
32+
add_compile_options(-g -O0 --coverage)
33+
add_link_options(--coverage)
34+
elseif (NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
35+
# Keep original logic for Release builds
2936
add_compile_options(-O2 -mtune=native)
3037
endif()
38+
3139
# Workaround: Eigen <3.4 produces *tons* of warnings in GCC >=6. See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1221
3240
if (NOT ${CMAKE_CXX_COMPILER_VERSION} LESS "6.0")
3341
add_compile_options(-Wno-ignored-attributes -Wno-int-in-bool-context)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![CI Check clang-format](https://github.com/jlblancoc/nanoflann/actions/workflows/check-clang-format.yml/badge.svg)](https://github.com/jlblancoc/nanoflann/actions/workflows/check-clang-format.yml)
66
[![CircleCI](https://circleci.com/gh/jlblancoc/nanoflann/tree/master.svg?style=svg)](https://circleci.com/gh/jlblancoc/nanoflann/tree/master)
77
[![Windows build status](https://ci.appveyor.com/api/projects/status/h8k1apfogxyqhskd/branch/master?svg=true)](https://ci.appveyor.com/project/jlblancoc/nanoflann/branch/master)
8+
[![codecov](https://codecov.io/gh/jlblancoc/nanoflann/graph/badge.svg?token=yOKq5lpizE)](https://codecov.io/gh/jlblancoc/nanoflann)
89

910

1011
## 1. About

0 commit comments

Comments
 (0)