cmCTestRunTest.cxx 23 KB

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