cmCTestTestHandler.cxx 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestTestHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include <cmsys/Process.h>
  18. #include <cmsys/RegularExpression.hxx>
  19. #include <cmsys/Base64.h>
  20. #include "cmMakefile.h"
  21. #include <stdlib.h>
  22. #include <math.h>
  23. #include <float.h>
  24. //----------------------------------------------------------------------
  25. bool TryExecutable(const char *dir, const char *file,
  26. std::string *fullPath, const char *subdir)
  27. {
  28. // try current directory
  29. std::string tryPath;
  30. if (dir && strcmp(dir,""))
  31. {
  32. tryPath = dir;
  33. tryPath += "/";
  34. }
  35. if (subdir && strcmp(subdir,""))
  36. {
  37. tryPath += subdir;
  38. tryPath += "/";
  39. }
  40. tryPath += file;
  41. if(cmSystemTools::FileExists(tryPath.c_str()))
  42. {
  43. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  44. return true;
  45. }
  46. tryPath += cmSystemTools::GetExecutableExtension();
  47. if(cmSystemTools::FileExists(tryPath.c_str()))
  48. {
  49. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  50. return true;
  51. }
  52. return false;
  53. }
  54. //----------------------------------------------------------------------
  55. // get the next number in a string with numbers separated by ,
  56. // pos is the start of the search and pos2 is the end of the search
  57. // pos becomes pos2 after a call to GetNextNumber.
  58. // -1 is returned at the end of the list.
  59. inline int GetNextNumber(std::string const& in,
  60. int& val,
  61. std::string::size_type& pos,
  62. std::string::size_type& pos2)
  63. {
  64. pos2 = in.find(',', pos);
  65. if(pos2 != in.npos)
  66. {
  67. if(pos2-pos == 0)
  68. {
  69. val = -1;
  70. }
  71. else
  72. {
  73. val = atoi(in.substr(pos, pos2-pos).c_str());
  74. }
  75. pos = pos2+1;
  76. return 1;
  77. }
  78. else
  79. {
  80. if(in.size()-pos == 0)
  81. {
  82. val = -1;
  83. }
  84. else
  85. {
  86. val = atoi(in.substr(pos, in.size()-pos).c_str());
  87. }
  88. return 0;
  89. }
  90. }
  91. //----------------------------------------------------------------------
  92. // get the next number in a string with numbers separated by ,
  93. // pos is the start of the search and pos2 is the end of the search
  94. // pos becomes pos2 after a call to GetNextNumber.
  95. // -1 is returned at the end of the list.
  96. inline int GetNextRealNumber(std::string const& in,
  97. double& val,
  98. std::string::size_type& pos,
  99. std::string::size_type& pos2)
  100. {
  101. pos2 = in.find(',', pos);
  102. if(pos2 != in.npos)
  103. {
  104. if(pos2-pos == 0)
  105. {
  106. val = -1;
  107. }
  108. else
  109. {
  110. val = atof(in.substr(pos, pos2-pos).c_str());
  111. }
  112. pos = pos2+1;
  113. return 1;
  114. }
  115. else
  116. {
  117. if(in.size()-pos == 0)
  118. {
  119. val = -1;
  120. }
  121. else
  122. {
  123. val = atof(in.substr(pos, in.size()-pos).c_str());
  124. }
  125. return 0;
  126. }
  127. }
  128. //----------------------------------------------------------------------
  129. cmCTestTestHandler::cmCTestTestHandler()
  130. {
  131. m_UseUnion = false;
  132. m_UseIncludeRegExp = false;
  133. m_UseExcludeRegExp = false;
  134. m_UseExcludeRegExpFirst = false;
  135. m_CustomMaximumPassedTestOutputSize = 1 * 1024;
  136. m_CustomMaximumFailedTestOutputSize = 300 * 1024;
  137. m_MemCheck = false;
  138. }
  139. //----------------------------------------------------------------------
  140. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
  141. {
  142. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  143. m_CustomPreTest);
  144. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  145. m_CustomPostTest);
  146. cmCTest::PopulateCustomVector(mf,
  147. "CTEST_CUSTOM_TESTS_IGNORE",
  148. m_CustomTestsIgnore);
  149. cmCTest::PopulateCustomInteger(mf,
  150. "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
  151. m_CustomMaximumPassedTestOutputSize);
  152. cmCTest::PopulateCustomInteger(mf,
  153. "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
  154. m_CustomMaximumFailedTestOutputSize);
  155. }
  156. //----------------------------------------------------------------------
  157. int cmCTestTestHandler::PreProcessHandler()
  158. {
  159. if ( !this->ExecuteCommands(m_CustomPreTest) )
  160. {
  161. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem executing pre-test command(s)." << std::endl);
  162. return 0;
  163. }
  164. return 1;
  165. }
  166. //----------------------------------------------------------------------
  167. int cmCTestTestHandler::PostProcessHandler()
  168. {
  169. if ( !this->ExecuteCommands(m_CustomPostTest) )
  170. {
  171. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem executing post-test command(s)." << std::endl);
  172. return 0;
  173. }
  174. return 1;
  175. }
  176. //----------------------------------------------------------------------
  177. //clearly it would be nice if this were broken up into a few smaller
  178. //functions and commented...
  179. int cmCTestTestHandler::ProcessHandler()
  180. {
  181. // Update internal data structure from generic one
  182. this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
  183. this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
  184. const char* val;
  185. val = this->GetOption("IncludeRegularExpression");
  186. if ( val )
  187. {
  188. this->UseIncludeRegExp();
  189. this->SetIncludeRegExp(val);
  190. }
  191. val = this->GetOption("ExcludeRegularExpression");
  192. if ( val )
  193. {
  194. this->UseExcludeRegExp();
  195. this->SetExcludeRegExp(val);
  196. }
  197. m_TestResults.clear();
  198. cmCTestLog(m_CTest, HANDLER_OUTPUT, (m_MemCheck ? "Memory check" : "Test") << " project" << std::endl);
  199. if ( ! this->PreProcessHandler() )
  200. {
  201. return -1;
  202. }
  203. std::vector<cmStdString> passed;
  204. std::vector<cmStdString> failed;
  205. int total;
  206. this->ProcessDirectory(passed, failed);
  207. total = int(passed.size()) + int(failed.size());
  208. if (total == 0)
  209. {
  210. if ( !m_CTest->GetShowOnly() )
  211. {
  212. cmCTestLog(m_CTest, ERROR_MESSAGE, "No tests were found!!!" << std::endl);
  213. }
  214. }
  215. else
  216. {
  217. if (m_HandlerVerbose && passed.size() &&
  218. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  219. {
  220. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl << "The following tests passed:" << std::endl);
  221. for(std::vector<cmStdString>::iterator j = passed.begin();
  222. j != passed.end(); ++j)
  223. {
  224. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j << std::endl);
  225. }
  226. }
  227. float percent = float(passed.size()) * 100.0f / total;
  228. if ( failed.size() > 0 && percent > 99)
  229. {
  230. percent = 99;
  231. }
  232. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl << std::setprecision(0) << percent << "% tests passed, "
  233. << failed.size() << " tests failed out of " << total << std::endl);
  234. //fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  235. // percent, int(failed.size()), total);
  236. if (failed.size())
  237. {
  238. cmGeneratedFileStream ofs;
  239. cmCTestLog(m_CTest, ERROR_MESSAGE, std::endl << "The following tests FAILED:" << std::endl);
  240. m_CTest->OpenOutputFile("Temporary", "LastTestsFailed.log", ofs);
  241. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  242. for(ftit = m_TestResults.begin();
  243. ftit != m_TestResults.end(); ++ftit)
  244. {
  245. if ( ftit->m_Status != cmCTestTestHandler::COMPLETED )
  246. {
  247. ofs << ftit->m_TestCount << ":" << ftit->m_Name << std::endl;
  248. cmCTestLog(m_CTest, HANDLER_OUTPUT, "\t" << std::setw(3) << ftit->m_TestCount << " - " << ftit->m_Name.c_str() << " (" << this->GetTestStatus(ftit->m_Status) << ")" << std::endl);
  249. //fprintf(stderr, "\t%3d - %s (%s)\n", ftit->m_TestCount, ftit->m_Name.c_str(),
  250. // this->GetTestStatus(ftit->m_Status));
  251. }
  252. }
  253. }
  254. }
  255. if ( m_CTest->GetProduceXML() )
  256. {
  257. cmGeneratedFileStream xmlfile;
  258. if( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(),
  259. (m_MemCheck ? "DynamicAnalysis.xml" : "Test.xml"), xmlfile, true) )
  260. {
  261. cmCTestLog(m_CTest, ERROR_MESSAGE, "Cannot create " << (m_MemCheck ? "memory check" : "testing")
  262. << " XML file" << std::endl);
  263. return 1;
  264. }
  265. this->GenerateDartOutput(xmlfile);
  266. }
  267. if ( ! this->PostProcessHandler() )
  268. {
  269. return -1;
  270. }
  271. if ( !failed.empty() )
  272. {
  273. return -1;
  274. }
  275. return 0;
  276. }
  277. //----------------------------------------------------------------------
  278. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  279. std::vector<cmStdString> &failed)
  280. {
  281. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  282. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  283. tm_ListOfTests testlist;
  284. this->GetListOfTests(&testlist);
  285. tm_ListOfTests::size_type tmsize = testlist.size();
  286. cmGeneratedFileStream ofs;
  287. cmGeneratedFileStream *olog = 0;
  288. if ( !m_CTest->GetShowOnly() && tmsize > 0 &&
  289. m_CTest->OpenOutputFile("Temporary",
  290. (m_MemCheck?"LastMemCheck.log":"LastTest.log"), ofs) )
  291. {
  292. olog = &ofs;
  293. }
  294. m_StartTest = m_CTest->CurrentTime();
  295. double elapsed_time_start = cmSystemTools::GetTime();
  296. if ( olog )
  297. {
  298. *olog << "Start testing: " << m_StartTest << std::endl
  299. << "----------------------------------------------------------"
  300. << std::endl;
  301. }
  302. // how many tests are in based on RegExp?
  303. int inREcnt = 0;
  304. tm_ListOfTests::iterator it;
  305. for ( it = testlist.begin(); it != testlist.end(); it ++ )
  306. {
  307. if (it->m_IsInBasedOnREOptions)
  308. {
  309. inREcnt ++;
  310. }
  311. }
  312. // expand the test list based on the union flag
  313. if (m_UseUnion)
  314. {
  315. this->ExpandTestsToRunInformation((int)tmsize);
  316. }
  317. else
  318. {
  319. this->ExpandTestsToRunInformation(inREcnt);
  320. }
  321. int cnt = 0;
  322. inREcnt = 0;
  323. std::string last_directory = "";
  324. for ( it = testlist.begin(); it != testlist.end(); it ++ )
  325. {
  326. cnt ++;
  327. if (it->m_IsInBasedOnREOptions)
  328. {
  329. inREcnt++;
  330. }
  331. const std::string& testname = it->m_Name;
  332. tm_VectorOfListFileArgs& args = it->m_Args;
  333. cmCTestTestResult cres;
  334. cres.m_Status = cmCTestTestHandler::NOT_RUN;
  335. cres.m_TestCount = cnt;
  336. if (!(last_directory == it->m_Directory))
  337. {
  338. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Changing directory into "
  339. << it->m_Directory.c_str() << "\n");
  340. last_directory = it->m_Directory;
  341. cmSystemTools::ChangeDirectory(it->m_Directory.c_str());
  342. }
  343. cres.m_Name = testname;
  344. cres.m_Path = it->m_Directory.c_str();
  345. if (m_UseUnion)
  346. {
  347. // if it is not in the list and not in the regexp then skip
  348. if ((m_TestsToRun.size() &&
  349. std::find(m_TestsToRun.begin(), m_TestsToRun.end(), cnt)
  350. == m_TestsToRun.end()) && !it->m_IsInBasedOnREOptions)
  351. {
  352. continue;
  353. }
  354. }
  355. else
  356. {
  357. // is this test in the list of tests to run? If not then skip it
  358. if ((m_TestsToRun.size() &&
  359. std::find(m_TestsToRun.begin(), m_TestsToRun.end(), inREcnt)
  360. == m_TestsToRun.end()) || !it->m_IsInBasedOnREOptions)
  361. {
  362. continue;
  363. }
  364. }
  365. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
  366. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " Testing ");
  367. std::string outname = testname;
  368. outname.resize(30, ' ');
  369. if ( m_CTest->GetShowOnly() )
  370. {
  371. cmCTestLog(m_CTest, HANDLER_OUTPUT, outname.c_str() << std::endl);
  372. }
  373. else
  374. {
  375. cmCTestLog(m_CTest, HANDLER_OUTPUT, outname.c_str());
  376. }
  377. cmCTestLog(m_CTest, DEBUG, "Testing " << args[0].Value.c_str() << " ... ");
  378. // find the test executable
  379. std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
  380. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  381. // continue if we did not find the executable
  382. if (testCommand == "")
  383. {
  384. cmCTestLog(m_CTest, ERROR_MESSAGE, "Unable to find executable: "
  385. << args[1].Value.c_str() << std::endl);
  386. if ( !m_CTest->GetShowOnly() )
  387. {
  388. cres.m_FullCommandLine = actualCommand;
  389. m_TestResults.push_back( cres );
  390. failed.push_back(testname);
  391. continue;
  392. }
  393. }
  394. // add the arguments
  395. tm_VectorOfListFileArgs::const_iterator j = args.begin();
  396. ++j;
  397. ++j;
  398. std::vector<const char*> arguments;
  399. this->GenerateTestCommand(arguments);
  400. arguments.push_back(actualCommand.c_str());
  401. for(;j != args.end(); ++j)
  402. {
  403. testCommand += " ";
  404. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  405. arguments.push_back(j->Value.c_str());
  406. }
  407. arguments.push_back(0);
  408. /**
  409. * Run an executable command and put the stdout in output.
  410. */
  411. std::string output;
  412. int retVal = 0;
  413. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, std::endl << (m_MemCheck?"MemCheck":"Test") << " command: " << testCommand << std::endl);
  414. if ( olog )
  415. {
  416. *olog << cnt << "/" << tmsize
  417. << " Test: " << testname.c_str() << std::endl;
  418. *olog << "Command: ";
  419. std::vector<cmStdString>::size_type ll;
  420. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  421. {
  422. *olog << "\"" << arguments[ll] << "\" ";
  423. }
  424. *olog
  425. << std::endl
  426. << "Directory: " << it->m_Directory << std::endl
  427. << "\"" << testname.c_str() << "\" start time: "
  428. << m_CTest->CurrentTime() << std::endl
  429. << "Output:" << std::endl
  430. << "----------------------------------------------------------"
  431. << std::endl;
  432. }
  433. int res = 0;
  434. double clock_start, clock_finish;
  435. clock_start = cmSystemTools::GetTime();
  436. if ( !m_CTest->GetShowOnly() )
  437. {
  438. res = m_CTest->RunTest(arguments, &output, &retVal, olog);
  439. }
  440. clock_finish = cmSystemTools::GetTime();
  441. if ( olog )
  442. {
  443. double ttime = clock_finish - clock_start;
  444. int hours = static_cast<int>(ttime / (60 * 60));
  445. int minutes = static_cast<int>(ttime / 60) % 60;
  446. int seconds = static_cast<int>(ttime) % 60;
  447. char buffer[100];
  448. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  449. *olog
  450. << "----------------------------------------------------------"
  451. << std::endl
  452. << "\"" << testname.c_str() << "\" end time: "
  453. << m_CTest->CurrentTime() << std::endl
  454. << "\"" << testname.c_str() << "\" time elapsed: "
  455. << buffer << std::endl
  456. << "----------------------------------------------------------"
  457. << std::endl << std::endl;
  458. }
  459. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  460. cres.m_FullCommandLine = testCommand;
  461. if ( !m_CTest->GetShowOnly() )
  462. {
  463. if (res == cmsysProcess_State_Exited && retVal == 0)
  464. {
  465. cmCTestLog(m_CTest, HANDLER_OUTPUT, " Passed" << std::endl);
  466. passed.push_back(testname);
  467. cres.m_Status = cmCTestTestHandler::COMPLETED;
  468. }
  469. else
  470. {
  471. cres.m_Status = cmCTestTestHandler::FAILED;
  472. if ( res == cmsysProcess_State_Expired )
  473. {
  474. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Timeout" << std::endl);
  475. cres.m_Status = cmCTestTestHandler::TIMEOUT;
  476. }
  477. else if ( res == cmsysProcess_State_Exception )
  478. {
  479. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Exception: ");
  480. switch ( retVal )
  481. {
  482. case cmsysProcess_Exception_Fault:
  483. cmCTestLog(m_CTest, HANDLER_OUTPUT, "SegFault");
  484. cres.m_Status = cmCTestTestHandler::SEGFAULT;
  485. break;
  486. case cmsysProcess_Exception_Illegal:
  487. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Illegal");
  488. cres.m_Status = cmCTestTestHandler::ILLEGAL;
  489. break;
  490. case cmsysProcess_Exception_Interrupt:
  491. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Interrupt");
  492. cres.m_Status = cmCTestTestHandler::INTERRUPT;
  493. break;
  494. case cmsysProcess_Exception_Numerical:
  495. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Numerical");
  496. cres.m_Status = cmCTestTestHandler::NUMERICAL;
  497. break;
  498. default:
  499. cmCTestLog(m_CTest, HANDLER_OUTPUT, "Other");
  500. cres.m_Status = cmCTestTestHandler::OTHER_FAULT;
  501. }
  502. cmCTestLog(m_CTest, HANDLER_OUTPUT, std::endl);
  503. }
  504. else if ( res == cmsysProcess_State_Error )
  505. {
  506. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Bad command " << res << std::endl);
  507. cres.m_Status = cmCTestTestHandler::BAD_COMMAND;
  508. }
  509. else
  510. {
  511. cmCTestLog(m_CTest, HANDLER_OUTPUT, "***Failed" << std::endl);
  512. }
  513. failed.push_back(testname);
  514. }
  515. if (output != "")
  516. {
  517. if (dartStuff.find(output.c_str()))
  518. {
  519. std::string dartString = dartStuff.match(1);
  520. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  521. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  522. }
  523. }
  524. }
  525. if ( cres.m_Status == cmCTestTestHandler::COMPLETED )
  526. {
  527. this->CleanTestOutput(output, static_cast<size_t>(m_CustomMaximumPassedTestOutputSize));
  528. }
  529. else
  530. {
  531. this->CleanTestOutput(output, static_cast<size_t>(m_CustomMaximumFailedTestOutputSize));
  532. }
  533. cres.m_Output = output;
  534. cres.m_ReturnValue = retVal;
  535. cres.m_CompletionStatus = "Completed";
  536. m_TestResults.push_back( cres );
  537. }
  538. m_EndTest = m_CTest->CurrentTime();
  539. m_ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  540. if ( olog )
  541. {
  542. *olog << "End testing: " << m_EndTest << std::endl;
  543. }
  544. cmSystemTools::ChangeDirectory(current_dir.c_str());
  545. }
  546. //----------------------------------------------------------------------
  547. void cmCTestTestHandler::GenerateTestCommand(std::vector<const char*>&)
  548. {
  549. }
  550. //----------------------------------------------------------------------
  551. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  552. {
  553. if ( !m_CTest->GetProduceXML() )
  554. {
  555. return;
  556. }
  557. m_CTest->StartXML(os);
  558. os << "<Testing>\n"
  559. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  560. << "\t<TestList>\n";
  561. tm_TestResultsVector::size_type cc;
  562. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  563. {
  564. cmCTestTestResult *result = &m_TestResults[cc];
  565. std::string testPath = result->m_Path + "/" + result->m_Name;
  566. os << "\t\t<Test>" << cmCTest::MakeXMLSafe(
  567. m_CTest->GetShortPathToFile(testPath.c_str()))
  568. << "</Test>" << std::endl;
  569. }
  570. os << "\t</TestList>\n";
  571. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  572. {
  573. cmCTestTestResult *result = &m_TestResults[cc];
  574. os << "\t<Test Status=\"";
  575. if ( result->m_Status == cmCTestTestHandler::COMPLETED )
  576. {
  577. os << "passed";
  578. }
  579. else if ( result->m_Status == cmCTestTestHandler::NOT_RUN )
  580. {
  581. os << "notrun";
  582. }
  583. else
  584. {
  585. os << "failed";
  586. }
  587. std::string testPath = result->m_Path + "/" + result->m_Name;
  588. os << "\">\n"
  589. << "\t\t<Name>" << cmCTest::MakeXMLSafe(result->m_Name) << "</Name>\n"
  590. << "\t\t<Path>" << cmCTest::MakeXMLSafe(
  591. m_CTest->GetShortPathToFile(result->m_Path.c_str())) << "</Path>\n"
  592. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(
  593. m_CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  594. << "\t\t<FullCommandLine>"
  595. << cmCTest::MakeXMLSafe(result->m_FullCommandLine)
  596. << "</FullCommandLine>\n"
  597. << "\t\t<Results>" << std::endl;
  598. if ( result->m_Status != cmCTestTestHandler::NOT_RUN )
  599. {
  600. if ( result->m_Status != cmCTestTestHandler::COMPLETED || result->m_ReturnValue )
  601. {
  602. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  603. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  604. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  605. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  606. }
  607. os << result->m_RegressionImages;
  608. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  609. << "name=\"Execution Time\"><Value>"
  610. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  611. os
  612. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  613. << "name=\"Completion Status\"><Value>"
  614. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  615. }
  616. os
  617. << "\t\t\t<Measurement>\n"
  618. << "\t\t\t\t<Value>";
  619. os << cmCTest::MakeXMLSafe(result->m_Output);
  620. os
  621. << "</Value>\n"
  622. << "\t\t\t</Measurement>\n"
  623. << "\t\t</Results>\n"
  624. << "\t</Test>" << std::endl;
  625. }
  626. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  627. << "<ElapsedMinutes>"
  628. << static_cast<int>(m_ElapsedTestingTime/6)/10.0
  629. << "</ElapsedMinutes>"
  630. << "</Testing>" << std::endl;
  631. m_CTest->EndXML(os);
  632. }
  633. //----------------------------------------------------------------------
  634. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  635. {
  636. std::vector<cmStdString>::iterator it;
  637. for ( it = vec.begin(); it != vec.end(); ++it )
  638. {
  639. int retVal = 0;
  640. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it << std::endl);
  641. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
  642. retVal != 0 )
  643. {
  644. cmCTestLog(m_CTest, ERROR_MESSAGE, "Problem running command: " << *it << std::endl);
  645. return 0;
  646. }
  647. }
  648. return 1;
  649. }
  650. //----------------------------------------------------------------------
  651. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  652. {
  653. std::string fullPath = "";
  654. std::string dir;
  655. std::string file;
  656. cmSystemTools::SplitProgramPath(exe, dir, file);
  657. if(m_CTest->GetConfigType() != "" &&
  658. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  659. m_CTest->GetConfigType().c_str()))
  660. {
  661. return fullPath;
  662. }
  663. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  664. {
  665. return fullPath;
  666. }
  667. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  668. {
  669. return fullPath;
  670. }
  671. if ( m_CTest->GetConfigType() == "" )
  672. {
  673. // No config type, so try to guess it
  674. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  675. {
  676. return fullPath;
  677. }
  678. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  679. {
  680. return fullPath;
  681. }
  682. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  683. {
  684. return fullPath;
  685. }
  686. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  687. {
  688. return fullPath;
  689. }
  690. }
  691. // if everything else failed, check the users path
  692. if (dir != "")
  693. {
  694. std::string path = cmSystemTools::FindProgram(file.c_str());
  695. if (path != "")
  696. {
  697. return path;
  698. }
  699. }
  700. if ( m_CTest->GetConfigType() != "" )
  701. {
  702. dir += "/";
  703. dir += m_CTest->GetConfigType();
  704. dir += "/";
  705. dir += file;
  706. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  707. dir.c_str());
  708. return "";
  709. }
  710. return fullPath;
  711. }
  712. //----------------------------------------------------------------------
  713. void cmCTestTestHandler::GetListOfTests(tm_ListOfTests* testlist)
  714. {
  715. const char* testFilename = 0;
  716. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  717. {
  718. // does the CTestTestfile.cmake exist ?
  719. testFilename = "CTestTestfile.cmake";
  720. }
  721. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  722. {
  723. // does the DartTestfile.txt exist ?
  724. testFilename = "DartTestfile.txt";
  725. }
  726. else
  727. {
  728. return;
  729. }
  730. // parse the file
  731. std::ifstream fin(testFilename);
  732. if(!fin)
  733. {
  734. return;
  735. }
  736. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  737. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  738. cmListFileCache cache;
  739. cmListFile* listFile = cache.GetFileCache(testFilename, false);
  740. for(std::vector<cmListFileFunction>::const_iterator f =
  741. listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
  742. {
  743. const cmListFileFunction& lff = *f;
  744. const std::string& name = lff.m_Name;
  745. const tm_VectorOfListFileArgs& args = lff.m_Arguments;
  746. if (name == "SUBDIRS")
  747. {
  748. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  749. for(tm_VectorOfListFileArgs::const_iterator j = args.begin();
  750. j != args.end(); ++j)
  751. {
  752. std::string nwd = cwd + "/";
  753. nwd += j->Value;
  754. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  755. {
  756. cmSystemTools::ChangeDirectory(nwd.c_str());
  757. this->GetListOfTests(testlist);
  758. }
  759. }
  760. // return to the original directory
  761. cmSystemTools::ChangeDirectory(cwd.c_str());
  762. }
  763. if (name == "ADD_TEST")
  764. {
  765. const std::string& testname = args[0].Value;
  766. if (this->m_UseExcludeRegExp &&
  767. this->m_UseExcludeRegExpFirst &&
  768. ereg.find(testname.c_str()))
  769. {
  770. continue;
  771. }
  772. if ( m_MemCheck )
  773. {
  774. std::vector<cmStdString>::iterator it;
  775. bool found = false;
  776. for ( it = m_CustomTestsIgnore.begin();
  777. it != m_CustomTestsIgnore.end(); ++ it )
  778. {
  779. if ( *it == testname )
  780. {
  781. found = true;
  782. break;
  783. }
  784. }
  785. if ( found )
  786. {
  787. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: " << *it << std::endl);
  788. continue;
  789. }
  790. }
  791. else
  792. {
  793. std::vector<cmStdString>::iterator it;
  794. bool found = false;
  795. for ( it = m_CustomTestsIgnore.begin();
  796. it != m_CustomTestsIgnore.end(); ++ it )
  797. {
  798. if ( *it == testname )
  799. {
  800. found = true;
  801. break;
  802. }
  803. }
  804. if ( found )
  805. {
  806. cmCTestLog(m_CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: " << *it << std::endl);
  807. continue;
  808. }
  809. }
  810. cmCTestTestProperties test;
  811. test.m_Name = testname;
  812. test.m_Args = args;
  813. test.m_Directory = cmSystemTools::GetCurrentWorkingDirectory();
  814. test.m_IsInBasedOnREOptions = true;
  815. if (this->m_UseIncludeRegExp && !ireg.find(testname.c_str()))
  816. {
  817. test.m_IsInBasedOnREOptions = false;
  818. }
  819. else if (this->m_UseExcludeRegExp &&
  820. !this->m_UseExcludeRegExpFirst &&
  821. ereg.find(testname.c_str()))
  822. {
  823. test.m_IsInBasedOnREOptions = false;
  824. }
  825. testlist->push_back(test);
  826. }
  827. }
  828. }
  829. //----------------------------------------------------------------------
  830. void cmCTestTestHandler::UseIncludeRegExp()
  831. {
  832. this->m_UseIncludeRegExp = true;
  833. }
  834. //----------------------------------------------------------------------
  835. void cmCTestTestHandler::UseExcludeRegExp()
  836. {
  837. this->m_UseExcludeRegExp = true;
  838. this->m_UseExcludeRegExpFirst = this->m_UseIncludeRegExp ? false : true;
  839. }
  840. //----------------------------------------------------------------------
  841. const char* cmCTestTestHandler::GetTestStatus(int status)
  842. {
  843. static const char statuses[][100] = {
  844. "Not Run",
  845. "Timeout",
  846. "SEGFAULT",
  847. "ILLEGAL",
  848. "INTERRUPT",
  849. "NUMERICAL",
  850. "OTHER_FAULT",
  851. "Failed",
  852. "BAD_COMMAND",
  853. "Completed"
  854. };
  855. if ( status < cmCTestTestHandler::NOT_RUN ||
  856. status > cmCTestTestHandler::COMPLETED )
  857. {
  858. return "No Status";
  859. }
  860. return statuses[status];
  861. }
  862. //----------------------------------------------------------------------
  863. void cmCTestTestHandler::ExpandTestsToRunInformation(int numTests)
  864. {
  865. if (this->TestsToRunString.empty())
  866. {
  867. return;
  868. }
  869. int start;
  870. int end = -1;
  871. double stride = -1;
  872. std::string::size_type pos = 0;
  873. std::string::size_type pos2;
  874. // read start
  875. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  876. {
  877. // read end
  878. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  879. {
  880. // read stride
  881. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  882. {
  883. int val =0;
  884. // now read specific numbers
  885. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  886. {
  887. m_TestsToRun.push_back(val);
  888. }
  889. m_TestsToRun.push_back(val);
  890. }
  891. }
  892. }
  893. // if start is not specified then we assume we start at 1
  894. if(start == -1)
  895. {
  896. start = 1;
  897. }
  898. // if end isnot specified then we assume we end with the last test
  899. if(end == -1)
  900. {
  901. end = numTests;
  902. }
  903. // if the stride wasn't specified then it defaults to 1
  904. if(stride == -1)
  905. {
  906. stride = 1;
  907. }
  908. // if we have a range then add it
  909. if(end != -1 && start != -1 && stride > 0)
  910. {
  911. int i = 0;
  912. while (i*stride + start <= end)
  913. {
  914. m_TestsToRun.push_back(static_cast<int>(i*stride+start));
  915. ++i;
  916. }
  917. }
  918. // sort the array
  919. std::sort(m_TestsToRun.begin(), m_TestsToRun.end(), std::less<int>());
  920. // remove duplicates
  921. std::vector<int>::iterator new_end =
  922. std::unique(m_TestsToRun.begin(), m_TestsToRun.end());
  923. m_TestsToRun.erase(new_end, m_TestsToRun.end());
  924. }
  925. //----------------------------------------------------------------------
  926. // Just for convenience
  927. #define SPACE_REGEX "[ \t\r\n]"
  928. //----------------------------------------------------------------------
  929. std::string cmCTestTestHandler::GenerateRegressionImages(
  930. const std::string& xml)
  931. {
  932. cmsys::RegularExpression twoattributes(
  933. "<DartMeasurement"
  934. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  935. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  936. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  937. cmsys::RegularExpression threeattributes(
  938. "<DartMeasurement"
  939. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  940. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  941. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  942. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  943. cmsys::RegularExpression fourattributes(
  944. "<DartMeasurement"
  945. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  946. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  947. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  948. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  949. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  950. cmsys::RegularExpression measurementfile(
  951. "<DartMeasurementFile"
  952. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  953. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  954. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  955. cmOStringStream ostr;
  956. bool done = false;
  957. std::string cxml = xml;
  958. while ( ! done )
  959. {
  960. if ( twoattributes.find(cxml) )
  961. {
  962. ostr
  963. << "\t\t\t<NamedMeasurement"
  964. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  965. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  966. << "><Value>" << twoattributes.match(5)
  967. << "</Value></NamedMeasurement>"
  968. << std::endl;
  969. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  970. }
  971. else if ( threeattributes.find(cxml) )
  972. {
  973. ostr
  974. << "\t\t\t<NamedMeasurement"
  975. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  976. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  977. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  978. << "><Value>" << threeattributes.match(7)
  979. << "</Value></NamedMeasurement>"
  980. << std::endl;
  981. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  982. }
  983. else if ( fourattributes.find(cxml) )
  984. {
  985. ostr
  986. << "\t\t\t<NamedMeasurement"
  987. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  988. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  989. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  990. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  991. << "><Value>" << fourattributes.match(9)
  992. << "</Value></NamedMeasurement>"
  993. << std::endl;
  994. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  995. }
  996. else if ( measurementfile.find(cxml) )
  997. {
  998. const std::string& filename =
  999. cmCTest::CleanString(measurementfile.match(5));
  1000. if ( cmSystemTools::FileExists(filename.c_str()) )
  1001. {
  1002. long len = cmSystemTools::FileLength(filename.c_str());
  1003. if ( len == 0 )
  1004. {
  1005. std::string k1 = measurementfile.match(1);
  1006. std::string v1 = measurementfile.match(2);
  1007. std::string k2 = measurementfile.match(3);
  1008. std::string v2 = measurementfile.match(4);
  1009. if ( cmSystemTools::LowerCase(k1) == "type" )
  1010. {
  1011. v1 = "text/string";
  1012. }
  1013. if ( cmSystemTools::LowerCase(k2) == "type" )
  1014. {
  1015. v2 = "text/string";
  1016. }
  1017. ostr
  1018. << "\t\t\t<NamedMeasurement"
  1019. << " " << k1 << "=\"" << v1 << "\""
  1020. << " " << k2 << "=\"" << v2 << "\""
  1021. << " encoding=\"none\""
  1022. << "><Value>Image " << filename.c_str()
  1023. << " is empty</Value></NamedMeasurement>";
  1024. }
  1025. else
  1026. {
  1027. std::ifstream ifs(filename.c_str(), std::ios::in
  1028. #ifdef _WIN32
  1029. | std::ios::binary
  1030. #endif
  1031. );
  1032. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1033. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1034. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1035. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1036. unsigned long cc;
  1037. ostr
  1038. << "\t\t\t<NamedMeasurement"
  1039. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  1040. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  1041. << " encoding=\"base64\""
  1042. << ">" << std::endl << "\t\t\t\t<Value>";
  1043. for ( cc = 0; cc < rlen; cc ++ )
  1044. {
  1045. ostr << encoded_buffer[cc];
  1046. if ( cc % 60 == 0 && cc )
  1047. {
  1048. ostr << std::endl;
  1049. }
  1050. }
  1051. ostr
  1052. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1053. << std::endl;
  1054. delete [] file_buffer;
  1055. delete [] encoded_buffer;
  1056. }
  1057. }
  1058. else
  1059. {
  1060. int idx = 4;
  1061. if ( measurementfile.match(1) == "name" )
  1062. {
  1063. idx = 2;
  1064. }
  1065. ostr
  1066. << "\t\t\t<NamedMeasurement"
  1067. << " name=\"" << measurementfile.match(idx) << "\""
  1068. << " text=\"text/string\""
  1069. << "><Value>File " << filename.c_str() << " not found</Value></NamedMeasurement>"
  1070. << std::endl;
  1071. cmCTestLog(m_CTest, HANDLER_OUTPUT, "File \"" << filename.c_str() << "\" not found." << std::endl);
  1072. }
  1073. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  1074. }
  1075. else
  1076. {
  1077. done = true;
  1078. }
  1079. }
  1080. return ostr.str();
  1081. }
  1082. //----------------------------------------------------------------------
  1083. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1084. {
  1085. m_IncludeRegExp = arg;
  1086. }
  1087. //----------------------------------------------------------------------
  1088. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1089. {
  1090. m_ExcludeRegExp = arg;
  1091. }
  1092. //----------------------------------------------------------------------
  1093. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1094. {
  1095. if ( !in )
  1096. {
  1097. return;
  1098. }
  1099. this->TestsToRunString = in;
  1100. // if the argument is a file, then read it and use the contents as the string
  1101. if(cmSystemTools::FileExists(in))
  1102. {
  1103. std::ifstream fin(in);
  1104. unsigned long filelen = cmSystemTools::FileLength(in);
  1105. char* buff = new char[filelen+1];
  1106. fin.getline(buff, filelen);
  1107. buff[fin.gcount()] = 0;
  1108. this->TestsToRunString = buff;
  1109. }
  1110. }
  1111. //----------------------------------------------------------------------
  1112. bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t remove_threshold)
  1113. {
  1114. if ( remove_threshold == 0 )
  1115. {
  1116. return true;
  1117. }
  1118. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  1119. {
  1120. return true;
  1121. }
  1122. cmOStringStream ostr;
  1123. std::string::size_type cc;
  1124. std::string::size_type skipsize = 0;
  1125. int inTag = 0;
  1126. int skipped = 0;
  1127. for ( cc = 0; cc < output.size(); cc ++ )
  1128. {
  1129. int ch = output[cc];
  1130. if ( ch < 0 || ch > 255 )
  1131. {
  1132. break;
  1133. }
  1134. if ( ch == '<' )
  1135. {
  1136. inTag = 1;
  1137. }
  1138. if ( !inTag )
  1139. {
  1140. int notskip = 0;
  1141. // Skip
  1142. if ( skipsize < remove_threshold )
  1143. {
  1144. ostr << static_cast<char>(ch);
  1145. notskip = 1;
  1146. }
  1147. skipsize ++;
  1148. if ( notskip && skipsize >= remove_threshold )
  1149. {
  1150. skipped = 1;
  1151. }
  1152. }
  1153. else
  1154. {
  1155. ostr << static_cast<char>(ch);
  1156. }
  1157. if ( ch == '>' )
  1158. {
  1159. inTag = 0;
  1160. }
  1161. }
  1162. if ( skipped )
  1163. {
  1164. ostr << "..." << std::endl << "The rest of the test output was removed since it exceeds the threshold of "
  1165. << remove_threshold << " characters." << std::endl;
  1166. }
  1167. output = ostr.str();
  1168. return true;
  1169. }