From 3d1ef0d0497952ca974dda4d8bf62e59969fcf21 Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Fri, 20 Jun 2025 18:23:26 +0200 Subject: [PATCH] CI: added code coverage workflow --- .github/workflows/coverage.yml | 63 ++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/cmake/flags.cmake | 5 ++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..6db6f2a --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,63 @@ +name: Code coverage + +on: + push: + branches: ["master", "test"] + paths-ignore: + - 'docker-compose/**' + - 'docs/**' + - 'README.md' + + pull_request: + +jobs: + coverage: + + timeout-minutes: 60 + runs-on: ubuntu-latest + + steps: + - name: Install dependencies + run: | + sudo apt update + sudo apt install -y cmake libuv1-dev libzmq3-dev libgss-dev libcurl4-openssl-dev libidn2-0-dev lcov + + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Build tests + run: | + cd tests + mkdir build + cd build + cmake .. -DCMAKE_BUILD_TYPE=Debug -DWITH_COVERAGE=ON -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14 -DCMAKE_POLICY_VERSION_MINIMUM="3.5" + make -j$(nproc) p2pool_tests + + - name: Run tests + run: | + cd tests/build + gunzip *.gz + ./p2pool_tests + + - name: Run gcov + run: | + cd tests/build/CMakeFiles/p2pool_tests.dir/home/runner/work/p2pool/p2pool/src + gcov-14 *.gcda + + - name: Run lcov + run: | + cd tests/build/CMakeFiles/p2pool_tests.dir/home/runner/work/p2pool/p2pool/src + lcov --gcov-tool gcov-14 --directory . --capture --output-file coverage.info + + - name: Run genhtml + run: | + cd tests/build/CMakeFiles/p2pool_tests.dir/home/runner/work/p2pool/p2pool/src + genhtml --demangle-cpp -o coverage coverage.info + + - name: Archive coverage data + uses: actions/upload-artifact@v4 + with: + name: p2pool-coverage + path: tests/build/CMakeFiles/p2pool_tests.dir/home/runner/work/p2pool/p2pool/src/coverage diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6363a8d..1afd146 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,7 @@ include(cmake/standard.cmake) option(STATIC_LIBS "Use locally built libuv and libzmq static libs" OFF) option(WITH_LTO "Use link-time compiler optimization (if linking fails for you, run cmake with -DWITH_LTO=OFF)" ON) +option(WITH_COVERAGE "Generate code coverage data" OFF) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") diff --git a/tests/cmake/flags.cmake b/tests/cmake/flags.cmake index 9f5f675..a131bd4 100644 --- a/tests/cmake/flags.cmake +++ b/tests/cmake/flags.cmake @@ -3,7 +3,10 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU) set(WARNING_FLAGS "-Wall -Wextra") if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(OPTIMIZATION_FLAGS "-O0 -g3 -ftrapv") + set(OPTIMIZATION_FLAGS "-O0 -g3") + if (WITH_COVERAGE) + set(OPTIMIZATION_FLAGS "${OPTIMIZATION_FLAGS} --coverage") + endif() else() set(OPTIMIZATION_FLAGS "-O3 -ffast-math -s") if (WITH_LTO)