From ce44c2cec306e6d7266ba3e5444ee36bce879e3d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 28 Aug 2021 15:12:30 -0400 Subject: ctest_memcheck: generate `DynamicAnalysis-Test.xml` as well This is useful so that memcheck results also show up as test results on CDash. It will be submitted with the other `MemCheck` parts. Fixes: #22190 --- Help/command/ctest_submit.rst | 3 ++- Help/release/dev/ctest_memcheck-generate-test.xml.rst | 6 ++++++ Source/CTest/cmCTestSubmitHandler.cxx | 1 + Source/CTest/cmCTestTestHandler.cxx | 15 +++++++++++++++ Tests/RunCMake/ctest_memcheck/ExpectedOutputs-check.cmake | 10 ++++++++++ Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stderr.txt | 1 + Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stdout.txt | 2 ++ Tests/RunCMake/ctest_memcheck/RunCMakeTest.cmake | 13 +++++++++++++ 8 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Help/release/dev/ctest_memcheck-generate-test.xml.rst create mode 100644 Tests/RunCMake/ctest_memcheck/ExpectedOutputs-check.cmake create mode 100644 Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stderr.txt create mode 100644 Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stdout.txt diff --git a/Help/command/ctest_submit.rst b/Help/command/ctest_submit.rst index e6d277f..d661825 100644 --- a/Help/command/ctest_submit.rst +++ b/Help/command/ctest_submit.rst @@ -30,7 +30,8 @@ The options are: Build = ctest_build results, in Build.xml Test = ctest_test results, in Test.xml Coverage = ctest_coverage results, in Coverage.xml - MemCheck = ctest_memcheck results, in DynamicAnalysis.xml + MemCheck = ctest_memcheck results, in DynamicAnalysis.xml and + DynamicAnalysis-Test.xml Notes = Files listed by CTEST_NOTES_FILES, in Notes.xml ExtraFiles = Files listed by CTEST_EXTRA_SUBMIT_FILES Upload = Files prepared for upload by ctest_upload(), in Upload.xml diff --git a/Help/release/dev/ctest_memcheck-generate-test.xml.rst b/Help/release/dev/ctest_memcheck-generate-test.xml.rst new file mode 100644 index 0000000..fac02d8 --- /dev/null +++ b/Help/release/dev/ctest_memcheck-generate-test.xml.rst @@ -0,0 +1,6 @@ +ctest_memcheck-generate-test.xml +-------------------------------- + +* The :command:`ctest_memcheck` command now also generates a + `DynamicAnalysis-Test.xml` file which may be used to submit test results to + CDash. diff --git a/Source/CTest/cmCTestSubmitHandler.cxx b/Source/CTest/cmCTestSubmitHandler.cxx index 5b54573..bf938e4 100644 --- a/Source/CTest/cmCTestSubmitHandler.cxx +++ b/Source/CTest/cmCTestSubmitHandler.cxx @@ -804,6 +804,7 @@ int cmCTestSubmitHandler::ProcessHandler() } } this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis.xml"); + this->CTest->AddIfExists(cmCTest::PartMemCheck, "DynamicAnalysis-Test.xml"); this->CTest->AddIfExists(cmCTest::PartMemCheck, "Purify.xml"); this->CTest->AddIfExists(cmCTest::PartNotes, "Notes.xml"); this->CTest->AddIfExists(cmCTest::PartUpload, "Upload.xml"); diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 1157d10..00c1443 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -705,6 +705,21 @@ bool cmCTestTestHandler::GenerateXML() this->GenerateCTestXML(xml); } + if (this->MemCheck) { + cmGeneratedFileStream xmlfile; + if (!this->StartResultingXML(cmCTest::PartTest, "DynamicAnalysis-Test", + xmlfile)) { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Cannot create testing XML file" << std::endl); + this->LogFile = nullptr; + return false; + } + cmXMLWriter xml(xmlfile); + // Explicitly call this class' `GenerateCTestXML` method to make `Test.xml` + // as well. + this->cmCTestTestHandler::GenerateCTestXML(xml); + } + return true; } diff --git a/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-check.cmake b/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-check.cmake new file mode 100644 index 0000000..9d2a059 --- /dev/null +++ b/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-check.cmake @@ -0,0 +1,10 @@ +function (find_xml_file name) + file(GLOB test_xml_file "${RunCMake_TEST_BINARY_DIR}/Testing/*/${name}.xml") + if (NOT test_xml_file) + message(FATAL_ERROR + "${name}.xml not created.") + endif () +endfunction () + +find_xml_file(DynamicAnalysis) +find_xml_file(DynamicAnalysis-Test) diff --git a/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stderr.txt b/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stderr.txt new file mode 100644 index 0000000..e1fc77a --- /dev/null +++ b/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stderr.txt @@ -0,0 +1 @@ +Cannot find memory tester output file: .*/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-build/Testing/Temporary/MemoryChecker.1.log\.\* diff --git a/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stdout.txt b/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stdout.txt new file mode 100644 index 0000000..b3473bf --- /dev/null +++ b/Tests/RunCMake/ctest_memcheck/ExpectedOutputs-stdout.txt @@ -0,0 +1,2 @@ +Memory checking results: +left shift of negative value -256 - 1 diff --git a/Tests/RunCMake/ctest_memcheck/RunCMakeTest.cmake b/Tests/RunCMake/ctest_memcheck/RunCMakeTest.cmake index 6e0a91c..cb8f696 100644 --- a/Tests/RunCMake/ctest_memcheck/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_memcheck/RunCMakeTest.cmake @@ -95,6 +95,19 @@ unset(CMAKELISTS_EXTRA_CODE) unset(CTEST_EXTRA_CODE) #----------------------------------------------------------------------------- +# add output test +set(CTEST_EXTRA_CODE +"set(CTEST_MEMORYCHECK_SANITIZER_OPTIONS \"simulate_sanitizer=1\") +") +set(CMAKELISTS_EXTRA_CODE +"add_test(NAME TestSan COMMAND \"\${CMAKE_COMMAND}\" +-P \"${RunCMake_SOURCE_DIR}/testUndefinedBehaviorSanitizer.cmake\") +") +run_mc_test(ExpectedOutputs "" -DMEMCHECK_TYPE=UndefinedBehaviorSanitizer) +unset(CMAKELISTS_EXTRA_CODE) +unset(CTEST_EXTRA_CODE) + +#----------------------------------------------------------------------------- set(CTEST_EXTRA_CODE "string(REPLACE \" \" \"\\\\ \" PRE_POST_COMMAND \"\${CTEST_MEMORYCHECK_COMMAND}\") set(CTEST_CUSTOM_PRE_MEMCHECK \"\${PRE_POST_COMMAND} pre command\") -- cgit v0.12