cmCTestRunTest.cxx 23 KB

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