From 1ebe8f53a0db770fe6e01972525d7d84b98dee0d Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 10:33:53 +0100 Subject: [PATCH 1/9] Add code coverage to CI workflow --- .github/workflows/main.yml | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d3591572..c20fd309 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,10 +39,10 @@ jobs: run: cmake --build . -j$(nproc) # ------------------------------------------------- - # 2. FULL BUILD + TEST + SIMPLE DAG RUN + DOCS (RelWithDebInfo + Eigen) + # 2. FULL BUILD + TEST + COVERAGE + DOCS (RelWithDebInfo + Eigen) # ------------------------------------------------- test_and_run: - name: Build & Test (RelWithDebInfo + Eigen) + name: Build, Test & Coverage (RelWithDebInfo + Eigen) runs-on: ubuntu-latest needs: build_matrix if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master' @@ -55,21 +55,38 @@ jobs: sudo apt-get update sudo apt-get install -y --no-install-recommends \ make gcc g++ git libboost-all-dev \ - doxygen graphviz python3-pip libeigen3-dev + doxygen graphviz python3-pip libeigen3-dev lcov pip3 install --upgrade pip pip3 install cmake==3.21.3 - name: Configure - run: cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON + run: cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON - name: Build all targets working-directory: ${{ github.workspace }}/build run: cmake --build . -j$(nproc) - - name: Run tests + - name: Run tests with coverage working-directory: ${{ github.workspace }}/build - run: ctest --output-on-failure --output-junit test_results.xml - continue-on-error: true + run: | + # Run tests while collecting coverage + ctest --output-on-failure --output-junit test_results.xml + + # Generate lcov report + sudo apt-get install -y lcov + lcov --capture --directory . --output-file coverage.info + + # Remove system and test files from report + lcov --remove coverage.info '/usr/*' '*/tests/*' '*/third_party/*' --output-file coverage.info + + # Generate HTML report + genhtml coverage.info --output-directory coverage_html + + - name: Upload coverage artifacts + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: build/coverage_html - name: Upload test results uses: actions/upload-artifact@v4 From 69f6e566b4cc0ac2c2ed6b530dfc89497c78afc1 Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 10:53:08 +0100 Subject: [PATCH 2/9] Correction --- .github/workflows/main.yml | 2 +- CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c20fd309..2d80e298 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,7 +74,7 @@ jobs: # Generate lcov report sudo apt-get install -y lcov - lcov --capture --directory . --output-file coverage.info + lcov --capture --directory . --output-file coverage.info --ignore-errors empty # Remove system and test files from report lcov --remove coverage.info '/usr/*' '*/tests/*' '*/third_party/*' --output-file coverage.info diff --git a/CMakeLists.txt b/CMakeLists.txt index 84c5327a..a2db9d05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,21 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Ensure C++17 standard is strictly enforced +# --- Code Coverage Configuration --- +option(ENABLE_COVERAGE "Enable code coverage flags" OFF) + +if(ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + message(STATUS "Code coverage enabled: adding --coverage flags") + add_compile_options(--coverage -O0 -g) + add_link_options(--coverage) +endif() + +# --- Override RelWithDebInfo flags when coverage is enabled --- +if(ENABLE_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + message(STATUS "Forcing Debug-like flags for RelWithDebInfo due to coverage") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O0 -g --coverage") +endif() + # Configure git hooks add_subdirectory(.githooks) From f908b6d93d97ece99d1d92d1d4e5af068a62663e Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 11:06:35 +0100 Subject: [PATCH 3/9] Ignoring geninfo mismatch issues --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2d80e298..6a2a419d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -74,7 +74,7 @@ jobs: # Generate lcov report sudo apt-get install -y lcov - lcov --capture --directory . --output-file coverage.info --ignore-errors empty + lcov --capture --directory . --output-file coverage.info --ignore-errors empty,mismatch # Remove system and test files from report lcov --remove coverage.info '/usr/*' '*/tests/*' '*/third_party/*' --output-file coverage.info From 05f046c2586a35631752d6e9c7aacb22084fb5fb Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 11:17:13 +0100 Subject: [PATCH 4/9] Test coverage only for files under include directory --- .github/workflows/main.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a2a419d..8a41f97a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,16 +72,20 @@ jobs: # Run tests while collecting coverage ctest --output-on-failure --output-junit test_results.xml - # Generate lcov report - sudo apt-get install -y lcov - lcov --capture --directory . --output-file coverage.info --ignore-errors empty,mismatch + # Generate lcov report ONLY for OneStopParallel/include + lcov --capture --directory . \ + --output-file coverage.info \ + --ignore-errors empty,mismatch \ + --include '*/OneStopParallel/include/*' - # Remove system and test files from report - lcov --remove coverage.info '/usr/*' '*/tests/*' '*/third_party/*' --output-file coverage.info + # Clean report (strip system + tests + apps if we want) + lcov --remove coverage.info '/usr/*' '*/tests/*' '*/apps/*' \ + --output-file coverage.info # Generate HTML report genhtml coverage.info --output-directory coverage_html + - name: Upload coverage artifacts uses: actions/upload-artifact@v4 with: From 5e686cd48073badfa8294a5a3ff6114f6bc54968 Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 11:31:23 +0100 Subject: [PATCH 5/9] Suppressing unused lcov exclude warnings --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8a41f97a..d8f4ac5f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,23 +69,23 @@ jobs: - name: Run tests with coverage working-directory: ${{ github.workspace }}/build run: | - # Run tests while collecting coverage ctest --output-on-failure --output-junit test_results.xml - # Generate lcov report ONLY for OneStopParallel/include + # Capture coverage ONLY from include/ lcov --capture --directory . \ --output-file coverage.info \ --ignore-errors empty,mismatch \ --include '*/OneStopParallel/include/*' - # Clean report (strip system + tests + apps if we want) - lcov --remove coverage.info '/usr/*' '*/tests/*' '*/apps/*' \ - --output-file coverage.info + # Remove unused warnings: this is the KEY fix + lcov --ignore-errors unused,empty,mismatch --remove coverage.info '*/tests/*' '*/apps/*' --output-file coverage.info + + # Optional: silence header template warnings + geninfo --rc geninfo_unexecuted_blocks=1 coverage.info # Generate HTML report genhtml coverage.info --output-directory coverage_html - - name: Upload coverage artifacts uses: actions/upload-artifact@v4 with: From 7f344d986fd044213ce6e57381112d9ed32ae199 Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 11:41:22 +0100 Subject: [PATCH 6/9] Removing invalid geninfo call --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d8f4ac5f..3df68e4f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -69,6 +69,7 @@ jobs: - name: Run tests with coverage working-directory: ${{ github.workspace }}/build run: | + # Run tests ctest --output-on-failure --output-junit test_results.xml # Capture coverage ONLY from include/ @@ -77,11 +78,10 @@ jobs: --ignore-errors empty,mismatch \ --include '*/OneStopParallel/include/*' - # Remove unused warnings: this is the KEY fix - lcov --ignore-errors unused,empty,mismatch --remove coverage.info '*/tests/*' '*/apps/*' --output-file coverage.info - - # Optional: silence header template warnings - geninfo --rc geninfo_unexecuted_blocks=1 coverage.info + # Remove unused warnings + ignore tests/apps + lcov --remove coverage.info '*/tests/*' '*/apps/*' \ + --ignore-errors unused,empty,mismatch \ + --output-file coverage.info # Generate HTML report genhtml coverage.info --output-directory coverage_html From 01b4d70eac9ca6dd026b9d78a9789ce7859e7bc9 Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 14:08:10 +0100 Subject: [PATCH 7/9] Small corrections --- .github/workflows/main.yml | 2 +- CMakeLists.txt | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3df68e4f..e2d96df1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,7 +39,7 @@ jobs: run: cmake --build . -j$(nproc) # ------------------------------------------------- - # 2. FULL BUILD + TEST + COVERAGE + DOCS (RelWithDebInfo + Eigen) + # 2. FULL BUILD + TEST + SIMPLE DAG RUN + COVERAGE + DOCS (RelWithDebInfo + Eigen) # ------------------------------------------------- test_and_run: name: Build, Test & Coverage (RelWithDebInfo + Eigen) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2db9d05..0453654d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,21 +25,15 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) # Ensure C++17 standard is strictly enforced -# --- Code Coverage Configuration --- +# --- Code Coverage (optional) --- option(ENABLE_COVERAGE "Enable code coverage flags" OFF) if(ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") - message(STATUS "Code coverage enabled: adding --coverage flags") + message(STATUS "Code coverage enabled") add_compile_options(--coverage -O0 -g) add_link_options(--coverage) endif() -# --- Override RelWithDebInfo flags when coverage is enabled --- -if(ENABLE_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - message(STATUS "Forcing Debug-like flags for RelWithDebInfo due to coverage") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O0 -g --coverage") -endif() - # Configure git hooks add_subdirectory(.githooks) From a7adf79ac6d55eca6e9eda153fda991e78345db6 Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 16:06:55 +0100 Subject: [PATCH 8/9] Remove optimization flag --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0453654d..39c9543a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ option(ENABLE_COVERAGE "Enable code coverage flags" OFF) if(ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") message(STATUS "Code coverage enabled") - add_compile_options(--coverage -O0 -g) + add_compile_options(--coverage -g) add_link_options(--coverage) endif() From 51496b561b5443ed4647e4361ffbe833b9a2d55e Mon Sep 17 00:00:00 2001 From: Christos Konstantinos Matzoros Date: Thu, 20 Nov 2025 16:22:00 +0100 Subject: [PATCH 9/9] add -DNDEBUG with RelWithDebInfo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39c9543a..bb0e0ae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,7 @@ target_compile_options(ProjectExecutableFlags INTERFACE # Else (not Debug) $, # RelWithDebInfo flags - -O3;-g, + -O3;-g;-DNDEBUG, # Release and other/custom flags -O3;-DNDEBUG >