Optionally generate test coverage reports

This commit is contained in:
Drew DeVault 2016-06-17 08:46:18 -04:00
parent cd64ad56b9
commit 074238e9f4
3 changed files with 200 additions and 1 deletions

View file

@ -24,6 +24,10 @@ function(configure_test)
list(APPEND CONFIGURE_TEST_WRAPPERS "malloc" "calloc" "realloc" "free")
if (enable-coverage)
add_compile_options(-g -O0 --coverage -fprofile-arcs -ftest-coverage)
endif()
list(LENGTH CONFIGURE_TEST_WRAPPERS WRAPPED_COUNT)
if(NOT ${WRAPPED_COUNT} STREQUAL "0")
@ -45,5 +49,12 @@ function(configure_test)
target_link_libraries(${CONFIGURE_TEST_NAME}_test ${CMOCKA_LIBRARIES} ${CONFIGURE_TEST_LIBRARIES})
set(test_targets ${test_targets} ${CONFIGURE_TEST_NAME}_test PARENT_SCOPE)
if (enable-coverage)
target_link_libraries(${CONFIGURE_TEST_NAME}_test gcov)
setup_target_for_coverage(
${CONFIGURE_TEST_NAME}_cov
${CONFIGURE_TEST_NAME}_test
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/coverage
)
endif()
endfunction()