I have set up CDash on my local machine and I'm using CTest to upload testing results to CDash - generating .gcov-files containing Branch Coverage info and packing them into gcov.tar beforehand (this is a modified version of the example from https://blog.kitware.com/additional-coverage-features-in-cdash/):
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(branch_coverage_example)
add_executable(foo foo.cxx)
include(CTest)
add_test(NAME foo COMMAND foo)
include(BranchCoverage)
BranchCoverage.cmake within my CMake modules path:
if(${CMAKE_BUILD_TYPE} STREQUAL "Profiling")
option(ALWAYS_GENERATE_BRANCH_COVERAGE_INFO "Run gcov branch coverage as part of the ALL target" ON)
if(ALWAYS_GENERATE_BRANCH_COVERAGE_INFO)
add_custom_target(BranchCoverage)
add_custom_command(TARGET BranchCoverage
POST_BUILD
COMMAND ${CMAKE_CTEST_COMMAND} -D ExperimentalSubmit -S cdash_tarball.cmake
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Generating gcov.tar containing branch coverage info..."
)
add_dependencies(BranchCoverage Experimental)
endif()
endif()
CTestConfig.cmake:
## This file should be placed in the root directory of your project.
## Then modify the CMakeLists.txt file in the root directory of your
## project to incorporate the testing dashboard.
##
## # The following are required to submit to the CDash dashboard:
## ENABLE_TESTING()
## INCLUDE(CTest)
set(CTEST_PROJECT_NAME "BranchCoverageExample")
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "localhost")
set(CTEST_DROP_LOCATION "/CDash/public/submit.php?project=BranchCoverageExample")
set(CTEST_DROP_SITE_CDASH TRUE)
cdash_upload.cmake:
# start, configure, build, test, coverage and submit
# have been executed by make <target> beforehand!
# generate a GCOV tarball and upload it to CDash.
include(CTestCoverageCollectGCOV)
ctest_coverage_collect_gcov(
TARBALL gcov.tar
SOURCE ${CTEST_SOURCE_DIRECTORY}
BUILD ${CTEST_BINARY_DIRECTORY}
GCOV_COMMAND ${CTEST_COVERAGE_COMMAND}
GCOV_OPTIONS -l -p -b
)
if(EXISTS "${CTEST_BINARY_DIRECTORY}/gcov.tar")
ctest_submit(CDASH_UPLOAD "${CTEST_BINARY_DIRECTORY}/gcov.tar"
CDASH_UPLOAD_TYPE GcovTar)
endif()
It works when I invoke the script from the example using ctest directly:
ctest -V -S run_example.cmake
This gives me wonderful branch coverage information in CDash. However this does not:
make Experimental
It ends up saying:
Generating gcov.tar containing branch coverage info...
CMake Error at /usr/local/share/cmake-3.6/Modules/CTestCoverageCollectGCOV.cmake:118 (file):
file STRINGS file "/CMakeFiles/TargetDirectories.txt" cannot be read.
Call Stack (most recent call first):
cdash_tarball.cmake:2 (ctest_coverage_collect_gcov)
ctest_coverage_collect_gcov: No .gcda files found, ignoring coverage request.
I guess this has something to do with the paths/env vars I need to give cdash_upload.cmake, when I do that using -DCTEST_SOURCE_DIRECTORY at add_custom_command in BranchCoverage.cmake, CDash returns a "Bad HTTP response", but doesn't give me any indication what I should fix and where.
Do you guys have any idea? Thanks in advance!
You are getting
file STRINGS file "/CMakeFiles/TargetDirectories.txt" cannot be read.
Because in this function call:
ctest_coverage_collect_gcov(
TARBALL gcov.tar
SOURCE ${CTEST_SOURCE_DIRECTORY}
BUILD ${CTEST_BINARY_DIRECTORY}
GCOV_COMMAND ${CTEST_COVERAGE_COMMAND}
GCOV_OPTIONS -l -p -b
)
CTEST_BINARY_DIRECTORY
is not defined,
it should be set to the build directory of your project, and turns out it isn't otherwise you should get instead of
"/CMakeFiles/TargetDirectories.txt"
smth like:
"build/Debug/CMakeFiles/TargetDirectories.txt"
Once it is set everything should work fine.
You can look up how is used here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With