diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d3591572..e2d96df1 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 + SIMPLE DAG RUN + 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,42 @@ 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 + ctest --output-on-failure --output-junit test_results.xml + + # Capture coverage ONLY from include/ + lcov --capture --directory . \ + --output-file coverage.info \ + --ignore-errors empty,mismatch \ + --include '*/OneStopParallel/include/*' + + # 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 + + - 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 84c5327a..bb0e0ae0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +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 (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") + add_compile_options(--coverage -g) + add_link_options(--coverage) +endif() + # Configure git hooks add_subdirectory(.githooks) @@ -102,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 >