7

我已经在我的本地机器上设置了 CDash,我正在使用 CTest 将测试结果上传到 CDash - 生成包含分支覆盖信息的 .gcov 文件并将它们预先打包到 gcov.tar 中(这是来自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)

我的 CMake 模块路径中的BranchCoverage.cmake :

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()

当我直接使用 ctest 从示例中调用脚本时,它可以工作:

ctest -V -S run_example.cmake

这为我提供了 Cdash 中出色的分支覆盖率信息。但是,这不会:

make Experimental

它最终说:

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.

我想这与我需要提供cdash_upload.cmake的路径/环境变量有关,当我在BranchCoverage.cmake的add_custom_command使用-DCTEST_SOURCE_DIRECTORY时,Cash 返回“错误的 HTTP 响应”,但没有给我任何指示我应该修复什么以及在哪里。

你们有什么想法吗?提前致谢!

4

1 回答 1

1

你得到

file STRINGS file "/CMakeFiles/TargetDirectories.txt" cannot be read.

因为在这个函数调用中:

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没有定义,

它应该设置为您项目的构建目录,事实证明它不是,否则您应该得到而不是

"/CMakeFiles/TargetDirectories.txt"

之类的:

"build/Debug/CMakeFiles/TargetDirectories.txt"

一旦设置好,一切都应该正常工作。

您可以在此处查看如何使用

于 2020-12-23T08:38:22.147 回答