From 70dfb249571c9deebf1c7a27956646ee1ee007b0 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Thu, 24 Oct 2024 22:18:02 +0200 Subject: [PATCH] cmCTestTestHandler: Consolidate simple options into cmCTestTestOptions --- Source/CTest/cmCTestTestCommand.cxx | 8 ++++---- Source/CTest/cmCTestTestHandler.cxx | 22 ++++++++-------------- Source/CTest/cmCTestTestHandler.h | 22 +++++++--------------- Source/cmCTest.cxx | 23 +++++++++-------------- 4 files changed, 28 insertions(+), 47 deletions(-) diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx index a3bd519f33..7cb1a3db87 100644 --- a/Source/CTest/cmCTestTestCommand.cxx +++ b/Source/CTest/cmCTestTestCommand.cxx @@ -103,16 +103,16 @@ cmCTestGenericHandler* cmCTestTestCommand::InitializeHandler() this->ExcludeFixtureCleanup; } if (this->StopOnFailure) { - handler->SetOption("StopOnFailure", "ON"); + handler->TestOptions.StopOnFailure = true; } if (this->ParallelLevel) { - handler->SetOption("ParallelLevel", *this->ParallelLevel); + handler->ParallelLevel = *this->ParallelLevel; } if (!this->Repeat.empty()) { - handler->SetOption("Repeat", this->Repeat); + handler->Repeat = this->Repeat; } if (!this->ScheduleRandom.empty()) { - handler->SetOption("ScheduleRandom", this->ScheduleRandom); + handler->TestOptions.ScheduleRandom = cmValue(this->ScheduleRandom).IsOn(); } if (!this->ResourceSpecFile.empty()) { handler->TestOptions.ResourceSpecFile = this->ResourceSpecFile; diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index ceda09e0be..b255d2cf84 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -276,8 +276,6 @@ inline int GetNextRealNumber(std::string const& in, double& val, cmCTestTestHandler::cmCTestTestHandler() { - this->UseUnion = false; - this->UseIncludeRegExpFlag = false; this->UseExcludeRegExpFlag = false; this->UseExcludeRegExpFirst = false; @@ -333,7 +331,6 @@ void cmCTestTestHandler::Initialize(cmCTest* ctest) this->TestsToExcludeByName.reset(); this->TestsToRunString.clear(); - this->UseUnion = false; this->TestList.clear(); } @@ -514,11 +511,10 @@ bool cmCTestTestHandler::ProcessOptions() { // Update internal data structure from generic one this->SetTestsToRunInformation(this->TestOptions.TestsToRunInformation); - this->SetUseUnion(this->GetOption("UseUnion").IsOn()); - if (this->GetOption("ScheduleRandom").IsOn()) { + if (this->TestOptions.ScheduleRandom) { this->CTest->SetScheduleType("Random"); } - if (cmValue repeat = this->GetOption("Repeat")) { + if (auto repeat = this->Repeat) { cmsys::RegularExpression repeatRegex( "^(UNTIL_FAIL|UNTIL_PASS|AFTER_TIMEOUT):([0-9]+)$"); if (repeatRegex.find(*repeat)) { @@ -542,8 +538,8 @@ bool cmCTestTestHandler::ProcessOptions() return false; } } - if (cmValue parallelLevel = this->GetOption("ParallelLevel")) { - if (parallelLevel.IsEmpty()) { + if (auto parallelLevel = this->ParallelLevel) { + if (parallelLevel->empty()) { // An empty value tells ctest to choose a default. this->CTest->SetParallelLevel(cm::nullopt); } else { @@ -559,7 +555,7 @@ bool cmCTestTestHandler::ProcessOptions() } } - if (this->GetOption("StopOnFailure")) { + if (this->TestOptions.StopOnFailure) { this->CTest->SetStopOnFailure(true); } @@ -573,8 +569,6 @@ bool cmCTestTestHandler::ProcessOptions() if (!this->TestOptions.ExcludeRegularExpression.empty()) { this->UseExcludeRegExp(); } - this->SetRerunFailed(this->GetOption("RerunFailed").IsOn()); - return true; } @@ -886,7 +880,7 @@ bool cmCTestTestHandler::ComputeTestList() return false; } - if (this->RerunFailed) { + if (this->TestOptions.RerunFailed) { return this->ComputeTestListForRerunFailed(); } @@ -900,7 +894,7 @@ bool cmCTestTestHandler::ComputeTestList() } } // expand the test list based on the union flag - if (this->UseUnion) { + if (this->TestOptions.UseUnion) { this->ExpandTestsToRunInformation(static_cast(tmsize)); } else { this->ExpandTestsToRunInformation(inREcnt); @@ -915,7 +909,7 @@ bool cmCTestTestHandler::ComputeTestList() inREcnt++; } - if (this->UseUnion) { + if (this->TestOptions.UseUnion) { // if it is not in the list and not in the regexp then skip if ((!this->TestsToRun.empty() && !cm::contains(this->TestsToRun, cnt)) && diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 15623306db..b5c35d5a5b 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -30,6 +30,11 @@ class cmXMLWriter; struct cmCTestTestOptions { + bool RerunFailed = false; + bool ScheduleRandom = false; + bool StopOnFailure = false; + bool UseUnion = false; + int OutputSizePassed = 1 * 1024; int OutputSizeFailed = 300 * 1024; cmCTestTypes::TruncationMode OutputTruncation = @@ -70,19 +75,6 @@ public: */ int ProcessHandler() override; - /** - * When both -R and -I are used should the resulting test list be the - * intersection or the union of the lists. By default it is the - * intersection. - */ - void SetUseUnion(bool val) { this->UseUnion = val; } - - /** - * Set whether or not CTest should only execute the tests that failed - * on the previous run. By default this is false. - */ - void SetRerunFailed(bool val) { this->RerunFailed = val; } - /** * This method is called when reading CTest custom file */ @@ -372,6 +364,8 @@ private: cmsys::RegularExpression ExcludeTestsRegularExpression; cm::optional> TestsToRunByName; cm::optional> TestsToExcludeByName; + cm::optional ParallelLevel; + cm::optional Repeat; void RecordCustomTestMeasurements(cmXMLWriter& xml, std::string content); void CheckLabelFilter(cmCTestTestProperties& it); @@ -379,7 +373,6 @@ private: void CheckLabelFilterInclude(cmCTestTestProperties& it); std::string TestsToRunString; - bool UseUnion; ListOfTests TestList; size_t TotalNumberOfTests; cmsys::RegularExpression AllTestMeasurementsRegex; @@ -391,7 +384,6 @@ private: cmCTest::Repeat RepeatMode = cmCTest::Repeat::Never; int RepeatCount = 1; - bool RerunFailed; friend class cmCTestTestCommand; }; diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 39a2a74e5c..e7ca5d184e 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -1819,10 +1819,8 @@ bool cmCTest::SetArgsFromPreset(const std::string& presetName, } } - if (expandedPreset->Filter->Include->UseUnion.value_or(false)) { - this->GetTestHandler()->SetPersistentOption("UseUnion", "true"); - this->GetMemCheckHandler()->SetPersistentOption("UseUnion", "true"); - } + this->Impl->TestOptions.UseUnion = + expandedPreset->Filter->Include->UseUnion.value_or(false); } if (expandedPreset->Filter->Exclude) { @@ -2132,8 +2130,7 @@ int cmCTest::Run(std::vector const& args) return true; }; auto const dashU = [this](std::string const&) -> bool { - this->Impl->TestHandler.SetPersistentOption("UseUnion", "true"); - this->Impl->MemCheckHandler.SetPersistentOption("UseUnion", "true"); + this->Impl->TestOptions.UseUnion = true; return true; }; auto const dashR = [this](std::string const& expr) -> bool { @@ -2615,16 +2612,14 @@ int cmCTest::Run(std::vector const& args) } }, CommandArgument{ "--schedule-random", CommandArgument::Values::Zero, [this](std::string const&) -> bool { - this->Impl->ScheduleType = "Random"; + this->Impl->TestOptions.ScheduleRandom = true; + return true; + } }, + CommandArgument{ "--rerun-failed", CommandArgument::Values::Zero, + [this](std::string const&) -> bool { + this->Impl->TestOptions.RerunFailed = true; return true; } }, - CommandArgument{ - "--rerun-failed", CommandArgument::Values::Zero, - [this](std::string const&) -> bool { - this->Impl->TestHandler.SetPersistentOption("RerunFailed", "true"); - this->Impl->MemCheckHandler.SetPersistentOption("RerunFailed", "true"); - return true; - } }, }; // process the command line arguments