CTestCoverageCollectGCOV: Support CTEST_CUSTOM_COVERAGE_EXCLUDE

This commit is contained in:
Nils Gladitz 2015-04-02 17:02:08 +02:00
parent f707460e42
commit 9a544f2d98
10 changed files with 128 additions and 18 deletions

View File

@ -147,8 +147,37 @@ function(ctest_coverage_collect_gcov)
\"Binary\": \"${binary_dir}\"
}")
# collect the gcov files
set(unfiltered_gcov_files)
file(GLOB_RECURSE unfiltered_gcov_files RELATIVE ${binary_dir} "${coverage_dir}/*.gcov")
set(gcov_files)
file(GLOB_RECURSE gcov_files RELATIVE ${binary_dir} "${coverage_dir}/*.gcov")
foreach(gcov_file ${unfiltered_gcov_files})
file(STRINGS ${binary_dir}/${gcov_file} first_line LIMIT_COUNT 1 ENCODING UTF-8)
set(is_excluded false)
if(first_line MATCHES "^ -: 0:Source:(.*)$")
set(source_file ${CMAKE_MATCH_1})
elseif(NOT GCOV_QUIET)
message(STATUS "Could not determine source file corresponding to: ${gcov_file}")
endif()
foreach(exclude_entry ${CTEST_CUSTOM_COVERAGE_EXCLUDE})
if(source_file MATCHES "${exclude_entry}")
set(is_excluded true)
if(NOT GCOV_QUIET)
message("Excluding coverage for: ${source_file} which matches ${exclude_entry}")
endif()
break()
endif()
endforeach()
if(NOT is_excluded)
list(APPEND gcov_files ${gcov_file})
endif()
endforeach()
# tar up the coverage info with the same date so that the md5
# sum will be the same for the tar file independent of file time
# stamps

View File

@ -2345,12 +2345,13 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
"${CMake_BINARY_DIR}/Tests/CTestCoverageCollectGCOV/test.cmake"
@ONLY ESCAPE_QUOTES)
add_test(CTestCoverageCollectGCOV ${CMAKE_CTEST_COMMAND}
-C \${CTEST_CONFIGURATION_TYPE}
-S "${CMake_BINARY_DIR}/Tests/CTestCoverageCollectGCOV/test.cmake" -VV
--output-log "${CMake_BINARY_DIR}/Tests/CTestCoverageCollectGCOV/testOut.log"
)
set_tests_properties(CTestCoverageCollectGCOV PROPERTIES
PASS_REGULAR_EXPRESSION
"PASSED with correct output.*Testing/CoverageInfo/echoargs.gcov")
"PASSED with correct output.*Testing/CoverageInfo/main.cpp.gcov")
configure_file(
"${CMake_SOURCE_DIR}/Tests/CTestTestEmptyBinaryDirectory/test.cmake.in"

View File

@ -0,0 +1 @@
void foo() {}

View File

@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.2)
project(TestProject CXX)
include(CTest)
set(SOURCES
main.cpp
3rdparty/foo.cpp
extra/extra.cpp
)
add_executable(myexecutable ${SOURCES})
set_property(SOURCE main.cpp APPEND PROPERTY LABELS SourceLabel)
set_property(TARGET myexecutable APPEND PROPERTY LABELS TargetLabel)
set(MYEXECUTABLE_INFO_FILE "${CMAKE_CURRENT_BINARY_DIR}/myexecutable_info.cmake")
file(WRITE "${MYEXECUTABLE_INFO_FILE}" "
set(TARGET myexecutable)
set(SOURCE_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\")
set(SOURCES \"${SOURCES}\")
")
add_custom_command(TARGET myexecutable
POST_BUILD
COMMAND ${CMAKE_COMMAND}
"-DINFO_FILE=${MYEXECUTABLE_INFO_FILE}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/fake_compile_time_gcno.cmake"
VERBATIM
)
add_test(NAME mytest
COMMAND ${CMAKE_COMMAND}
"-DMYEXECUTABLE=$<TARGET_FILE:myexecutable>"
"-DTARGETDIR=${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/myexecutable.dir"
-P "${CMAKE_CURRENT_SOURCE_DIR}/fake_run_time_gcda.cmake"
)
set_property(TEST mytest APPEND PROPERTY LABELS TestLabel)

View File

@ -0,0 +1 @@
void extra() {}

View File

@ -0,0 +1,7 @@
include("${INFO_FILE}")
foreach(source ${SOURCES})
file(WRITE "CMakeFiles/${TARGET}.dir/${source}.gcno"
"${SOURCE_DIR}/${source}"
)
endforeach()

View File

@ -0,0 +1,12 @@
execute_process(COMMAND ${MYEXECUTABLE} RESULT_VARIABLE RESULT)
if(NOT RESULT_VARIABLE STREQUAL "0")
message("Test failure")
endif()
file(GLOB_RECURSE gcno_files "${TARGETDIR}/*.gcno")
foreach(gcno_file ${gcno_files})
string(REPLACE ".gcno" ".gcda" gcda_file "${gcno_file}")
configure_file(${gcno_file} ${gcda_file} COPYONLY)
endforeach()

View File

@ -0,0 +1 @@
int main() {}

View File

@ -3,6 +3,12 @@ foreach(I RANGE 0 ${CMAKE_ARGC})
set(gcda_file "${CMAKE_ARGV${I}}")
endif()
endforeach()
get_filename_component(gcda_file ${gcda_file} NAME_WE)
file(WRITE "${CMAKE_SOURCE_DIR}/${gcda_file}.gcov"
"fake gcov file")
get_filename_component(gcda_name ${gcda_file} NAME)
string(REPLACE ".gcda" ".gcov" gcov_name "${gcda_name}")
file(STRINGS "${gcda_file}" source_file LIMIT_COUNT 1 ENCODING UTF-8)
file(WRITE "${CMAKE_SOURCE_DIR}/${gcov_name}"
" -: 0:Source:${source_file}"
)

View File

@ -1,16 +1,21 @@
cmake_minimum_required(VERSION 2.8.12)
set(CTEST_PROJECT_NAME "SmallAndFast")
set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestTest/SmallAndFast")
set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestCoverageCollectGCOV")
set(CTEST_PROJECT_NAME "TestProject")
set(CTEST_SOURCE_DIRECTORY "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/TestProject")
set(CTEST_BINARY_DIRECTORY "@CMake_BINARY_DIR@/Tests/CTestCoverageCollectGCOV/TestProject")
set(CTEST_CMAKE_GENERATOR "@CMAKE_GENERATOR@")
ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY})
ctest_start(Experimental)
ctest_configure()
ctest_build()
ctest_test()
file(WRITE ${CTEST_BINARY_DIRECTORY}/CMakeFiles/echoargs.dir/echoargs.gcda
"dummy
")
list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE
"/foo/something"
"/3rdparty/"
"/bar/somethingelse"
)
include(CTestCoverageCollectGCOV)
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.tar)
@ -22,15 +27,21 @@ ctest_coverage_collect_gcov(
GCOV_OPTIONS -P "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/fakegcov.cmake")
execute_process(COMMAND
${CMAKE_COMMAND} -E tar tf ${tar_file}
OUTPUT_VARIABLE out
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
${CMAKE_COMMAND} -E tar tf ${tar_file}
OUTPUT_VARIABLE out
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\n" ";" out "${out}")
list(SORT out)
set(expected_out
"Testing/CoverageInfo/echoargs.gcov
Testing/CoverageInfo/data.json
CMakeFiles/echoargs.dir/Labels.json
")
CMakeFiles/myexecutable.dir/Labels.json
Testing/CoverageInfo/data.json
Testing/CoverageInfo/extra.cpp.gcov
Testing/CoverageInfo/main.cpp.gcov
)
if("${out}" STREQUAL "${expected_out}")
message("PASSED with correct output: ${out}")