cmake/Source/CTest/cmCTestTestHandler.cxx

2631 lines
86 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestTestHandler.h"
2020-02-01 23:06:01 +01:00
2016-10-30 18:24:19 +01:00
#include <algorithm>
2018-04-23 21:13:27 +02:00
#include <chrono>
2019-11-11 23:01:05 +01:00
#include <cmath>
2020-08-30 11:54:41 +02:00
#include <cstddef> // IWYU pragma: keep
2020-02-01 23:06:01 +01:00
#include <cstdio>
#include <cstdlib>
2018-08-09 18:06:22 +02:00
#include <cstring>
2020-02-01 23:06:01 +01:00
#include <ctime>
2016-10-30 18:24:19 +01:00
#include <functional>
#include <iomanip>
#include <iterator>
#include <set>
#include <sstream>
2020-02-01 23:06:01 +01:00
#include <utility>
2023-07-02 19:51:09 +02:00
#ifndef _WIN32
# include <csignal>
#endif
2020-02-01 23:06:01 +01:00
#include <cm/memory>
2020-08-30 11:54:41 +02:00
#include <cm/string_view>
#include <cmext/algorithm>
#include <cmext/string_view>
2020-02-01 23:06:01 +01:00
#include "cmsys/FStream.hxx"
#include <cmsys/Base64.h>
#include <cmsys/Directory.hxx>
#include <cmsys/RegularExpression.hxx>
#include "cm_utf8.h"
2017-04-14 19:02:05 +02:00
#include "cmCTest.h"
#include "cmCTestMultiProcessHandler.h"
2020-02-01 23:06:01 +01:00
#include "cmCTestResourceGroupsLexerHelper.h"
2021-11-20 13:41:27 +01:00
#include "cmCTestTestMeasurementXMLParser.h"
2018-04-23 21:13:27 +02:00
#include "cmDuration.h"
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#include "cmGeneratedFileStream.h"
#include "cmGlobalGenerator.h"
2023-07-02 19:51:09 +02:00
#include "cmJSONState.h"
#include "cmList.h"
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
#include "cmState.h"
#include "cmStateSnapshot.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
2021-09-14 00:13:48 +02:00
#include "cmTimestamp.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2017-07-20 19:35:53 +02:00
#include "cmWorkingDirectory.h"
2017-04-14 19:02:05 +02:00
#include "cmXMLWriter.h"
#include "cmake.h"
2020-02-01 23:06:01 +01:00
namespace {
2020-02-01 23:06:01 +01:00
class cmCTestCommand
{
public:
2020-02-01 23:06:01 +01:00
cmCTestCommand(cmCTestTestHandler* testHandler)
: TestHandler(testHandler)
2016-07-09 11:21:54 +02:00
{
}
2020-02-01 23:06:01 +01:00
virtual ~cmCTestCommand() = default;
2022-03-29 21:10:50 +02:00
cmCTestCommand(const cmCTestCommand&) = default;
cmCTestCommand& operator=(const cmCTestCommand&) = default;
2020-02-01 23:06:01 +01:00
bool operator()(std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status)
{
cmMakefile& mf = status.GetMakefile();
std::vector<std::string> expandedArguments;
if (!mf.ExpandArguments(args, expandedArguments)) {
// There was an error expanding arguments. It was already
// reported, so we can skip this command without error.
return true;
}
return this->InitialPass(expandedArguments, status);
}
virtual bool InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) = 0;
cmCTestTestHandler* TestHandler;
};
2022-03-29 21:10:50 +02:00
bool ReadSubdirectory(std::string fname, cmExecutionStatus& status)
{
if (!cmSystemTools::FileExists(fname)) {
// No subdirectory? So what...
return true;
}
bool readit = false;
{
cmWorkingDirectory workdir(fname);
if (workdir.Failed()) {
status.SetError("Failed to change directory to " + fname + " : " +
std::strerror(workdir.GetLastResult()));
return false;
}
const char* testFilename;
if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
// does the CTestTestfile.cmake exist ?
testFilename = "CTestTestfile.cmake";
} else if (cmSystemTools::FileExists("DartTestfile.txt")) {
// does the DartTestfile.txt exist ?
testFilename = "DartTestfile.txt";
} else {
// No CTestTestfile? Who cares...
return true;
}
fname += "/";
fname += testFilename;
readit = status.GetMakefile().ReadDependentFile(fname);
}
if (!readit) {
status.SetError(cmStrCat("Could not find include file: ", fname));
return false;
}
return true;
}
2020-02-01 23:06:01 +01:00
bool cmCTestSubdirCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
2018-01-26 17:06:56 +01:00
for (std::string const& arg : args) {
2009-11-14 01:56:15 +02:00
std::string fname;
2018-04-23 21:13:27 +02:00
if (cmSystemTools::FileIsFullPath(arg)) {
2018-01-26 17:06:56 +01:00
fname = arg;
2016-07-09 11:21:54 +02:00
} else {
2020-02-01 23:06:01 +01:00
fname = cmStrCat(cwd, '/', arg);
2016-07-09 11:21:54 +02:00
}
2009-11-10 20:23:57 +02:00
2022-03-29 21:10:50 +02:00
if (!ReadSubdirectory(std::move(fname), status)) {
return false;
}
2016-07-09 11:21:54 +02:00
}
return true;
}
2020-02-01 23:06:01 +01:00
bool cmCTestAddSubdirectoryCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-10-30 18:24:19 +01:00
if (args.empty()) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
std::string fname =
cmStrCat(cmSystemTools::GetCurrentWorkingDirectory(), '/', args[0]);
2022-03-29 21:10:50 +02:00
return ReadSubdirectory(std::move(fname), status);
}
2020-02-01 23:06:01 +01:00
class cmCTestAddTestCommand : public cmCTestCommand
{
public:
2020-02-01 23:06:01 +01:00
using cmCTestCommand::cmCTestCommand;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
*/
2016-10-30 18:24:19 +01:00
bool InitialPass(std::vector<std::string> const& /*args*/,
2018-01-26 17:06:56 +01:00
cmExecutionStatus& /*unused*/) override;
};
2016-07-09 11:21:54 +02:00
bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& args,
2020-02-01 23:06:01 +01:00
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
2020-02-01 23:06:01 +01:00
status.SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
return this->TestHandler->AddTest(args);
}
2020-02-01 23:06:01 +01:00
class cmCTestSetTestsPropertiesCommand : public cmCTestCommand
{
public:
2020-02-01 23:06:01 +01:00
using cmCTestCommand::cmCTestCommand;
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
2017-07-20 19:35:53 +02:00
*/
2016-10-30 18:24:19 +01:00
bool InitialPass(std::vector<std::string> const& /*args*/,
2018-01-26 17:06:56 +01:00
cmExecutionStatus& /*unused*/) override;
};
2016-07-09 11:21:54 +02:00
bool cmCTestSetTestsPropertiesCommand::InitialPass(
2016-10-30 18:24:19 +01:00
std::vector<std::string> const& args, cmExecutionStatus& /*unused*/)
{
return this->TestHandler->SetTestsProperties(args);
}
2020-02-01 23:06:01 +01:00
class cmCTestSetDirectoryPropertiesCommand : public cmCTestCommand
2018-01-26 17:06:56 +01:00
{
public:
2020-02-01 23:06:01 +01:00
using cmCTestCommand::cmCTestCommand;
2018-01-26 17:06:56 +01:00
/**
* This is called when the command is first encountered in
* the CMakeLists.txt file.
2018-08-09 18:06:22 +02:00
*/
2018-01-26 17:06:56 +01:00
bool InitialPass(std::vector<std::string> const& /*unused*/,
cmExecutionStatus& /*unused*/) override;
};
bool cmCTestSetDirectoryPropertiesCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
return this->TestHandler->SetDirectoryProperties(args);
}
// get the next number in a string with numbers separated by ,
// pos is the start of the search and pos2 is the end of the search
// pos becomes pos2 after a call to GetNextNumber.
// -1 is returned at the end of the list.
2016-07-09 11:21:54 +02:00
inline int GetNextNumber(std::string const& in, int& val,
std::string::size_type& pos,
std::string::size_type& pos2)
{
pos2 = in.find(',', pos);
2017-07-20 19:35:53 +02:00
if (pos2 != std::string::npos) {
2016-07-09 11:21:54 +02:00
if (pos2 - pos == 0) {
val = -1;
2016-07-09 11:21:54 +02:00
} else {
val = atoi(in.substr(pos, pos2 - pos).c_str());
}
pos = pos2 + 1;
return 1;
2016-10-30 18:24:19 +01:00
}
if (in.size() - pos == 0) {
val = -1;
2016-07-09 11:21:54 +02:00
} else {
2016-10-30 18:24:19 +01:00
val = atoi(in.substr(pos, in.size() - pos).c_str());
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
return 0;
}
// get the next number in a string with numbers separated by ,
// pos is the start of the search and pos2 is the end of the search
// pos becomes pos2 after a call to GetNextNumber.
// -1 is returned at the end of the list.
2016-07-09 11:21:54 +02:00
inline int GetNextRealNumber(std::string const& in, double& val,
std::string::size_type& pos,
std::string::size_type& pos2)
{
pos2 = in.find(',', pos);
2017-07-20 19:35:53 +02:00
if (pos2 != std::string::npos) {
2016-07-09 11:21:54 +02:00
if (pos2 - pos == 0) {
val = -1;
2016-07-09 11:21:54 +02:00
} else {
val = atof(in.substr(pos, pos2 - pos).c_str());
}
pos = pos2 + 1;
return 1;
2016-10-30 18:24:19 +01:00
}
if (in.size() - pos == 0) {
val = -1;
2016-07-09 11:21:54 +02:00
} else {
2016-10-30 18:24:19 +01:00
val = atof(in.substr(pos, in.size() - pos).c_str());
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
return 0;
}
2020-02-01 23:06:01 +01:00
} // namespace
cmCTestTestHandler::cmCTestTestHandler()
{
this->UseUnion = false;
2016-07-09 11:21:54 +02:00
this->UseIncludeRegExpFlag = false;
this->UseExcludeRegExpFlag = false;
this->UseExcludeRegExpFirst = false;
2020-02-01 23:06:01 +01:00
this->UseResourceSpec = false;
this->CustomMaximumPassedTestOutputSize = 1 * 1024;
this->CustomMaximumFailedTestOutputSize = 300 * 1024;
2022-08-04 22:12:04 +02:00
this->TestOutputTruncation = cmCTestTypes::TruncationMode::Tail;
this->MemCheck = false;
2018-01-26 17:06:56 +01:00
this->LogFile = nullptr;
2021-09-14 00:13:48 +02:00
// Support for JUnit XML output.
this->JUnitXMLFileName = "";
2021-11-20 13:41:27 +01:00
// Regular expressions to scan test output for custom measurements.
2021-09-14 00:13:48 +02:00
2021-11-20 13:41:27 +01:00
// Capture the whole section of test output from the first opening
// <(CTest|Dart)Measurement*> tag to the last </(CTest|Dart)Measurement*>
// closing tag.
this->AllTestMeasurementsRegex.compile(
"(<(CTest|Dart)Measurement.*/(CTest|Dart)Measurement[a-zA-Z]*>)");
// Capture a single <(CTest|Dart)Measurement*> XML element.
this->SingleTestMeasurementRegex.compile(
"(<(CTest|Dart)Measurement[^<]*</(CTest|Dart)Measurement[a-zA-Z]*>)");
// Capture content from <CTestDetails>...</CTestDetails>
2021-09-14 00:13:48 +02:00
this->CustomCompletionStatusRegex.compile(
"<CTestDetails>(.*)</CTestDetails>");
2021-11-20 13:41:27 +01:00
// Capture content from <CTestLabel>...</CTestLabel>
this->CustomLabelRegex.compile("<CTestLabel>(.*)</CTestLabel>");
}
void cmCTestTestHandler::Initialize()
{
this->Superclass::Initialize();
2018-04-23 21:13:27 +02:00
this->ElapsedTestingTime = cmDuration();
this->TestResults.clear();
this->CustomTestsIgnore.clear();
2018-01-26 17:06:56 +01:00
this->StartTest.clear();
this->EndTest.clear();
this->CustomPreTest.clear();
this->CustomPostTest.clear();
this->CustomMaximumPassedTestOutputSize = 1 * 1024;
this->CustomMaximumFailedTestOutputSize = 300 * 1024;
2022-08-04 22:12:04 +02:00
this->TestOutputTruncation = cmCTestTypes::TruncationMode::Tail;
this->TestsToRun.clear();
this->UseIncludeRegExpFlag = false;
this->UseExcludeRegExpFlag = false;
this->UseExcludeRegExpFirst = false;
2021-09-14 00:13:48 +02:00
this->IncludeLabelRegularExpressions.clear();
this->ExcludeLabelRegularExpressions.clear();
2018-01-26 17:06:56 +01:00
this->IncludeRegExp.clear();
this->ExcludeRegExp.clear();
2017-07-20 19:35:53 +02:00
this->ExcludeFixtureRegExp.clear();
this->ExcludeFixtureSetupRegExp.clear();
this->ExcludeFixtureCleanupRegExp.clear();
2021-09-14 00:13:48 +02:00
this->TestsToRunString.clear();
this->UseUnion = false;
this->TestList.clear();
}
2016-07-09 11:21:54 +02:00
void cmCTestTestHandler::PopulateCustomVectors(cmMakefile* mf)
{
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
2016-07-09 11:21:54 +02:00
this->CustomPreTest);
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
2016-07-09 11:21:54 +02:00
this->CustomPostTest);
this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_TESTS_IGNORE",
this->CustomTestsIgnore);
this->CTest->PopulateCustomInteger(
mf, "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
this->CustomMaximumPassedTestOutputSize);
this->CTest->PopulateCustomInteger(
mf, "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
this->CustomMaximumFailedTestOutputSize);
2022-08-04 22:12:04 +02:00
cmValue dval = mf->GetDefinition("CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION");
if (dval) {
2023-05-23 16:38:00 +02:00
if (!this->SetTestOutputTruncation(*dval)) {
2022-09-13 21:35:23 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Invalid value for CTEST_CUSTOM_TEST_OUTPUT_TRUNCATION: "
2023-05-23 16:38:00 +02:00
<< *dval << std::endl);
2022-09-13 21:35:23 +02:00
}
2022-08-04 22:12:04 +02:00
}
}
int cmCTestTestHandler::PreProcessHandler()
{
2016-07-09 11:21:54 +02:00
if (!this->ExecuteCommands(this->CustomPreTest)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
"Problem executing pre-test command(s)." << std::endl);
return 0;
2016-07-09 11:21:54 +02:00
}
return 1;
}
int cmCTestTestHandler::PostProcessHandler()
{
2016-07-09 11:21:54 +02:00
if (!this->ExecuteCommands(this->CustomPostTest)) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2016-07-09 11:21:54 +02:00
"Problem executing post-test command(s)." << std::endl);
return 0;
2016-07-09 11:21:54 +02:00
}
return 1;
}
int cmCTestTestHandler::ProcessHandler()
{
2020-02-01 23:06:01 +01:00
if (!this->ProcessOptions()) {
return -1;
2017-07-20 19:35:53 +02:00
}
2011-06-19 15:41:06 +03:00
this->TestResults.clear();
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
(this->MemCheck ? "Memory check" : "Test")
<< " project "
<< cmSystemTools::GetCurrentWorkingDirectory()
<< std::endl,
this->Quiet);
2016-07-09 11:21:54 +02:00
if (!this->PreProcessHandler()) {
return -1;
2016-07-09 11:21:54 +02:00
}
cmGeneratedFileStream mLogFile;
this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
this->LogFile = &mLogFile;
2015-04-27 22:25:09 +02:00
std::vector<std::string> passed;
std::vector<std::string> failed;
2016-07-09 11:21:54 +02:00
// start the real time clock
2018-04-23 21:13:27 +02:00
auto clock_start = std::chrono::steady_clock::now();
2009-10-04 10:30:41 +03:00
2020-08-30 11:54:41 +02:00
if (!this->ProcessDirectory(passed, failed)) {
return -1;
}
2018-04-23 21:13:27 +02:00
auto clock_finish = std::chrono::steady_clock::now();
2009-10-04 10:30:41 +03:00
2020-08-30 11:54:41 +02:00
bool noTestsFoundError = false;
2020-02-01 23:06:01 +01:00
if (passed.size() + failed.size() == 0) {
2020-08-30 11:54:41 +02:00
if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels() &&
this->CTest->GetNoTestsMode() != cmCTest::NoTests::Ignore) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"No tests were found!!!" << std::endl);
2020-08-30 11:54:41 +02:00
if (this->CTest->GetNoTestsMode() == cmCTest::NoTests::Error) {
noTestsFoundError = true;
}
}
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
if (this->HandlerVerbose && !passed.empty() &&
2016-07-09 11:21:54 +02:00
(this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag)) {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
std::endl
2016-07-09 11:21:54 +02:00
<< "The following tests passed:" << std::endl,
this->Quiet);
2018-01-26 17:06:56 +01:00
for (std::string const& j : passed) {
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2018-01-26 17:06:56 +01:00
"\t" << j << std::endl, this->Quiet);
}
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
SetOfTests resultsSet(this->TestResults.begin(), this->TestResults.end());
std::vector<cmCTestTestHandler::cmCTestTestResult> disabledTests;
2018-01-26 17:06:56 +01:00
for (cmCTestTestResult const& ft : resultsSet) {
2020-02-01 23:06:01 +01:00
if (cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_") ||
2018-01-26 17:06:56 +01:00
ft.CompletionStatus == "Disabled") {
disabledTests.push_back(ft);
2017-07-20 19:35:53 +02:00
}
}
2020-02-01 23:06:01 +01:00
cmDuration durationInSecs = clock_finish - clock_start;
this->LogTestSummary(passed, failed, durationInSecs);
2009-10-11 10:55:36 +03:00
2020-02-01 23:06:01 +01:00
this->LogDisabledTests(disabledTests);
this->LogFailedTests(failed, resultsSet);
}
if (!this->GenerateXML()) {
return 1;
}
2021-09-14 00:13:48 +02:00
if (!this->WriteJUnitXML()) {
return 1;
}
2020-02-01 23:06:01 +01:00
if (!this->PostProcessHandler()) {
this->LogFile = nullptr;
return -1;
}
if (!failed.empty()) {
this->LogFile = nullptr;
return -1;
}
2020-08-30 11:54:41 +02:00
if (noTestsFoundError) {
this->LogFile = nullptr;
return -1;
}
2020-02-01 23:06:01 +01:00
this->LogFile = nullptr;
return 0;
}
2021-09-14 00:13:48 +02:00
/* Given a multi-option value `parts`, compile those parts into
* regular expressions in `expressions`. Skip empty values.
* Returns true if there were any expressions.
*/
static bool BuildLabelRE(const std::vector<std::string>& parts,
std::vector<cmsys::RegularExpression>& expressions)
{
expressions.clear();
for (const auto& p : parts) {
if (!p.empty()) {
expressions.emplace_back(p);
}
}
return !expressions.empty();
}
2020-02-01 23:06:01 +01:00
bool cmCTestTestHandler::ProcessOptions()
{
// Update internal data structure from generic one
this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
this->SetUseUnion(cmIsOn(this->GetOption("UseUnion")));
if (cmIsOn(this->GetOption("ScheduleRandom"))) {
this->CTest->SetScheduleType("Random");
}
2021-11-20 13:41:27 +01:00
if (cmValue repeat = this->GetOption("Repeat")) {
2020-08-30 11:54:41 +02:00
cmsys::RegularExpression repeatRegex(
"^(UNTIL_FAIL|UNTIL_PASS|AFTER_TIMEOUT):([0-9]+)$");
2023-05-23 16:38:00 +02:00
if (repeatRegex.find(*repeat)) {
2020-08-30 11:54:41 +02:00
std::string const& count = repeatRegex.match(2);
unsigned long n = 1;
cmStrToULong(count, &n); // regex guarantees success
this->RepeatCount = static_cast<int>(n);
if (this->RepeatCount > 1) {
std::string const& mode = repeatRegex.match(1);
if (mode == "UNTIL_FAIL") {
this->RepeatMode = cmCTest::Repeat::UntilFail;
} else if (mode == "UNTIL_PASS") {
this->RepeatMode = cmCTest::Repeat::UntilPass;
} else if (mode == "AFTER_TIMEOUT") {
this->RepeatMode = cmCTest::Repeat::AfterTimeout;
}
}
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2023-05-23 16:38:00 +02:00
"Repeat option invalid value: " << *repeat << std::endl);
2020-08-30 11:54:41 +02:00
return false;
}
}
2020-02-01 23:06:01 +01:00
if (this->GetOption("ParallelLevel")) {
2023-05-23 16:38:00 +02:00
this->CTest->SetParallelLevel(
std::stoi(*this->GetOption("ParallelLevel")));
2020-02-01 23:06:01 +01:00
}
2020-08-30 11:54:41 +02:00
if (this->GetOption("StopOnFailure")) {
this->CTest->SetStopOnFailure(true);
}
2021-09-14 00:13:48 +02:00
BuildLabelRE(this->GetMultiOption("LabelRegularExpression"),
this->IncludeLabelRegularExpressions);
BuildLabelRE(this->GetMultiOption("ExcludeLabelRegularExpression"),
this->ExcludeLabelRegularExpressions);
2021-11-20 13:41:27 +01:00
cmValue val = this->GetOption("IncludeRegularExpression");
2020-02-01 23:06:01 +01:00
if (val) {
this->UseIncludeRegExp();
2023-05-23 16:38:00 +02:00
this->SetIncludeRegExp(*val);
2020-02-01 23:06:01 +01:00
}
val = this->GetOption("ExcludeRegularExpression");
if (val) {
this->UseExcludeRegExp();
2023-05-23 16:38:00 +02:00
this->SetExcludeRegExp(*val);
2020-02-01 23:06:01 +01:00
}
val = this->GetOption("ExcludeFixtureRegularExpression");
if (val) {
2021-11-20 13:41:27 +01:00
this->ExcludeFixtureRegExp = *val;
2020-02-01 23:06:01 +01:00
}
val = this->GetOption("ExcludeFixtureSetupRegularExpression");
if (val) {
2021-11-20 13:41:27 +01:00
this->ExcludeFixtureSetupRegExp = *val;
2020-02-01 23:06:01 +01:00
}
val = this->GetOption("ExcludeFixtureCleanupRegularExpression");
if (val) {
2021-11-20 13:41:27 +01:00
this->ExcludeFixtureCleanupRegExp = *val;
2020-02-01 23:06:01 +01:00
}
val = this->GetOption("ResourceSpecFile");
if (val) {
2021-11-20 13:41:27 +01:00
this->ResourceSpecFile = *val;
2020-02-01 23:06:01 +01:00
}
2020-08-30 11:54:41 +02:00
this->SetRerunFailed(cmIsOn(this->GetOption("RerunFailed")));
2020-02-01 23:06:01 +01:00
return true;
}
void cmCTestTestHandler::LogTestSummary(const std::vector<std::string>& passed,
const std::vector<std::string>& failed,
const cmDuration& durationInSecs)
{
std::size_t total = passed.size() + failed.size();
2022-08-04 22:12:04 +02:00
float percent =
static_cast<float>(passed.size()) * 100.0f / static_cast<float>(total);
2020-02-01 23:06:01 +01:00
if (!failed.empty() && percent > 99) {
percent = 99;
}
std::string passColorCode;
std::string failedColorCode;
if (failed.empty()) {
passColorCode = this->CTest->GetColorCode(cmCTest::Color::GREEN);
} else {
failedColorCode = this->CTest->GetColorCode(cmCTest::Color::RED);
}
cmCTestLog(this->CTest, HANDLER_OUTPUT,
std::endl
<< passColorCode << std::lround(percent) << "% tests passed"
<< this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
<< ", " << failedColorCode << failed.size() << " tests failed"
<< this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
<< " out of " << total << std::endl);
if ((!this->CTest->GetLabelsForSubprojects().empty() &&
this->CTest->GetSubprojectSummary())) {
this->PrintLabelOrSubprojectSummary(true);
}
if (this->CTest->GetLabelSummary()) {
this->PrintLabelOrSubprojectSummary(false);
}
char realBuf[1024];
2022-03-29 21:10:50 +02:00
snprintf(realBuf, sizeof(realBuf), "%6.2f sec", durationInSecs.count());
2020-02-01 23:06:01 +01:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"\nTotal Test time (real) = " << realBuf << "\n",
this->Quiet);
}
void cmCTestTestHandler::LogDisabledTests(
const std::vector<cmCTestTestResult>& disabledTests)
{
if (!disabledTests.empty()) {
cmGeneratedFileStream ofs;
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
std::endl
2020-02-01 23:06:01 +01:00
<< "The following tests did not run:" << std::endl);
this->StartLogFile("TestsDisabled", ofs);
2017-07-20 19:35:53 +02:00
2020-02-01 23:06:01 +01:00
const char* disabled_reason;
cmCTestLog(this->CTest, HANDLER_OUTPUT,
this->CTest->GetColorCode(cmCTest::Color::BLUE));
for (cmCTestTestResult const& dt : disabledTests) {
ofs << dt.TestCount << ":" << dt.Name << std::endl;
if (dt.CompletionStatus == "Disabled") {
disabled_reason = "Disabled";
} else {
disabled_reason = "Skipped";
2017-07-20 19:35:53 +02:00
}
2019-11-11 23:01:05 +01:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
2020-02-01 23:06:01 +01:00
"\t" << std::setw(3) << dt.TestCount << " - " << dt.Name
<< " (" << disabled_reason << ")" << std::endl);
2017-07-20 19:35:53 +02:00
}
2020-02-01 23:06:01 +01:00
cmCTestLog(this->CTest, HANDLER_OUTPUT,
this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR));
}
}
2017-07-20 19:35:53 +02:00
2020-02-01 23:06:01 +01:00
void cmCTestTestHandler::LogFailedTests(const std::vector<std::string>& failed,
const SetOfTests& resultsSet)
{
if (!failed.empty()) {
cmGeneratedFileStream ofs;
cmCTestLog(this->CTest, HANDLER_OUTPUT,
std::endl
<< "The following tests FAILED:" << std::endl);
this->StartLogFile("TestsFailed", ofs);
for (cmCTestTestResult const& ft : resultsSet) {
if (ft.Status != cmCTestTestHandler::COMPLETED &&
!cmHasLiteralPrefix(ft.CompletionStatus, "SKIP_") &&
ft.CompletionStatus != "Disabled") {
ofs << ft.TestCount << ":" << ft.Name << std::endl;
auto testColor = cmCTest::Color::RED;
if (this->GetTestStatus(ft) == "Not Run") {
testColor = cmCTest::Color::YELLOW;
}
2020-02-01 23:06:01 +01:00
cmCTestLog(
this->CTest, HANDLER_OUTPUT,
"\t" << this->CTest->GetColorCode(testColor) << std::setw(3)
<< ft.TestCount << " - " << ft.Name << " ("
<< this->GetTestStatus(ft) << ")"
<< this->CTest->GetColorCode(cmCTest::Color::CLEAR_COLOR)
<< std::endl);
}
}
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
}
2020-02-01 23:06:01 +01:00
bool cmCTestTestHandler::GenerateXML()
{
2016-07-09 11:21:54 +02:00
if (this->CTest->GetProduceXML()) {
cmGeneratedFileStream xmlfile;
2016-07-09 11:21:54 +02:00
if (!this->StartResultingXML(
2009-10-04 10:30:41 +03:00
(this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
2016-07-09 11:21:54 +02:00
(this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot create "
2016-07-09 11:21:54 +02:00
<< (this->MemCheck ? "memory check" : "testing")
<< " XML file" << std::endl);
2018-01-26 17:06:56 +01:00
this->LogFile = nullptr;
2020-02-01 23:06:01 +01:00
return false;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
cmXMLWriter xml(xmlfile);
2021-11-20 13:41:27 +01:00
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);
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
return true;
}
2018-01-26 17:06:56 +01:00
void cmCTestTestHandler::PrintLabelOrSubprojectSummary(bool doSubProject)
{
2018-01-26 17:06:56 +01:00
// collect subproject labels
std::vector<std::string> subprojects =
this->CTest->GetLabelsForSubprojects();
2015-04-27 22:25:09 +02:00
std::map<std::string, double> labelTimes;
2015-11-17 17:22:37 +01:00
std::map<std::string, int> labelCounts;
2015-04-27 22:25:09 +02:00
std::set<std::string> labels;
2009-10-04 10:30:41 +03:00
std::string::size_type maxlen = 0;
2018-01-26 17:06:56 +01:00
// initialize maps
for (cmCTestTestProperties& p : this->TestList) {
for (std::string const& l : p.Labels) {
// first check to see if the current label is a subproject label
bool isSubprojectLabel = false;
2020-02-01 23:06:01 +01:00
auto subproject = std::find(subprojects.begin(), subprojects.end(), l);
2018-01-26 17:06:56 +01:00
if (subproject != subprojects.end()) {
isSubprojectLabel = true;
}
// if we are doing sub projects and this label is one, then use it
// if we are not doing sub projects and the label is not one use it
2020-02-01 23:06:01 +01:00
if (doSubProject == isSubprojectLabel) {
2018-01-26 17:06:56 +01:00
if (l.size() > maxlen) {
maxlen = l.size();
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
labels.insert(l);
labelTimes[l] = 0;
labelCounts[l] = 0;
2009-10-04 10:30:41 +03:00
}
}
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// fill maps
2018-01-26 17:06:56 +01:00
for (cmCTestTestResult& result : this->TestResults) {
2010-03-17 14:00:29 +02:00
cmCTestTestProperties& p = *result.Properties;
2018-01-26 17:06:56 +01:00
for (std::string const& l : p.Labels) {
// only use labels found in labels
2020-08-30 11:54:41 +02:00
if (cm::contains(labels, l)) {
2018-04-23 21:13:27 +02:00
labelTimes[l] +=
result.ExecutionTime.count() * result.Properties->Processors;
2018-01-26 17:06:56 +01:00
++labelCounts[l];
2009-10-04 10:30:41 +03:00
}
}
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
// if no labels are found return and print nothing
if (labels.empty()) {
return;
}
2011-06-19 15:41:06 +03:00
// now print times
2018-01-26 17:06:56 +01:00
if (doSubProject) {
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"\nSubproject Time Summary:", this->Quiet);
} else {
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"\nLabel Time Summary:", this->Quiet);
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
for (std::string const& i : labels) {
std::string label = i;
2016-07-09 11:21:54 +02:00
label.resize(maxlen + 3, ' ');
2015-11-17 17:22:37 +01:00
2009-10-04 10:30:41 +03:00
char buf[1024];
2022-03-29 21:10:50 +02:00
snprintf(buf, sizeof(buf), "%6.2f sec*proc", labelTimes[i]);
2015-11-17 17:22:37 +01:00
std::ostringstream labelCountStr;
2018-01-26 17:06:56 +01:00
labelCountStr << "(" << labelCounts[i] << " test";
if (labelCounts[i] > 1) {
2015-11-17 17:22:37 +01:00
labelCountStr << "s";
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
labelCountStr << ")";
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
"\n"
2016-07-09 11:21:54 +02:00
<< label << " = " << buf << " "
<< labelCountStr.str(),
this->Quiet);
if (this->LogFile) {
2018-01-26 17:06:56 +01:00
*this->LogFile << "\n" << i << " = " << buf << "\n";
2016-07-09 11:21:54 +02:00
}
}
2018-01-26 17:06:56 +01:00
if (this->LogFile) {
*this->LogFile << "\n";
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet);
2009-10-04 10:30:41 +03:00
}
2021-09-14 00:13:48 +02:00
/**
* Check if the labels (from a test) match all the expressions.
*
* Each of the RE's must match at least one label
* (e.g. all of the REs must match **some** label,
* in order for the filter to apply to the test).
*/
static bool MatchLabelsAgainstFilterRE(
const std::vector<std::string>& labels,
const std::vector<cmsys::RegularExpression>& expressions)
{
for (const auto& re : expressions) {
// check to see if the label regular expression matches
bool found = false; // assume it does not match
cmsys::RegularExpressionMatch match;
// loop over all labels and look for match
for (std::string const& l : labels) {
if (re.find(l.c_str(), match)) {
found = true;
break;
}
}
// if no match was found, exclude the test
if (!found) {
return false;
}
}
return true;
}
2009-10-04 10:30:41 +03:00
void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
{
// if not using Labels to filter then return
2021-09-14 00:13:48 +02:00
if (this->IncludeLabelRegularExpressions.empty()) {
2009-10-04 10:30:41 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// if there are no labels and we are filtering by labels
// then exclude the test as it does not have the label
2016-07-09 11:21:54 +02:00
if (it.Labels.empty()) {
2009-10-04 10:30:41 +03:00
it.IsInBasedOnREOptions = false;
return;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// if no match was found, exclude the test
2021-09-14 00:13:48 +02:00
if (!MatchLabelsAgainstFilterRE(it.Labels,
this->IncludeLabelRegularExpressions)) {
2009-10-04 10:30:41 +03:00
it.IsInBasedOnREOptions = false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
}
2009-10-04 10:30:41 +03:00
void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
{
// if not using Labels to filter then return
2021-09-14 00:13:48 +02:00
if (this->ExcludeLabelRegularExpressions.empty()) {
2009-10-04 10:30:41 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// if there are no labels and we are excluding by labels
// then do nothing as a no label can not be a match
2016-07-09 11:21:54 +02:00
if (it.Labels.empty()) {
2009-10-04 10:30:41 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// if match was found, exclude the test
2021-09-14 00:13:48 +02:00
if (MatchLabelsAgainstFilterRE(it.Labels,
this->ExcludeLabelRegularExpressions)) {
2009-10-04 10:30:41 +03:00
it.IsInBasedOnREOptions = false;
2016-07-09 11:21:54 +02:00
}
}
2009-10-04 10:30:41 +03:00
void cmCTestTestHandler::CheckLabelFilter(cmCTestTestProperties& it)
{
2009-10-04 10:30:41 +03:00
this->CheckLabelFilterInclude(it);
this->CheckLabelFilterExclude(it);
}
2021-09-14 00:13:48 +02:00
bool cmCTestTestHandler::ComputeTestList()
2009-10-04 10:30:41 +03:00
{
this->TestList.clear(); // clear list of test
2021-09-14 00:13:48 +02:00
if (!this->GetListOfTests()) {
return false;
}
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
if (this->RerunFailed) {
2014-08-03 19:52:23 +02:00
this->ComputeTestListForRerunFailed();
2021-09-14 00:13:48 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
// how many tests are in based on RegExp?
int inREcnt = 0;
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& tp : this->TestList) {
this->CheckLabelFilter(tp);
if (tp.IsInBasedOnREOptions) {
2016-07-09 11:21:54 +02:00
inREcnt++;
}
2016-07-09 11:21:54 +02:00
}
// expand the test list based on the union flag
2016-07-09 11:21:54 +02:00
if (this->UseUnion) {
2018-01-26 17:06:56 +01:00
this->ExpandTestsToRunInformation(static_cast<int>(tmsize));
2016-07-09 11:21:54 +02:00
} else {
this->ExpandTestsToRunInformation(inREcnt);
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
// Now create a final list of tests to run
int cnt = 0;
inREcnt = 0;
2017-04-14 19:02:05 +02:00
std::string last_directory;
2009-10-04 10:30:41 +03:00
ListOfTests finalList;
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& tp : this->TestList) {
2016-07-09 11:21:54 +02:00
cnt++;
2018-01-26 17:06:56 +01:00
if (tp.IsInBasedOnREOptions) {
inREcnt++;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (this->UseUnion) {
// if it is not in the list and not in the regexp then skip
2020-08-30 11:54:41 +02:00
if ((!this->TestsToRun.empty() &&
!cm::contains(this->TestsToRun, cnt)) &&
2018-01-26 17:06:56 +01:00
!tp.IsInBasedOnREOptions) {
continue;
}
2016-07-09 11:21:54 +02:00
} else {
// is this test in the list of tests to run? If not then skip it
2015-04-27 22:25:09 +02:00
if ((!this->TestsToRun.empty() &&
2020-08-30 11:54:41 +02:00
!cm::contains(this->TestsToRun, inREcnt)) ||
2018-01-26 17:06:56 +01:00
!tp.IsInBasedOnREOptions) {
continue;
}
2009-10-04 10:30:41 +03:00
}
2018-01-26 17:06:56 +01:00
tp.Index = cnt; // save the index into the test list for this test
finalList.push_back(tp);
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
2021-09-14 00:13:48 +02:00
this->UpdateForFixtures(finalList);
2016-10-30 18:24:19 +01:00
2009-10-04 10:30:41 +03:00
// Save the total number of tests before exclusions
this->TotalNumberOfTests = this->TestList.size();
// Set the TestList to the final list of all test
this->TestList = finalList;
2014-08-03 19:52:23 +02:00
this->UpdateMaxTestNameWidth();
2021-09-14 00:13:48 +02:00
return true;
2014-08-03 19:52:23 +02:00
}
void cmCTestTestHandler::ComputeTestListForRerunFailed()
{
this->ExpandTestsToRunInformationForRerunFailed();
ListOfTests finalList;
int cnt = 0;
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& tp : this->TestList) {
2016-07-09 11:21:54 +02:00
cnt++;
2014-08-03 19:52:23 +02:00
// if this test is not in our list of tests to run, then skip it.
2020-08-30 11:54:41 +02:00
if (!this->TestsToRun.empty() && !cm::contains(this->TestsToRun, cnt)) {
2014-08-03 19:52:23 +02:00
continue;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2018-01-26 17:06:56 +01:00
tp.Index = cnt;
finalList.push_back(tp);
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2021-09-14 00:13:48 +02:00
this->UpdateForFixtures(finalList);
2016-10-30 18:24:19 +01:00
2014-08-03 19:52:23 +02:00
// Save the total number of tests before exclusions
this->TotalNumberOfTests = this->TestList.size();
// Set the TestList to the list of failed tests to rerun
this->TestList = finalList;
this->UpdateMaxTestNameWidth();
}
2016-10-30 18:24:19 +01:00
void cmCTestTestHandler::UpdateForFixtures(ListOfTests& tests) const
{
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Updating test list for fixtures" << std::endl,
this->Quiet);
2017-07-20 19:35:53 +02:00
// Prepare regular expression evaluators
std::string setupRegExp(this->ExcludeFixtureRegExp);
std::string cleanupRegExp(this->ExcludeFixtureRegExp);
if (!this->ExcludeFixtureSetupRegExp.empty()) {
if (setupRegExp.empty()) {
setupRegExp = this->ExcludeFixtureSetupRegExp;
} else {
setupRegExp.append("(" + setupRegExp + ")|(" +
this->ExcludeFixtureSetupRegExp + ")");
}
}
if (!this->ExcludeFixtureCleanupRegExp.empty()) {
if (cleanupRegExp.empty()) {
cleanupRegExp = this->ExcludeFixtureCleanupRegExp;
} else {
cleanupRegExp.append("(" + cleanupRegExp + ")|(" +
this->ExcludeFixtureCleanupRegExp + ")");
}
}
cmsys::RegularExpression excludeSetupRegex(setupRegExp);
cmsys::RegularExpression excludeCleanupRegex(cleanupRegExp);
2016-10-30 18:24:19 +01:00
// Prepare some maps to help us find setup and cleanup tests for
// any given fixture
2020-02-01 23:06:01 +01:00
using TestIterator = ListOfTests::const_iterator;
using FixtureDependencies = std::multimap<std::string, TestIterator>;
using FixtureDepsIterator = FixtureDependencies::const_iterator;
2016-10-30 18:24:19 +01:00
FixtureDependencies fixtureSetups;
2017-07-20 19:35:53 +02:00
FixtureDependencies fixtureCleanups;
2016-10-30 18:24:19 +01:00
2020-02-01 23:06:01 +01:00
for (auto it = this->TestList.begin(); it != this->TestList.end(); ++it) {
2016-10-30 18:24:19 +01:00
const cmCTestTestProperties& p = *it;
2018-01-26 17:06:56 +01:00
for (std::string const& deps : p.FixturesSetup) {
fixtureSetups.insert(std::make_pair(deps, it));
2016-10-30 18:24:19 +01:00
}
2018-01-26 17:06:56 +01:00
for (std::string const& deps : p.FixturesCleanup) {
fixtureCleanups.insert(std::make_pair(deps, it));
2016-10-30 18:24:19 +01:00
}
}
// Prepare fast lookup of tests already included in our list of tests
std::set<std::string> addedTests;
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties const& p : tests) {
2016-10-30 18:24:19 +01:00
addedTests.insert(p.Name);
}
2017-04-14 19:02:05 +02:00
// These are lookups of fixture name to a list of indices into the final
// tests array for tests which require that fixture and tests which are
// setups for that fixture. They are needed at the end to populate
// dependencies of the cleanup tests in our final list of tests.
2018-01-26 17:06:56 +01:00
std::map<std::string, std::vector<size_t>> fixtureRequirements;
std::map<std::string, std::vector<size_t>> setupFixturesAdded;
2016-10-30 18:24:19 +01:00
// Use integer index for iteration because we append to
// the tests vector as we go
size_t fixtureTestsAdded = 0;
std::set<std::string> addedFixtures;
for (size_t i = 0; i < tests.size(); ++i) {
2017-07-20 19:35:53 +02:00
// Skip disabled tests
if (tests[i].Disabled) {
continue;
}
2017-04-14 19:02:05 +02:00
// There are two things to do for each test:
// 1. For every fixture required by this test, record that fixture as
// being required and create dependencies on that fixture's setup
// tests.
// 2. Record all setup tests in the final test list so we can later make
// cleanup tests in the test list depend on their associated setup
// tests to enforce correct ordering.
// 1. Handle fixture requirements
//
// Must copy the set of fixtures required because we may invalidate
2016-10-30 18:24:19 +01:00
// the tests array by appending to it
2017-04-14 19:02:05 +02:00
std::set<std::string> fixtures = tests[i].FixturesRequired;
2018-01-26 17:06:56 +01:00
for (std::string const& requiredFixtureName : fixtures) {
2016-10-30 18:24:19 +01:00
if (requiredFixtureName.empty()) {
continue;
}
fixtureRequirements[requiredFixtureName].push_back(i);
// Add dependencies to this test for all of the setup tests
// associated with the required fixture. If any of those setup
// tests fail, this test should not run. We make the fixture's
// cleanup tests depend on this test case later.
2017-04-14 19:02:05 +02:00
std::pair<FixtureDepsIterator, FixtureDepsIterator> setupRange =
fixtureSetups.equal_range(requiredFixtureName);
2020-02-01 23:06:01 +01:00
for (auto sIt = setupRange.first; sIt != setupRange.second; ++sIt) {
2017-04-14 19:02:05 +02:00
const std::string& setupTestName = sIt->second->Name;
tests[i].RequireSuccessDepends.insert(setupTestName);
2020-08-30 11:54:41 +02:00
if (!cm::contains(tests[i].Depends, setupTestName)) {
2017-04-14 19:02:05 +02:00
tests[i].Depends.push_back(setupTestName);
2016-10-30 18:24:19 +01:00
}
}
// Append any fixture setup/cleanup tests to our test list if they
// are not already in it (they could have been in the original
// set of tests passed to us at the outset or have already been
// added from a previously checked test). A fixture isn't required
// to have setup/cleanup tests.
if (!addedFixtures.insert(requiredFixtureName).second) {
2017-07-20 19:35:53 +02:00
// Already seen this fixture, no need to check it again
2016-10-30 18:24:19 +01:00
continue;
}
2017-07-20 19:35:53 +02:00
// Only add setup tests if this fixture has not been excluded
if (setupRegExp.empty() ||
!excludeSetupRegex.find(requiredFixtureName)) {
std::pair<FixtureDepsIterator, FixtureDepsIterator> fixtureRange =
fixtureSetups.equal_range(requiredFixtureName);
2020-02-01 23:06:01 +01:00
for (auto it = fixtureRange.first; it != fixtureRange.second; ++it) {
2017-07-20 19:35:53 +02:00
ListOfTests::const_iterator lotIt = it->second;
const cmCTestTestProperties& p = *lotIt;
if (!addedTests.insert(p.Name).second) {
// Already have p in our test list
continue;
}
// This is a test not yet in our list, so add it and
// update its index to reflect where it was in the original
// full list of all tests (needed to track individual tests
// across ctest runs for re-run failed, etc.)
tests.push_back(p);
tests.back().Index =
1 + static_cast<int>(std::distance(this->TestList.begin(), lotIt));
++fixtureTestsAdded;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Added setup test "
<< p.Name << " required by fixture "
<< requiredFixtureName << std::endl,
this->Quiet);
2016-10-30 18:24:19 +01:00
}
2017-07-20 19:35:53 +02:00
}
2016-10-30 18:24:19 +01:00
2017-07-20 19:35:53 +02:00
// Only add cleanup tests if this fixture has not been excluded
if (cleanupRegExp.empty() ||
!excludeCleanupRegex.find(requiredFixtureName)) {
std::pair<FixtureDepsIterator, FixtureDepsIterator> fixtureRange =
fixtureCleanups.equal_range(requiredFixtureName);
2020-02-01 23:06:01 +01:00
for (auto it = fixtureRange.first; it != fixtureRange.second; ++it) {
2017-07-20 19:35:53 +02:00
ListOfTests::const_iterator lotIt = it->second;
const cmCTestTestProperties& p = *lotIt;
if (!addedTests.insert(p.Name).second) {
// Already have p in our test list
continue;
}
// This is a test not yet in our list, so add it and
// update its index to reflect where it was in the original
// full list of all tests (needed to track individual tests
// across ctest runs for re-run failed, etc.)
tests.push_back(p);
tests.back().Index =
1 + static_cast<int>(std::distance(this->TestList.begin(), lotIt));
++fixtureTestsAdded;
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Added cleanup test "
<< p.Name << " required by fixture "
<< requiredFixtureName << std::endl,
this->Quiet);
}
2016-10-30 18:24:19 +01:00
}
}
2017-04-14 19:02:05 +02:00
// 2. Record all setup fixtures included in the final list of tests
2018-01-26 17:06:56 +01:00
for (std::string const& setupFixtureName : tests[i].FixturesSetup) {
2017-04-14 19:02:05 +02:00
if (setupFixtureName.empty()) {
continue;
}
setupFixturesAdded[setupFixtureName].push_back(i);
}
2016-10-30 18:24:19 +01:00
}
// Now that we have the final list of tests, we can update all cleanup
2017-04-14 19:02:05 +02:00
// tests to depend on those tests which require that fixture and on any
// setup tests for that fixture. The latter is required to handle the
// pathological case where setup and cleanup tests are in the test set
// but no other test has that fixture as a requirement.
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& p : tests) {
2016-10-30 18:24:19 +01:00
const std::set<std::string>& cleanups = p.FixturesCleanup;
2018-01-26 17:06:56 +01:00
for (std::string const& fixture : cleanups) {
2017-04-14 19:02:05 +02:00
// This cleanup test could be part of the original test list that was
// passed in. It is then possible that no other test requires the
// fIt fixture, so we have to check for this.
2020-02-01 23:06:01 +01:00
auto cIt = fixtureRequirements.find(fixture);
2017-04-14 19:02:05 +02:00
if (cIt != fixtureRequirements.end()) {
const std::vector<size_t>& indices = cIt->second;
2018-01-26 17:06:56 +01:00
for (size_t index : indices) {
const std::string& reqTestName = tests[index].Name;
2020-08-30 11:54:41 +02:00
if (!cm::contains(p.Depends, reqTestName)) {
2017-04-14 19:02:05 +02:00
p.Depends.push_back(reqTestName);
}
}
2016-10-30 18:24:19 +01:00
}
2017-04-14 19:02:05 +02:00
// Ensure fixture cleanup tests always run after their setup tests, even
// if no other test cases require the fixture
cIt = setupFixturesAdded.find(fixture);
if (cIt != setupFixturesAdded.end()) {
const std::vector<size_t>& indices = cIt->second;
2018-01-26 17:06:56 +01:00
for (size_t index : indices) {
const std::string& setupTestName = tests[index].Name;
2020-08-30 11:54:41 +02:00
if (!cm::contains(p.Depends, setupTestName)) {
2017-04-14 19:02:05 +02:00
p.Depends.push_back(setupTestName);
}
2016-10-30 18:24:19 +01:00
}
}
}
}
2018-08-09 18:06:22 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Added " << fixtureTestsAdded
<< " tests to meet fixture requirements"
<< std::endl,
2016-10-30 18:24:19 +01:00
this->Quiet);
}
2014-08-03 19:52:23 +02:00
void cmCTestTestHandler::UpdateMaxTestNameWidth()
{
2009-10-04 10:30:41 +03:00
std::string::size_type max = this->CTest->GetMaxTestNameWidth();
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& p : this->TestList) {
2016-07-09 11:21:54 +02:00
if (max < p.Name.size()) {
2009-10-04 10:30:41 +03:00
max = p.Name.size();
}
2016-07-09 11:21:54 +02:00
}
if (static_cast<std::string::size_type>(
this->CTest->GetMaxTestNameWidth()) != max) {
2009-10-04 10:30:41 +03:00
this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
}
2011-06-19 15:41:06 +03:00
2016-07-09 11:21:54 +02:00
bool cmCTestTestHandler::GetValue(const char* tag, int& value,
2014-08-03 19:52:23 +02:00
std::istream& fin)
2009-10-04 10:30:41 +03:00
{
std::string line;
bool ret = true;
cmSystemTools::GetLineFromStream(fin, line);
2016-07-09 11:21:54 +02:00
if (line == tag) {
2009-10-04 10:30:41 +03:00
fin >> value;
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2016-07-09 11:21:54 +02:00
} else {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: " << tag << " found [" << line << "]"
<< std::endl);
2009-10-04 10:30:41 +03:00
ret = false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
return ret;
}
2016-07-09 11:21:54 +02:00
bool cmCTestTestHandler::GetValue(const char* tag, double& value,
2014-08-03 19:52:23 +02:00
std::istream& fin)
2009-10-04 10:30:41 +03:00
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
bool ret = true;
2016-07-09 11:21:54 +02:00
if (line == tag) {
2009-10-04 10:30:41 +03:00
fin >> value;
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2016-07-09 11:21:54 +02:00
} else {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: " << tag << " found [" << line << "]"
<< std::endl);
2009-10-04 10:30:41 +03:00
ret = false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
return ret;
}
2016-07-09 11:21:54 +02:00
bool cmCTestTestHandler::GetValue(const char* tag, bool& value,
2014-08-03 19:52:23 +02:00
std::istream& fin)
2009-10-04 10:30:41 +03:00
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
bool ret = true;
2016-07-09 11:21:54 +02:00
if (line == tag) {
2009-10-04 10:30:41 +03:00
#ifdef __HAIKU__
int tmp = 0;
fin >> tmp;
value = false;
2016-07-09 11:21:54 +02:00
if (tmp) {
2009-10-04 10:30:41 +03:00
value = true;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
#else
fin >> value;
#endif
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2016-07-09 11:21:54 +02:00
} else {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: " << tag << " found [" << line << "]"
<< std::endl);
2009-10-04 10:30:41 +03:00
ret = false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
return ret;
}
2016-07-09 11:21:54 +02:00
bool cmCTestTestHandler::GetValue(const char* tag, size_t& value,
2014-08-03 19:52:23 +02:00
std::istream& fin)
2009-10-04 10:30:41 +03:00
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
bool ret = true;
2016-07-09 11:21:54 +02:00
if (line == tag) {
2009-10-04 10:30:41 +03:00
fin >> value;
ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
2016-07-09 11:21:54 +02:00
} else {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: " << tag << " found [" << line << "]"
<< std::endl);
2009-10-04 10:30:41 +03:00
ret = false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
return ret;
}
2016-07-09 11:21:54 +02:00
bool cmCTestTestHandler::GetValue(const char* tag, std::string& value,
2014-08-03 19:52:23 +02:00
std::istream& fin)
2009-10-04 10:30:41 +03:00
{
std::string line;
cmSystemTools::GetLineFromStream(fin, line);
bool ret = true;
2016-07-09 11:21:54 +02:00
if (line == tag) {
ret = cmSystemTools::GetLineFromStream(fin, value);
} else {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"parse error: missing tag: " << tag << " found [" << line << "]"
<< std::endl);
2009-10-04 10:30:41 +03:00
ret = false;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
return ret;
}
2020-08-30 11:54:41 +02:00
bool cmCTestTestHandler::ProcessDirectory(std::vector<std::string>& passed,
2016-07-09 11:21:54 +02:00
std::vector<std::string>& failed)
2009-10-04 10:30:41 +03:00
{
2021-09-14 00:13:48 +02:00
if (!this->ComputeTestList()) {
return false;
}
2009-10-04 10:30:41 +03:00
this->StartTest = this->CTest->CurrentTime();
2018-04-23 21:13:27 +02:00
this->StartTestTime = std::chrono::system_clock::now();
auto elapsed_time_start = std::chrono::steady_clock::now();
2009-10-04 10:30:41 +03:00
2020-08-30 11:54:41 +02:00
auto parallel = cm::make_unique<cmCTestMultiProcessHandler>();
2009-10-04 10:30:41 +03:00
parallel->SetCTest(this->CTest);
parallel->SetParallelLevel(this->CTest->GetParallelLevel());
parallel->SetTestHandler(this);
2020-08-30 11:54:41 +02:00
if (this->RepeatMode != cmCTest::Repeat::Never) {
parallel->SetRepeatMode(this->RepeatMode, this->RepeatCount);
} else {
parallel->SetRepeatMode(this->CTest->GetRepeatMode(),
this->CTest->GetRepeatCount());
}
2015-08-17 11:37:30 +02:00
parallel->SetQuiet(this->Quiet);
2016-07-09 11:21:54 +02:00
if (this->TestLoad > 0) {
2015-11-17 17:22:37 +01:00
parallel->SetTestLoad(this->TestLoad);
2016-07-09 11:21:54 +02:00
} else {
2015-11-17 17:22:37 +01:00
parallel->SetTestLoad(this->CTest->GetTestLoad());
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
if (!this->ResourceSpecFile.empty()) {
this->UseResourceSpec = true;
2023-07-02 19:51:09 +02:00
if (!this->ResourceSpec.ReadFromJSONFile(this->ResourceSpecFile)) {
2020-08-30 11:54:41 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Could not read/parse resource spec file "
<< this->ResourceSpecFile << ": "
2023-07-02 19:51:09 +02:00
<< this->ResourceSpec.parseState.GetErrorMessage()
2020-08-30 11:54:41 +02:00
<< std::endl);
return false;
}
2020-02-01 23:06:01 +01:00
parallel->InitResourceAllocator(this->ResourceSpec);
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
*this->LogFile
<< "Start testing: " << this->CTest->CurrentTime() << std::endl
2009-10-04 10:30:41 +03:00
<< "----------------------------------------------------------"
<< std::endl;
cmCTestMultiProcessHandler::TestMap tests;
cmCTestMultiProcessHandler::PropertiesMap properties;
2011-06-19 15:41:06 +03:00
2010-03-17 14:00:29 +02:00
bool randomSchedule = this->CTest->GetScheduleType() == "Random";
2016-07-09 11:21:54 +02:00
if (randomSchedule) {
2018-01-26 17:06:56 +01:00
srand(static_cast<unsigned>(time(nullptr)));
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& p : this->TestList) {
2009-10-04 10:30:41 +03:00
cmCTestMultiProcessHandler::TestSet depends;
2016-07-09 11:21:54 +02:00
if (randomSchedule) {
2010-11-13 01:00:53 +02:00
p.Cost = static_cast<float>(rand());
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2016-07-09 11:21:54 +02:00
if (!p.Depends.empty()) {
2018-01-26 17:06:56 +01:00
for (std::string const& i : p.Depends) {
for (cmCTestTestProperties const& it2 : this->TestList) {
if (it2.Name == i) {
depends.insert(it2.Index);
2009-10-04 10:30:41 +03:00
break; // break out of test loop as name can only match 1
}
}
}
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
tests[p.Index] = depends;
properties[p.Index] = &p;
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
parallel->SetTests(tests, properties);
parallel->SetPassFailVectors(&passed, &failed);
this->TestResults.clear();
parallel->SetTestResults(&this->TestResults);
2020-02-01 23:06:01 +01:00
parallel->CheckResourcesAvailable();
2010-11-13 01:00:53 +02:00
2016-07-09 11:21:54 +02:00
if (this->CTest->ShouldPrintLabels()) {
2010-11-13 01:00:53 +02:00
parallel->PrintLabels();
2016-07-09 11:21:54 +02:00
} else if (this->CTest->GetShowOnly()) {
2009-10-04 10:30:41 +03:00
parallel->PrintTestList();
2016-07-09 11:21:54 +02:00
} else {
2009-10-04 10:30:41 +03:00
parallel->RunTests();
2016-07-09 11:21:54 +02:00
}
this->EndTest = this->CTest->CurrentTime();
2018-04-23 21:13:27 +02:00
this->EndTestTime = std::chrono::system_clock::now();
this->ElapsedTestingTime =
std::chrono::steady_clock::now() - elapsed_time_start;
2016-07-09 11:21:54 +02:00
*this->LogFile << "End testing: " << this->CTest->CurrentTime() << std::endl;
2020-08-30 11:54:41 +02:00
return true;
}
2016-10-30 18:24:19 +01:00
void cmCTestTestHandler::GenerateTestCommand(
std::vector<std::string>& /*unused*/, int /*unused*/)
{
}
2021-11-20 13:41:27 +01:00
void cmCTestTestHandler::GenerateCTestXML(cmXMLWriter& xml)
{
2016-07-09 11:21:54 +02:00
if (!this->CTest->GetProduceXML()) {
return;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
this->CTest->StartXML(xml, this->AppendXML);
2018-01-26 17:06:56 +01:00
this->CTest->GenerateSubprojectsOutput(xml);
2015-08-17 11:37:30 +02:00
xml.StartElement("Testing");
xml.Element("StartDateTime", this->StartTest);
xml.Element("StartTestTime", this->StartTestTime);
xml.StartElement("TestList");
2018-01-26 17:06:56 +01:00
for (cmCTestTestResult const& result : this->TestResults) {
std::string testPath = result.Path + "/" + result.Name;
2021-09-14 00:13:48 +02:00
xml.Element("Test", this->CTest->GetShortPathToFile(testPath));
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
xml.EndElement(); // TestList
2018-01-26 17:06:56 +01:00
for (cmCTestTestResult& result : this->TestResults) {
2015-08-17 11:37:30 +02:00
this->WriteTestResultHeader(xml, result);
xml.StartElement("Results");
2017-07-20 19:35:53 +02:00
2018-01-26 17:06:56 +01:00
if (result.Status != cmCTestTestHandler::NOT_RUN) {
if (result.Status != cmCTestTestHandler::COMPLETED ||
result.ReturnValue) {
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Exit Code");
2018-01-26 17:06:56 +01:00
xml.Element("Value", this->GetTestStatus(result));
2015-08-17 11:37:30 +02:00
xml.EndElement(); // NamedMeasurement
2017-07-20 19:35:53 +02:00
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Exit Value");
2018-01-26 17:06:56 +01:00
xml.Element("Value", result.ReturnValue);
2015-08-17 11:37:30 +02:00
xml.EndElement(); // NamedMeasurement
2016-07-09 11:21:54 +02:00
}
2021-11-20 13:41:27 +01:00
this->RecordCustomTestMeasurements(xml, result.TestMeasurementsOutput);
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "numeric/double");
xml.Attribute("name", "Execution Time");
2018-04-23 21:13:27 +02:00
xml.Element("Value", result.ExecutionTime.count());
2015-08-17 11:37:30 +02:00
xml.EndElement(); // NamedMeasurement
2018-01-26 17:06:56 +01:00
if (!result.Reason.empty()) {
2009-10-04 10:30:41 +03:00
const char* reasonType = "Pass Reason";
2018-01-26 17:06:56 +01:00
if (result.Status != cmCTestTestHandler::COMPLETED) {
2009-10-04 10:30:41 +03:00
reasonType = "Fail Reason";
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", reasonType);
2018-01-26 17:06:56 +01:00
xml.Element("Value", result.Reason);
2015-08-17 11:37:30 +02:00
xml.EndElement(); // NamedMeasurement
2016-07-09 11:21:54 +02:00
}
}
2017-07-20 19:35:53 +02:00
2018-01-26 17:06:56 +01:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "numeric/double");
xml.Attribute("name", "Processors");
xml.Element("Value", result.Properties->Processors);
xml.EndElement(); // NamedMeasurement
2017-07-20 19:35:53 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Completion Status");
2021-09-14 00:13:48 +02:00
if (result.CustomCompletionStatus.empty()) {
xml.Element("Value", result.CompletionStatus);
} else {
xml.Element("Value", result.CustomCompletionStatus);
}
2017-07-20 19:35:53 +02:00
xml.EndElement(); // NamedMeasurement
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Command Line");
2018-01-26 17:06:56 +01:00
xml.Element("Value", result.FullCommandLine);
2015-08-17 11:37:30 +02:00
xml.EndElement(); // NamedMeasurement
2020-08-30 11:54:41 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
xml.Attribute("name", "Environment");
xml.Element("Value", result.Environment);
xml.EndElement(); // NamedMeasurement
2018-01-26 17:06:56 +01:00
for (auto const& measure : result.Properties->Measurements) {
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
xml.Attribute("type", "text/string");
2018-01-26 17:06:56 +01:00
xml.Attribute("name", measure.first);
xml.Element("Value", measure.second);
2015-08-17 11:37:30 +02:00
xml.EndElement(); // NamedMeasurement
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
xml.StartElement("Measurement");
xml.StartElement("Value");
2018-01-26 17:06:56 +01:00
if (result.CompressOutput) {
2015-08-17 11:37:30 +02:00
xml.Attribute("encoding", "base64");
xml.Attribute("compression", "gzip");
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
xml.Content(result.Output);
2015-08-17 11:37:30 +02:00
xml.EndElement(); // Value
xml.EndElement(); // Measurement
xml.EndElement(); // Results
this->AttachFiles(xml, result);
this->WriteTestResultFooter(xml, result);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
xml.Element("EndDateTime", this->EndTest);
xml.Element("EndTestTime", this->EndTestTime);
2018-04-23 21:13:27 +02:00
xml.Element(
"ElapsedMinutes",
std::chrono::duration_cast<std::chrono::minutes>(this->ElapsedTestingTime)
.count());
2015-08-17 11:37:30 +02:00
xml.EndElement(); // Testing
this->CTest->EndXML(xml);
}
2015-08-17 11:37:30 +02:00
void cmCTestTestHandler::WriteTestResultHeader(cmXMLWriter& xml,
2018-01-26 17:06:56 +01:00
cmCTestTestResult const& result)
2009-10-04 10:30:41 +03:00
{
2015-08-17 11:37:30 +02:00
xml.StartElement("Test");
2018-01-26 17:06:56 +01:00
if (result.Status == cmCTestTestHandler::COMPLETED) {
2015-08-17 11:37:30 +02:00
xml.Attribute("Status", "passed");
2018-01-26 17:06:56 +01:00
} else if (result.Status == cmCTestTestHandler::NOT_RUN) {
2015-08-17 11:37:30 +02:00
xml.Attribute("Status", "notrun");
2016-07-09 11:21:54 +02:00
} else {
2015-08-17 11:37:30 +02:00
xml.Attribute("Status", "failed");
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
std::string testPath = result.Path + "/" + result.Name;
xml.Element("Name", result.Name);
2021-09-14 00:13:48 +02:00
xml.Element("Path", this->CTest->GetShortPathToFile(result.Path));
xml.Element("FullName", this->CTest->GetShortPathToFile(testPath));
2018-01-26 17:06:56 +01:00
xml.Element("FullCommandLine", result.FullCommandLine);
2009-10-04 10:30:41 +03:00
}
2015-08-17 11:37:30 +02:00
void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml,
2018-01-26 17:06:56 +01:00
cmCTestTestResult const& result)
2009-10-04 10:30:41 +03:00
{
2018-01-26 17:06:56 +01:00
if (!result.Properties->Labels.empty()) {
2015-08-17 11:37:30 +02:00
xml.StartElement("Labels");
2018-01-26 17:06:56 +01:00
std::vector<std::string> const& labels = result.Properties->Labels;
for (std::string const& label : labels) {
xml.Element("Label", label);
2009-10-04 10:30:41 +03:00
}
2016-07-09 11:21:54 +02:00
xml.EndElement(); // Labels
}
2009-10-04 10:30:41 +03:00
2015-08-17 11:37:30 +02:00
xml.EndElement(); // Test
2009-10-04 10:30:41 +03:00
}
2015-08-17 11:37:30 +02:00
void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml,
2018-01-26 17:06:56 +01:00
cmCTestTestResult& result)
2010-03-17 14:00:29 +02:00
{
2018-01-26 17:06:56 +01:00
if (result.Status != cmCTestTestHandler::COMPLETED &&
!result.Properties->AttachOnFail.empty()) {
result.Properties->AttachedFiles.insert(
result.Properties->AttachedFiles.end(),
result.Properties->AttachOnFail.begin(),
result.Properties->AttachOnFail.end());
}
for (std::string const& file : result.Properties->AttachedFiles) {
2021-09-14 00:13:48 +02:00
this->AttachFile(xml, file, "");
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
}
2021-09-14 00:13:48 +02:00
void cmCTestTestHandler::AttachFile(cmXMLWriter& xml, std::string const& file,
std::string const& name)
{
const std::string& base64 = this->CTest->Base64GzipEncodeFile(file);
std::string const fname = cmSystemTools::GetFilenameName(file);
xml.StartElement("NamedMeasurement");
std::string measurement_name = name;
if (measurement_name.empty()) {
measurement_name = "Attached File";
}
xml.Attribute("name", measurement_name);
xml.Attribute("encoding", "base64");
xml.Attribute("compression", "tar/gzip");
xml.Attribute("filename", fname);
xml.Attribute("type", "file");
xml.Element("Value", base64);
xml.EndElement(); // NamedMeasurement
}
2015-04-27 22:25:09 +02:00
int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
{
2018-01-26 17:06:56 +01:00
for (std::string const& it : vec) {
int retVal = 0;
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2018-01-26 17:06:56 +01:00
"Run command: " << it << std::endl, this->Quiet);
2019-11-11 23:01:05 +01:00
if (!cmSystemTools::RunSingleCommand(it, nullptr, nullptr, &retVal,
2018-01-26 17:06:56 +01:00
nullptr, cmSystemTools::OUTPUT_MERGE
2016-07-09 11:21:54 +02:00
/*this->Verbose*/) ||
retVal != 0) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
2018-01-26 17:06:56 +01:00
"Problem running command: " << it << std::endl);
return 0;
}
2016-07-09 11:21:54 +02:00
}
return 1;
}
// Find the appropriate executable to run for a test
2021-09-14 00:13:48 +02:00
std::string cmCTestTestHandler::FindTheExecutable(const std::string& exe)
{
std::string resConfig;
std::vector<std::string> extraPaths;
std::vector<std::string> failedPaths;
2021-09-14 00:13:48 +02:00
if (exe == "NOT_AVAILABLE") {
2011-06-19 15:41:06 +03:00
return exe;
2016-07-09 11:21:54 +02:00
}
return cmCTestTestHandler::FindExecutable(this->CTest, exe, resConfig,
extraPaths, failedPaths);
}
// add additional configurations to the search path
2016-07-09 11:21:54 +02:00
void cmCTestTestHandler::AddConfigurations(
cmCTest* ctest, std::vector<std::string>& attempted,
std::vector<std::string>& attemptedConfigs, std::string filepath,
std::string& filename)
2010-03-17 14:00:29 +02:00
{
std::string tempPath;
2016-07-09 11:21:54 +02:00
if (!filepath.empty() && filepath[filepath.size() - 1] != '/') {
filepath += "/";
2016-07-09 11:21:54 +02:00
}
tempPath = filepath + filename;
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back();
2011-06-19 15:41:06 +03:00
2016-07-09 11:21:54 +02:00
if (!ctest->GetConfigType().empty()) {
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, ctest->GetConfigType(), '/', filename);
attempted.push_back(tempPath);
attemptedConfigs.push_back(ctest->GetConfigType());
2013-11-03 12:27:13 +02:00
// If the file is an OSX bundle then the configtype
// will be at the start of the path
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(ctest->GetConfigType(), '/', filepath, filename);
attempted.push_back(tempPath);
attemptedConfigs.push_back(ctest->GetConfigType());
2016-07-09 11:21:54 +02:00
} else {
2013-11-03 12:27:13 +02:00
// no config specified - try some options...
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, "Release/", filename);
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back("Release");
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, "Debug/", filename);
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back("Debug");
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, "MinSizeRel/", filename);
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back("MinSizeRel");
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, "RelWithDebInfo/", filename);
2011-06-19 15:41:06 +03:00
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back("RelWithDebInfo");
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, "Deployment/", filename);
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back("Deployment");
2020-02-01 23:06:01 +01:00
tempPath = cmStrCat(filepath, "Development/", filename);
attempted.push_back(tempPath);
2019-11-11 23:01:05 +01:00
attemptedConfigs.emplace_back("Deployment");
2016-07-09 11:21:54 +02:00
}
}
// Find the appropriate executable to run for a test
2016-07-09 11:21:54 +02:00
std::string cmCTestTestHandler::FindExecutable(
2021-09-14 00:13:48 +02:00
cmCTest* ctest, const std::string& testCommand, std::string& resultingConfig,
2016-07-09 11:21:54 +02:00
std::vector<std::string>& extraPaths, std::vector<std::string>& failed)
{
// now run the compiled test if we can find it
std::vector<std::string> attempted;
std::vector<std::string> attemptedConfigs;
std::string tempPath;
2016-07-09 11:21:54 +02:00
std::string filepath = cmSystemTools::GetFilenamePath(testCommand);
std::string filename = cmSystemTools::GetFilenameName(testCommand);
2016-07-09 11:21:54 +02:00
cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
filepath, filename);
2009-10-04 10:30:41 +03:00
// even if a fullpath was specified also try it relative to the current
// directory
2016-07-09 11:21:54 +02:00
if (!filepath.empty() && filepath[0] == '/') {
std::string localfilepath = filepath.substr(1, filepath.size() - 1);
cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
localfilepath, filename);
}
2011-06-19 15:41:06 +03:00
// if extraPaths are provided and we were not passed a full path, try them,
// try any extra paths
2016-07-09 11:21:54 +02:00
if (filepath.empty()) {
2018-01-26 17:06:56 +01:00
for (std::string const& extraPath : extraPaths) {
std::string filepathExtra = cmSystemTools::GetFilenamePath(extraPath);
std::string filenameExtra = cmSystemTools::GetFilenameName(extraPath);
2016-07-09 11:21:54 +02:00
cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
filepathExtra, filenameExtra);
2011-06-19 15:41:06 +03:00
}
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
// store the final location in fullPath
std::string fullPath;
// now look in the paths we specified above
2016-07-09 11:21:54 +02:00
for (unsigned int ai = 0; ai < attempted.size() && fullPath.empty(); ++ai) {
// first check without exe extension
2018-04-23 21:13:27 +02:00
if (cmSystemTools::FileExists(attempted[ai]) &&
2016-07-09 11:21:54 +02:00
!cmSystemTools::FileIsDirectory(attempted[ai])) {
2015-04-27 22:25:09 +02:00
fullPath = cmSystemTools::CollapseFullPath(attempted[ai]);
resultingConfig = attemptedConfigs[ai];
2016-07-09 11:21:54 +02:00
}
// then try with the exe extension
2016-07-09 11:21:54 +02:00
else {
2015-04-27 22:25:09 +02:00
failed.push_back(attempted[ai]);
2020-02-01 23:06:01 +01:00
tempPath =
cmStrCat(attempted[ai], cmSystemTools::GetExecutableExtension());
2018-04-23 21:13:27 +02:00
if (cmSystemTools::FileExists(tempPath) &&
2016-07-09 11:21:54 +02:00
!cmSystemTools::FileIsDirectory(tempPath)) {
2015-04-27 22:25:09 +02:00
fullPath = cmSystemTools::CollapseFullPath(tempPath);
resultingConfig = attemptedConfigs[ai];
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
failed.push_back(tempPath);
}
}
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
// if everything else failed, check the users path, but only if a full path
// wasn't specified
2016-07-09 11:21:54 +02:00
if (fullPath.empty() && filepath.empty()) {
2021-09-14 00:13:48 +02:00
std::string path = cmSystemTools::FindProgram(filename.c_str());
2018-01-26 17:06:56 +01:00
if (!path.empty()) {
resultingConfig.clear();
return path;
}
2016-07-09 11:21:54 +02:00
}
if (fullPath.empty()) {
2018-08-09 18:06:22 +02:00
cmCTestLog(ctest, HANDLER_OUTPUT,
"Could not find executable "
2016-07-09 11:21:54 +02:00
<< testCommand << "\n"
<< "Looked in the following places:\n");
2018-01-26 17:06:56 +01:00
for (std::string const& f : failed) {
cmCTestLog(ctest, HANDLER_OUTPUT, f << "\n");
}
2016-07-09 11:21:54 +02:00
}
2011-06-19 15:41:06 +03:00
return fullPath;
}
2020-02-01 23:06:01 +01:00
bool cmCTestTestHandler::ParseResourceGroupsProperty(
const std::string& val,
std::vector<std::vector<cmCTestTestResourceRequirement>>& resourceGroups)
{
cmCTestResourceGroupsLexerHelper lexer(resourceGroups);
return lexer.ParseString(val);
}
2021-09-14 00:13:48 +02:00
bool cmCTestTestHandler::GetListOfTests()
{
2016-07-09 11:21:54 +02:00
if (!this->IncludeRegExp.empty()) {
2021-09-14 00:13:48 +02:00
this->IncludeTestsRegularExpression.compile(this->IncludeRegExp);
2016-07-09 11:21:54 +02:00
}
if (!this->ExcludeRegExp.empty()) {
2021-09-14 00:13:48 +02:00
this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
"Constructing a list of tests" << std::endl, this->Quiet);
2019-11-11 23:01:05 +01:00
cmake cm(cmake::RoleScript, cmState::CTest);
2015-08-17 11:37:30 +02:00
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
2016-03-13 13:35:51 +01:00
cm.GetCurrentSnapshot().SetDefaultDefinitions();
2015-08-17 11:37:30 +02:00
cmGlobalGenerator gg(&cm);
2018-01-26 17:06:56 +01:00
cmMakefile mf(&gg, cm.GetCurrentSnapshot());
2020-02-01 23:06:01 +01:00
mf.AddDefinition("CTEST_CONFIGURATION_TYPE", this->CTest->GetConfigType());
// Add handler for ADD_TEST
2020-02-01 23:06:01 +01:00
cm.GetState()->AddBuiltinCommand("add_test", cmCTestAddTestCommand(this));
// Add handler for SUBDIRS
2020-02-01 23:06:01 +01:00
cm.GetState()->AddBuiltinCommand("subdirs", cmCTestSubdirCommand);
// Add handler for ADD_SUBDIRECTORY
2020-02-01 23:06:01 +01:00
cm.GetState()->AddBuiltinCommand("add_subdirectory",
cmCTestAddSubdirectoryCommand);
2017-07-20 19:35:53 +02:00
// Add handler for SET_TESTS_PROPERTIES
2020-02-01 23:06:01 +01:00
cm.GetState()->AddBuiltinCommand("set_tests_properties",
cmCTestSetTestsPropertiesCommand(this));
2018-01-26 17:06:56 +01:00
// Add handler for SET_DIRECTORY_PROPERTIES
2018-11-29 20:27:00 +01:00
cm.GetState()->RemoveBuiltinCommand("set_directory_properties");
2020-02-01 23:06:01 +01:00
cm.GetState()->AddBuiltinCommand("set_directory_properties",
cmCTestSetDirectoryPropertiesCommand(this));
2018-01-26 17:06:56 +01:00
const char* testFilename;
2016-07-09 11:21:54 +02:00
if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
// does the CTestTestfile.cmake exist ?
testFilename = "CTestTestfile.cmake";
2016-07-09 11:21:54 +02:00
} else if (cmSystemTools::FileExists("DartTestfile.txt")) {
// does the DartTestfile.txt exist ?
testFilename = "DartTestfile.txt";
2016-07-09 11:21:54 +02:00
} else {
2021-09-14 00:13:48 +02:00
return true;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (!mf.ReadListFile(testFilename)) {
2021-09-14 00:13:48 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2022-08-04 22:12:04 +02:00
if (cmSystemTools::GetErrorOccurredFlag()) {
2021-09-14 00:13:48 +02:00
// SEND_ERROR or FATAL_ERROR in CTestTestfile or TEST_INCLUDE_FILES
return false;
2016-07-09 11:21:54 +02:00
}
2021-11-20 13:41:27 +01:00
cmValue specFile = mf.GetDefinition("CTEST_RESOURCE_SPEC_FILE");
2020-08-30 11:54:41 +02:00
if (this->ResourceSpecFile.empty() && specFile) {
2021-09-14 00:13:48 +02:00
this->ResourceSpecFile = *specFile;
2020-08-30 11:54:41 +02:00
}
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
"Done constructing a list of tests" << std::endl,
this->Quiet);
2021-09-14 00:13:48 +02:00
return true;
}
void cmCTestTestHandler::UseIncludeRegExp()
{
this->UseIncludeRegExpFlag = true;
}
void cmCTestTestHandler::UseExcludeRegExp()
{
this->UseExcludeRegExpFlag = true;
2016-10-30 18:24:19 +01:00
this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag;
}
2019-11-11 23:01:05 +01:00
std::string cmCTestTestHandler::GetTestStatus(cmCTestTestResult const& result)
{
2017-07-20 19:35:53 +02:00
static const char* statuses[] = { "Not Run", "Timeout", "SEGFAULT",
"ILLEGAL", "INTERRUPT", "NUMERICAL",
"OTHER_FAULT", "Failed", "BAD_COMMAND",
"Completed" };
2018-01-26 17:06:56 +01:00
int status = result.Status;
2016-07-09 11:21:54 +02:00
if (status < cmCTestTestHandler::NOT_RUN ||
status > cmCTestTestHandler::COMPLETED) {
return "No Status";
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (status == cmCTestTestHandler::OTHER_FAULT) {
2019-11-11 23:01:05 +01:00
return result.ExceptionStatus;
2018-01-26 17:06:56 +01:00
}
return statuses[status];
}
2009-10-04 10:30:41 +03:00
void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
{
2016-07-09 11:21:54 +02:00
if (this->TestsToRunString.empty()) {
return;
2016-07-09 11:21:54 +02:00
}
int start;
int end = -1;
double stride = -1;
std::string::size_type pos = 0;
std::string::size_type pos2;
// read start
2016-07-09 11:21:54 +02:00
if (GetNextNumber(this->TestsToRunString, start, pos, pos2)) {
// read end
2016-07-09 11:21:54 +02:00
if (GetNextNumber(this->TestsToRunString, end, pos, pos2)) {
// read stride
2016-07-09 11:21:54 +02:00
if (GetNextRealNumber(this->TestsToRunString, stride, pos, pos2)) {
int val = 0;
// now read specific numbers
2016-07-09 11:21:54 +02:00
while (GetNextNumber(this->TestsToRunString, val, pos, pos2)) {
this->TestsToRun.push_back(val);
}
2016-07-09 11:21:54 +02:00
this->TestsToRun.push_back(val);
}
}
2016-07-09 11:21:54 +02:00
}
// if start is not specified then we assume we start at 1
2016-07-09 11:21:54 +02:00
if (start == -1) {
start = 1;
2016-07-09 11:21:54 +02:00
}
// if end isnot specified then we assume we end with the last test
2016-07-09 11:21:54 +02:00
if (end == -1) {
2009-10-04 10:30:41 +03:00
end = static_cast<int>(numTests);
2016-07-09 11:21:54 +02:00
}
// if the stride wasn't specified then it defaults to 1
2016-07-09 11:21:54 +02:00
if (stride == -1) {
stride = 1;
2016-07-09 11:21:54 +02:00
}
// if we have a range then add it
2016-07-09 11:21:54 +02:00
if (end != -1 && start != -1 && stride > 0) {
int i = 0;
2016-07-09 11:21:54 +02:00
while (i * stride + start <= end) {
this->TestsToRun.push_back(static_cast<int>(i * stride + start));
++i;
}
2016-07-09 11:21:54 +02:00
}
// sort the array
std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
2016-07-09 11:21:54 +02:00
std::less<int>());
// remove duplicates
2020-02-01 23:06:01 +01:00
auto new_end = std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
this->TestsToRun.erase(new_end, this->TestsToRun.end());
}
2014-08-03 19:52:23 +02:00
void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
{
std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
cmsys::Directory directory;
2021-09-14 00:13:48 +02:00
if (!directory.Load(dirName)) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Unable to read the contents of " << dirName << std::endl);
2014-08-03 19:52:23 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
int numFiles =
static_cast<int>(cmsys::Directory::GetNumberOfFilesInDirectory(dirName));
2014-08-03 19:52:23 +02:00
std::string pattern = "LastTestsFailed";
2017-04-14 19:02:05 +02:00
std::string logName;
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
for (int i = 0; i < numFiles; ++i) {
2014-08-03 19:52:23 +02:00
std::string fileName = directory.GetFile(i);
// bcc crashes if we attempt a normal substring comparison,
// hence the following workaround
std::string fileNameSubstring = fileName.substr(0, pattern.length());
2017-07-20 19:35:53 +02:00
if (fileNameSubstring != pattern) {
2014-08-03 19:52:23 +02:00
continue;
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (logName.empty()) {
2014-08-03 19:52:23 +02:00
logName = fileName;
2016-07-09 11:21:54 +02:00
} else {
2014-08-03 19:52:23 +02:00
// if multiple matching logs were found we use the most recently
// modified one.
int res;
2015-04-27 22:25:09 +02:00
cmSystemTools::FileTimeCompare(logName, fileName, &res);
2016-07-09 11:21:54 +02:00
if (res == -1) {
2014-08-03 19:52:23 +02:00
logName = fileName;
}
}
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
std::string lastTestsFailedLog =
this->CTest->GetBinaryDir() + "/Testing/Temporary/" + logName;
2014-08-03 19:52:23 +02:00
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(lastTestsFailedLog)) {
2016-07-09 11:21:54 +02:00
if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
lastTestsFailedLog << " does not exist!" << std::endl);
2014-08-03 19:52:23 +02:00
}
2016-07-09 11:21:54 +02:00
return;
}
2014-08-03 19:52:23 +02:00
// parse the list of tests to rerun from LastTestsFailed.log
cmsys::ifstream ifs(lastTestsFailedLog.c_str());
2016-07-09 11:21:54 +02:00
if (ifs) {
2014-08-03 19:52:23 +02:00
std::string line;
std::string::size_type pos;
2016-07-09 11:21:54 +02:00
while (cmSystemTools::GetLineFromStream(ifs, line)) {
2014-08-03 19:52:23 +02:00
pos = line.find(':', 0);
2017-07-20 19:35:53 +02:00
if (pos == std::string::npos) {
2014-08-03 19:52:23 +02:00
continue;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
2020-08-30 11:54:41 +02:00
line.erase(pos);
int val = atoi(line.c_str());
2014-08-03 19:52:23 +02:00
this->TestsToRun.push_back(val);
}
2016-07-09 11:21:54 +02:00
ifs.close();
} else if (!this->CTest->GetShowOnly() &&
!this->CTest->ShouldPrintLabels()) {
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Problem reading file: "
2016-07-09 11:21:54 +02:00
<< lastTestsFailedLog
<< " while generating list of previously failed tests."
<< std::endl);
}
2014-08-03 19:52:23 +02:00
}
2021-11-20 13:41:27 +01:00
void cmCTestTestHandler::RecordCustomTestMeasurements(cmXMLWriter& xml,
std::string content)
{
2021-11-20 13:41:27 +01:00
while (this->SingleTestMeasurementRegex.find(content)) {
// Extract regex match from content and parse it as an XML element.
auto measurement_str = this->SingleTestMeasurementRegex.match(1);
auto parser = cmCTestTestMeasurementXMLParser();
parser.Parse(measurement_str.c_str());
if (parser.ElementName == "CTestMeasurement" ||
parser.ElementName == "DartMeasurement") {
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
2021-11-20 13:41:27 +01:00
xml.Attribute("type", parser.MeasurementType);
xml.Attribute("name", parser.MeasurementName);
xml.Element("Value", parser.CharacterData);
2015-08-17 11:37:30 +02:00
xml.EndElement();
2021-11-20 13:41:27 +01:00
} else if (parser.ElementName == "CTestMeasurementFile" ||
parser.ElementName == "DartMeasurementFile") {
const std::string& filename = cmCTest::CleanString(parser.CharacterData);
if (!cmSystemTools::FileExists(filename)) {
xml.StartElement("NamedMeasurement");
xml.Attribute("name", parser.MeasurementName);
xml.Attribute("text", "text/string");
xml.Element("Value", "File " + filename + " not found");
xml.EndElement();
cmCTestOptionalLog(
this->CTest, HANDLER_OUTPUT,
"File \"" << filename << "\" not found." << std::endl, this->Quiet);
} else {
2015-04-27 22:25:09 +02:00
long len = cmSystemTools::FileLength(filename);
2016-07-09 11:21:54 +02:00
if (len == 0) {
2015-08-17 11:37:30 +02:00
xml.StartElement("NamedMeasurement");
2021-11-20 13:41:27 +01:00
xml.Attribute("name", parser.MeasurementName);
xml.Attribute("type", "text/string");
2015-08-17 11:37:30 +02:00
xml.Attribute("encoding", "none");
xml.Element("Value", "Image " + filename + " is empty");
xml.EndElement();
2016-07-09 11:21:54 +02:00
} else {
2021-11-20 13:41:27 +01:00
if (parser.MeasurementType == "file") {
2021-09-14 00:13:48 +02:00
// Treat this measurement like an "ATTACHED_FILE" when the type
// is explicitly "file" (not an image).
2021-11-20 13:41:27 +01:00
this->AttachFile(xml, filename, parser.MeasurementName);
2021-09-14 00:13:48 +02:00
} else {
cmsys::ifstream ifs(filename.c_str(),
std::ios::in
#ifdef _WIN32
2021-09-14 00:13:48 +02:00
| std::ios::binary
#endif
2021-09-14 00:13:48 +02:00
);
auto file_buffer = cm::make_unique<unsigned char[]>(len + 1);
ifs.read(reinterpret_cast<char*>(file_buffer.get()), len);
auto encoded_buffer = cm::make_unique<unsigned char[]>(
static_cast<int>(static_cast<double>(len) * 1.5 + 5.0));
size_t rlen = cmsysBase64_Encode(file_buffer.get(), len,
encoded_buffer.get(), 1);
xml.StartElement("NamedMeasurement");
2021-11-20 13:41:27 +01:00
xml.Attribute("name", parser.MeasurementName);
xml.Attribute("type", parser.MeasurementType);
2021-09-14 00:13:48 +02:00
xml.Attribute("encoding", "base64");
std::ostringstream ostr;
for (size_t cc = 0; cc < rlen; cc++) {
ostr << encoded_buffer[cc];
if (cc % 60 == 0 && cc) {
ostr << std::endl;
}
}
2021-09-14 00:13:48 +02:00
xml.Element("Value", ostr.str());
xml.EndElement(); // NamedMeasurement
2016-07-09 11:21:54 +02:00
}
}
}
}
2021-11-20 13:41:27 +01:00
// Remove this element from content.
cmSystemTools::ReplaceString(content, measurement_str.c_str(), "");
2016-07-09 11:21:54 +02:00
}
}
2021-11-20 13:41:27 +01:00
void cmCTestTestHandler::SetIncludeRegExp(const std::string& arg)
{
this->IncludeRegExp = arg;
}
2021-11-20 13:41:27 +01:00
void cmCTestTestHandler::SetExcludeRegExp(const std::string& arg)
{
this->ExcludeRegExp = arg;
}
2022-08-04 22:12:04 +02:00
bool cmCTestTestHandler::SetTestOutputTruncation(const std::string& mode)
{
if (mode == "tail") {
this->TestOutputTruncation = cmCTestTypes::TruncationMode::Tail;
} else if (mode == "middle") {
this->TestOutputTruncation = cmCTestTypes::TruncationMode::Middle;
} else if (mode == "head") {
this->TestOutputTruncation = cmCTestTypes::TruncationMode::Head;
} else {
return false;
}
return true;
}
2021-11-20 13:41:27 +01:00
void cmCTestTestHandler::SetTestsToRunInformation(cmValue in)
{
2016-07-09 11:21:54 +02:00
if (!in) {
return;
2016-07-09 11:21:54 +02:00
}
2021-11-20 13:41:27 +01:00
this->TestsToRunString = *in;
// if the argument is a file, then read it and use the contents as the
// string
2023-05-23 16:38:00 +02:00
if (cmSystemTools::FileExists(*in)) {
2021-11-20 13:41:27 +01:00
cmsys::ifstream fin(in->c_str());
2023-05-23 16:38:00 +02:00
unsigned long filelen = cmSystemTools::FileLength(*in);
2020-08-30 11:54:41 +02:00
auto buff = cm::make_unique<char[]>(filelen + 1);
fin.getline(buff.get(), filelen);
buff[fin.gcount()] = 0;
2020-08-30 11:54:41 +02:00
this->TestsToRunString = buff.get();
2016-07-09 11:21:54 +02:00
}
}
2022-08-04 22:12:04 +02:00
void cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length,
cmCTestTypes::TruncationMode truncate)
{
2016-07-09 11:21:54 +02:00
if (!length || length >= output.size() ||
2017-07-20 19:35:53 +02:00
output.find("CTEST_FULL_OUTPUT") != std::string::npos) {
2020-08-30 11:54:41 +02:00
return;
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
2022-08-04 22:12:04 +02:00
// Advance n bytes in string delimited by begin/end but do not break in the
// middle of a multi-byte UTF-8 encoding.
auto utf8_advance = [](char const* const begin, char const* const end,
size_t n) -> const char* {
char const* const stop = begin + n;
char const* current = begin;
while (current < stop) {
unsigned int ch;
if (const char* next = cm_utf8_decode_character(current, end, &ch)) {
if (next > stop) {
break;
}
current = next;
} else // Bad byte will be handled by cmXMLWriter.
{
++current;
}
}
2022-08-04 22:12:04 +02:00
return current;
};
// Truncation message.
const std::string msg =
"\n[This part of the test output was removed since it "
"exceeds the threshold of " +
std::to_string(length) + " bytes.]\n";
2011-01-16 11:35:12 +01:00
2022-08-04 22:12:04 +02:00
char const* const begin = output.c_str();
char const* const end = begin + output.size();
// Erase head, middle or tail of output.
if (truncate == cmCTestTypes::TruncationMode::Head) {
char const* current = utf8_advance(begin, end, output.size() - length);
output.erase(0, current - begin);
output.insert(0, msg + "...");
} else if (truncate == cmCTestTypes::TruncationMode::Middle) {
char const* current = utf8_advance(begin, end, length / 2);
output.erase(current - begin, output.size() - length);
output.insert(current - begin, "..." + msg + "...");
} else { // default or "tail"
char const* current = utf8_advance(begin, end, length);
output.erase(current - begin);
output += ("..." + msg);
}
}
2023-07-02 19:51:09 +02:00
void cmCTestTestHandler::cmCTestTestProperties::AppendError(
cm::string_view err)
{
if (this->Error) {
*this->Error = cmStrCat(*this->Error, '\n', err);
} else {
this->Error = err;
}
}
bool cmCTestTestHandler::SetTestsProperties(
const std::vector<std::string>& args)
{
std::vector<std::string>::const_iterator it;
2015-04-27 22:25:09 +02:00
std::vector<std::string> tests;
bool found = false;
2016-07-09 11:21:54 +02:00
for (it = args.begin(); it != args.end(); ++it) {
if (*it == "PROPERTIES") {
found = true;
break;
}
2016-07-09 11:21:54 +02:00
tests.push_back(*it);
}
if (!found) {
return false;
2016-07-09 11:21:54 +02:00
}
++it; // skip PROPERTIES
for (; it != args.end(); ++it) {
2020-08-30 11:54:41 +02:00
std::string const& key = *it;
2016-07-09 11:21:54 +02:00
++it;
if (it == args.end()) {
break;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
std::string const& val = *it;
2018-01-26 17:06:56 +01:00
for (std::string const& t : tests) {
for (cmCTestTestProperties& rt : this->TestList) {
if (t == rt.Name) {
2020-08-30 11:54:41 +02:00
if (key == "_BACKTRACE_TRIPLES"_s) {
2019-11-11 23:01:05 +01:00
// allow empty args in the triples
2023-07-02 19:51:09 +02:00
cmList triples{ val, cmList::EmptyElements::Yes };
2019-11-11 23:01:05 +01:00
// Ensure we have complete triples otherwise the data is corrupt.
if (triples.size() % 3 == 0) {
2021-11-20 13:41:27 +01:00
cmState state(cmState::Unknown);
2022-03-29 21:10:50 +02:00
rt.Backtrace = cmListFileBacktrace();
2019-11-11 23:01:05 +01:00
// the first entry represents the top of the trace so we need to
// reconstruct the backtrace in reverse
2023-07-02 19:51:09 +02:00
for (auto i = triples.size(); i >= 3; i -= 3) {
2019-11-11 23:01:05 +01:00
cmListFileContext fc;
fc.FilePath = triples[i - 3];
long line = 0;
2020-02-01 23:06:01 +01:00
if (!cmStrToLong(triples[i - 2], &line)) {
2019-11-11 23:01:05 +01:00
line = 0;
}
fc.Line = line;
fc.Name = triples[i - 1];
rt.Backtrace = rt.Backtrace.Push(fc);
}
}
2020-08-30 11:54:41 +02:00
} else if (key == "WILL_FAIL"_s) {
2020-02-01 23:06:01 +01:00
rt.WillFail = cmIsOn(val);
2020-08-30 11:54:41 +02:00
} else if (key == "DISABLED"_s) {
2020-02-01 23:06:01 +01:00
rt.Disabled = cmIsOn(val);
2020-08-30 11:54:41 +02:00
} else if (key == "ATTACHED_FILES"_s) {
2020-02-01 23:06:01 +01:00
cmExpandList(val, rt.AttachedFiles);
2020-08-30 11:54:41 +02:00
} else if (key == "ATTACHED_FILES_ON_FAIL"_s) {
2020-02-01 23:06:01 +01:00
cmExpandList(val, rt.AttachOnFail);
2020-08-30 11:54:41 +02:00
} else if (key == "RESOURCE_LOCK"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2010-06-23 01:18:35 +03:00
2018-01-26 17:06:56 +01:00
rt.LockedResources.insert(lval.begin(), lval.end());
2020-08-30 11:54:41 +02:00
} else if (key == "FIXTURES_SETUP"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2016-10-30 18:24:19 +01:00
2018-01-26 17:06:56 +01:00
rt.FixturesSetup.insert(lval.begin(), lval.end());
2020-08-30 11:54:41 +02:00
} else if (key == "FIXTURES_CLEANUP"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2016-10-30 18:24:19 +01:00
2018-01-26 17:06:56 +01:00
rt.FixturesCleanup.insert(lval.begin(), lval.end());
2020-08-30 11:54:41 +02:00
} else if (key == "FIXTURES_REQUIRED"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2016-10-30 18:24:19 +01:00
2018-01-26 17:06:56 +01:00
rt.FixturesRequired.insert(lval.begin(), lval.end());
2020-08-30 11:54:41 +02:00
} else if (key == "TIMEOUT"_s) {
2018-04-23 21:13:27 +02:00
rt.Timeout = cmDuration(atof(val.c_str()));
2023-07-02 19:51:09 +02:00
} else if (key == "TIMEOUT_SIGNAL_NAME"_s) {
#ifdef _WIN32
rt.AppendError("TIMEOUT_SIGNAL_NAME is not supported on Windows.");
#else
std::string const& signalName = val;
Signal s;
if (signalName == "SIGINT"_s) {
s.Number = SIGINT;
} else if (signalName == "SIGQUIT"_s) {
s.Number = SIGQUIT;
} else if (signalName == "SIGTERM"_s) {
s.Number = SIGTERM;
} else if (signalName == "SIGUSR1"_s) {
s.Number = SIGUSR1;
} else if (signalName == "SIGUSR2"_s) {
s.Number = SIGUSR2;
}
if (s.Number) {
s.Name = signalName;
rt.TimeoutSignal = std::move(s);
} else {
rt.AppendError(cmStrCat("TIMEOUT_SIGNAL_NAME \"", signalName,
"\" not supported on this platform."));
}
#endif
} else if (key == "TIMEOUT_SIGNAL_GRACE_PERIOD"_s) {
#ifdef _WIN32
rt.AppendError(
"TIMEOUT_SIGNAL_GRACE_PERIOD is not supported on Windows.");
#else
std::string const& gracePeriod = val;
static cmDuration minGracePeriod{ 0 };
static cmDuration maxGracePeriod{ 60 };
cmDuration gp = cmDuration(atof(gracePeriod.c_str()));
if (gp <= minGracePeriod) {
rt.AppendError(cmStrCat("TIMEOUT_SIGNAL_GRACE_PERIOD \"",
gracePeriod, "\" is not greater than \"",
minGracePeriod.count(), "\" seconds."));
} else if (gp > maxGracePeriod) {
rt.AppendError(cmStrCat("TIMEOUT_SIGNAL_GRACE_PERIOD \"",
gracePeriod,
"\" is not less than the maximum of \"",
maxGracePeriod.count(), "\" seconds."));
} else {
rt.TimeoutGracePeriod = gp;
}
#endif
2020-08-30 11:54:41 +02:00
} else if (key == "COST"_s) {
2018-01-26 17:06:56 +01:00
rt.Cost = static_cast<float>(atof(val.c_str()));
2020-08-30 11:54:41 +02:00
} else if (key == "REQUIRED_FILES"_s) {
2020-02-01 23:06:01 +01:00
cmExpandList(val, rt.RequiredFiles);
2020-08-30 11:54:41 +02:00
} else if (key == "RUN_SERIAL"_s) {
2020-02-01 23:06:01 +01:00
rt.RunSerial = cmIsOn(val);
2020-08-30 11:54:41 +02:00
} else if (key == "FAIL_REGULAR_EXPRESSION"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2018-01-26 17:06:56 +01:00
for (std::string const& cr : lval) {
2018-04-23 21:13:27 +02:00
rt.ErrorRegularExpressions.emplace_back(cr, cr);
}
2020-08-30 11:54:41 +02:00
} else if (key == "SKIP_REGULAR_EXPRESSION"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2020-02-01 23:06:01 +01:00
for (std::string const& cr : lval) {
rt.SkipRegularExpressions.emplace_back(cr, cr);
}
2020-08-30 11:54:41 +02:00
} else if (key == "PROCESSORS"_s) {
2018-01-26 17:06:56 +01:00
rt.Processors = atoi(val.c_str());
if (rt.Processors < 1) {
rt.Processors = 1;
2009-10-04 10:30:41 +03:00
}
2020-08-30 11:54:41 +02:00
} else if (key == "PROCESSOR_AFFINITY"_s) {
2020-02-01 23:06:01 +01:00
rt.WantAffinity = cmIsOn(val);
2020-08-30 11:54:41 +02:00
} else if (key == "RESOURCE_GROUPS"_s) {
2020-02-01 23:06:01 +01:00
if (!ParseResourceGroupsProperty(val, rt.ResourceGroups)) {
return false;
}
2020-08-30 11:54:41 +02:00
} else if (key == "SKIP_RETURN_CODE"_s) {
2018-01-26 17:06:56 +01:00
rt.SkipReturnCode = atoi(val.c_str());
if (rt.SkipReturnCode < 0 || rt.SkipReturnCode > 255) {
rt.SkipReturnCode = -1;
2014-08-03 19:52:23 +02:00
}
2020-08-30 11:54:41 +02:00
} else if (key == "DEPENDS"_s) {
2020-02-01 23:06:01 +01:00
cmExpandList(val, rt.Depends);
2020-08-30 11:54:41 +02:00
} else if (key == "ENVIRONMENT"_s) {
2020-02-01 23:06:01 +01:00
cmExpandList(val, rt.Environment);
2021-11-20 13:41:27 +01:00
} else if (key == "ENVIRONMENT_MODIFICATION"_s) {
cmExpandList(val, rt.EnvironmentModification);
2020-08-30 11:54:41 +02:00
} else if (key == "LABELS"_s) {
2023-07-02 19:51:09 +02:00
cmList Labels{ val };
2018-01-26 17:06:56 +01:00
rt.Labels.insert(rt.Labels.end(), Labels.begin(), Labels.end());
// sort the array
std::sort(rt.Labels.begin(), rt.Labels.end());
// remove duplicates
2020-02-01 23:06:01 +01:00
auto new_end = std::unique(rt.Labels.begin(), rt.Labels.end());
2018-01-26 17:06:56 +01:00
rt.Labels.erase(new_end, rt.Labels.end());
2020-08-30 11:54:41 +02:00
} else if (key == "MEASUREMENT"_s) {
2016-07-09 11:21:54 +02:00
size_t pos = val.find_first_of('=');
2017-07-20 19:35:53 +02:00
if (pos != std::string::npos) {
std::string mKey = val.substr(0, pos);
2019-11-11 23:01:05 +01:00
std::string mVal = val.substr(pos + 1);
rt.Measurements[mKey] = std::move(mVal);
2016-07-09 11:21:54 +02:00
} else {
2018-01-26 17:06:56 +01:00
rt.Measurements[val] = "1";
}
2020-08-30 11:54:41 +02:00
} else if (key == "PASS_REGULAR_EXPRESSION"_s) {
2023-07-02 19:51:09 +02:00
cmList lval{ val };
2018-01-26 17:06:56 +01:00
for (std::string const& cr : lval) {
2018-04-23 21:13:27 +02:00
rt.RequiredRegularExpressions.emplace_back(cr, cr);
}
2020-08-30 11:54:41 +02:00
} else if (key == "WORKING_DIRECTORY"_s) {
2018-01-26 17:06:56 +01:00
rt.Directory = val;
2020-08-30 11:54:41 +02:00
} else if (key == "TIMEOUT_AFTER_MATCH"_s) {
2023-07-02 19:51:09 +02:00
cmList propArgs{ val };
2016-07-09 11:21:54 +02:00
if (propArgs.size() != 2) {
cmCTestLog(this->CTest, WARNING,
"TIMEOUT_AFTER_MATCH expects two arguments, found "
<< propArgs.size() << std::endl);
} else {
2018-04-23 21:13:27 +02:00
rt.AlternateTimeout = cmDuration(atof(propArgs[0].c_str()));
2023-07-02 19:51:09 +02:00
cmList lval{ propArgs[1] };
2018-01-26 17:06:56 +01:00
for (std::string const& cr : lval) {
2018-04-23 21:13:27 +02:00
rt.TimeoutRegularExpressions.emplace_back(cr, cr);
2016-07-09 11:21:54 +02:00
}
2011-01-16 11:35:12 +01:00
}
}
}
}
}
2016-07-09 11:21:54 +02:00
}
return true;
}
2018-01-26 17:06:56 +01:00
bool cmCTestTestHandler::SetDirectoryProperties(
const std::vector<std::string>& args)
{
std::vector<std::string>::const_iterator it;
std::vector<std::string> tests;
bool found = false;
for (it = args.begin(); it != args.end(); ++it) {
if (*it == "PROPERTIES") {
found = true;
break;
}
tests.push_back(*it);
}
if (!found) {
return false;
}
++it; // skip PROPERTIES
for (; it != args.end(); ++it) {
2020-08-30 11:54:41 +02:00
std::string const& key = *it;
2018-01-26 17:06:56 +01:00
++it;
if (it == args.end()) {
break;
}
2020-08-30 11:54:41 +02:00
std::string const& val = *it;
2018-01-26 17:06:56 +01:00
for (cmCTestTestProperties& rt : this->TestList) {
std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
if (cwd == rt.Directory) {
2020-08-30 11:54:41 +02:00
if (key == "LABELS"_s) {
2023-07-02 19:51:09 +02:00
cmList DirectoryLabels{ val };
2018-01-26 17:06:56 +01:00
rt.Labels.insert(rt.Labels.end(), DirectoryLabels.begin(),
DirectoryLabels.end());
// sort the array
std::sort(rt.Labels.begin(), rt.Labels.end());
// remove duplicates
2020-02-01 23:06:01 +01:00
auto new_end = std::unique(rt.Labels.begin(), rt.Labels.end());
2018-01-26 17:06:56 +01:00
rt.Labels.erase(new_end, rt.Labels.end());
}
}
}
}
return true;
}
bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
{
const std::string& testname = args[0];
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl,
2016-07-09 11:21:54 +02:00
this->Quiet);
2010-03-17 14:00:29 +02:00
2016-07-09 11:21:54 +02:00
if (this->UseExcludeRegExpFlag && this->UseExcludeRegExpFirst &&
2018-10-28 12:09:07 +01:00
this->ExcludeTestsRegularExpression.find(testname)) {
return true;
2016-07-09 11:21:54 +02:00
}
if (this->MemCheck) {
2015-04-27 22:25:09 +02:00
std::vector<std::string>::iterator it;
bool found = false;
2016-07-09 11:21:54 +02:00
for (it = this->CustomTestsIgnore.begin();
it != this->CustomTestsIgnore.end(); ++it) {
if (*it == testname) {
found = true;
break;
}
2016-07-09 11:21:54 +02:00
}
if (found) {
2015-08-17 11:37:30 +02:00
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
2016-07-09 11:21:54 +02:00
"Ignore memcheck: " << *it << std::endl, this->Quiet);
return true;
}
2016-07-09 11:21:54 +02:00
} else {
2015-04-27 22:25:09 +02:00
std::vector<std::string>::iterator it;
bool found = false;
2016-07-09 11:21:54 +02:00
for (it = this->CustomTestsIgnore.begin();
it != this->CustomTestsIgnore.end(); ++it) {
if (*it == testname) {
found = true;
break;
}
2016-07-09 11:21:54 +02:00
}
if (found) {
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Ignore test: " << *it << std::endl, this->Quiet);
return true;
}
2016-07-09 11:21:54 +02:00
}
cmCTestTestProperties test;
test.Name = testname;
test.Args = args;
test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
2016-07-09 11:21:54 +02:00
cmCTestOptionalLog(this->CTest, DEBUG,
"Set test directory: " << test.Directory << std::endl,
this->Quiet);
2011-06-19 15:41:06 +03:00
if (this->UseIncludeRegExpFlag &&
2020-08-30 11:54:41 +02:00
(!this->IncludeTestsRegularExpression.find(testname) ||
(!this->UseExcludeRegExpFirst &&
this->ExcludeTestsRegularExpression.find(testname)))) {
test.IsInBasedOnREOptions = false;
2016-07-09 11:21:54 +02:00
}
this->TestList.push_back(test);
return true;
}
2020-02-01 23:06:01 +01:00
bool cmCTestTestHandler::cmCTestTestResourceRequirement::operator==(
const cmCTestTestResourceRequirement& other) const
{
return this->ResourceType == other.ResourceType &&
this->SlotsNeeded == other.SlotsNeeded &&
this->UnitsNeeded == other.UnitsNeeded;
}
bool cmCTestTestHandler::cmCTestTestResourceRequirement::operator!=(
const cmCTestTestResourceRequirement& other) const
{
return !(*this == other);
}
2021-09-14 00:13:48 +02:00
void cmCTestTestHandler::SetJUnitXMLFileName(const std::string& filename)
{
this->JUnitXMLFileName = filename;
}
bool cmCTestTestHandler::WriteJUnitXML()
{
if (this->JUnitXMLFileName.empty()) {
return true;
}
// Open new XML file for writing.
cmGeneratedFileStream xmlfile;
xmlfile.SetTempExt("tmp");
xmlfile.Open(this->JUnitXMLFileName);
if (!xmlfile) {
cmCTestLog(this->CTest, ERROR_MESSAGE,
"Problem opening file: " << this->JUnitXMLFileName
<< std::endl);
return false;
}
cmXMLWriter xml(xmlfile);
// Iterate over the test results to get the number of tests that
// passed, failed, etc.
auto num_tests = 0;
auto num_failed = 0;
auto num_notrun = 0;
auto num_disabled = 0;
SetOfTests resultsSet(this->TestResults.begin(), this->TestResults.end());
for (cmCTestTestResult const& result : resultsSet) {
num_tests++;
2022-08-04 22:12:04 +02:00
if (result.Status == cmCTestTestHandler::NOT_RUN) {
2021-09-14 00:13:48 +02:00
if (result.CompletionStatus == "Disabled") {
num_disabled++;
} else {
num_notrun++;
}
2022-08-04 22:12:04 +02:00
} else if (result.Status != cmCTestTestHandler::COMPLETED) {
2021-09-14 00:13:48 +02:00
num_failed++;
}
}
// Write <testsuite> element.
xml.StartDocument();
xml.StartElement("testsuite");
xml.Attribute("name",
cmCTest::SafeBuildIdField(
this->CTest->GetCTestConfiguration("BuildName")));
xml.BreakAttributes();
xml.Attribute("tests", num_tests);
xml.Attribute("failures", num_failed);
// CTest disabled => JUnit disabled
xml.Attribute("disabled", num_disabled);
// Otherwise, CTest notrun => JUnit skipped.
// The distinction between JUnit disabled vs. skipped is that
// skipped tests can have a message associated with them
// (why the test was skipped).
xml.Attribute("skipped", num_notrun);
xml.Attribute("hostname", this->CTest->GetCTestConfiguration("Site"));
xml.Attribute(
"time",
std::chrono::duration_cast<std::chrono::seconds>(this->ElapsedTestingTime)
.count());
const std::time_t start_test_time_t =
std::chrono::system_clock::to_time_t(this->StartTestTime);
cmTimestamp cmts;
xml.Attribute("timestamp",
cmts.CreateTimestampFromTimeT(start_test_time_t,
"%Y-%m-%dT%H:%M:%S", false));
// Write <testcase> elements.
for (cmCTestTestResult const& result : resultsSet) {
xml.StartElement("testcase");
xml.Attribute("name", result.Name);
xml.Attribute("classname", result.Name);
xml.Attribute("time", result.ExecutionTime.count());
std::string status;
if (result.Status == cmCTestTestHandler::COMPLETED) {
status = "run";
} else if (result.Status == cmCTestTestHandler::NOT_RUN) {
if (result.CompletionStatus == "Disabled") {
status = "disabled";
} else {
status = "notrun";
}
} else {
status = "fail";
}
xml.Attribute("status", status);
if (status == "notrun") {
xml.StartElement("skipped");
xml.Attribute("message", result.CompletionStatus);
xml.EndElement(); // </skipped>
} else if (status == "fail") {
xml.StartElement("failure");
2023-07-02 19:51:09 +02:00
xml.Attribute("message", this->GetTestStatus(result));
2021-09-14 00:13:48 +02:00
xml.EndElement(); // </failure>
}
// Note: compressed test output is unconditionally disabled when
// --output-junit is specified.
xml.Element("system-out", result.Output);
xml.EndElement(); // </testcase>
}
xml.EndElement(); // </testsuite>
xml.EndDocument();
return true;
}