-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathcompareGCOV.cmake
90 lines (70 loc) · 3.13 KB
/
compareGCOV.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Heavily inspired by the CTestCoverageCollectGCOV CMake module.
# Functions for handling coverage data
# - create gcov files
# - compare multiple runs
# - create tar file for CDash upload
# Generate gcov files from gcda and gcno files
# Create the data.json file cdash expects
function(GENERATE_GCOV BINARY_DIR OUTPUT_DIR GCOV_OPTIONS SOURCE_DIR)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
file(GLOB_RECURSE GCDA_FILES "${BINARY_DIR}/*.gcda")
set(GCOV_CMD_OPTIONS "-b;-p")
if(GCOV_OPTIONS STREQUAL "USE_LONG_FILE_NAMES")
set(GCOV_CMD_OPTIONS "${GCOV_CMD_OPTIONS};-l;-s;${SOURCE_DIR}")
endif()
message("GCOV_CMD_OPTIONS = ${GCOV_CMD_OPTIONS}")
foreach(GCDA_FILE ${GCDA_FILES})
execute_process(
COMMAND gcov ${GCOV_CMD_OPTIONS} ${GCDA_FILE}
WORKING_DIRECTORY ${OUTPUT_DIR}
OUTPUT_VARIABLE out)
endforeach()
file(
WRITE ${OUTPUT_DIR}/data.json
"{
\"Source\":\"${CTEST_SOURCE_DIRECTORY}\",
\"Binary\":\"${CTEST_BINARY_DIRECTORY}\"
}")
endfunction()
# Remove unwanted gcov files (files in /usr, unit tests, files with coverage only in static initializers, etc.)
function(FILTER_GCOV GCOV_DIR)
execute_process(COMMAND ${CTEST_SOURCE_DIRECTORY}/tests/coverage/compare_gcov.py --action process --base-dir
${GCOV_DIR})
endfunction()
# Use after running gcov with the -l (--long-file-names) option to merge all the
# gcov files from the input directory into one gcov file for each source file in
# the output directory.
function(MERGE_GCOV INPUT_DIR OUTPUT_DIR SOURCE_DIR)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
execute_process(COMMAND python ${CTEST_SOURCE_DIRECTORY}/tests/coverage/compare_gcov.py --action merge --base-dir
${INPUT_DIR} --output-dir ${OUTPUT_DIR} --prefix ${SOURCE_DIR})
file(COPY ${INPUT_DIR}/data.json DESTINATION ${OUTPUT_DIR})
endfunction()
# Create tar file of gcov files
function(CREATE_GCOV_TAR BINARY_DIRECTORY OUTPUT_DIR)
execute_process(COMMAND tar cfj gcov_${OUTPUT_DIR}.tar "--mtime=1970-01-01 0:0:0 UTC" ${OUTPUT_DIR}
WORKING_DIRECTORY ${BINARY_DIRECTORY})
endfunction()
# Clear the coverage data files in preparation for another run
function(CLEAR_GCDA BINARY_DIRECTORY)
file(GLOB_RECURSE GCDA_FILES "${BINARY_DIRECTORY}/*.gcda")
foreach(GCDA_FILE ${GCDA_FILES})
file(REMOVE ${GCDA_FILE})
endforeach()
endfunction()
# Compare two coverage runs
function(COMPARE_GCOV BASE_DIR UNIT_DIR OUTPUT_DIR REL_OUTPUT_DIR)
file(MAKE_DIRECTORY ${OUTPUT_DIR})
execute_process(COMMAND python ${CTEST_SOURCE_DIRECTORY}/tests/coverage/compare_gcov.py --action compare --base-dir
${BASE_DIR} --unit-dir ${UNIT_DIR} --output-dir ${OUTPUT_DIR})
file(
WRITE ${OUTPUT_DIR}/data.json
"{
\"Source\":\"${CTEST_SOURCE_DIRECTORY}\",
\"Binary\":\"${CTEST_BINARY_DIRECTORY}\"
}")
#FILE(RELATIVE_PATH REL_OUTPUT_DIR ${CTEST_BINARY_DIRECTORY} ${OUTPUT_DIR})
##MESSAGE("*** Relative output dir = ${REL_OUTPUT_DIR}")
execute_process(COMMAND tar cfj gcov.tar "--mtime=1970-01-01 0:0:0 UTC" ${REL_OUTPUT_DIR}
WORKING_DIRECTORY ${CTEST_BINARY_DIRECTORY})
endfunction()