cmCTest: Separate InitializeTesting function

This commit is contained in:
Daniel Pfeifer
2024-10-17 13:56:14 +02:00
committed by Brad King
parent 60b822da52
commit d28947913c
2 changed files with 198 additions and 180 deletions

View File

@@ -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");

View File

@@ -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.
*/