Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runs:
export CC=/usr/bin/gcc-13
export CXX=/usr/bin/g++-13
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DGMGPOLAR_TEST_COVERAGE=ON ..
cmake -DCMAKE_BUILD_TYPE=Debug -DGMGPOLAR_ENABLE_COVERAGE=ON ..
make -j4
- name: create build dir archive
shell: bash
Expand Down
44 changes: 22 additions & 22 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ runs:
cd build/tests
sudo chmod a+x gmgpolar_tests
./gmgpolar_tests --gtest_output="xml:testreport.xml"
# - name: Compute code coverage
# shell: bash
# # compute code coverage
# run: |
# cd build
# cmake --build . --target coverage/fast
# - name: Upload test report
# uses: actions/upload-artifact@v4
# with:
# name: test-report
# path: build/tests/testreport.xml
# if-no-files-found: error
# retention-days: 3
# - name: Upload coverage reports
# uses: actions/upload-artifact@v4
# with:
# name: test-coverage-reports
# path: |
# build/coverage.info
# build/coverage
# if-no-files-found: error
# retention-days: 1
- name: Compute code coverage
shell: bash
# compute code coverage
run: |
cd build
cmake --build . --target coverage
- name: Upload test report
uses: actions/upload-artifact@v4
with:
name: test-report
path: build/tests/testreport.xml
if-no-files-found: error
retention-days: 3
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: test-coverage-reports
path: |
build/coverage-filtered.info
build/coverage
if-no-files-found: error
retention-days: 1
36 changes: 16 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,19 @@ jobs:
with:
build-artifact: build-cpp-linux-gmgpolar

# codecov:
# if: github.event.pull_request.draft == false
# needs: [run-unit-test]
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Install dependencies
# run: |
# sudo apt-get -qq update
# sudo apt-get -qq -y install git curl
# - name: Download cpp coverage report
# uses: actions/download-artifact@v4
# with:
# name: test-coverage-reports
# - name: Deploy to codecov.io
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# files: ./coverage.info
# verbose: true
codecov:
if: github.event.pull_request.draft == false
needs: [run-unit-test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download cpp coverage report
uses: actions/download-artifact@v4
with:
name: test-coverage-reports
- name: Deploy to codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage-filtered.info
verbose: true
71 changes: 54 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
cmake_minimum_required(VERSION 3.12)
project(GMGPolar VERSION 2.0.0 LANGUAGES CXX)

# Options should be defined before they're used
option(GMGPOLAR_BUILD_TESTS "Build GMGPolar unit tests." ON)
option(GMGPOLAR_USE_LIKWID "Use LIKWID to measure code (regions)." OFF)
option(GMGPOLAR_USE_MUMPS "Use MUMPS to solve linear systems." OFF)
option(GMGPOLAR_ENABLE_COVERAGE "Enable code coverage reporting (requires GCC/Clang)" OFF)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

# Set build type - must come before compiler flags
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

# Set compiler flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -pedantic -Wno-unused -Wno-psabi")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -mtune=generic -Wno-psabi")

# code coverage analysis
# Note: this only works under linux and with make
# Ninja creates different directory names which do not work together with this scrupt
# as STREQUAL is case-sensitive https://github.com/TriBITSPub/TriBITS/issues/131, also allow DEBUG as accepted input
option(GMGPOLAR_TEST_COVERAGE "Enable GCov coverage analysis (adds a 'coverage' target)" OFF)

if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "DEBUG")
if(GMGPOLAR_TEST_COVERAGE)
message(STATUS "Coverage enabled")
include(CodeCoverage)
append_coverage_compiler_flags()
setup_target_for_coverage_lcov(
NAME coverage
EXECUTABLE tests/gmgpolar_tests
LCOV_ARGS --ignore-errors gcov,mismatch
EXCLUDE "${CMAKE_SOURCE_DIR}/tests*" "${CMAKE_SOURCE_DIR}/src/InputFunctions*" "${CMAKE_BINARY_DIR}/*" "/usr*"
)
# Set coverage compiler flags - must come before any targets are defined
if(GMGPOLAR_ENABLE_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(STATUS "Enabling code coverage flags")
# Use generator expressions to apply only to specific configurations
add_compile_options($<$<CONFIG:Debug>:--coverage>)
add_link_options($<$<CONFIG:Debug>:--coverage>)
# Force Debug build when coverage is enabled
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Forcing Debug build for coverage")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)
endif()
else()
message(WARNING "Code coverage requires GCC or Clang. Current compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()

Expand All @@ -54,4 +55,40 @@ if(GMGPOLAR_BUILD_TESTS)
enable_testing()
add_subdirectory(third-party)
add_subdirectory(tests)

# Add coverage target - moved after test configuration
if(GMGPOLAR_ENABLE_COVERAGE)
find_program(LCOV_PATH lcov)
find_program(GENHTML_PATH genhtml)

if(LCOV_PATH AND GENHTML_PATH)
add_custom_target(coverage
# Reset counters
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --zerocounters
# Run tests
COMMAND ctest --test-dir ${CMAKE_BINARY_DIR} || true
# Capture coverage data
COMMAND ${LCOV_PATH} --directory ${CMAKE_BINARY_DIR} --capture
--output-file ${CMAKE_BINARY_DIR}/coverage.info
--ignore-errors mismatch,unused
--rc geninfo_unexecuted_blocks=1
# Filter out system and unwanted directories
COMMAND ${LCOV_PATH} --remove ${CMAKE_BINARY_DIR}/coverage.info
'/usr/*'
'*/tests/*'
'*/third-party/*'
'*/_deps/googletest-src/*'
'*/include/InputFunctions/*'
'*/src/InputFunctions/*'
--output-file ${CMAKE_BINARY_DIR}/coverage-filtered.info
--ignore-errors unused
# Generate HTML report
COMMAND ${GENHTML_PATH} ${CMAKE_BINARY_DIR}/coverage-filtered.info
--output-directory ${CMAKE_BINARY_DIR}/coverage-report
--ignore-errors source
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating code coverage report"
)
endif()
endif()
endif()
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[![GMGPolarCI](https://github.com/SciCompMod/GMGPolar/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/SciCompMod/GMGPolar/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/SciCompMod/GMGPolar/graph/badge.svg?token=D0IVLUW51J)](https://codecov.io/gh/SciCompMod/GMGPolar)

GMGPolar
=======

Expand Down
Loading