CTestCoverageCollectGCOV: Add TARBALL_COMPRESSION option

For large projects, the default bzip2 compression of gcov data is
prohibitively expensively (could take several hours).  Introduce options
that allow the consumer to choose between file size and compression time.

Add a new optional argument `TARBALL_COMPRESSION` for the macro
`ctest_coverage_collect_gcov`. This option accepts the values `GZIP`,
`BZIP2`, `XZ`, `FROM_EXT`, or an expression that evaluates to `FALSE`.
The default value is `BZIP2` to preserve prior behavior.

Fixes: #20593
This commit is contained in:
Kelly (KT) Thompson 2020-04-22 11:10:31 -06:00 committed by Brad King
parent 81e83510a0
commit 40ca6ef125
3 changed files with 192 additions and 15 deletions

View File

@ -0,0 +1,7 @@
CTestCoverageCollectGCOV-compress-opts
--------------------------------------
* The :module:`CTestCoverageCollectGCOV` module
:command:`ctest_coverage_collect_gcov` function gained a
``TARBALL_COMPRESSION`` option to control compression of the
tarball of collected results.

View File

@ -37,6 +37,17 @@ After generating this tar file, it can be sent to CDash for display with the
upload to CDash. Relative paths will be interpreted with respect
to the top-level build directory.
``TARBALL_COMPRESSION <option>`` Specify a compression algorithm for the
``TARBALL`` data file. Using this option reduces the size of the data file
before it is submitted to CDash. ``<option>`` must be one of ``GZIP``,
``BZIP2``, ``XZ``, ``ZSTD``, ``FROM_EXT``, or an expression that CMake
evaluates as ``FALSE``. The default value is ``BZIP2``.
If ``FROM_EXT`` is specified, the resulting file will be compressed based on
the file extension of the ``<tarfile>`` (i.e. ``.tar.gz`` will use ``GZIP``
compression). File extensions that will produce compressed output include
``.tar.gz``, ``.tgz``, ``.tar.bzip2``, ``.tbz``, ``.tar.xz``, and ``.txz``.
``SOURCE <source_dir>``
Specify the top-level source directory for the build.
Default is the value of :variable:`CTEST_SOURCE_DIRECTORY`.
@ -68,7 +79,7 @@ After generating this tar file, it can be sent to CDash for display with the
function(ctest_coverage_collect_gcov)
set(options QUIET GLOB DELETE)
set(oneValueArgs TARBALL SOURCE BUILD GCOV_COMMAND)
set(oneValueArgs TARBALL SOURCE BUILD GCOV_COMMAND TARBALL_COMPRESSION)
set(multiValueArgs GCOV_OPTIONS)
cmake_parse_arguments(GCOV "${options}" "${oneValueArgs}"
"${multiValueArgs}" "" ${ARGN} )
@ -91,6 +102,13 @@ function(ctest_coverage_collect_gcov)
else()
set(gcov_command "${GCOV_GCOV_COMMAND}")
endif()
if(NOT DEFINED GCOV_TARBALL_COMPRESSION)
set(GCOV_TARBALL_COMPRESSION "BZIP2")
elseif( GCOV_TARBALL_COMPRESSION AND
NOT GCOV_TARBALL_COMPRESSION MATCHES "^(GZIP|BZIP2|XZ|ZSTD|FROM_EXT)$")
message(FATAL_ERROR "TARBALL_COMPRESSION must be one of OFF, GZIP, "
"BZIP2, XZ, ZSTD, or FROM_EXT for ctest_coverage_collect_gcov")
endif()
# run gcov on each gcda file in the binary tree
set(gcda_files)
set(label_files)
@ -270,14 +288,38 @@ ${label_files}
${uncovered_files_for_tar}
")
if (GCOV_QUIET)
set(tar_opts "cfj")
else()
set(tar_opts "cvfj")
# Prepare tar command line arguments
set(tar_opts "")
# Select data compression mode
if( GCOV_TARBALL_COMPRESSION STREQUAL "FROM_EXT")
if( GCOV_TARBALL MATCHES [[\.(tgz|tar.gz)$]] )
string(APPEND tar_opts "z")
elseif( GCOV_TARBALL MATCHES [[\.(txz|tar.xz)$]] )
string(APPEND tar_opts "J")
elseif( GCOV_TARBALL MATCHES [[\.(tbz|tar.bz)$]] )
string(APPEND tar_opts "j")
endif()
elseif(GCOV_TARBALL_COMPRESSION STREQUAL "GZIP")
string(APPEND tar_opts "z")
elseif(GCOV_TARBALL_COMPRESSION STREQUAL "XZ")
string(APPEND tar_opts "J")
elseif(GCOV_TARBALL_COMPRESSION STREQUAL "BZIP2")
string(APPEND tar_opts "j")
elseif(GCOV_TARBALL_COMPRESSION STREQUAL "ZSTD")
set(zstd_tar_opt "--zstd")
endif()
# Verbosity options
if(NOT GCOV_QUIET AND NOT tar_opts MATCHES v)
string(APPEND tar_opts "v")
endif()
# Prepend option 'c' specifying 'create'
string(PREPEND tar_opts "c")
# Append option 'f' so that the next argument is the filename
string(APPEND tar_opts "f")
execute_process(COMMAND
${CMAKE_COMMAND} -E tar ${tar_opts} ${GCOV_TARBALL}
${CMAKE_COMMAND} -E tar ${tar_opts} ${GCOV_TARBALL} ${zstd_tar_opt}
"--mtime=1970-01-01 0:0:0 UTC"
"--format=gnutar"
--files-from=${coverage_dir}/coverage_file_list.txt

View File

@ -8,6 +8,10 @@ ctest_configure()
ctest_build()
ctest_test()
#------------------------------------------------------------------------------#
# Common setup for all tests.
#------------------------------------------------------------------------------#
list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE
"/foo/something"
"/3rdparty/"
@ -15,15 +19,28 @@ list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE
"/CMakeFiles/"
)
list(APPEND CTEST_EXTRA_COVERAGE_GLOB "*.cpp")
include(CTestCoverageCollectGCOV)
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.tar)
set(expected_out
CMakeFiles/myexecutable.dir/Labels.json
Testing/CoverageInfo/data.json
Testing/CoverageInfo/extra.cpp.gcov
Testing/CoverageInfo/main.cpp.gcov
uncovered/extra/uncovered1.cpp
uncovered/uncovered2.cpp
)
#------------------------------------------------------------------------------#
# Test 1: with standard arguments
#------------------------------------------------------------------------------#
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.tbz)
ctest_coverage_collect_gcov(
TARBALL "${tar_file}"
SOURCE "${CTEST_SOURCE_DIRECTORY}"
BUILD "${CTEST_BINARY_DIRECTORY}"
GCOV_COMMAND "${CMAKE_COMMAND}"
GCOV_OPTIONS -P "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/fakegcov.cmake")
file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}/uncovered")
execute_process(COMMAND
${CMAKE_COMMAND} -E tar tf ${tar_file}
@ -35,15 +52,126 @@ execute_process(COMMAND
string(REPLACE "\n" ";" out "${out}")
list(SORT out)
set(expected_out
CMakeFiles/myexecutable.dir/Labels.json
Testing/CoverageInfo/data.json
Testing/CoverageInfo/extra.cpp.gcov
Testing/CoverageInfo/main.cpp.gcov
uncovered/extra/uncovered1.cpp
uncovered/uncovered2.cpp
if("${out}" STREQUAL "${expected_out}")
message("PASSED with correct output: ${out}")
else()
message(FATAL_ERROR "FAILED: expected:\n${expected_out}\nGot:\n${out}")
endif()
#------------------------------------------------------------------------------#
# Test 2: with optional argument: TARBALL_COMPRESSION "GZIP"
#------------------------------------------------------------------------------#
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.tgz)
ctest_coverage_collect_gcov(
TARBALL "${tar_file}"
TARBALL_COMPRESSION "GZIP"
SOURCE "${CTEST_SOURCE_DIRECTORY}"
BUILD "${CTEST_BINARY_DIRECTORY}"
GCOV_COMMAND "${CMAKE_COMMAND}"
GCOV_OPTIONS -P "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/fakegcov.cmake")
file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}/uncovered")
execute_process(COMMAND
${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)
if("${out}" STREQUAL "${expected_out}")
message("PASSED with correct output: ${out}")
else()
message(FATAL_ERROR "FAILED: expected:\n${expected_out}\nGot:\n${out}")
endif()
#------------------------------------------------------------------------------#
# Test 3: with optional argument: TARBALL_COMPRESSION "FROM_EXT"
#------------------------------------------------------------------------------#
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.txz)
ctest_coverage_collect_gcov(
TARBALL "${tar_file}"
TARBALL_COMPRESSION "FROM_EXT"
SOURCE "${CTEST_SOURCE_DIRECTORY}"
BUILD "${CTEST_BINARY_DIRECTORY}"
GCOV_COMMAND "${CMAKE_COMMAND}"
GCOV_OPTIONS -P "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/fakegcov.cmake")
file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}/uncovered")
execute_process(COMMAND
${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)
if("${out}" STREQUAL "${expected_out}")
message("PASSED with correct output: ${out}")
else()
message(FATAL_ERROR "FAILED: expected:\n${expected_out}\nGot:\n${out}")
endif()
#------------------------------------------------------------------------------#
# Test 4: with optional argument: TARBALL_COMPRESSION "FALSE"
#------------------------------------------------------------------------------#
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.tar)
ctest_coverage_collect_gcov(
TARBALL "${tar_file}"
TARBALL_COMPRESSION "FALSE"
SOURCE "${CTEST_SOURCE_DIRECTORY}"
BUILD "${CTEST_BINARY_DIRECTORY}"
GCOV_COMMAND "${CMAKE_COMMAND}"
GCOV_OPTIONS -P "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/fakegcov.cmake")
file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}/uncovered")
execute_process(COMMAND
${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)
if("${out}" STREQUAL "${expected_out}")
message("PASSED with correct output: ${out}")
else()
message(FATAL_ERROR "FAILED: expected:\n${expected_out}\nGot:\n${out}")
endif()
#------------------------------------------------------------------------------#
# Test 5: with optional argument: TARBALL_COMPRESSION "ZSTD"
#------------------------------------------------------------------------------#
set(tar_file ${CTEST_BINARY_DIRECTORY}/gcov.zstd)
ctest_coverage_collect_gcov(
TARBALL "${tar_file}"
TARBALL_COMPRESSION "ZSTD"
SOURCE "${CTEST_SOURCE_DIRECTORY}"
BUILD "${CTEST_BINARY_DIRECTORY}"
GCOV_COMMAND "${CMAKE_COMMAND}"
GCOV_OPTIONS -P "@CMake_SOURCE_DIR@/Tests/CTestCoverageCollectGCOV/fakegcov.cmake")
file(REMOVE_RECURSE "${CTEST_BINARY_DIRECTORY}/uncovered")
execute_process(COMMAND
${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)
if("${out}" STREQUAL "${expected_out}")
message("PASSED with correct output: ${out}")
else()