Skip to content

Commit

Permalink
[TEST] Add code coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Lydia Buntrock <[email protected]>
  • Loading branch information
Irallia committed Apr 30, 2021
1 parent d54a41d commit 93f8b50
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ jobs:
build: unit
build_type: Release

- name: "CodeCoverage"
os: ubuntu-20.04
requires_toolchain: true
requires_ccache: true
cxx: "g++-10"
cc: "gcc-10"
build: coverage
build_type: Debug

- name: "Documentation"
os: ubuntu-20.04
requires_toolchain: false
Expand Down Expand Up @@ -203,7 +212,7 @@ jobs:
if: matrix.build == 'coverage'
run: |
sudo apt-get install --yes lcov
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-7 100
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100
- name: Get cached build
if: matrix.requires_ccache
Expand All @@ -224,7 +233,11 @@ jobs:
run: |
mkdir app-build
cd app-build
cmake ../app -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
if [[ "${{ matrix.build }}" =~ ^(coverage)$ ]]; then
cmake ../app -DCODE_COVERAGE=ON -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
else
cmake ../app -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}"
fi
- name: Build tests
env:
Expand Down Expand Up @@ -252,6 +265,13 @@ jobs:
ctest . -j2 --output-on-failure
fi
- name: Run lcov
if: matrix.build == 'coverage'
run: |
lcov --directory ./app-build/ --capture --output-file ./app-build/app_coverage --gcov-tool gcov-10
lcov --remove ./app-build/app_coverage '/usr/*' "${HOME}"'/.cache/*' '*/lib/*' --output-file ./app-build/app_coverage
lcov --list ./app-build/app_coverage
- name: Submit coverage build
if: matrix.build == 'coverage'
shell: bash
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ set (FontReset "${Esc}[m")
# Dependency: SeqAn3.
find_package (SeqAn3 QUIET REQUIRED HINTS lib/seqan3/build_system)

# Code Coverage Configuration
add_library(coverage_config INTERFACE)

option(CODE_COVERAGE "Enable coverage reporting" OFF)
if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")
message (STATUS "Hallo CMAKE_CXX_COMPILER_ID")
# 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 AND CMAKE_CXX_COMPILER_ID MATCHES "GNU")

add_subdirectory (src)
message (STATUS "${FontBold}You can run `make` to build the application.${FontReset}")

Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ target_link_libraries ("${PROJECT_NAME}_lib" PUBLIC seqan3::seqan3)
target_include_directories ("${PROJECT_NAME}_lib" PUBLIC ../include)

add_executable ("${PROJECT_NAME}" main.cpp)
target_link_libraries ("${PROJECT_NAME}" "${PROJECT_NAME}_lib")
target_link_libraries ("${PROJECT_NAME}" PRIVATE "${PROJECT_NAME}_lib")

# Include code-coverage settings:
target_link_libraries("${PROJECT_NAME}" PUBLIC coverage_config)

0 comments on commit 93f8b50

Please sign in to comment.