cmCTestRunTest.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCTestRunTest.h"
  11. #include "cmCTestMemCheckHandler.h"
  12. #include "cmCTest.h"
  13. #include "cmSystemTools.h"
  14. #include "cm_curl.h"
  15. #include <cm_zlib.h>
  16. #include <cmsys/Base64.h>
  17. cmCTestRunTest::cmCTestRunTest(cmCTestTestHandler* handler)
  18. {
  19. this->CTest = handler->CTest;
  20. this->TestHandler = handler;
  21. this->TestProcess = 0;
  22. this->TestResult.ExecutionTime =0;
  23. this->TestResult.ReturnValue = 0;
  24. this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
  25. this->TestResult.TestCount = 0;
  26. this->TestResult.Properties = 0;
  27. this->ProcessOutput = "";
  28. this->CompressedOutput = "";
  29. this->CompressionRatio = 2;
  30. this->StopTimePassed = false;
  31. }
  32. cmCTestRunTest::~cmCTestRunTest()
  33. {
  34. }
  35. //----------------------------------------------------------------------------
  36. bool cmCTestRunTest::CheckOutput()
  37. {
  38. // Read lines for up to 0.1 seconds of total time.
  39. double timeout = 0.1;
  40. double timeEnd = cmSystemTools::GetTime() + timeout;
  41. std::string line;
  42. while((timeout = timeEnd - cmSystemTools::GetTime(), timeout > 0))
  43. {
  44. int p = this->TestProcess->GetNextOutputLine(line, timeout);
  45. if(p == cmsysProcess_Pipe_None)
  46. {
  47. // Process has terminated and all output read.
  48. return false;
  49. }
  50. else if(p == cmsysProcess_Pipe_STDOUT ||
  51. p == cmsysProcess_Pipe_STDERR)
  52. {
  53. // Store this line of output.
  54. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  55. this->GetIndex() << ": " << line << std::endl);
  56. this->ProcessOutput += line;
  57. this->ProcessOutput += "\n";
  58. }
  59. else // if(p == cmsysProcess_Pipe_Timeout)
  60. {
  61. break;
  62. }
  63. }
  64. return true;
  65. }
  66. //---------------------------------------------------------
  67. // Streamed compression of test output. The compressed data
  68. // is appended to this->CompressedOutput
  69. void cmCTestRunTest::CompressOutput()
  70. {
  71. int ret;
  72. z_stream strm;
  73. unsigned char* in =
  74. reinterpret_cast<unsigned char*>(
  75. const_cast<char*>(this->ProcessOutput.c_str()));
  76. //zlib makes the guarantee that this is the maximum output size
  77. int outSize = static_cast<int>(
  78. static_cast<double>(this->ProcessOutput.size()) * 1.001 + 13.0);
  79. unsigned char* out = new unsigned char[outSize];
  80. strm.zalloc = Z_NULL;
  81. strm.zfree = Z_NULL;
  82. strm.opaque = Z_NULL;
  83. ret = deflateInit(&strm, -1); //default compression level
  84. if (ret != Z_OK)
  85. {
  86. return;
  87. }
  88. strm.avail_in = static_cast<uInt>(this->ProcessOutput.size());
  89. strm.next_in = in;
  90. strm.avail_out = outSize;
  91. strm.next_out = out;
  92. ret = deflate(&strm, Z_FINISH);
  93. if(ret == Z_STREAM_ERROR || ret != Z_STREAM_END)
  94. {
  95. cmCTestLog(this->CTest, ERROR_MESSAGE, "Error during output "
  96. "compression. Sending uncompressed output." << std::endl);
  97. return;
  98. }
  99. (void)deflateEnd(&strm);
  100. unsigned char *encoded_buffer
  101. = new unsigned char[static_cast<int>(outSize * 1.5)];
  102. unsigned long rlen
  103. = cmsysBase64_Encode(out, strm.total_out, encoded_buffer, 1);
  104. for(unsigned long i = 0; i < rlen; i++)
  105. {
  106. this->CompressedOutput += encoded_buffer[i];
  107. }
  108. if(strm.total_in)
  109. {
  110. this->CompressionRatio = static_cast<double>(strm.total_out) /
  111. static_cast<double>(strm.total_in);
  112. }
  113. delete [] encoded_buffer;
  114. delete [] out;
  115. }
  116. //---------------------------------------------------------
  117. bool cmCTestRunTest::EndTest(size_t completed, size_t total, bool started)
  118. {
  119. if ((!this->TestHandler->MemCheck &&
  120. this->CTest->ShouldCompressTestOutput()) ||
  121. (this->TestHandler->MemCheck &&
  122. this->CTest->ShouldCompressMemCheckOutput()))
  123. {
  124. this->CompressOutput();
  125. }
  126. this->WriteLogOutputTop(completed, total);
  127. std::string reason;
  128. bool passed = true;
  129. int res = started ? this->TestProcess->GetProcessStatus()
  130. : cmsysProcess_State_Error;
  131. int retVal = this->TestProcess->GetExitValue();
  132. std::vector<std::pair<cmsys::RegularExpression,
  133. std::string> >::iterator passIt;
  134. bool forceFail = false;
  135. bool outputTestErrorsToConsole = false;
  136. if ( this->TestProperties->RequiredRegularExpressions.size() > 0 )
  137. {
  138. bool found = false;
  139. for ( passIt = this->TestProperties->RequiredRegularExpressions.begin();
  140. passIt != this->TestProperties->RequiredRegularExpressions.end();
  141. ++ passIt )
  142. {
  143. if ( passIt->first.find(this->ProcessOutput.c_str()) )
  144. {
  145. found = true;
  146. reason = "Required regular expression found.";
  147. }
  148. }
  149. if ( !found )
  150. {
  151. reason = "Required regular expression not found.";
  152. forceFail = true;
  153. }
  154. reason += "Regex=[";
  155. for ( passIt = this->TestProperties->RequiredRegularExpressions.begin();
  156. passIt != this->TestProperties->RequiredRegularExpressions.end();
  157. ++ passIt )
  158. {
  159. reason += passIt->second;
  160. reason += "\n";
  161. }
  162. reason += "]";
  163. }
  164. if ( this->TestProperties->ErrorRegularExpressions.size() > 0 )
  165. {
  166. for ( passIt = this->TestProperties->ErrorRegularExpressions.begin();
  167. passIt != this->TestProperties->ErrorRegularExpressions.end();
  168. ++ passIt )
  169. {
  170. if ( passIt->first.find(this->ProcessOutput.c_str()) )
  171. {
  172. reason = "Error regular expression found in output.";
  173. reason += " Regex=[";
  174. reason += passIt->second;
  175. reason += "]";
  176. forceFail = true;
  177. }
  178. }
  179. }
  180. if (res == cmsysProcess_State_Exited)
  181. {
  182. bool success =
  183. !forceFail && (retVal == 0 ||
  184. this->TestProperties->RequiredRegularExpressions.size());
  185. if((success && !this->TestProperties->WillFail)
  186. || (!success && this->TestProperties->WillFail))
  187. {
  188. this->TestResult.Status = cmCTestTestHandler::COMPLETED;
  189. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed " );
  190. }
  191. else
  192. {
  193. this->TestResult.Status = cmCTestTestHandler::FAILED;
  194. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason );
  195. outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
  196. }
  197. }
  198. else if ( res == cmsysProcess_State_Expired )
  199. {
  200. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout ");
  201. this->TestResult.Status = cmCTestTestHandler::TIMEOUT;
  202. outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
  203. }
  204. else if ( res == cmsysProcess_State_Exception )
  205. {
  206. outputTestErrorsToConsole = this->CTest->OutputTestOutputOnTestFailure;
  207. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
  208. switch(this->TestProcess->GetExitException())
  209. {
  210. case cmsysProcess_Exception_Fault:
  211. cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
  212. this->TestResult.Status = cmCTestTestHandler::SEGFAULT;
  213. break;
  214. case cmsysProcess_Exception_Illegal:
  215. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
  216. this->TestResult.Status = cmCTestTestHandler::ILLEGAL;
  217. break;
  218. case cmsysProcess_Exception_Interrupt:
  219. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
  220. this->TestResult.Status = cmCTestTestHandler::INTERRUPT;
  221. break;
  222. case cmsysProcess_Exception_Numerical:
  223. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
  224. this->TestResult.Status = cmCTestTestHandler::NUMERICAL;
  225. break;
  226. default:
  227. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
  228. this->TestResult.Status = cmCTestTestHandler::OTHER_FAULT;
  229. }
  230. }
  231. else //cmsysProcess_State_Error
  232. {
  233. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Not Run ");
  234. }
  235. passed = this->TestResult.Status == cmCTestTestHandler::COMPLETED;
  236. char buf[1024];
  237. sprintf(buf, "%6.2f sec", this->TestProcess->GetTotalTime());
  238. cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n" );
  239. if ( outputTestErrorsToConsole )
  240. {
  241. cmCTestLog(this->CTest, HANDLER_OUTPUT, this->ProcessOutput << std::endl );
  242. }
  243. if ( this->TestHandler->LogFile )
  244. {
  245. *this->TestHandler->LogFile << "Test time = " << buf << std::endl;
  246. }
  247. // Set the working directory to the tests directory
  248. std::string oldpath = cmSystemTools::GetCurrentWorkingDirectory();
  249. cmSystemTools::ChangeDirectory(this->TestProperties->Directory.c_str());
  250. this->DartProcessing();
  251. // restore working directory
  252. cmSystemTools::ChangeDirectory(oldpath.c_str());
  253. // if this is doing MemCheck then all the output needs to be put into
  254. // Output since that is what is parsed by cmCTestMemCheckHandler
  255. if(!this->TestHandler->MemCheck && started)
  256. {
  257. this->TestHandler->CleanTestOutput(this->ProcessOutput,
  258. static_cast<size_t>
  259. (this->TestResult.Status == cmCTestTestHandler::COMPLETED ?
  260. this->TestHandler->CustomMaximumPassedTestOutputSize :
  261. this->TestHandler->CustomMaximumFailedTestOutputSize));
  262. }
  263. this->TestResult.Reason = reason;
  264. if (this->TestHandler->LogFile)
  265. {
  266. bool pass = true;
  267. const char* reasonType = "Test Pass Reason";
  268. if(this->TestResult.Status != cmCTestTestHandler::COMPLETED &&
  269. this->TestResult.Status != cmCTestTestHandler::NOT_RUN)
  270. {
  271. reasonType = "Test Fail Reason";
  272. pass = false;
  273. }
  274. double ttime = this->TestProcess->GetTotalTime();
  275. int hours = static_cast<int>(ttime / (60 * 60));
  276. int minutes = static_cast<int>(ttime / 60) % 60;
  277. int seconds = static_cast<int>(ttime) % 60;
  278. char buffer[100];
  279. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  280. *this->TestHandler->LogFile
  281. << "----------------------------------------------------------"
  282. << std::endl;
  283. if(this->TestResult.Reason.size())
  284. {
  285. *this->TestHandler->LogFile << reasonType << ":\n"
  286. << this->TestResult.Reason << "\n";
  287. }
  288. else
  289. {
  290. if(pass)
  291. {
  292. *this->TestHandler->LogFile << "Test Passed.\n";
  293. }
  294. else
  295. {
  296. *this->TestHandler->LogFile << "Test Failed.\n";
  297. }
  298. }
  299. *this->TestHandler->LogFile << "\"" << this->TestProperties->Name.c_str()
  300. << "\" end time: " << this->CTest->CurrentTime() << std::endl
  301. << "\"" << this->TestProperties->Name.c_str() << "\" time elapsed: "
  302. << buffer << std::endl
  303. << "----------------------------------------------------------"
  304. << std::endl << std::endl;
  305. }
  306. // if the test actually started and ran
  307. // record the results in TestResult
  308. if(started)
  309. {
  310. bool compress = !this->TestHandler->MemCheck &&
  311. this->CompressionRatio < 1 &&
  312. this->CTest->ShouldCompressTestOutput();
  313. this->TestResult.Output = compress ? this->CompressedOutput
  314. : this->ProcessOutput;
  315. this->TestResult.CompressOutput = compress;
  316. this->TestResult.ReturnValue = this->TestProcess->GetExitValue();
  317. this->TestResult.CompletionStatus = "Completed";
  318. this->TestResult.ExecutionTime = this->TestProcess->GetTotalTime();
  319. this->MemCheckPostProcess();
  320. this->ComputeWeightedCost();
  321. }
  322. // Always push the current TestResult onto the
  323. // TestHandler vector
  324. this->TestHandler->TestResults.push_back(this->TestResult);
  325. delete this->TestProcess;
  326. return passed;
  327. }
  328. //----------------------------------------------------------------------
  329. void cmCTestRunTest::ComputeWeightedCost()
  330. {
  331. double prev = static_cast<double>(this->TestProperties->PreviousRuns);
  332. double avgcost = static_cast<double>(this->TestProperties->Cost);
  333. double current = this->TestResult.ExecutionTime;
  334. if(this->TestResult.Status == cmCTestTestHandler::COMPLETED)
  335. {
  336. this->TestProperties->Cost =
  337. static_cast<float>(((prev * avgcost) + current) / (prev + 1.0));
  338. this->TestProperties->PreviousRuns++;
  339. }
  340. }
  341. //----------------------------------------------------------------------
  342. void cmCTestRunTest::MemCheckPostProcess()
  343. {
  344. if(!this->TestHandler->MemCheck)
  345. {
  346. return;
  347. }
  348. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index
  349. << ": process test output now: "
  350. << this->TestProperties->Name.c_str() << " "
  351. << this->TestResult.Name.c_str() << std::endl);
  352. cmCTestMemCheckHandler * handler = static_cast<cmCTestMemCheckHandler*>
  353. (this->TestHandler);
  354. if(handler->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER)
  355. {
  356. handler->PostProcessBoundsCheckerTest(this->TestResult);
  357. }
  358. else if(handler->MemoryTesterStyle == cmCTestMemCheckHandler::PURIFY)
  359. {
  360. handler->PostProcessPurifyTest(this->TestResult);
  361. }
  362. }
  363. //----------------------------------------------------------------------
  364. // Starts the execution of a test. Returns once it has started
  365. bool cmCTestRunTest::StartTest(size_t total)
  366. {
  367. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(2*getNumWidth(total) + 8)
  368. << "Start "
  369. << std::setw(getNumWidth(this->TestHandler->GetMaxIndex()))
  370. << this->TestProperties->Index << ": "
  371. << this->TestProperties->Name << std::endl);
  372. this->ComputeArguments();
  373. std::vector<std::string>& args = this->TestProperties->Args;
  374. this->TestResult.Properties = this->TestProperties;
  375. this->TestResult.ExecutionTime = 0;
  376. this->TestResult.CompressOutput = false;
  377. this->TestResult.ReturnValue = -1;
  378. this->TestResult.CompletionStatus = "Failed to start";
  379. this->TestResult.Status = cmCTestTestHandler::BAD_COMMAND;
  380. this->TestResult.TestCount = this->TestProperties->Index;
  381. this->TestResult.Name = this->TestProperties->Name;
  382. this->TestResult.Path = this->TestProperties->Directory.c_str();
  383. // Check if all required files exist
  384. for(std::vector<std::string>::iterator i =
  385. this->TestProperties->RequiredFiles.begin();
  386. i != this->TestProperties->RequiredFiles.end(); ++i)
  387. {
  388. std::string file = *i;
  389. if(!cmSystemTools::FileExists(file.c_str()))
  390. {
  391. //Required file was not found
  392. this->TestProcess = new cmProcess;
  393. *this->TestHandler->LogFile << "Unable to find required file: "
  394. << file.c_str() << std::endl;
  395. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find required file: "
  396. << file.c_str() << std::endl);
  397. this->TestResult.Output = "Unable to find required file: " + file;
  398. this->TestResult.FullCommandLine = "";
  399. this->TestResult.CompletionStatus = "Not Run";
  400. this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
  401. return false;
  402. }
  403. }
  404. // log and return if we did not find the executable
  405. if (this->ActualCommand == "")
  406. {
  407. // if the command was not found create a TestResult object
  408. // that has that information
  409. this->TestProcess = new cmProcess;
  410. *this->TestHandler->LogFile << "Unable to find executable: "
  411. << args[1].c_str() << std::endl;
  412. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
  413. << args[1].c_str() << std::endl);
  414. this->TestResult.Output = "Unable to find executable: " + args[1];
  415. this->TestResult.FullCommandLine = "";
  416. this->TestResult.CompletionStatus = "Not Run";
  417. this->TestResult.Status = cmCTestTestHandler::NOT_RUN;
  418. return false;
  419. }
  420. this->StartTime = this->CTest->CurrentTime();
  421. double timeout = this->ResolveTimeout();
  422. if(this->StopTimePassed)
  423. {
  424. return false;
  425. }
  426. return this->ForkProcess(timeout, this->TestProperties->ExplicitTimeout,
  427. &this->TestProperties->Environment);
  428. }
  429. //----------------------------------------------------------------------
  430. void cmCTestRunTest::ComputeArguments()
  431. {
  432. std::vector<std::string>::const_iterator j =
  433. this->TestProperties->Args.begin();
  434. ++j; // skip test name
  435. // find the test executable
  436. if(this->TestHandler->MemCheck)
  437. {
  438. cmCTestMemCheckHandler * handler = static_cast<cmCTestMemCheckHandler*>
  439. (this->TestHandler);
  440. this->ActualCommand = handler->MemoryTester.c_str();
  441. this->TestProperties->Args[1] = this->TestHandler->FindTheExecutable(
  442. this->TestProperties->Args[1].c_str());
  443. }
  444. else
  445. {
  446. this->ActualCommand =
  447. this->TestHandler->FindTheExecutable(
  448. this->TestProperties->Args[1].c_str());
  449. ++j; //skip the executable (it will be actualCommand)
  450. }
  451. std::string testCommand
  452. = cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str());
  453. //Prepends memcheck args to our command string
  454. this->TestHandler->GenerateTestCommand(this->Arguments);
  455. for(std::vector<std::string>::iterator i = this->Arguments.begin();
  456. i != this->Arguments.end(); ++i)
  457. {
  458. testCommand += " \"";
  459. testCommand += *i;
  460. testCommand += "\"";
  461. }
  462. for(;j != this->TestProperties->Args.end(); ++j)
  463. {
  464. testCommand += " \"";
  465. testCommand += *j;
  466. testCommand += "\"";
  467. this->Arguments.push_back(*j);
  468. }
  469. this->TestResult.FullCommandLine = testCommand;
  470. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  471. << this->Index << ": "
  472. << (this->TestHandler->MemCheck?"MemCheck":"Test")
  473. << " command: " << testCommand
  474. << std::endl);
  475. }
  476. //----------------------------------------------------------------------
  477. void cmCTestRunTest::DartProcessing()
  478. {
  479. if (!this->ProcessOutput.empty() &&
  480. this->ProcessOutput.find("<DartMeasurement") != this->ProcessOutput.npos)
  481. {
  482. if (this->TestHandler->DartStuff.find(this->ProcessOutput.c_str()))
  483. {
  484. std::string dartString = this->TestHandler->DartStuff.match(1);
  485. // keep searching and replacing until none are left
  486. while (this->TestHandler->DartStuff1.find(this->ProcessOutput.c_str()))
  487. {
  488. // replace the exact match for the string
  489. cmSystemTools::ReplaceString(this->ProcessOutput,
  490. this->TestHandler->DartStuff1.match(1).c_str(), "");
  491. }
  492. this->TestResult.RegressionImages
  493. = this->TestHandler->GenerateRegressionImages(dartString);
  494. }
  495. }
  496. }
  497. //----------------------------------------------------------------------
  498. double cmCTestRunTest::ResolveTimeout()
  499. {
  500. double timeout = this->TestProperties->Timeout;
  501. if(this->CTest->GetStopTime() == "")
  502. {
  503. return timeout;
  504. }
  505. struct tm* lctime;
  506. time_t current_time = time(0);
  507. lctime = gmtime(&current_time);
  508. int gm_hour = lctime->tm_hour;
  509. time_t gm_time = mktime(lctime);
  510. lctime = localtime(&current_time);
  511. int local_hour = lctime->tm_hour;
  512. int tzone_offset = local_hour - gm_hour;
  513. if(gm_time > current_time && gm_hour < local_hour)
  514. {
  515. // this means gm_time is on the next day
  516. tzone_offset -= 24;
  517. }
  518. else if(gm_time < current_time && gm_hour > local_hour)
  519. {
  520. // this means gm_time is on the previous day
  521. tzone_offset += 24;
  522. }
  523. tzone_offset *= 100;
  524. char buf[1024];
  525. // add todays year day and month to the time in str because
  526. // curl_getdate no longer assumes the day is today
  527. sprintf(buf, "%d%02d%02d %s %+05i",
  528. lctime->tm_year + 1900,
  529. lctime->tm_mon + 1,
  530. lctime->tm_mday,
  531. this->CTest->GetStopTime().c_str(),
  532. tzone_offset);
  533. time_t stop_time = curl_getdate(buf, &current_time);
  534. if(stop_time == -1)
  535. {
  536. return timeout;
  537. }
  538. //the stop time refers to the next day
  539. if(this->CTest->NextDayStopTime)
  540. {
  541. stop_time += 24*60*60;
  542. }
  543. int stop_timeout = static_cast<int>(stop_time - current_time) % (24*60*60);
  544. this->CTest->LastStopTimeout = stop_timeout;
  545. if(stop_timeout <= 0 || stop_timeout > this->CTest->LastStopTimeout)
  546. {
  547. cmCTestLog(this->CTest, ERROR_MESSAGE, "The stop time has been passed. "
  548. "Stopping all tests." << std::endl);
  549. this->StopTimePassed = true;
  550. return 0;
  551. }
  552. return timeout == 0 ? stop_timeout :
  553. (timeout < stop_timeout ? timeout : stop_timeout);
  554. }
  555. //----------------------------------------------------------------------
  556. bool cmCTestRunTest::ForkProcess(double testTimeOut, bool explicitTimeout,
  557. std::vector<std::string>* environment)
  558. {
  559. this->TestProcess = new cmProcess;
  560. this->TestProcess->SetId(this->Index);
  561. this->TestProcess->SetWorkingDirectory(
  562. this->TestProperties->Directory.c_str());
  563. this->TestProcess->SetCommand(this->ActualCommand.c_str());
  564. this->TestProcess->SetCommandArguments(this->Arguments);
  565. // determine how much time we have
  566. double timeout = this->CTest->GetRemainingTimeAllowed() - 120;
  567. if (this->CTest->GetTimeOut() > 0 && this->CTest->GetTimeOut() < timeout)
  568. {
  569. timeout = this->CTest->GetTimeOut();
  570. }
  571. if (testTimeOut > 0
  572. && testTimeOut < this->CTest->GetRemainingTimeAllowed())
  573. {
  574. timeout = testTimeOut;
  575. }
  576. // always have at least 1 second if we got to here
  577. if (timeout <= 0)
  578. {
  579. timeout = 1;
  580. }
  581. // handle timeout explicitly set to 0
  582. if (testTimeOut == 0 && explicitTimeout)
  583. {
  584. timeout = 0;
  585. }
  586. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, this->Index << ": "
  587. << "Test timeout computed to be: " << timeout << "\n");
  588. this->TestProcess->SetTimeout(timeout);
  589. #ifdef CMAKE_BUILD_WITH_CMAKE
  590. cmSystemTools::SaveRestoreEnvironment sre;
  591. #endif
  592. if (environment && environment->size()>0)
  593. {
  594. cmSystemTools::AppendEnv(environment);
  595. }
  596. return this->TestProcess->StartProcess();
  597. }
  598. void cmCTestRunTest::WriteLogOutputTop(size_t completed, size_t total)
  599. {
  600. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
  601. << completed << "/");
  602. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(getNumWidth(total))
  603. << total << " ");
  604. if ( this->TestHandler->MemCheck )
  605. {
  606. cmCTestLog(this->CTest, HANDLER_OUTPUT, "MemCheck");
  607. }
  608. else
  609. {
  610. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Test");
  611. }
  612. cmOStringStream indexStr;
  613. indexStr << " #" << this->Index << ":";
  614. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  615. std::setw(3 + getNumWidth(this->TestHandler->GetMaxIndex()))
  616. << indexStr.str().c_str());
  617. cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
  618. const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
  619. std::string outname = this->TestProperties->Name + " ";
  620. outname.resize(maxTestNameWidth + 4, '.');
  621. *this->TestHandler->LogFile << this->TestProperties->Index << "/"
  622. << this->TestHandler->TotalNumberOfTests << " Testing: "
  623. << this->TestProperties->Name << std::endl;
  624. *this->TestHandler->LogFile << this->TestProperties->Index << "/"
  625. << this->TestHandler->TotalNumberOfTests
  626. << " Test: " << this->TestProperties->Name.c_str() << std::endl;
  627. *this->TestHandler->LogFile << "Command: \"" << this->ActualCommand << "\"";
  628. for (std::vector<std::string>::iterator i = this->Arguments.begin();
  629. i != this->Arguments.end(); ++i)
  630. {
  631. *this->TestHandler->LogFile
  632. << " \"" << i->c_str() << "\"";
  633. }
  634. *this->TestHandler->LogFile << std::endl
  635. << "Directory: " << this->TestProperties->Directory << std::endl
  636. << "\"" << this->TestProperties->Name.c_str() << "\" start time: "
  637. << this->StartTime << std::endl;
  638. *this->TestHandler->LogFile
  639. << "Output:" << std::endl
  640. << "----------------------------------------------------------"
  641. << std::endl;
  642. *this->TestHandler->LogFile
  643. << this->ProcessOutput.c_str() << "<end of output>" << std::endl;
  644. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
  645. cmCTestLog(this->CTest, DEBUG, "Testing "
  646. << this->TestProperties->Name.c_str() << " ... ");
  647. }