diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 99185bd..90e5b5d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -29,10 +29,14 @@ jobs: sudo apt-get install -y can-utils iproute2 linux-modules-extra-$(uname -r) sudo apt-get install -y python3 python3-pybind11 sudo apt-get install -y libboost-all-dev libgmock-dev libgtest-dev + - name: Install gcovr + run: | + sudo apt-get update + sudo apt-get install -y gcovr - name: Create build folder run: mkdir ${GITHUB_WORKSPACE}/build - name: Run CMake - run: cmake -B ${GITHUB_WORKSPACE}/build -S ${GITHUB_WORKSPACE} -D PYTHON_BINDINGS=on -D BUILD_TESTING=on + run: cmake -B ${GITHUB_WORKSPACE}/build -S ${GITHUB_WORKSPACE} -D PYTHON_BINDINGS=on -D BUILD_TESTING=on -D ENABLE_COVERAGE=on - name: Compile with Make run: make -j $(nproc) -C ${GITHUB_WORKSPACE}/build - name: Set-up virtual CAN interface for loopback tests @@ -42,8 +46,14 @@ jobs: sudo ip link set up ${VCAN_IFNAME} - name: Run tests run: (cd ${GITHUB_WORKSPACE}/build && ctest) + - name: Generate code coverage report + run: gcovr -j $(nproc) --filter ${GITHUB_WORKSPACE}/include --filter ${GITHUB_WORKSPACE}/src --print-summary --xml-pretty --xml ${GITHUB_WORKSPACE}/build/coverage.xml + - name: Update Codecov code coverage report + uses: codecov/codecov-action@v4 + with: + files: ${GITHUB_WORKSPACE}/build/coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} - name: Remove virtual CAN interface run: | sudo ip link set down ${VCAN_IFNAME} sudo ip link delete ${VCAN_IFNAME} - diff --git a/CMakeLists.txt b/CMakeLists.txt index 658511a..f51d22c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,16 @@ option(PYTHON_BINDINGS "Building Python bindings" OFF) option(BUILD_TESTING "Build unit and integration tests" OFF) option(SETUP_TEST_IFNAME "Set-up the test VCAN interface automatically" OFF) +if (CMAKE_COMPILER_IS_GNUCC) + option(ENABLE_COVERAGE "Enable coverage reporting for GCC/Clang" OFF) + + if (ENABLE_COVERAGE) + message(STATUS "Building with coverage reporting for GCC/Clang.") + add_compile_options(--coverage -O0) + link_libraries(--coverage) + endif() +endif() + if(NOT UNIX) message(FATAL_ERROR "Currently this driver only supports Linux!") endif()