Skip to content
Snippets Groups Projects
Commit 0f4d3b79 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Code transition from gcovr to the more classical lcov interface

This is freely inspired/adapted from https://github.com/MASCOTNUM/libKriging
Thanks @hpwfx
parent 4fb917ed
Branches
Tags
1 merge request!24Feature/back to lcov
...@@ -226,45 +226,56 @@ add_custom_target(run_unit_tests ...@@ -226,45 +226,56 @@ add_custom_target(run_unit_tests
# unit tests coverage # unit tests coverage
if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage") if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage")
find_program(GCOVR gcovr) find_program(LCOV lcov)
if(NOT GCOVR) if(NOT LCOV)
message(FATAL_ERROR "gcovr not found, cannot perform coverage.") message(FATAL_ERROR "lcov not found, cannot perform coverage.")
endif() endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set (LCOV_REMOVE_PATTERN
string(REPLACE "clang++" "llvm-cov" LLVM_COV "${CMAKE_CXX_COMPILER}") )
if(NOT EXISTS "${LLVM_COV}")
message(FATAL_ERROR "could not find ${LLVM_COV}, cannot perform coverage (using g++ for coverage is recommended).")
endif()
set(GCOVR_EXTRA "--gcov-executable=${LLVM_COV} gcov") add_custom_target(coverage
endif() ALL # in coverage mode we do coverage!
# Cleanup previously generated profiling data
COMMAND ${LCOV} -q --base-directory "${PUGS_SOURCE_DIR}/src" --directory "${PUGS_BINARY_DIR}" --zerocounters
# Initialize profiling data with zero coverage for every instrumented line of the project
# This way the percentage of total lines covered will always be correct, even when not all source code files were loaded during the test(s)
COMMAND ${LCOV} -q --base-directory "${PUGS_SOURCE_DIR}/src" --directory "${PUGS_BINARY_DIR}" --capture --initial --output-file coverage_base.info
# Run tests
COMMAND ${CMAKE_CTEST_COMMAND} -j ${PROCESSOR_COUNT}
# Collect data from executions
COMMAND ${LCOV} --base-directory "${PUGS_SOURCE_DIR}/src" --directory "${PUGS_BINARY_DIR}" --capture --output-file coverage_ctest.info
# Combine base and ctest results
COMMAND ${LCOV} -q --add-tracefile coverage_base.info --add-tracefile coverage_ctest.info --output-file coverage_full.info
# Extract only project data (--no-capture or --remove options may be used to select collected data)
COMMAND ${LCOV} -q --extract coverage_full.info "'${PUGS_SOURCE_DIR}/src/*'" --output-file coverage_extract.info
set (GCOVR_EXCLUDE # Remove unwanted stuff
-e "${PUGS_SOURCE_DIR}/src/main.cpp" COMMAND ${LCOV} --remove coverage_extract.info --output-file coverage.info
-e "${PUGS_SOURCE_DIR}/src/utils/BacktraceManager.cpp" '${PUGS_SOURCE_DIR}/src/main.cpp'
-e "${PUGS_SOURCE_DIR}/src/utils/BacktraceManager.hpp" '${PUGS_SOURCE_DIR}/utils/BacktraceManager.*'
)
set(GCOVR_OPTIONS --object-directory="${PUGS_BINARY_DIR}" -r "${PUGS_SOURCE_DIR}/src" ${GCOVR_EXCLUDE} ${GCOVR_EXTRA}) COMMAND ${LCOV} --list coverage.info
add_custom_target(coverage DEPENDS unit_tests mpi_unit_tests
ALL COMMENT "Running test coverage."
COMMAND ${GCOVR} ${GCOVR_OPTIONS} --exclude-unreachable-branches --sort-percentage WORKING_DIRECTORY "${PUGS_BINARY_DIR}"
DEPENDS run_unit_tests pugs
COMMENT "Running gcovr to build coverage report."
) )
find_program(GENHTML genhtml)
if(NOT GENHTML)
message(WARNING "genhtml not found, cannot perform report-coverage.")
else()
add_custom_target(coverage-report add_custom_target(coverage-report
ALL ALL
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PUGS_BINARY_DIR}/coverage" COMMAND ${CMAKE_COMMAND} -E remove_directory "${PUGS_BINARY_DIR}/coverage"
COMMAND ${CMAKE_COMMAND} -E make_directory "${PUGS_BINARY_DIR}/coverage" COMMAND ${CMAKE_COMMAND} -E make_directory "${PUGS_BINARY_DIR}/coverage"
COMMAND ${GCOVR} ${GCOVR_OPTIONS} --delete --html --html-details -o "${PUGS_BINARY_DIR}/coverage/index.html" COMMAND ${GENHTML} -q -o coverage -t "${CMAKE_PROJECT_NAME} test coverage" --ignore-errors source --legend --num-spaces 4 coverage.info
DEPENDS coverage DEPENDS coverage
COMMENT "Building coverage html report." COMMENT "Building coverage html report."
WORKING_DIRECTORY "${PUGS_BINARY_DIR}" WORKING_DIRECTORY "${PUGS_BINARY_DIR}"
) )
endif()
endif() endif()
#------------------------------------------------------ #------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment