From d28947913ca5c69fc1d638243ae603736cb8c737 Mon Sep 17 00:00:00 2001 From: Daniel Pfeifer Date: Thu, 17 Oct 2024 13:56:14 +0200 Subject: [PATCH] cmCTest: Separate InitializeTesting function --- Source/cmCTest.cxx | 373 +++++++++++++++++++++++---------------------- Source/cmCTest.h | 5 + 2 files changed, 198 insertions(+), 180 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index fb3db95f13..496c2f57b7 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -441,29 +441,25 @@ int cmCTest::Initialize(const std::string& binary_dir, this->UpdateCTestConfiguration(); cmCTestOptionalLog(this, DEBUG, "Here: " << __LINE__ << std::endl, quiet); - if (this->Impl->ProduceXML) { + cmCTestOptionalLog(this, OUTPUT, + " Site: " << this->GetCTestConfiguration("Site") + << std::endl + << " Build name: " + << cmCTest::SafeBuildIdField( + this->GetCTestConfiguration("BuildName")) + << std::endl, + quiet); + cmCTestOptionalLog(this, DEBUG, "Produce XML is on" << std::endl, quiet); + if (this->Impl->TestModel == cmCTest::NIGHTLY && + this->GetCTestConfiguration("NightlyStartTime").empty()) { + cmCTestOptionalLog( + this, WARNING, + "WARNING: No nightly start time found please set in CTestConfig.cmake" + " or DartConfig.cmake" + << std::endl, + quiet); cmCTestOptionalLog(this, DEBUG, "Here: " << __LINE__ << std::endl, quiet); - cmCTestOptionalLog(this, OUTPUT, - " Site: " - << this->GetCTestConfiguration("Site") << std::endl - << " Build name: " - << cmCTest::SafeBuildIdField( - this->GetCTestConfiguration("BuildName")) - << std::endl, - quiet); - cmCTestOptionalLog(this, DEBUG, "Produce XML is on" << std::endl, quiet); - if (this->Impl->TestModel == cmCTest::NIGHTLY && - this->GetCTestConfiguration("NightlyStartTime").empty()) { - cmCTestOptionalLog( - this, WARNING, - "WARNING: No nightly start time found please set in CTestConfig.cmake" - " or DartConfig.cmake" - << std::endl, - quiet); - cmCTestOptionalLog(this, DEBUG, "Here: " << __LINE__ << std::endl, - quiet); - return 0; - } + return 0; } cmake cm(cmake::RoleScript, cmState::CTest); @@ -474,175 +470,197 @@ int cmCTest::Initialize(const std::string& binary_dir, cmMakefile mf(&gg, cm.GetCurrentSnapshot()); this->ReadCustomConfigurationFileTree(this->Impl->BinaryDir, &mf); - if (this->Impl->ProduceXML) { - // Verify "Testing" directory exists: - // - std::string testingDir = this->Impl->BinaryDir + "/Testing"; - if (cmSystemTools::FileExists(testingDir)) { - if (!cmSystemTools::FileIsDirectory(testingDir)) { - cmCTestLog(this, ERROR_MESSAGE, - "File " << testingDir - << " is in the place of the testing directory" - << std::endl); - return 0; - } - } else { - if (!cmSystemTools::MakeDirectory(testingDir)) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot create directory " << testingDir << std::endl); - return 0; - } + // Verify "Testing" directory exists: + // + std::string testingDir = this->Impl->BinaryDir + "/Testing"; + if (cmSystemTools::FileExists(testingDir)) { + if (!cmSystemTools::FileIsDirectory(testingDir)) { + cmCTestLog(this, ERROR_MESSAGE, + "File " << testingDir + << " is in the place of the testing directory" + << std::endl); + return 0; } - - // Create new "TAG" file or read existing one: - // - bool createNewTag = true; - if (command) { - createNewTag = command->ShouldCreateNewTag(); + } else { + if (!cmSystemTools::MakeDirectory(testingDir)) { + cmCTestLog(this, ERROR_MESSAGE, + "Cannot create directory " << testingDir << std::endl); + return 0; } + } - std::string tagfile = testingDir + "/TAG"; - cmsys::ifstream tfin(tagfile.c_str()); - std::string tag; + // Create new "TAG" file or read existing one: + // + bool createNewTag = true; + if (command) { + createNewTag = command->ShouldCreateNewTag(); + } - if (createNewTag) { - time_t tctime = time(nullptr); - if (this->Impl->TomorrowTag) { - tctime += (24 * 60 * 60); + std::string tagfile = testingDir + "/TAG"; + cmsys::ifstream tfin(tagfile.c_str()); + std::string tag; + + if (createNewTag) { + time_t tctime = time(nullptr); + if (this->Impl->TomorrowTag) { + tctime += (24 * 60 * 60); + } + struct tm* lctime = gmtime(&tctime); + if (tfin && cmSystemTools::GetLineFromStream(tfin, tag)) { + int year = 0; + int mon = 0; + int day = 0; + int hour = 0; + int min = 0; + sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d", &year, &mon, &day, &hour, + &min); + if (year != lctime->tm_year + 1900 || mon != lctime->tm_mon + 1 || + day != lctime->tm_mday) { + tag.clear(); } - struct tm* lctime = gmtime(&tctime); - if (tfin && cmSystemTools::GetLineFromStream(tfin, tag)) { - int year = 0; - int mon = 0; - int day = 0; - int hour = 0; - int min = 0; - sscanf(tag.c_str(), "%04d%02d%02d-%02d%02d", &year, &mon, &day, &hour, - &min); - if (year != lctime->tm_year + 1900 || mon != lctime->tm_mon + 1 || - day != lctime->tm_mday) { - tag.clear(); - } - std::string group; - if (cmSystemTools::GetLineFromStream(tfin, group) && - !this->Impl->Parts[PartStart] && !command) { - this->Impl->SpecificGroup = group; - } - std::string model; - if (cmSystemTools::GetLineFromStream(tfin, model) && - !this->Impl->Parts[PartStart] && !command) { - this->Impl->TestModel = GetTestModelFromString(model); - } - tfin.close(); - } - if (tag.empty() || command || this->Impl->Parts[PartStart]) { - cmCTestOptionalLog( - this, DEBUG, - "TestModel: " << this->GetTestModelString() << std::endl, quiet); - cmCTestOptionalLog(this, DEBUG, - "TestModel: " << this->Impl->TestModel << std::endl, - quiet); - if (this->Impl->TestModel == cmCTest::NIGHTLY) { - lctime = this->GetNightlyTime( - this->GetCTestConfiguration("NightlyStartTime"), - this->Impl->TomorrowTag); - } - char datestring[100]; - snprintf(datestring, sizeof(datestring), "%04d%02d%02d-%02d%02d", - lctime->tm_year + 1900, lctime->tm_mon + 1, lctime->tm_mday, - lctime->tm_hour, lctime->tm_min); - tag = datestring; - cmsys::ofstream ofs(tagfile.c_str()); - if (ofs) { - ofs << tag << std::endl; - ofs << this->GetTestModelString() << std::endl; - switch (this->Impl->TestModel) { - case cmCTest::EXPERIMENTAL: - ofs << "Experimental" << std::endl; - break; - case cmCTest::NIGHTLY: - ofs << "Nightly" << std::endl; - break; - case cmCTest::CONTINUOUS: - ofs << "Continuous" << std::endl; - break; - } - } - ofs.close(); - if (!command) { - cmCTestOptionalLog(this, OUTPUT, - "Create new tag: " << tag << " - " - << this->GetTestModelString() - << std::endl, - quiet); - } - } - } else { std::string group; - std::string modelStr; - int model = cmCTest::UNKNOWN; - - if (tfin) { - cmSystemTools::GetLineFromStream(tfin, tag); - cmSystemTools::GetLineFromStream(tfin, group); - if (cmSystemTools::GetLineFromStream(tfin, modelStr)) { - model = GetTestModelFromString(modelStr); - } - tfin.close(); - } - - if (tag.empty()) { - cmCTestLog(this, ERROR_MESSAGE, - "Cannot read existing TAG file in " << testingDir - << std::endl); - return 0; - } - - if (this->Impl->TestModel == cmCTest::UNKNOWN) { - if (model == cmCTest::UNKNOWN) { - cmCTestLog(this, ERROR_MESSAGE, - "TAG file does not contain model and " - "no model specified in start command" - << std::endl); - return 0; - } - - this->SetTestModel(model); - } - - if (model != this->Impl->TestModel && model != cmCTest::UNKNOWN && - this->Impl->TestModel != cmCTest::UNKNOWN) { - cmCTestOptionalLog(this, WARNING, - "Model given in TAG does not match " - "model given in ctest_start()" - << std::endl, - quiet); - } - - if (!this->Impl->SpecificGroup.empty() && - group != this->Impl->SpecificGroup) { - cmCTestOptionalLog(this, WARNING, - "Group given in TAG does not match " - "group given in ctest_start()" - << std::endl, - quiet); - } else { + if (cmSystemTools::GetLineFromStream(tfin, group) && + !this->Impl->Parts[PartStart] && !command) { this->Impl->SpecificGroup = group; } + std::string model; + if (cmSystemTools::GetLineFromStream(tfin, model) && + !this->Impl->Parts[PartStart] && !command) { + this->Impl->TestModel = GetTestModelFromString(model); + } + tfin.close(); + } + if (tag.empty() || command || this->Impl->Parts[PartStart]) { + cmCTestOptionalLog( + this, DEBUG, "TestModel: " << this->GetTestModelString() << std::endl, + quiet); + cmCTestOptionalLog(this, DEBUG, + "TestModel: " << this->Impl->TestModel << std::endl, + quiet); + if (this->Impl->TestModel == cmCTest::NIGHTLY) { + lctime = + this->GetNightlyTime(this->GetCTestConfiguration("NightlyStartTime"), + this->Impl->TomorrowTag); + } + char datestring[100]; + snprintf(datestring, sizeof(datestring), "%04d%02d%02d-%02d%02d", + lctime->tm_year + 1900, lctime->tm_mon + 1, lctime->tm_mday, + lctime->tm_hour, lctime->tm_min); + tag = datestring; + cmsys::ofstream ofs(tagfile.c_str()); + if (ofs) { + ofs << tag << std::endl; + ofs << this->GetTestModelString() << std::endl; + switch (this->Impl->TestModel) { + case cmCTest::EXPERIMENTAL: + ofs << "Experimental" << std::endl; + break; + case cmCTest::NIGHTLY: + ofs << "Nightly" << std::endl; + break; + case cmCTest::CONTINUOUS: + ofs << "Continuous" << std::endl; + break; + } + } + ofs.close(); + if (!command) { + cmCTestOptionalLog(this, OUTPUT, + "Create new tag: " << tag << " - " + << this->GetTestModelString() + << std::endl, + quiet); + } + } + } else { + std::string group; + std::string modelStr; + int model = cmCTest::UNKNOWN; - cmCTestOptionalLog(this, OUTPUT, - " Use existing tag: " << tag << " - " - << this->GetTestModelString() - << std::endl, + if (tfin) { + cmSystemTools::GetLineFromStream(tfin, tag); + cmSystemTools::GetLineFromStream(tfin, group); + if (cmSystemTools::GetLineFromStream(tfin, modelStr)) { + model = GetTestModelFromString(modelStr); + } + tfin.close(); + } + + if (tag.empty()) { + cmCTestLog(this, ERROR_MESSAGE, + "Cannot read existing TAG file in " << testingDir + << std::endl); + return 0; + } + + if (this->Impl->TestModel == cmCTest::UNKNOWN) { + if (model == cmCTest::UNKNOWN) { + cmCTestLog(this, ERROR_MESSAGE, + "TAG file does not contain model and " + "no model specified in start command" + << std::endl); + return 0; + } + + this->SetTestModel(model); + } + + if (model != this->Impl->TestModel && model != cmCTest::UNKNOWN && + this->Impl->TestModel != cmCTest::UNKNOWN) { + cmCTestOptionalLog(this, WARNING, + "Model given in TAG does not match " + "model given in ctest_start()" + << std::endl, quiet); } - this->Impl->CurrentTag = tag; + if (!this->Impl->SpecificGroup.empty() && + group != this->Impl->SpecificGroup) { + cmCTestOptionalLog(this, WARNING, + "Group given in TAG does not match " + "group given in ctest_start()" + << std::endl, + quiet); + } else { + this->Impl->SpecificGroup = group; + } + + cmCTestOptionalLog(this, OUTPUT, + " Use existing tag: " << tag << " - " + << this->GetTestModelString() + << std::endl, + quiet); } + this->Impl->CurrentTag = tag; return 1; } +void cmCTest::InitializeTesting(const std::string& binary_dir) +{ + cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl); + if (!this->Impl->InteractiveDebugMode) { + this->BlockTestErrorDiagnostics(); + } else { + cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1"); + } + + this->Impl->BinaryDir = binary_dir; + cmSystemTools::ConvertToUnixSlashes(this->Impl->BinaryDir); + + this->UpdateCTestConfiguration(); + + cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl); + + cmake cm(cmake::RoleScript, cmState::CTest); + cm.SetHomeDirectory(""); + cm.SetHomeOutputDirectory(""); + cm.GetCurrentSnapshot().SetDefaultDefinitions(); + cmGlobalGenerator gg(&cm); + cmMakefile mf(&gg, cm.GetCurrentSnapshot()); + this->ReadCustomConfigurationFileTree(this->Impl->BinaryDir, &mf); +} + bool cmCTest::UpdateCTestConfiguration() { if (this->Impl->SuppressUpdatingCTestConfiguration) { @@ -2901,12 +2919,7 @@ int cmCTest::ExecuteTests() return 1; } - if (!this->Initialize(workDir, nullptr)) { - cmCTestLog(this, ERROR_MESSAGE, - "Problem initializing the dashboard." << std::endl); - return 12; - } - + this->InitializeTesting(workDir); this->GetTestHandler()->SetVerbose(this->Impl->Verbose); if (this->GetTestHandler()->ProcessHandler() < 0) { cmCTestLog(this, ERROR_MESSAGE, "Errors while running CTest\n"); diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 4e51214af6..9d621cbd10 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -77,6 +77,11 @@ public: */ int Initialize(const std::string& binary_dir, cmCTestStartCommand* command); + /** + * Initialize ctest for executing tests. + */ + void InitializeTesting(const std::string& binary_dir); + /** * Process the dashboard client steps. */