Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-24.04]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
Expand All @@ -19,13 +22,13 @@ jobs:
sudo apt-get install -y cmake build-essential libgtest-dev lcov

- name: Configure & build (with coverage)
run: cmake -S . -B build \
run: |
cmake -S . -B build \
-DENABLE_COVERAGE=ON \
-DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=Debug

- name: Build
run: cmake --build build --parallel
cmake --build build --parallel

- name: Zero coverage counters
run: lcov -d build -z
Expand All @@ -34,18 +37,18 @@ jobs:
run: ctest --test-dir build --output-on-failure

- name: Capture coverage
run: lcov -d build -c -o coverage.info
run: lcov -c -d build/CMakeFiles/capancdt_proximity_sensor_lib.dir/src -o coverage.info

- name: Filter coverage
run: lcov -r coverage.info '/usr/*' '*/test/*' -o coverage.filtered.info
run: lcov --ignore-errors unused -r coverage.info '/usr/*' '*/test/*' -o coverage.filtered.info

- name: Generate HTML report
run: genhtml coverage.filtered.info --output-directory coverage-report

- name: Upload coverage-report
uses: actions/upload-artifact@v4
with:
name: coverage-report
name: coverage-report-${{ matrix.os }}
path: coverage-report

- name: Upload coverage reports to Codecov
Expand Down
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ project(capancdt_proximity_sensor_lib LANGUAGES CXX)

option(ENABLE_COVERAGE "Enable coverage reporting" OFF)
if(ENABLE_COVERAGE)
message(STATUS "Building with coverage support")
# GCC/Clang coverage instrumentation
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -O0 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -O0 -g")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
message(STATUS "Building with coverage instrumentation")
set(COVERAGE_FLAGS "--coverage -O0 -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ Install GTest and lcov for testing. On ubuntu you can do this with:
sudo apt-get install libgtest-dev lcov
```

You may need to build GTest:

```bash
cd /usr/src/googletest
sudo cmake .
sudo make
sudo make install
```

Build the project:

```bash
Expand Down