From 1d0f402d5b860ea6bb900597e9c030e686fb17de Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 17:30:36 -0400 Subject: [PATCH 01/10] Generate baseline coverage before running tests --- .github/actions/coverage_epilogue/action.yml | 31 +++++++++++++++----- .github/actions/coverage_prologue/action.yml | 23 +++++++++++++++ .github/workflows/cmake-multi-platform.yml | 5 ++++ CMakePresets.json | 4 +-- 4 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 .github/actions/coverage_prologue/action.yml diff --git a/.github/actions/coverage_epilogue/action.yml b/.github/actions/coverage_epilogue/action.yml index f5de5588..bd07aadc 100644 --- a/.github/actions/coverage_epilogue/action.yml +++ b/.github/actions/coverage_epilogue/action.yml @@ -10,18 +10,32 @@ inputs: runs: using: "composite" steps: - - name: "Install lcov" - shell: bash - run: | - sudo apt-get update - sudo apt-get install -y lcov - - name: Generate Coverage Report shell: bash run: | - lcov --capture --directory ${{ inputs.build-output-dir }} --output-file coverage.info --ignore-errors mismatch - lcov --remove coverage.info '/usr/*' '*/_deps/*' '*/include/bitlib/bit-algorithms/libpopcnt.h' '*/test/inc/*' '*/test/src/*' --output-file coverage.info + # Capture actual coverage data after tests + lcov --capture \ + --directory "${{ inputs.build-output-dir }}" \ + --output-file coverage.info \ + --ignore-errors mismatch + + # Combine with baseline + lcov --add-tracefile coverage.baseline \ + --add-tracefile coverage.info\ + --output-file coverage.info + + # Clean the coverage report from system and external deps + lcov --remove coverage.merged.info \ + '/usr/*' \ + '*/_deps/*' \ + '*/include/bitlib/bit-algorithms/libpopcnt.h' \ + '*/test/inc/*' \ + '*/test/src/*' \ + --output-file coverage.info + + # Show a summary in the logs lcov --list coverage.info + # Generate an HTML report genhtml coverage.info --output-directory out/coverage @@ -31,6 +45,7 @@ runs: name: coverage-report path: | out/coverage + coverage.baseline coverage.info - name: Coveralls diff --git a/.github/actions/coverage_prologue/action.yml b/.github/actions/coverage_prologue/action.yml new file mode 100644 index 00000000..1bdf3f0e --- /dev/null +++ b/.github/actions/coverage_prologue/action.yml @@ -0,0 +1,23 @@ +name: "Coverage Prologue" +description: "Installs lcov and generates the baseline coverage" +inputs: + build-output-dir: + required: true + description: 'Build output directory' + +runs: + using: "composite" + steps: + - name: "Install lcov" + shell: bash + run: | + sudo apt-get update + sudo apt-get install -y lcov + + - name: "Initialize 0% coverage baseline" + shell: bash + run: | + lcov --capture --initial \ + --base-directory "$GITHUB_WORKSPACE" \ + --directory "${{ inputs.build-output-dir }}" \ + --output-file coverage.baseline diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 8b8cf439..d0deabd5 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -115,6 +115,11 @@ jobs: - name: Unregister Compiler Problem Matcher run: echo "::remove-matcher owner=${{ matrix.compiler}}::" + - uses: ./.github/actions/coverage_prologue + if: matrix.preset == 'coverage' + with: + build-output-dir: ${{ steps.strings.outputs.build-output-dir }} + - name: Test # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail diff --git a/CMakePresets.json b/CMakePresets.json index 1a4cebb9..a09aafee 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -41,8 +41,8 @@ "name": "gnu_base", "hidden": true, "cacheVariables": { - "CMAKE_C_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline", - "CMAKE_CXX_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -DPOPCNT_NO_UNALIGNED -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline", + "CMAKE_C_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline -fno-inline-small-functions -fno-default-inline -fkeep-inline-functions", + "CMAKE_CXX_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -DPOPCNT_NO_UNALIGNED -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline -fno-inline-small-functions -fno-default-inline -fkeep-inline-functions", "CMAKE_C_FLAGS_RELEASE": "-O3 -DNDEBUG -march=native", "CMAKE_CXX_FLAGS_RELEASE": "-O3 -DNDEBUG -march=native" } From b9791a1c95ae9f9b083ea0c7a09d9e8b7f6e920b Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 17:38:30 -0400 Subject: [PATCH 02/10] Hunt and peck failing gcc inline flag --- CMakePresets.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index a09aafee..d17d5ed2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -41,8 +41,8 @@ "name": "gnu_base", "hidden": true, "cacheVariables": { - "CMAKE_C_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline -fno-inline-small-functions -fno-default-inline -fkeep-inline-functions", - "CMAKE_CXX_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -DPOPCNT_NO_UNALIGNED -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline -fno-inline-small-functions -fno-default-inline -fkeep-inline-functions", + "CMAKE_C_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline -fno-inline-small-functions -fno-default-inline", + "CMAKE_CXX_FLAGS_DEBUG": "-DPOPCNT_NO_UNALIGNED -g3 -fno-omit-frame-pointer -DPOPCNT_NO_UNALIGNED -fstack-protector-all -fsanitize=address -fsanitize=undefined -finstrument-functions -fno-inline -fno-inline-small-functions -fno-default-inline", "CMAKE_C_FLAGS_RELEASE": "-O3 -DNDEBUG -march=native", "CMAKE_CXX_FLAGS_RELEASE": "-O3 -DNDEBUG -march=native" } From c1136cb6a308356756253f1a6d2dbbdb8d35cb70 Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 17:47:36 -0400 Subject: [PATCH 03/10] ignore mismatch on baseline --- .github/actions/coverage_prologue/action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/actions/coverage_prologue/action.yml b/.github/actions/coverage_prologue/action.yml index 1bdf3f0e..0aea436c 100644 --- a/.github/actions/coverage_prologue/action.yml +++ b/.github/actions/coverage_prologue/action.yml @@ -20,4 +20,5 @@ runs: lcov --capture --initial \ --base-directory "$GITHUB_WORKSPACE" \ --directory "${{ inputs.build-output-dir }}" \ - --output-file coverage.baseline + --output-file coverage.baseline \ + --ignore-errors mismatch From 5419288529829e75e562ecbddc637d3397a3ddd7 Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 17:52:49 -0400 Subject: [PATCH 04/10] Move build so it's easier to generate baseline without --- .github/workflows/cmake-multi-platform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index d0deabd5..69417f87 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -93,7 +93,7 @@ jobs: id: strings shell: bash run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + echo "build-output-dir=${{ github.workspace }}/../build" >> "$GITHUB_OUTPUT" - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. From ca6d5bafcc413a6045cb07d7875a4ea46bc95705 Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 17:58:22 -0400 Subject: [PATCH 05/10] Clean checkout --- .github/workflows/cmake-multi-platform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 69417f87..a2042c01 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -76,6 +76,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + clean: true - name: "Install Clang 19" if: matrix.os == 'linux' && matrix.c_compiler == 'clang-19' From ddaa466a8ac9f70319a5015053bfdc19e0015522 Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 18:51:51 -0400 Subject: [PATCH 06/10] Clean any cmake probing files that create coverage --- .github/workflows/cmake-multi-platform.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index a2042c01..36ef056f 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -76,8 +76,6 @@ jobs: steps: - uses: actions/checkout@v4 - with: - clean: true - name: "Install Clang 19" if: matrix.os == 'linux' && matrix.c_compiler == 'clang-19' @@ -100,13 +98,17 @@ jobs: - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} -S ${{ github.workspace }} - --preset=${{ matrix.preset }}_${{ matrix.os }}_${{ matrix.compiler }}_${{ matrix.stdlib }} - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + run: | + # Configure + cmake -B ${{ steps.strings.outputs.build-output-dir }} -S ${{ github.workspace }} \ + --preset=${{ matrix.preset }}_${{ matrix.os }}_${{ matrix.compiler }}_${{ matrix.stdlib }} \ + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} \ + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} \ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + # Delete any coverage files created from CMake probing + find ${{ github.workspace }} -name '*.gcno' -delete + - name: Register Compiler Problem Matcher run: echo "::add-matcher::.github/problem_matchers/${{ matrix.compiler}}_problem_matcher.json" From 4b4d3e3bde17a978eb5898c9babef703e4a82f07 Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 18:56:39 -0400 Subject: [PATCH 07/10] Try both gcna gcno clean before build --- .github/workflows/cmake-multi-platform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 36ef056f..4f0a63d4 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -107,7 +107,7 @@ jobs: -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} # Delete any coverage files created from CMake probing - find ${{ github.workspace }} -name '*.gcno' -delete + find ${{ github.workspace }} \( -name '*.gcno' -o -name '*.gcda' \) -delete - name: Register Compiler Problem Matcher run: echo "::add-matcher::.github/problem_matchers/${{ matrix.compiler}}_problem_matcher.json" From cfd7e29e60d123435b5fdbf343a95e195ebf34fe Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 19:00:01 -0400 Subject: [PATCH 08/10] Post configure clean up build dir too --- .github/workflows/cmake-multi-platform.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 4f0a63d4..7aec9ee8 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -108,6 +108,7 @@ jobs: # Delete any coverage files created from CMake probing find ${{ github.workspace }} \( -name '*.gcno' -o -name '*.gcda' \) -delete + find ${{ steps.strings.outputs.build-output-dir }} \( -name '*.gcno' -o -name '*.gcda' \) -delete - name: Register Compiler Problem Matcher run: echo "::add-matcher::.github/problem_matchers/${{ matrix.compiler}}_problem_matcher.json" From 538a29bbf44232e500658dfc01ca414d8bb4ac15 Mon Sep 17 00:00:00 2001 From: Peter McLean Date: Sun, 11 May 2025 19:09:15 -0400 Subject: [PATCH 09/10] Typo --- .github/actions/coverage_epilogue/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/coverage_epilogue/action.yml b/.github/actions/coverage_epilogue/action.yml index bd07aadc..12c373b8 100644 --- a/.github/actions/coverage_epilogue/action.yml +++ b/.github/actions/coverage_epilogue/action.yml @@ -25,7 +25,7 @@ runs: --output-file coverage.info # Clean the coverage report from system and external deps - lcov --remove coverage.merged.info \ + lcov --remove coverage.info \ '/usr/*' \ '*/_deps/*' \ '*/include/bitlib/bit-algorithms/libpopcnt.h' \ From b072934b479e9bddbe768ae2fc0d2dede4fe36f9 Mon Sep 17 00:00:00 2001 From: PeterCDMcLean Date: Sun, 11 May 2025 19:30:52 -0400 Subject: [PATCH 10/10] set build dir to absolute --- .github/workflows/cmake-multi-platform.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 7aec9ee8..d3e327f1 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -93,8 +93,8 @@ jobs: id: strings shell: bash run: | - echo "build-output-dir=${{ github.workspace }}/../build" >> "$GITHUB_OUTPUT" - + echo "build-output-dir=$(readlink -f "${{ github.workspace }}/../build")" >> "$GITHUB_OUTPUT" + - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type