From 1c783e84eb66a0e409d2e37e3ccab03bf1c1d8bd Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 2 Mar 2020 22:31:11 +0100 Subject: [PATCH] added code coverage --- .travis.yml | 14 ++++++++++++-- CMakeLists.txt | 27 +++++++++++++++++++++++++++ README.md | 1 + cmake/coverage.cmake | 30 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 cmake/coverage.cmake diff --git a/.travis.yml b/.travis.yml index d0368df..814ffb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,13 @@ addons: - ninja-build - libconfig-dev +env: + matrix: + - BUILD_TYPE=Coverage CHECK_TARGET=check + - BUILD_TYPE=Debug CHECK_TARGET=memcheck + - BUILD_TPYE=Release CHECK_TARGET=check + - BUILD_TYPE=MinSizeRel CHECK_TARGET=check + before_install: - mkdir .deps @@ -80,7 +87,10 @@ before_install: before_script: - mkdir build - cd build - - cmake .. + - cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. script: - make \ No newline at end of file + make $CHECK_TARGET + +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c97bb44..c8e6e7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(C_WARNINGS -Wall -Wextra) set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") +include(coverage) + add_library(userdb STATIC src/userdb/userdb.c ) @@ -119,4 +122,28 @@ configure_file(etc/webfused.conf webfused.conf COPYONLY) enable_testing() gtest_discover_tests(alltests TEST_PREFIX alltests:) +add_custom_target(check + ./alltests) +add_dependencies(check alltests) + +add_custom_target(memcheck + valgrind ./alltests) +add_dependencies(memcheck alltests) + +add_custom_target(coverage + mkdir -p coverage + COMMAND lcov --initial --capture --directory . --output-file coverage/lcov.info + COMMAND ./alltests + COMMAND lcov --capture --directory . --output-file coverage/lcov.info + COMMAND lcov --remove coverage/lcov.info '/usr/*' --output-file coverage/lcov.info +# COMMAND lcov --remove coverage/lcov.info '*/test/*' --output-file coverage/lcov.info +) +add_dependencies(coverage alltests) + +add_custom_target(coverage-report + COMMAND genhtml -branch-coverage --highlight --legend coverage/lcov.info --output-directory coverage/report +) +add_dependencies(coverage-report coverage) + + endif(NOT WITHOUT_TESTS) diff --git a/README.md b/README.md index 8ce0f5f..3164b7a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Build Status](https://travis-ci.org/falk-werner/webfused.svg?branch=master)](https://travis-ci.org/falk-werner/webfused) +[![codecov](https://codecov.io/gh/falk-werner/webfused/branch/config_file/graph/badge.svg)](https://codecov.io/gh/falk-werner/webfused) # webfused diff --git a/cmake/coverage.cmake b/cmake/coverage.cmake new file mode 100644 index 0000000..35b6e0e --- /dev/null +++ b/cmake/coverage.cmake @@ -0,0 +1,30 @@ +set(CMAKE_C_FLAGS_COVERAGE + "${CMAKE_C_FLAGS_DEBUG} -pg --coverage -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C compiler during coverage builds" + FORCE +) + +set(CMAKE_CXX_FLAGS_COVERAGE + "${CMAKE_CXX_FLAGS_DEBUG} -pg --coverage -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE +) + +set(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE +) + +set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE +) + +mark_as_advanced( + CMAKE_C_FLAGS_COVERAGE + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE +) \ No newline at end of file