diff options
Diffstat (limited to 'Source/cmCTest.cxx')
-rw-r--r-- | Source/cmCTest.cxx | 315 |
1 files changed, 176 insertions, 139 deletions
diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index bc36c5a..0101049 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -51,7 +51,7 @@ #include <math.h> #include <stdlib.h> -#include <cmsys/auto_ptr.hxx> +#include <cm_auto_ptr.hxx> #include <cm_zlib.h> #include <cmsys/Base64.h> @@ -70,7 +70,7 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) { struct tm* lctime; - time_t tctime = time(0); + time_t tctime = time(CM_NULLPTR); lctime = gmtime(&tctime); char buf[1024]; // add todays year day and month to the time in str because @@ -88,7 +88,7 @@ struct tm* cmCTest::GetNightlyTime(std::string const& str, bool tomorrowtag) // As such, this time may be in the past or in the future. time_t ntime = curl_getdate(buf, &tctime); cmCTestLog(this, DEBUG, " Get curl time: " << ntime << std::endl); - tctime = time(0); + tctime = time(CM_NULLPTR); cmCTestLog(this, DEBUG, " Get the current time: " << tctime << std::endl); const int dayLength = 24 * 60 * 60; @@ -134,7 +134,7 @@ std::string cmCTest::CleanString(const std::string& str) std::string cmCTest::CurrentTime() { - time_t currenttime = time(0); + time_t currenttime = time(CM_NULLPTR); struct tm* t = localtime(¤ttime); // return ::CleanString(ctime(¤ttime)); char current_time[1024]; @@ -244,7 +244,7 @@ std::string cmCTest::DecodeURL(const std::string& in) for (const char* c = in.c_str(); *c; ++c) { if (*c == '%' && isxdigit(*(c + 1)) && isxdigit(*(c + 2))) { char buf[3] = { *(c + 1), *(c + 2), 0 }; - out.append(1, char(strtoul(buf, 0, 16))); + out.append(1, char(strtoul(buf, CM_NULLPTR, 16))); c += 2; } else { out.append(1, *c); @@ -288,7 +288,7 @@ cmCTest::cmCTest() this->ScheduleType = ""; this->StopTime = ""; this->NextDayStopTime = false; - this->OutputLogFile = 0; + this->OutputLogFile = CM_NULLPTR; this->OutputLogFileLastTag = -1; this->SuppressUpdatingCTestConfiguration = false; this->DartVersion = 1; @@ -298,9 +298,10 @@ cmCTest::cmCTest() this->ComputedCompressMemCheckOutput = false; this->RepeatTests = 1; // default to run each test once this->RepeatUntilFail = false; - if (const char* outOnFail = - cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE")) { - this->OutputTestOutputOnTestFailure = !cmSystemTools::IsOff(outOnFail); + std::string outOnFail; + if (cmSystemTools::GetEnv("CTEST_OUTPUT_ON_FAILURE", outOnFail)) { + this->OutputTestOutputOnTestFailure = + !cmSystemTools::IsOff(outOnFail.c_str()); } this->InitStreams(); @@ -347,7 +348,7 @@ cmCTest::cmCTest() cmCTest::~cmCTest() { cmDeleteAll(this->TestingHandlers); - this->SetOutputLogFileName(0); + this->SetOutputLogFileName(CM_NULLPTR); } void cmCTest::SetParallelLevel(int level) @@ -474,7 +475,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) cm.SetHomeOutputDirectory(""); cm.GetCurrentSnapshot().SetDefaultDefinitions(); cmGlobalGenerator gg(&cm); - cmsys::auto_ptr<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); + CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot())); if (!this->ReadCustomConfigurationFileTree(this->BinaryDir.c_str(), mf.get())) { cmCTestOptionalLog( @@ -515,7 +516,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) std::string tag; if (createNewTag) { - time_t tctime = time(0); + time_t tctime = time(CM_NULLPTR); if (this->TomorrowTag) { tctime += (24 * 60 * 60); } @@ -540,7 +541,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) } tfin.close(); } - if (tag.empty() || (0 != command) || this->Parts[PartStart]) { + if (tag.empty() || (CM_NULLPTR != command) || this->Parts[PartStart]) { cmCTestOptionalLog( this, DEBUG, "TestModel: " << this->GetTestModelString() << std::endl, quiet); @@ -562,7 +563,7 @@ int cmCTest::Initialize(const char* binary_dir, cmCTestStartCommand* command) ofs << this->GetTestModelString() << std::endl; } ofs.close(); - if (0 == command) { + if (CM_NULLPTR == command) { cmCTestOptionalLog(this, OUTPUT, "Create new tag: " << tag << " - " << this->GetTestModelString() << std::endl, @@ -860,7 +861,7 @@ cmCTestGenericHandler* cmCTest::GetInitializedHandler(const char* handler) cmCTest::t_TestingHandlers::iterator it = this->TestingHandlers.find(handler); if (it == this->TestingHandlers.end()) { - return 0; + return CM_NULLPTR; } it->second->Initialize(); return it->second; @@ -871,7 +872,7 @@ cmCTestGenericHandler* cmCTest::GetHandler(const char* handler) cmCTest::t_TestingHandlers::iterator it = this->TestingHandlers.find(handler); if (it == this->TestingHandlers.end()) { - return 0; + return CM_NULLPTR; } return it->second; } @@ -886,7 +887,7 @@ int cmCTest::ExecuteHandler(const char* shandler) return handler->ProcessHandler(); } -int cmCTest::ProcessTests() +int cmCTest::ProcessSteps() { int res = 0; bool notest = true; @@ -1020,7 +1021,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, // First generate the command and arguments std::vector<std::string> args = cmSystemTools::ParseArguments(command); - if (args.size() < 1) { + if (args.empty()) { return false; } @@ -1029,7 +1030,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, a != args.end(); ++a) { argv.push_back(a->c_str()); } - argv.push_back(0); + argv.push_back(CM_NULLPTR); output = ""; cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, "Run command:"); @@ -1057,7 +1058,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Each . represents " << tick_len << " bytes of output" << std::endl << " " << std::flush); - while (cmsysProcess_WaitForData(cp, &data, &length, 0)) { + while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { for (int cc = 0; cc < length; ++cc) { if (data[cc] == 0) { data[cc] = '\n'; @@ -1082,7 +1083,7 @@ int cmCTest::RunMakeCommand(const char* command, std::string& output, cmCTestLog(this, HANDLER_PROGRESS_OUTPUT, " Size of output: " << int(double(output.size()) / 1024.0) << "K" << std::endl); - cmsysProcess_WaitForExit(cp, 0); + cmsysProcess_WaitForExit(cp, CM_NULLPTR); int result = cmsysProcess_GetState(cp); @@ -1165,7 +1166,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, } std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory(); - cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv; + CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv; if (modifyEnv) { saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); cmSystemTools::AppendEnv(*environment); @@ -1193,7 +1194,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, *output = ""; } - cmsys::auto_ptr<cmSystemTools::SaveRestoreEnvironment> saveEnv; + CM_AUTO_PTR<cmSystemTools::SaveRestoreEnvironment> saveEnv; if (modifyEnv) { saveEnv.reset(new cmSystemTools::SaveRestoreEnvironment); cmSystemTools::AppendEnv(*environment); @@ -1211,7 +1212,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, char* data; int length; - while (cmsysProcess_WaitForData(cp, &data, &length, 0)) { + while (cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR)) { if (output) { tempOutput.insert(tempOutput.end(), data, data + length); } @@ -1221,7 +1222,7 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, } } - cmsysProcess_WaitForExit(cp, 0); + cmsysProcess_WaitForExit(cp, CM_NULLPTR); if (output && tempOutput.begin() != tempOutput.end()) { output->append(&*tempOutput.begin(), tempOutput.size()); } @@ -1245,16 +1246,16 @@ int cmCTest::RunTest(std::vector<const char*> argv, std::string* output, if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl + << std::flush); } else if (result == cmsysProcess_State_Error) { std::string outerr = "\n*** ERROR executing: "; outerr += cmsysProcess_GetErrorString(cp); if (output) { *output += outerr; } - cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr.c_str() << std::endl - << std::flush); + cmCTestLog(this, HANDLER_VERBOSE_OUTPUT, outerr << std::endl + << std::flush); } cmsysProcess_Delete(cp); @@ -2018,7 +2019,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) // handle the script arguments -S -SR -SP this->HandleScriptArguments(i, args, SRArgumentSpecified); - // handle a request for a dashboard + // --dashboard: handle a request for a dashboard std::string arg = args[i]; if (this->CheckArgument(arg, "-D", "--dashboard") && i < args.size() - 1) { this->ProduceXML = true; @@ -2044,54 +2045,18 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) this->AddVariableDefinition(input); } - if (this->CheckArgument(arg, "-T", "--test-action") && - (i < args.size() - 1)) { - this->ProduceXML = true; - i++; - if (!this->SetTest(args[i].c_str(), false)) { - executeTests = false; - cmCTestLog(this, ERROR_MESSAGE, - "CTest -T called with incorrect option: " << args[i] - << std::endl); - cmCTestLog(this, ERROR_MESSAGE, "Available options are:" - << std::endl - << " " << ctestExec << " -T all" << std::endl - << " " << ctestExec << " -T start" << std::endl - << " " << ctestExec << " -T update" << std::endl - << " " << ctestExec << " -T configure" << std::endl - << " " << ctestExec << " -T build" << std::endl - << " " << ctestExec << " -T test" << std::endl - << " " << ctestExec << " -T coverage" << std::endl - << " " << ctestExec << " -T memcheck" << std::endl - << " " << ctestExec << " -T notes" << std::endl - << " " << ctestExec << " -T submit" << std::endl); - } + // --test-action: calls SetTest(<stage>, /*report=*/ false) to enable + // the corresponding stage + if (!this->HandleTestActionArgument(ctestExec, i, args)) { + executeTests = false; } - // what type of test model - if (this->CheckArgument(arg, "-M", "--test-model") && - (i < args.size() - 1)) { - i++; - std::string const& str = args[i]; - if (cmSystemTools::LowerCase(str) == "nightly") { - this->SetTestModel(cmCTest::NIGHTLY); - } else if (cmSystemTools::LowerCase(str) == "continuous") { - this->SetTestModel(cmCTest::CONTINUOUS); - } else if (cmSystemTools::LowerCase(str) == "experimental") { - this->SetTestModel(cmCTest::EXPERIMENTAL); - } else { - executeTests = false; - cmCTestLog(this, ERROR_MESSAGE, - "CTest -M called with incorrect option: " << str - << std::endl); - cmCTestLog(this, ERROR_MESSAGE, "Available options are:" - << std::endl - << " " << ctestExec << " -M Continuous" << std::endl - << " " << ctestExec << " -M Experimental" << std::endl - << " " << ctestExec << " -M Nightly" << std::endl); - } + // --test-model: what type of test model + if (!this->HandleTestModelArgument(ctestExec, i, args)) { + executeTests = false; } + // --extra-submit if (this->CheckArgument(arg, "--extra-submit") && i < args.size() - 1) { this->ProduceXML = true; this->SetTest("Submit"); @@ -2106,6 +2071,7 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) cmakeAndTest = true; } + // --schedule-random if (this->CheckArgument(arg, "--schedule-random")) { this->ScheduleType = "Random"; } @@ -2124,80 +2090,151 @@ int cmCTest::Run(std::vector<std::string>& args, std::string* output) } } // the close of the for argument loop + // handle CTEST_PARALLEL_LEVEL environment variable if (!this->ParallelLevelSetInCli) { - if (const char* parallel = cmSystemTools::GetEnv("CTEST_PARALLEL_LEVEL")) { - int plevel = atoi(parallel); + std::string parallel; + if (cmSystemTools::GetEnv("CTEST_PARALLEL_LEVEL", parallel)) { + int plevel = atoi(parallel.c_str()); this->SetParallelLevel(plevel); } } - // now what sould cmake do? if --build-and-test was specified then + // now what should cmake do? if --build-and-test was specified then // we run the build and test handler and return if (cmakeAndTest) { - this->Verbose = true; - cmCTestBuildAndTestHandler* handler = - static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest")); - int retv = handler->ProcessHandler(); - *output = handler->GetOutput(); -#ifdef CMAKE_BUILD_WITH_CMAKE - cmDynamicLoader::FlushCache(); -#endif - if (retv != 0) { - cmCTestLog(this, DEBUG, - "build and test failing returning: " << retv << std::endl); - } - return retv; + return this->RunCMakeAndTest(output); } if (executeTests) { - int res; - // call process directory - if (this->RunConfigurationScript) { - if (this->ExtraVerbose) { - cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl); - } - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); - it != this->TestingHandlers.end(); ++it) { - it->second->SetVerbose(this->ExtraVerbose); - it->second->SetSubmitIndex(this->SubmitIndex); - } - this->GetHandler("script")->SetVerbose(this->Verbose); - res = this->GetHandler("script")->ProcessHandler(); - if (res != 0) { - cmCTestLog(this, DEBUG, - "running script failing returning: " << res << std::endl); - } + return this->ExecuteTests(); + } + return 1; +} + +bool cmCTest::HandleTestActionArgument(const char* ctestExec, size_t& i, + const std::vector<std::string>& args) +{ + bool success = true; + std::string arg = args[i]; + if (this->CheckArgument(arg, "-T", "--test-action") && + (i < args.size() - 1)) { + this->ProduceXML = true; + i++; + if (!this->SetTest(args[i].c_str(), false)) { + success = false; + cmCTestLog(this, ERROR_MESSAGE, "CTest -T called with incorrect option: " + << args[i] << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Available options are:" + << std::endl + << " " << ctestExec << " -T all" << std::endl + << " " << ctestExec << " -T start" << std::endl + << " " << ctestExec << " -T update" << std::endl + << " " << ctestExec << " -T configure" << std::endl + << " " << ctestExec << " -T build" << std::endl + << " " << ctestExec << " -T test" << std::endl + << " " << ctestExec << " -T coverage" << std::endl + << " " << ctestExec << " -T memcheck" << std::endl + << " " << ctestExec << " -T notes" << std::endl + << " " << ctestExec << " -T submit" << std::endl); + } + } + return success; +} + +bool cmCTest::HandleTestModelArgument(const char* ctestExec, size_t& i, + const std::vector<std::string>& args) +{ + bool success = true; + std::string arg = args[i]; + if (this->CheckArgument(arg, "-M", "--test-model") && + (i < args.size() - 1)) { + i++; + std::string const& str = args[i]; + if (cmSystemTools::LowerCase(str) == "nightly") { + this->SetTestModel(cmCTest::NIGHTLY); + } else if (cmSystemTools::LowerCase(str) == "continuous") { + this->SetTestModel(cmCTest::CONTINUOUS); + } else if (cmSystemTools::LowerCase(str) == "experimental") { + this->SetTestModel(cmCTest::EXPERIMENTAL); } else { - // What is this? -V seems to be the same as -VV, - // and Verbose is always on in this case - this->ExtraVerbose = this->Verbose; - this->Verbose = true; - cmCTest::t_TestingHandlers::iterator it; - for (it = this->TestingHandlers.begin(); - it != this->TestingHandlers.end(); ++it) { - it->second->SetVerbose(this->Verbose); - it->second->SetSubmitIndex(this->SubmitIndex); - } - std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); - if (!this->Initialize(cwd.c_str(), 0)) { - res = 12; - cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard." - << std::endl); - } else { - res = this->ProcessTests(); - } - this->Finalize(); + success = false; + cmCTestLog(this, ERROR_MESSAGE, "CTest -M called with incorrect option: " + << str << std::endl); + cmCTestLog(this, ERROR_MESSAGE, "Available options are:" + << std::endl + << " " << ctestExec << " -M Continuous" << std::endl + << " " << ctestExec << " -M Experimental" << std::endl + << " " << ctestExec << " -M Nightly" << std::endl); } + } + return success; +} + +int cmCTest::ExecuteTests() +{ + int res; + // call process directory + if (this->RunConfigurationScript) { + if (this->ExtraVerbose) { + cmCTestLog(this, OUTPUT, "* Extra verbosity turned on" << std::endl); + } + cmCTest::t_TestingHandlers::iterator it; + for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); + ++it) { + it->second->SetVerbose(this->ExtraVerbose); + it->second->SetSubmitIndex(this->SubmitIndex); + } + this->GetHandler("script")->SetVerbose(this->Verbose); + res = this->GetHandler("script")->ProcessHandler(); if (res != 0) { cmCTestLog(this, DEBUG, - "Running a test(s) failed returning : " << res << std::endl); + "running script failing returning: " << res << std::endl); } - return res; + + } else { + // What is this? -V seems to be the same as -VV, + // and Verbose is always on in this case + this->ExtraVerbose = this->Verbose; + this->Verbose = true; + cmCTest::t_TestingHandlers::iterator it; + for (it = this->TestingHandlers.begin(); it != this->TestingHandlers.end(); + ++it) { + it->second->SetVerbose(this->Verbose); + it->second->SetSubmitIndex(this->SubmitIndex); + } + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + if (!this->Initialize(cwd.c_str(), CM_NULLPTR)) { + res = 12; + cmCTestLog(this, ERROR_MESSAGE, "Problem initializing the dashboard." + << std::endl); + } else { + res = this->ProcessSteps(); + } + this->Finalize(); } + if (res != 0) { + cmCTestLog(this, DEBUG, + "Running a test(s) failed returning : " << res << std::endl); + } + return res; +} - return 1; +int cmCTest::RunCMakeAndTest(std::string* output) +{ + this->Verbose = true; + cmCTestBuildAndTestHandler* handler = + static_cast<cmCTestBuildAndTestHandler*>(this->GetHandler("buildtest")); + int retv = handler->ProcessHandler(); + *output = handler->GetOutput(); +#ifdef CMAKE_BUILD_WITH_CMAKE + cmDynamicLoader::FlushCache(); +#endif + if (retv != 0) { + cmCTestLog(this, DEBUG, "build and test failing returning: " << retv + << std::endl); + } + return retv; } void cmCTest::SetNotesFiles(const char* notes) @@ -2325,7 +2362,7 @@ std::string cmCTest::GetShortPathToFile(const char* cfname) bool inBld = bldRelpath.find("..") == bldRelpath.npos; // TODO: Handle files with .. in their name - std::string* res = 0; + std::string* res = CM_NULLPTR; if (inSrc && inBld) { // If both have relative path with no dots, pick the shorter one @@ -2375,7 +2412,7 @@ void cmCTest::EmptyCTestConfiguration() void cmCTest::DetermineNextDayStop() { struct tm* lctime; - time_t current_time = time(0); + time_t current_time = time(CM_NULLPTR); lctime = gmtime(¤t_time); int gm_hour = lctime->tm_hour; time_t gm_time = mktime(lctime); @@ -2459,7 +2496,7 @@ bool cmCTest::GetProduceXML() const char* cmCTest::GetSpecificTrack() { if (this->SpecificTrack.empty()) { - return 0; + return CM_NULLPTR; } return this->SpecificTrack.c_str(); } @@ -2525,7 +2562,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, { std::vector<std::string> args = cmSystemTools::ParseArguments(command); - if (args.size() < 1) { + if (args.empty()) { return false; } @@ -2534,7 +2571,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, a != args.end(); ++a) { argv.push_back(a->c_str()); } - argv.push_back(0); + argv.push_back(CM_NULLPTR); *stdOut = ""; *stdErr = ""; @@ -2555,7 +2592,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, int res; bool done = false; while (!done) { - res = cmsysProcess_WaitForData(cp, &data, &length, 0); + res = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR); switch (res) { case cmsysProcess_Pipe_STDOUT: tempOutput.insert(tempOutput.end(), data, data + length); @@ -2572,7 +2609,7 @@ bool cmCTest::RunCommand(const char* command, std::string* stdOut, } } - cmsysProcess_WaitForExit(cp, 0); + cmsysProcess_WaitForExit(cp, CM_NULLPTR); if (!tempOutput.empty()) { stdOut->append(&*tempOutput.begin(), tempOutput.size()); } @@ -2614,7 +2651,7 @@ void cmCTest::SetOutputLogFileName(const char* name) { if (this->OutputLogFile) { delete this->OutputLogFile; - this->OutputLogFile = 0; + this->OutputLogFile = CM_NULLPTR; } if (name) { this->OutputLogFile = new cmGeneratedFileStream(name); @@ -2628,7 +2665,7 @@ static const char* cmCTestStringLogType[] = { "DEBUG", "HANDLER_VERBOSE_OUTPUT", "WARNING", "ERROR_MESSAGE", - 0 }; + CM_NULLPTR }; #ifdef cerr #undef cerr |