cmake/Source/CTest/cmCTestTestCommand.cxx

168 lines
5.7 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 "cmCTestTestCommand.h"
2020-02-01 23:06:01 +01:00
#include <chrono>
#include <cstdlib>
2023-12-07 09:12:54 +01:00
#include <ratio>
2020-02-01 23:06:01 +01:00
#include <sstream>
2020-08-30 11:54:41 +02:00
#include <cmext/string_view>
2020-02-01 23:06:01 +01:00
#include "cmCTest.h"
2019-11-11 23:01:05 +01:00
#include "cmCTestTestHandler.h"
2018-04-23 21:13:27 +02:00
#include "cmDuration.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2021-11-20 13:41:27 +01:00
#include "cmValue.h"
2016-10-30 18:24:19 +01:00
2020-02-01 23:06:01 +01:00
void cmCTestTestCommand::BindArguments()
{
2020-02-01 23:06:01 +01:00
this->cmCTestHandlerCommand::BindArguments();
this->Bind("START"_s, this->Start);
this->Bind("END"_s, this->End);
this->Bind("STRIDE"_s, this->Stride);
this->Bind("EXCLUDE"_s, this->Exclude);
this->Bind("INCLUDE"_s, this->Include);
this->Bind("EXCLUDE_LABEL"_s, this->ExcludeLabel);
this->Bind("INCLUDE_LABEL"_s, this->IncludeLabel);
2024-04-14 22:45:38 +02:00
this->Bind("EXCLUDE_FROM_FILE"_s, this->ExcludeTestsFromFile);
this->Bind("INCLUDE_FROM_FILE"_s, this->IncludeTestsFromFile);
2020-02-01 23:06:01 +01:00
this->Bind("EXCLUDE_FIXTURE"_s, this->ExcludeFixture);
this->Bind("EXCLUDE_FIXTURE_SETUP"_s, this->ExcludeFixtureSetup);
this->Bind("EXCLUDE_FIXTURE_CLEANUP"_s, this->ExcludeFixtureCleanup);
this->Bind("PARALLEL_LEVEL"_s, this->ParallelLevel);
2020-08-30 11:54:41 +02:00
this->Bind("REPEAT"_s, this->Repeat);
2020-02-01 23:06:01 +01:00
this->Bind("SCHEDULE_RANDOM"_s, this->ScheduleRandom);
this->Bind("STOP_TIME"_s, this->StopTime);
this->Bind("TEST_LOAD"_s, this->TestLoad);
this->Bind("RESOURCE_SPEC_FILE"_s, this->ResourceSpecFile);
2020-08-30 11:54:41 +02:00
this->Bind("STOP_ON_FAILURE"_s, this->StopOnFailure);
2021-09-14 00:13:48 +02:00
this->Bind("OUTPUT_JUNIT"_s, this->OutputJUnit);
}
cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler()
{
2021-11-20 13:41:27 +01:00
cmValue ctestTimeout = this->Makefile->GetDefinition("CTEST_TEST_TIMEOUT");
2010-03-17 14:00:29 +02:00
2018-04-23 21:13:27 +02:00
cmDuration timeout;
2016-07-09 11:21:54 +02:00
if (ctestTimeout) {
2021-09-14 00:13:48 +02:00
timeout = cmDuration(atof(ctestTimeout->c_str()));
2016-07-09 11:21:54 +02:00
} else {
2017-07-20 19:35:53 +02:00
timeout = this->CTest->GetTimeOut();
2018-04-23 21:13:27 +02:00
if (timeout <= cmDuration::zero()) {
// By default use timeout of 10 minutes
2018-04-23 21:13:27 +02:00
timeout = std::chrono::minutes(10);
}
2016-07-09 11:21:54 +02:00
}
this->CTest->SetTimeOut(timeout);
2020-08-30 11:54:41 +02:00
2021-11-20 13:41:27 +01:00
cmValue resourceSpecFile =
2020-08-30 11:54:41 +02:00
this->Makefile->GetDefinition("CTEST_RESOURCE_SPEC_FILE");
if (this->ResourceSpecFile.empty() && resourceSpecFile) {
2021-09-14 00:13:48 +02:00
this->ResourceSpecFile = *resourceSpecFile;
2020-08-30 11:54:41 +02:00
}
2021-09-14 00:13:48 +02:00
cmCTestTestHandler* handler = this->InitializeActualHandler();
2020-02-01 23:06:01 +01:00
if (!this->Start.empty() || !this->End.empty() || !this->Stride.empty()) {
handler->SetOption(
"TestsToRunInformation",
2021-11-20 13:41:27 +01:00
cmStrCat(this->Start, ',', this->End, ',', this->Stride));
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->Exclude.empty()) {
2021-11-20 13:41:27 +01:00
handler->SetOption("ExcludeRegularExpression", this->Exclude);
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->Include.empty()) {
2021-11-20 13:41:27 +01:00
handler->SetOption("IncludeRegularExpression", this->Include);
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->ExcludeLabel.empty()) {
2021-09-14 00:13:48 +02:00
handler->AddMultiOption("ExcludeLabelRegularExpression",
this->ExcludeLabel);
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->IncludeLabel.empty()) {
2021-09-14 00:13:48 +02:00
handler->AddMultiOption("LabelRegularExpression", this->IncludeLabel);
2016-07-09 11:21:54 +02:00
}
2024-04-14 22:45:38 +02:00
if (!this->ExcludeTestsFromFile.empty()) {
handler->SetOption("ExcludeTestListFile", this->ExcludeTestsFromFile);
}
if (!this->IncludeTestsFromFile.empty()) {
handler->SetOption("TestListFile", this->IncludeTestsFromFile);
}
2020-02-01 23:06:01 +01:00
if (!this->ExcludeFixture.empty()) {
2017-07-20 19:35:53 +02:00
handler->SetOption("ExcludeFixtureRegularExpression",
2021-11-20 13:41:27 +01:00
this->ExcludeFixture);
2017-07-20 19:35:53 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->ExcludeFixtureSetup.empty()) {
2017-07-20 19:35:53 +02:00
handler->SetOption("ExcludeFixtureSetupRegularExpression",
2021-11-20 13:41:27 +01:00
this->ExcludeFixtureSetup);
2017-07-20 19:35:53 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->ExcludeFixtureCleanup.empty()) {
2017-07-20 19:35:53 +02:00
handler->SetOption("ExcludeFixtureCleanupRegularExpression",
2021-11-20 13:41:27 +01:00
this->ExcludeFixtureCleanup);
2020-02-01 23:06:01 +01:00
}
2020-08-30 11:54:41 +02:00
if (this->StopOnFailure) {
handler->SetOption("StopOnFailure", "ON");
}
2024-04-14 22:45:38 +02:00
if (this->ParallelLevel) {
handler->SetOption("ParallelLevel", *this->ParallelLevel);
2017-07-20 19:35:53 +02:00
}
2020-08-30 11:54:41 +02:00
if (!this->Repeat.empty()) {
2021-11-20 13:41:27 +01:00
handler->SetOption("Repeat", this->Repeat);
2020-08-30 11:54:41 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->ScheduleRandom.empty()) {
2021-11-20 13:41:27 +01:00
handler->SetOption("ScheduleRandom", this->ScheduleRandom);
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->ResourceSpecFile.empty()) {
2021-11-20 13:41:27 +01:00
handler->SetOption("ResourceSpecFile", this->ResourceSpecFile);
2016-07-09 11:21:54 +02:00
}
2020-02-01 23:06:01 +01:00
if (!this->StopTime.empty()) {
this->CTest->SetStopTime(this->StopTime);
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
// Test load is determined by: TEST_LOAD argument,
// or CTEST_TEST_LOAD script variable, or ctest --test-load
// command line argument... in that order.
unsigned long testLoad;
2021-11-20 13:41:27 +01:00
cmValue ctestTestLoad = this->Makefile->GetDefinition("CTEST_TEST_LOAD");
2020-02-01 23:06:01 +01:00
if (!this->TestLoad.empty()) {
2021-09-14 00:13:48 +02:00
if (!cmStrToULong(this->TestLoad, &testLoad)) {
2015-11-17 17:22:37 +01:00
testLoad = 0;
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, WARNING,
2020-02-01 23:06:01 +01:00
"Invalid value for 'TEST_LOAD' : " << this->TestLoad
<< std::endl);
2015-11-17 17:22:37 +01:00
}
2021-09-14 00:13:48 +02:00
} else if (cmNonempty(ctestTestLoad)) {
if (!cmStrToULong(*ctestTestLoad, &testLoad)) {
2015-11-17 17:22:37 +01:00
testLoad = 0;
2018-08-09 18:06:22 +02:00
cmCTestLog(this->CTest, WARNING,
2021-09-14 00:13:48 +02:00
"Invalid value for 'CTEST_TEST_LOAD' : " << *ctestTestLoad
2018-08-09 18:06:22 +02:00
<< std::endl);
2015-11-17 17:22:37 +01:00
}
2016-07-09 11:21:54 +02:00
} else {
2015-11-17 17:22:37 +01:00
testLoad = this->CTest->GetTestLoad();
2016-07-09 11:21:54 +02:00
}
2015-11-17 17:22:37 +01:00
handler->SetTestLoad(testLoad);
2021-11-20 13:41:27 +01:00
if (cmValue labelsForSubprojects =
2018-01-26 17:06:56 +01:00
this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
this->CTest->SetCTestConfiguration("LabelsForSubprojects",
2021-09-14 00:13:48 +02:00
*labelsForSubprojects, this->Quiet);
}
if (!this->OutputJUnit.empty()) {
handler->SetJUnitXMLFileName(this->OutputJUnit);
2018-01-26 17:06:56 +01:00
}
2015-08-17 11:37:30 +02:00
handler->SetQuiet(this->Quiet);
return handler;
}
2021-09-14 00:13:48 +02:00
cmCTestTestHandler* cmCTestTestCommand::InitializeActualHandler()
{
2019-11-11 23:01:05 +01:00
cmCTestTestHandler* handler = this->CTest->GetTestHandler();
handler->Initialize();
return handler;
}