From f85f633346928fa5572be3fe22af88c283ae46c4 Mon Sep 17 00:00:00 2001 From: Jamie Westell Date: Sun, 28 Feb 2021 14:19:24 -0800 Subject: [PATCH] chore(travis): add code coverage report generation This change adds a cmake configuration switch to enable code coverage instrumentation during the compilation of the project. When tests are executed, the instrumentation outputs coverage data to output files in the build directory. Programs such as lcov/gcovr can turn that data into reports. This change also adds steps to the travis CI configuration to build with this configuration switch and then use lcov to generate the consolidated report and publish to codecov.io --- .travis.yml | 11 +++++++++++ .travis/build-ubuntu-16-04.sh | 8 +++++++- CMakeLists.txt | 17 ++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 86a96f0c2..8fd7dc8da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,7 +45,18 @@ jobs: - stage: Linux os: linux env: JOB=build-ubuntu-16-04 + addons: + apt: + packages: + - lcov script: "./.travis/$JOB.sh" + after_success: + # Create lcov report + - lcov --directory _debug --capture --output-file coverage.info + # Filter out system headers and test sources + - lcov --remove coverage.info '/usr/*' '*/test/*' '*/*_autogen/*' --output-file coverage.info + # Upload report to codecov.io + - bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports" - stage: "Windows Stage 1: Dependencies (OpenSSL, Qt)" os: linux # Makes the cache this job creates avaiable only to jobs with WINDOWS_BUILD_ARCH_CACHE_TRICK_VARIABLE=i686, diff --git a/.travis/build-ubuntu-16-04.sh b/.travis/build-ubuntu-16-04.sh index d1387140f..eec44e3c9 100755 --- a/.travis/build-ubuntu-16-04.sh +++ b/.travis/build-ubuntu-16-04.sh @@ -203,9 +203,15 @@ build_qtox() { } test_qtox() { - local BUILDDIR=_build + local BUILDDIR=_debug + + cmake -H. -B"$BUILDDIR" \ + -DUPDATE_CHECK=ON \ + -DSTRICT_OPTIONS=ON \ + -DCODE_COVERAGE=ON cd $BUILDDIR + make -j$(nproc) make test cd - } diff --git a/CMakeLists.txt b/CMakeLists.txt index 74e556f8a..fc971f8fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -579,6 +579,20 @@ MESSAGE( STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS} ) # the compiler flags for compiling C++ sources MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} ) +# Interface library to propagate code coverage flags if enabled +add_library(coverage_config INTERFACE) +option(CODE_COVERAGE "Enable coverage reporting" OFF) +if (CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(coverage_config INTERFACE -O0 -g --coverage) + 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() + +link_libraries(coverage_config) + add_subdirectory(util) add_subdirectory(audio) add_subdirectory(translations) @@ -589,7 +603,8 @@ add_library(${PROJECT_NAME}_static ${${PROJECT_NAME}_SOURCES}) target_link_libraries(${PROJECT_NAME}_static ${CMAKE_REQUIRED_LIBRARIES} - ${ALL_LIBRARIES}) + ${ALL_LIBRARIES} + coverage_config) target_link_libraries(${PROJECT_NAME}_static util_library) target_link_libraries(${PROJECT_NAME}_static audio_library)