diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b70a275..ef15e94 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 @@ -34,10 +37,10 @@ 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 @@ -45,7 +48,7 @@ jobs: - 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index a3565ad..18ceb5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index 5d846ce..609cb53 100644 --- a/README.md +++ b/README.md @@ -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