instrumentation: Don't expect staged CDash files when cdashSubmit is disabled

This commit is contained in:
Martin Duffy
2026-09-14 15:38:40 -04:00
parent f5efe7a6b5
commit 77443e7258
7 changed files with 70 additions and 2 deletions
+5
View File
@@ -608,6 +608,11 @@ void cmCTestBuildHandler::GenerateXMLLogScraped(cmXMLWriter& xml)
void cmCTestBuildHandler::GenerateInstrumentationXML(cmXMLWriter& xml)
{
if (!this->CTest->GetInstrumentation().HasOption(
cmInstrumentationQuery::Option::CDashSubmit)) {
return;
}
// Record instrumentation data on a per-target basis.
cmsys::Directory targets_dir;
std::string targets_snippet_dir = cmStrCat(
+3 -1
View File
@@ -1659,7 +1659,9 @@ void cmCTestTestHandler::GenerateCTestXML(cmXMLWriter& xml)
xml.EndElement(); // Value
xml.EndElement(); // Measurement
if (!result.InstrumentationFile.empty()) {
if (!result.InstrumentationFile.empty() &&
this->CTest->GetInstrumentation().HasOption(
cmInstrumentationQuery::Option::CDashSubmit)) {
std::string instrument_file_path =
cmStrCat(this->CTest->GetInstrumentation().GetCDashDir(), "/test/",
result.InstrumentationFile);
+5
View File
@@ -3869,6 +3869,11 @@ cmInstrumentation& cmCTest::GetInstrumentation()
void cmCTest::ConvertInstrumentationSnippetsToXML(cmXMLWriter& xml,
std::string const& subdir)
{
if (!this->GetInstrumentation().HasOption(
cmInstrumentationQuery::Option::CDashSubmit)) {
return;
}
std::string data_dir =
cmStrCat(this->GetInstrumentation().GetCDashDir(), '/', subdir);
@@ -0,0 +1,28 @@
include("${RunCMake_SOURCE_DIR}/NoInstrumentationInCTestXML-check.cmake")
# Instrumentation should still produce snippets, but CTest must not look
# for their CDash staging copies when cdashSubmit has not been requested.
set(instrumentation_dir "${RunCMake_TEST_BINARY_DIR}/.cmake/instrumentation/v1")
if(ARGS_USE_STALE_CDASH)
foreach(subdir configure build/commands build/targets/old-target)
if(NOT EXISTS "${instrumentation_dir}/cdash/${subdir}/old.json")
set(RunCMake_TEST_FAILED "Stale CDash snippet was consumed: ${subdir}/old.json")
return()
endif()
endforeach()
elseif(EXISTS "${instrumentation_dir}/cdash")
set(RunCMake_TEST_FAILED "Unexpected CDash staging directory")
return()
endif()
file(GLOB snippets "${instrumentation_dir}/data/test-*.json")
list(LENGTH snippets count)
if(NOT count EQUAL 1)
set(RunCMake_TEST_FAILED "Expected one local test snippet, found ${count}")
return()
endif()
file(READ "${snippets}" snippet)
string(JSON role GET "${snippet}" role)
string(JSON test_name GET "${snippet}" testName)
if(NOT role STREQUAL "test" OR NOT test_name STREQUAL "main")
set(RunCMake_TEST_FAILED "Unexpected local test snippet: ${snippet}")
endif()
@@ -0,0 +1 @@
include("${RunCMake_SOURCE_DIR}/InstrumentationWithoutCDashSubmit-check.cmake")
@@ -1,7 +1,7 @@
include(RunCTest)
function(run_InstrumentationInCTestXML CASE_NAME)
cmake_parse_arguments(ARGS "USE_INSTRUMENTATION_ENV_VARS;USE_VERBOSE_INSTRUMENTATION;USE_INSTRUMENTATION_CMD" "" "" ${ARGN})
cmake_parse_arguments(ARGS "USE_INSTRUMENTATION_ENV_VARS;USE_VERBOSE_INSTRUMENTATION;USE_INSTRUMENTATION_CMD;USE_LOCAL_INSTRUMENTATION;USE_STALE_CDASH" "" "" ${ARGN})
if(ARGS_USE_VERBOSE_INSTRUMENTATION)
set(ENV{CTEST_USE_VERBOSE_INSTRUMENTATION} "1")
set(RunCMake_USE_VERBOSE_INSTRUMENTATION 1)
@@ -22,6 +22,26 @@ function(run_InstrumentationInCTestXML CASE_NAME)
set(RunCMake_USE_VERBOSE_INSTRUMENTATION 0)
endif()
if(ARGS_USE_LOCAL_INSTRUMENTATION)
set(CASE_CMAKELISTS_SUFFIX_CODE [[
cmake_instrumentation(
API_VERSION 1
DATA_VERSION 1
)
]])
endif()
if(ARGS_USE_STALE_CDASH)
set(CASE_CTEST_PREFIX_CODE [=[
# Simulate staged data left by an earlier run with cdashSubmit enabled.
foreach(subdir configure build/commands build/targets/old-target)
file(WRITE "${CTEST_BINARY_DIRECTORY}/.cmake/instrumentation/v1/cdash/${subdir}/old.json"
[[{"command":"old","role":"custom","dynamicSystemInformation":{"afterHostMemoryUsed":123}}]]
)
endforeach()
]=])
endif()
configure_file(${RunCMake_SOURCE_DIR}/main.c
${RunCMake_BINARY_DIR}/${CASE_NAME}/main.c COPYONLY)
run_ctest("${CASE_NAME}")
@@ -39,3 +59,9 @@ run_InstrumentationInCTestXML(VerboseInstrumentationInCTestXML
run_InstrumentationInCTestXML(InstrumentationInCTestXMLWithCmd
USE_INSTRUMENTATION_CMD
)
run_InstrumentationInCTestXML(InstrumentationWithoutCDashSubmit
USE_LOCAL_INSTRUMENTATION
)
run_InstrumentationInCTestXML(InstrumentationWithoutCDashSubmitWithStaleData
USE_LOCAL_INSTRUMENTATION USE_STALE_CDASH
)
@@ -11,6 +11,7 @@ set(CTEST_BUILD_CONFIGURATION "$ENV{CMAKE_CONFIG_TYPE}")
set(CTEST_USE_LAUNCHERS TRUE)
ctest_start(Experimental)
@CASE_CTEST_PREFIX_CODE@
ctest_configure()
ctest_build()
ctest_test()