1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmCTestTestCommand.h"
#include <chrono>
#include <cstdlib>
#include <ratio>
#include <sstream>
#include <utility>
#include <vector>
#include <cm/memory>
#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
#include "cmCTestTestHandler.h"
#include "cmDuration.h"
#include "cmExecutionStatus.h"
#include "cmMakefile.h"
#include "cmStringAlgorithms.h"
#include "cmValue.h"
std::unique_ptr<cmCTestGenericHandler> cmCTestTestCommand::InitializeHandler(
HandlerArguments& arguments, cmExecutionStatus& status) const
{
cmMakefile& mf = status.GetMakefile();
auto& args = static_cast<TestArguments&>(arguments);
cmValue ctestTimeout = mf.GetDefinition("CTEST_TEST_TIMEOUT");
cmDuration timeout;
if (ctestTimeout) {
timeout = cmDuration(atof(ctestTimeout->c_str()));
} else {
timeout = this->CTest->GetTimeOut();
if (timeout <= cmDuration::zero()) {
// By default use timeout of 10 minutes
timeout = std::chrono::minutes(10);
}
}
this->CTest->SetTimeOut(timeout);
cmValue resourceSpecFile = mf.GetDefinition("CTEST_RESOURCE_SPEC_FILE");
if (args.ResourceSpecFile.empty() && resourceSpecFile) {
args.ResourceSpecFile = *resourceSpecFile;
}
auto handler = this->InitializeActualHandler(args, status);
if (!args.Start.empty() || !args.End.empty() || !args.Stride.empty()) {
handler->TestOptions.TestsToRunInformation =
cmStrCat(args.Start, ',', args.End, ',', args.Stride);
}
if (!args.Exclude.empty()) {
handler->TestOptions.ExcludeRegularExpression = args.Exclude;
}
if (!args.Include.empty()) {
handler->TestOptions.IncludeRegularExpression = args.Include;
}
if (!args.ExcludeLabel.empty()) {
handler->TestOptions.ExcludeLabelRegularExpression.push_back(
args.ExcludeLabel);
}
if (!args.IncludeLabel.empty()) {
handler->TestOptions.LabelRegularExpression.push_back(args.IncludeLabel);
}
if (!args.ExcludeTestsFromFile.empty()) {
handler->TestOptions.ExcludeTestListFile = args.ExcludeTestsFromFile;
}
if (!args.IncludeTestsFromFile.empty()) {
handler->TestOptions.TestListFile = args.IncludeTestsFromFile;
}
if (!args.ExcludeFixture.empty()) {
handler->TestOptions.ExcludeFixtureRegularExpression = args.ExcludeFixture;
}
if (!args.ExcludeFixtureSetup.empty()) {
handler->TestOptions.ExcludeFixtureSetupRegularExpression =
args.ExcludeFixtureSetup;
}
if (!args.ExcludeFixtureCleanup.empty()) {
handler->TestOptions.ExcludeFixtureCleanupRegularExpression =
args.ExcludeFixtureCleanup;
}
if (args.StopOnFailure) {
handler->TestOptions.StopOnFailure = true;
}
if (args.ParallelLevel) {
handler->ParallelLevel = *args.ParallelLevel;
}
if (!args.Repeat.empty()) {
handler->Repeat = args.Repeat;
}
if (!args.ScheduleRandom.empty()) {
handler->TestOptions.ScheduleRandom = cmValue(args.ScheduleRandom).IsOn();
}
if (!args.ResourceSpecFile.empty()) {
handler->TestOptions.ResourceSpecFile = args.ResourceSpecFile;
}
if (!args.StopTime.empty()) {
this->CTest->SetStopTime(args.StopTime);
}
// 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;
cmValue ctestTestLoad = mf.GetDefinition("CTEST_TEST_LOAD");
if (!args.TestLoad.empty()) {
if (!cmStrToULong(args.TestLoad, &testLoad)) {
testLoad = 0;
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'TEST_LOAD' : " << args.TestLoad
<< std::endl);
}
} else if (cmNonempty(ctestTestLoad)) {
if (!cmStrToULong(*ctestTestLoad, &testLoad)) {
testLoad = 0;
cmCTestLog(this->CTest, WARNING,
"Invalid value for 'CTEST_TEST_LOAD' : " << *ctestTestLoad
<< std::endl);
}
} else {
testLoad = this->CTest->GetTestLoad();
}
handler->SetTestLoad(testLoad);
if (cmValue labelsForSubprojects =
mf.GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
this->CTest->SetCTestConfiguration("LabelsForSubprojects",
*labelsForSubprojects, args.Quiet);
}
if (!args.OutputJUnit.empty()) {
handler->SetJUnitXMLFileName(args.OutputJUnit);
}
handler->SetQuiet(args.Quiet);
return std::unique_ptr<cmCTestGenericHandler>(std::move(handler));
}
std::unique_ptr<cmCTestTestHandler>
cmCTestTestCommand::InitializeActualHandler(HandlerArguments&,
cmExecutionStatus&) const
{
return cm::make_unique<cmCTestTestHandler>(this->CTest);
}
bool cmCTestTestCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus& status) const
{
static auto const parser = MakeTestParser<TestArguments>();
return this->Invoke(parser, args, status, [&](TestArguments& a) {
return this->ExecuteHandlerCommand(a, status);
});
}
|