diff --git a/.github/workflows/ut-backup.yml b/.github/workflows/ut-backup.yml index df8db2cb..620fe46c 100644 --- a/.github/workflows/ut-backup.yml +++ b/.github/workflows/ut-backup.yml @@ -21,6 +21,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: InstallLcov + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends lcov + - name: Build run: | mkdir build && cd build @@ -51,3 +56,16 @@ jobs: set -e cd build && make pylib-copy mpirun --allow-run-as-root -tag-output -np 8 $(which pytest) ../python/test/test_mscclpp.py -x + + - name: ReportCoverage + run: | + cd build + lcov --capture --directory . --output-file coverage.info + lcov --remove coverage.info \ + '/usr/*' \ + '/tmp/*' \ + '*/python/*' \ + '*/test/*' \ + '*/tools/*' \ + --output-file coverage.info + lcov --list coverage.info diff --git a/CMakeLists.txt b/CMakeLists.txt index 2aef18aa..ba67bc94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,18 @@ set(CMAKE_CUDA_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wall,-Wextra") +# Code coverage from https://github.com/codecov/example-cpp11-cmake +add_library(coverage_config INTERFACE) +if(CMAKE_BUILD_TYPE MATCHES "Debug" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + # Add required flags (GCC & LLVM/Clang) + target_compile_options(coverage_config INTERFACE + -O0 # no optimization + -g # generate debug info + --coverage # sets all required flags + ) + target_link_options(coverage_config INTERFACE --coverage) +endif() + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) # Format targets