Skip to content
Merged

Test #26

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
67 changes: 67 additions & 0 deletions .github/workflows/CodeCov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CodeCoverage Report

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug

jobs:
build_and_generate_report:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: true
token: ${{ secrets.TOKEN }}
fetch-depth: 0

- name: Update apt-get
run: sudo apt-get update

# LCOV
- name: Install lcov
run: sudo apt-get install lcov

# CODECOV
- name: Install codecov
shell: bash
run: sudo pip install codecov

- name: Setup cache
uses: mikehardy/buildcache-action@v1
if: matrix.config.os != 'windows-latest'
with:
cache_key: codecov

- name: Configure CMake
env:
CC: gcc-10
CXX: g++-10
run: cmake -B ${{github.workspace}}/build -DAUTOTESTS=1 -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=buildcache -DCMAKE_CXX_COMPILER_LAUNCHER=buildcache -DCODE_COVERAGE=1

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel 4

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}

# CODE COVERAGE
- name: Code coverage - Capture coverage info
working-directory: ${{runner.workspace}}
run: lcov --directory ${{github.workspace}} --capture --output-file coverage.info
- name: Code coverage - Filter out system, external, and unit test source files
working-directory: ${{runner.workspace}}
run: lcov --remove coverage.info '/usr/*' "${HOME}"'/.cache/*' '*/tests/*' '*/submodules/*' --output-file coverage.info
- name: Code coverage - Output coverage data for debugging
working-directory: ${{runner.workspace}}
run: lcov --list coverage.info
- name: Code coverage - Upload to CodeCov
working-directory: ${{runner.workspace}}
run: bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
27 changes: 17 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,23 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(TEST_RESULTS_DIR ${CMAKE_BINARY_DIR}/test_results)
set(BUILD_TESTS ON CACHE BOOL "Enable unit tests building" FORCE)

# if (AUTOTESTS AND MSVC)
# # PDB debug information is not supported by buildcache.
# # Store debug info in the object files.
# string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
# string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
# string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
# string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
# string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
# string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
# endif()
# Code Coverage Configuration
add_library(coverage_config INTERFACE)

option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE)
# Add required flags (GCC & LLVM/Clang)
target_compile_options(coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(coverage_config INTERFACE --coverage)
else()
target_link_libraries(coverage_config INTERFACE --coverage)
endif()
endif(CODE_COVERAGE)


# ================== TESTS ==================
Expand Down
1 change: 1 addition & 0 deletions src/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ file(GLOB_RECURSE FILES "*.h")
add_library(rpp INTERFACE ${FILES})
target_sources(rpp INTERFACE ${FILES})
target_include_directories(rpp INTERFACE .)
target_link_libraries(rpp INTERFACE coverage_config)

foreach(FILE ${FILES})
get_filename_component(PARENT_DIR "${FILE}" PATH)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_executable(${TARGET}
copy_count_tracker.h
)

target_link_libraries(${TARGET} PRIVATE rpp Catch2WithMain)
target_link_libraries(${TARGET} PRIVATE rpp Catch2WithMain coverage_config)

set_target_properties(${TARGET} PROPERTIES FOLDER Tests)

Expand Down