cmCTestTestHandler.cxx 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653
  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 <cmsys/Process.h>
  17. #include <cmsys/RegularExpression.hxx>
  18. #include <cmsys/Base64.h>
  19. #include "cmMakefile.h"
  20. static const char* cmCTestMemCheckResultStrings[] = {
  21. "ABR",
  22. "ABW",
  23. "ABWL",
  24. "COR",
  25. "EXU",
  26. "FFM",
  27. "FIM",
  28. "FMM",
  29. "FMR",
  30. "FMW",
  31. "FUM",
  32. "IPR",
  33. "IPW",
  34. "MAF",
  35. "MLK",
  36. "MPK",
  37. "NPR",
  38. "ODS",
  39. "PAR",
  40. "PLK",
  41. "UMC",
  42. "UMR",
  43. 0
  44. };
  45. static const char* cmCTestMemCheckResultLongStrings[] = {
  46. "Threading Problem",
  47. "ABW",
  48. "ABWL",
  49. "COR",
  50. "EXU",
  51. "FFM",
  52. "FIM",
  53. "Mismatched deallocation",
  54. "FMR",
  55. "FMW",
  56. "FUM",
  57. "IPR",
  58. "IPW",
  59. "MAF",
  60. "Memory Leak",
  61. "Potential Memory Leak",
  62. "NPR",
  63. "ODS",
  64. "Invalid syscall param",
  65. "PLK",
  66. "Uninitialized Memory Conditional",
  67. "Uninitialized Memory Read",
  68. 0
  69. };
  70. bool TryExecutable(const char *dir, const char *file,
  71. std::string *fullPath, const char *subdir)
  72. {
  73. // try current directory
  74. std::string tryPath;
  75. if (dir && strcmp(dir,""))
  76. {
  77. tryPath = dir;
  78. tryPath += "/";
  79. }
  80. if (subdir && strcmp(subdir,""))
  81. {
  82. tryPath += subdir;
  83. tryPath += "/";
  84. }
  85. tryPath += file;
  86. if(cmSystemTools::FileExists(tryPath.c_str()))
  87. {
  88. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  89. return true;
  90. }
  91. tryPath += cmSystemTools::GetExecutableExtension();
  92. if(cmSystemTools::FileExists(tryPath.c_str()))
  93. {
  94. *fullPath = cmSystemTools::CollapseFullPath(tryPath.c_str());
  95. return true;
  96. }
  97. return false;
  98. }
  99. // get the next number in a string with numbers separated by ,
  100. // pos is the start of the search and pos2 is the end of the search
  101. // pos becomes pos2 after a call to GetNextNumber.
  102. // -1 is returned at the end of the list.
  103. inline int GetNextNumber(std::string const& in,
  104. int& val,
  105. std::string::size_type& pos,
  106. std::string::size_type& pos2)
  107. {
  108. pos2 = in.find(',', pos);
  109. if(pos2 != in.npos)
  110. {
  111. if(pos2-pos == 0)
  112. {
  113. val = -1;
  114. }
  115. else
  116. {
  117. val = atoi(in.substr(pos, pos2-pos).c_str());
  118. }
  119. pos = pos2+1;
  120. return 1;
  121. }
  122. else
  123. {
  124. if(in.size()-pos == 0)
  125. {
  126. val = -1;
  127. }
  128. else
  129. {
  130. val = atoi(in.substr(pos, in.size()-pos).c_str());
  131. }
  132. return 0;
  133. }
  134. }
  135. // get the next number in a string with numbers separated by ,
  136. // pos is the start of the search and pos2 is the end of the search
  137. // pos becomes pos2 after a call to GetNextNumber.
  138. // -1 is returned at the end of the list.
  139. inline int GetNextRealNumber(std::string const& in,
  140. double& val,
  141. std::string::size_type& pos,
  142. std::string::size_type& pos2)
  143. {
  144. pos2 = in.find(',', pos);
  145. if(pos2 != in.npos)
  146. {
  147. if(pos2-pos == 0)
  148. {
  149. val = -1;
  150. }
  151. else
  152. {
  153. val = atof(in.substr(pos, pos2-pos).c_str());
  154. }
  155. pos = pos2+1;
  156. return 1;
  157. }
  158. else
  159. {
  160. if(in.size()-pos == 0)
  161. {
  162. val = -1;
  163. }
  164. else
  165. {
  166. val = atof(in.substr(pos, in.size()-pos).c_str());
  167. }
  168. return 0;
  169. }
  170. }
  171. //----------------------------------------------------------------------
  172. cmCTestTestHandler::cmCTestTestHandler()
  173. {
  174. m_Verbose = false;
  175. m_CTest = 0;
  176. m_UseIncludeRegExp = false;
  177. m_UseExcludeRegExp = false;
  178. m_UseExcludeRegExpFirst = false;
  179. m_MaximumPassedTestResultSize = 100 * 1024;
  180. m_MaximumFailedTestResultSize = 200 * 1024;
  181. }
  182. //----------------------------------------------------------------------
  183. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
  184. {
  185. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  186. m_CustomPreTest);
  187. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  188. m_CustomPostTest);
  189. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK",
  190. m_CustomPreMemCheck);
  191. cmCTest::PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK",
  192. m_CustomPostMemCheck);
  193. const char* maxstr =
  194. mf->GetDefinition("CTEST_CUSTOM_PASSED_TEST_STRING_MAXLEN");
  195. if ( maxstr )
  196. {
  197. long val = atoi(maxstr);
  198. if ( val > 0 )
  199. {
  200. m_MaximumPassedTestResultSize = val;
  201. }
  202. }
  203. maxstr = mf->GetDefinition("CTEST_CUSTOM_FAILED_TEST_STRING_MAXLEN");
  204. if ( maxstr )
  205. {
  206. long val = atoi(maxstr);
  207. if ( val > 0 )
  208. {
  209. m_MaximumFailedTestResultSize = val;
  210. }
  211. }
  212. cmCTest::PopulateCustomVector(mf,
  213. "CTEST_CUSTOM_TESTS_IGNORE",
  214. m_CustomTestsIgnore);
  215. cmCTest::PopulateCustomVector(mf,
  216. "CTEST_CUSTOM_MEMCHECK_IGNORE",
  217. m_CustomMemCheckIgnore);
  218. }
  219. //----------------------------------------------------------------------
  220. //clearly it would be nice if this were broken up into a few smaller
  221. //functions and commented...
  222. int cmCTestTestHandler::TestDirectory(cmCTest *ctest_inst, bool memcheck)
  223. {
  224. m_CTest = ctest_inst;
  225. m_TestResults.clear();
  226. std::cout << (memcheck ? "Memory check" : "Test") << " project" << std::endl;
  227. if ( memcheck )
  228. {
  229. if ( !this->InitializeMemoryChecking() )
  230. {
  231. return 1;
  232. }
  233. }
  234. if ( memcheck )
  235. {
  236. if ( !this->ExecuteCommands(m_CustomPreMemCheck) )
  237. {
  238. std::cerr << "Problem executing pre-memcheck command(s)." << std::endl;
  239. return 1;
  240. }
  241. }
  242. else
  243. {
  244. if ( !this->ExecuteCommands(m_CustomPreTest) )
  245. {
  246. std::cerr << "Problem executing pre-test command(s)." << std::endl;
  247. return 1;
  248. }
  249. }
  250. std::vector<cmStdString> passed;
  251. std::vector<cmStdString> failed;
  252. int total;
  253. this->ProcessDirectory(passed, failed, memcheck);
  254. total = int(passed.size()) + int(failed.size());
  255. if (total == 0)
  256. {
  257. if ( !m_CTest->GetShowOnly() )
  258. {
  259. std::cerr << "No tests were found!!!\n";
  260. }
  261. }
  262. else
  263. {
  264. if (m_Verbose && passed.size() &&
  265. (m_UseIncludeRegExp || m_UseExcludeRegExp))
  266. {
  267. std::cerr << "\nThe following tests passed:\n";
  268. for(std::vector<cmStdString>::iterator j = passed.begin();
  269. j != passed.end(); ++j)
  270. {
  271. std::cerr << "\t" << *j << "\n";
  272. }
  273. }
  274. float percent = float(passed.size()) * 100.0f / total;
  275. if ( failed.size() > 0 && percent > 99)
  276. {
  277. percent = 99;
  278. }
  279. fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  280. percent, int(failed.size()), total);
  281. if (failed.size())
  282. {
  283. std::ofstream ofs;
  284. std::cerr << "\nThe following tests FAILED:\n";
  285. m_CTest->OpenOutputFile("Temporary", "LastTestsFailed.log", ofs);
  286. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  287. for(ftit = m_TestResults.begin();
  288. ftit != m_TestResults.end(); ++ftit)
  289. {
  290. if ( ftit->m_Status != cmCTestTestHandler::COMPLETED )
  291. {
  292. ofs << ftit->m_TestCount << ":" << ftit->m_Name << std::endl;
  293. fprintf(stderr, "\t%3d - %s (%s)\n", ftit->m_TestCount, ftit->m_Name.c_str(),
  294. this->GetTestStatus(ftit->m_Status));
  295. }
  296. }
  297. }
  298. }
  299. if ( m_CTest->GetProduceXML() )
  300. {
  301. std::ofstream xmlfile;
  302. if( !m_CTest->OpenOutputFile(m_CTest->GetCurrentTag(),
  303. (memcheck ? "DynamicAnalysis.xml" : "Test.xml"), xmlfile) )
  304. {
  305. std::cerr << "Cannot create " << (memcheck ? "memory check" : "testing")
  306. << " XML file" << std::endl;
  307. return 1;
  308. }
  309. if ( memcheck )
  310. {
  311. this->GenerateDartMemCheckOutput(xmlfile);
  312. }
  313. else
  314. {
  315. this->GenerateDartTestOutput(xmlfile);
  316. }
  317. }
  318. if ( memcheck )
  319. {
  320. if ( !this->ExecuteCommands(m_CustomPostMemCheck) )
  321. {
  322. std::cerr << "Problem executing post-memcheck command(s)." << std::endl;
  323. return 1;
  324. }
  325. }
  326. else
  327. {
  328. if ( !this->ExecuteCommands(m_CustomPostTest) )
  329. {
  330. std::cerr << "Problem executing post-test command(s)." << std::endl;
  331. return 1;
  332. }
  333. }
  334. return int(failed.size());
  335. }
  336. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  337. std::vector<cmStdString> &failed,
  338. bool memcheck)
  339. {
  340. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  341. cmsys::RegularExpression dartStuff("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  342. tm_ListOfTests testlist;
  343. this->GetListOfTests(&testlist, memcheck);
  344. tm_ListOfTests::size_type tmsize = testlist.size();
  345. std::ofstream ofs;
  346. std::ofstream *olog = 0;
  347. if ( !m_CTest->GetShowOnly() && tmsize > 0 &&
  348. m_CTest->OpenOutputFile("Temporary",
  349. (memcheck?"LastMemCheck.log":"LastTest.log"), ofs) )
  350. {
  351. olog = &ofs;
  352. }
  353. m_StartTest = m_CTest->CurrentTime();
  354. double elapsed_time_start = cmSystemTools::GetTime();
  355. if ( olog )
  356. {
  357. *olog << "Start testing: " << m_StartTest << std::endl
  358. << "----------------------------------------------------------"
  359. << std::endl;
  360. }
  361. // expand the test list
  362. this->ExpandTestsToRunInformation((int)tmsize);
  363. int cnt = 0;
  364. tm_ListOfTests::iterator it;
  365. std::string last_directory = "";
  366. for ( it = testlist.begin(); it != testlist.end(); it ++ )
  367. {
  368. cnt ++;
  369. const std::string& testname = it->m_Name;
  370. tm_VectorOfListFileArgs& args = it->m_Args;
  371. cmCTestTestResult cres;
  372. cres.m_Status = cmCTestTestHandler::NOT_RUN;
  373. cres.m_TestCount = cnt;
  374. if (!(last_directory == it->m_Directory))
  375. {
  376. if ( m_Verbose )
  377. {
  378. std::cerr << "Changing directory into "
  379. << it->m_Directory.c_str() << "\n";
  380. }
  381. last_directory = it->m_Directory;
  382. cmSystemTools::ChangeDirectory(it->m_Directory.c_str());
  383. }
  384. cres.m_Name = testname;
  385. if(m_TestsToRun.size() &&
  386. std::find(m_TestsToRun.begin(), m_TestsToRun.end(), cnt) == m_TestsToRun.end())
  387. {
  388. continue;
  389. }
  390. if ( m_CTest->GetShowOnly() )
  391. {
  392. std::cerr.width(3);
  393. std::cerr << cnt << "/";
  394. std::cerr.width(3);
  395. std::cerr << tmsize << " Testing ";
  396. std::string outname = testname;
  397. outname.resize(30, ' ');
  398. std::cerr << outname.c_str() << "\n";
  399. }
  400. else
  401. {
  402. std::cerr.width(3);
  403. std::cerr << cnt << "/";
  404. std::cerr.width(3);
  405. std::cerr << tmsize << " Testing ";
  406. std::string outname = testname;
  407. outname.resize(30, ' ');
  408. std::cerr << outname.c_str();
  409. std::cerr.flush();
  410. }
  411. //std::cerr << "Testing " << args[0] << " ... ";
  412. // find the test executable
  413. std::string actualCommand = this->FindTheExecutable(args[1].Value.c_str());
  414. std::string testCommand = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  415. std::string memcheckcommand = "";
  416. // continue if we did not find the executable
  417. if (testCommand == "")
  418. {
  419. std::cerr << "Unable to find executable: " <<
  420. args[1].Value.c_str() << "\n";
  421. if ( !m_CTest->GetShowOnly() )
  422. {
  423. m_TestResults.push_back( cres );
  424. failed.push_back(testname);
  425. continue;
  426. }
  427. }
  428. // add the arguments
  429. tm_VectorOfListFileArgs::const_iterator j = args.begin();
  430. ++j;
  431. ++j;
  432. std::vector<const char*> arguments;
  433. if ( memcheck )
  434. {
  435. std::vector<cmStdString>::size_type pp;
  436. arguments.push_back(m_MemoryTester.c_str());
  437. memcheckcommand = m_MemoryTester;
  438. for ( pp = 0; pp < m_MemoryTesterOptionsParsed.size(); pp ++ )
  439. {
  440. arguments.push_back(m_MemoryTesterOptionsParsed[pp].c_str());
  441. memcheckcommand += " ";
  442. memcheckcommand += cmSystemTools::EscapeSpaces(m_MemoryTesterOptionsParsed[pp].c_str());
  443. }
  444. }
  445. arguments.push_back(actualCommand.c_str());
  446. for(;j != args.end(); ++j)
  447. {
  448. testCommand += " ";
  449. testCommand += cmSystemTools::EscapeSpaces(j->Value.c_str());
  450. arguments.push_back(j->Value.c_str());
  451. }
  452. arguments.push_back(0);
  453. /**
  454. * Run an executable command and put the stdout in output.
  455. */
  456. std::string output;
  457. int retVal = 0;
  458. if ( m_Verbose )
  459. {
  460. std::cout << std::endl << (memcheck?"MemCheck":"Test") << " command: " << testCommand << std::endl;
  461. if ( memcheck )
  462. {
  463. std::cout << "Memory check command: " << memcheckcommand << std::endl;
  464. }
  465. }
  466. if ( olog )
  467. {
  468. *olog << cnt << "/" << tmsize
  469. << " Test: " << testname.c_str() << std::endl;
  470. *olog << "Command: ";
  471. std::vector<cmStdString>::size_type ll;
  472. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  473. {
  474. *olog << "\"" << arguments[ll] << "\" ";
  475. }
  476. *olog
  477. << std::endl
  478. << "Directory: " << it->m_Directory << std::endl
  479. << "\"" << testname.c_str() << "\" start time: "
  480. << m_CTest->CurrentTime() << std::endl
  481. << "Output:" << std::endl
  482. << "----------------------------------------------------------"
  483. << std::endl;
  484. }
  485. int res = 0;
  486. double clock_start, clock_finish;
  487. clock_start = cmSystemTools::GetTime();
  488. if ( !m_CTest->GetShowOnly() )
  489. {
  490. res = m_CTest->RunTest(arguments, &output, &retVal, olog);
  491. }
  492. clock_finish = cmSystemTools::GetTime();
  493. if ( olog )
  494. {
  495. double ttime = clock_finish - clock_start;
  496. int hours = static_cast<int>(ttime / (60 * 60));
  497. int minutes = static_cast<int>(ttime / 60) % 60;
  498. int seconds = static_cast<int>(ttime) % 60;
  499. char buffer[100];
  500. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  501. *olog
  502. << "----------------------------------------------------------"
  503. << std::endl
  504. << "\"" << testname.c_str() << "\" end time: "
  505. << m_CTest->CurrentTime() << std::endl
  506. << "\"" << testname.c_str() << "\" time elapsed: "
  507. << buffer << std::endl
  508. << "----------------------------------------------------------"
  509. << std::endl << std::endl;
  510. }
  511. cres.m_ExecutionTime = (double)(clock_finish - clock_start);
  512. cres.m_FullCommandLine = testCommand;
  513. if ( !m_CTest->GetShowOnly() )
  514. {
  515. if (res == cmsysProcess_State_Exited && retVal == 0)
  516. {
  517. std::cerr << " Passed\n";
  518. passed.push_back(testname);
  519. cres.m_Status = cmCTestTestHandler::COMPLETED;
  520. }
  521. else
  522. {
  523. cres.m_Status = cmCTestTestHandler::FAILED;
  524. if ( res == cmsysProcess_State_Expired )
  525. {
  526. std::cerr << "***Timeout\n";
  527. cres.m_Status = cmCTestTestHandler::TIMEOUT;
  528. }
  529. else if ( res == cmsysProcess_State_Exception )
  530. {
  531. std::cerr << "***Exception: ";
  532. switch ( retVal )
  533. {
  534. case cmsysProcess_Exception_Fault:
  535. std::cerr << "SegFault";
  536. cres.m_Status = cmCTestTestHandler::SEGFAULT;
  537. break;
  538. case cmsysProcess_Exception_Illegal:
  539. std::cerr << "Illegal";
  540. cres.m_Status = cmCTestTestHandler::ILLEGAL;
  541. break;
  542. case cmsysProcess_Exception_Interrupt:
  543. std::cerr << "Interrupt";
  544. cres.m_Status = cmCTestTestHandler::INTERRUPT;
  545. break;
  546. case cmsysProcess_Exception_Numerical:
  547. std::cerr << "Numerical";
  548. cres.m_Status = cmCTestTestHandler::NUMERICAL;
  549. break;
  550. default:
  551. std::cerr << "Other";
  552. cres.m_Status = cmCTestTestHandler::OTHER_FAULT;
  553. }
  554. std::cerr << "\n";
  555. }
  556. else if ( res == cmsysProcess_State_Error )
  557. {
  558. std::cerr << "***Bad command " << res << "\n";
  559. cres.m_Status = cmCTestTestHandler::BAD_COMMAND;
  560. }
  561. else
  562. {
  563. std::cerr << "***Failed\n";
  564. }
  565. failed.push_back(testname);
  566. }
  567. if (output != "")
  568. {
  569. if (dartStuff.find(output.c_str()))
  570. {
  571. std::string dartString = dartStuff.match(1);
  572. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  573. cres.m_RegressionImages = this->GenerateRegressionImages(dartString);
  574. }
  575. }
  576. }
  577. cres.m_Output = output;
  578. cres.m_ReturnValue = retVal;
  579. std::string nwd = it->m_Directory;
  580. if ( nwd.size() > m_CTest->GetToplevelPath().size() )
  581. {
  582. nwd = "." + nwd.substr(m_CTest->GetToplevelPath().size(), nwd.npos);
  583. }
  584. cmSystemTools::ReplaceString(nwd, "\\", "/");
  585. cres.m_Path = nwd;
  586. cres.m_CompletionStatus = "Completed";
  587. m_TestResults.push_back( cres );
  588. }
  589. m_EndTest = m_CTest->CurrentTime();
  590. m_ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  591. if ( olog )
  592. {
  593. *olog << "End testing: " << m_EndTest << std::endl;
  594. }
  595. cmSystemTools::ChangeDirectory(current_dir.c_str());
  596. }
  597. void cmCTestTestHandler::GenerateDartMemCheckOutput(std::ostream& os)
  598. {
  599. if ( !m_CTest->GetProduceXML() )
  600. {
  601. return;
  602. }
  603. m_CTest->StartXML(os);
  604. os << "<DynamicAnalysis Checker=\"";
  605. switch ( m_MemoryTesterStyle )
  606. {
  607. case cmCTestTestHandler::VALGRIND:
  608. os << "Valgrind";
  609. break;
  610. case cmCTestTestHandler::PURIFY:
  611. os << "Purify";
  612. break;
  613. case cmCTestTestHandler::BOUNDS_CHECKER:
  614. os << "BoundsChecker";
  615. break;
  616. default:
  617. os << "Unknown";
  618. }
  619. os << "\">" << std::endl;
  620. os << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  621. << "\t<TestList>\n";
  622. tm_TestResultsVector::size_type cc;
  623. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  624. {
  625. cmCTestTestResult *result = &m_TestResults[cc];
  626. os << "\t\t<Test>" << cmCTest::MakeXMLSafe(result->m_Path)
  627. << "/" << cmCTest::MakeXMLSafe(result->m_Name)
  628. << "</Test>" << std::endl;
  629. }
  630. os << "\t</TestList>\n";
  631. std::cout << "-- Processing memory checking output: ";
  632. unsigned int total = m_TestResults.size();
  633. unsigned int step = total / 10;
  634. unsigned int current = 0;
  635. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  636. {
  637. cmCTestTestResult *result = &m_TestResults[cc];
  638. std::string memcheckstr;
  639. int memcheckresults[cmCTestTestHandler::NO_MEMORY_FAULT];
  640. int kk;
  641. bool res = this->ProcessMemCheckOutput(result->m_Output, memcheckstr, memcheckresults);
  642. if ( res && result->m_Status == cmCTestTestHandler::COMPLETED )
  643. {
  644. continue;
  645. }
  646. os << "\t<Test Status=\"";
  647. if ( result->m_Status == cmCTestTestHandler::COMPLETED )
  648. {
  649. os << "passed";
  650. }
  651. else if ( result->m_Status == cmCTestTestHandler::NOT_RUN )
  652. {
  653. os << "notrun";
  654. }
  655. else
  656. {
  657. os << "failed";
  658. }
  659. os << "\">\n"
  660. << "\t\t<Name>" << cmCTest::MakeXMLSafe(result->m_Name) << "</Name>\n"
  661. << "\t\t<Path>" << cmCTest::MakeXMLSafe(result->m_Path) << "</Path>\n"
  662. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(result->m_Path)
  663. << "/" << cmCTest::MakeXMLSafe(result->m_Name) << "</FullName>\n"
  664. << "\t\t<FullCommandLine>"
  665. << cmCTest::MakeXMLSafe(result->m_FullCommandLine)
  666. << "</FullCommandLine>\n"
  667. << "\t\t<Results>" << std::endl;
  668. for ( kk = 0; cmCTestMemCheckResultLongStrings[kk]; kk ++ )
  669. {
  670. if ( memcheckresults[kk] )
  671. {
  672. os << "\t\t\t<Defect type=\"" << cmCTestMemCheckResultLongStrings[kk] << "\">"
  673. << memcheckresults[kk]
  674. << "</Defect>" << std::endl;
  675. }
  676. m_MemoryTesterGlobalResults[kk] += memcheckresults[kk];
  677. }
  678. os
  679. << "\t\t</Results>\n"
  680. << "\t<Log>\n" << memcheckstr << std::endl
  681. << "\t</Log>\n"
  682. << "\t</Test>" << std::endl;
  683. if ( current < cc )
  684. {
  685. std::cout << "#";
  686. std::cout.flush();
  687. current += step;
  688. }
  689. }
  690. std::cout << std::endl;
  691. std::cerr << "Memory checking results:" << std::endl;
  692. os << "\t<DefectList>" << std::endl;
  693. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  694. {
  695. if ( m_MemoryTesterGlobalResults[cc] )
  696. {
  697. std::cerr.width(35);
  698. std::cerr << cmCTestMemCheckResultLongStrings[cc] << " - "
  699. << m_MemoryTesterGlobalResults[cc] << std::endl;
  700. os << "\t\t<Defect Type=\"" << cmCTestMemCheckResultLongStrings[cc] << "\"/>" << std::endl;
  701. }
  702. }
  703. os << "\t</DefectList>" << std::endl;
  704. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>" << std::endl;
  705. os << "<ElapsedMinutes>"
  706. << static_cast<int>(m_ElapsedTestingTime/6)/10.0
  707. << "</ElapsedMinutes>\n";
  708. os << "</DynamicAnalysis>" << std::endl;
  709. m_CTest->EndXML(os);
  710. }
  711. void cmCTestTestHandler::GenerateDartTestOutput(std::ostream& os)
  712. {
  713. if ( !m_CTest->GetProduceXML() )
  714. {
  715. return;
  716. }
  717. m_CTest->StartXML(os);
  718. os << "<Testing>\n"
  719. << "\t<StartDateTime>" << m_StartTest << "</StartDateTime>\n"
  720. << "\t<TestList>\n";
  721. tm_TestResultsVector::size_type cc;
  722. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  723. {
  724. cmCTestTestResult *result = &m_TestResults[cc];
  725. os << "\t\t<Test>" << cmCTest::MakeXMLSafe(result->m_Path)
  726. << "/" << cmCTest::MakeXMLSafe(result->m_Name)
  727. << "</Test>" << std::endl;
  728. }
  729. os << "\t</TestList>\n";
  730. for ( cc = 0; cc < m_TestResults.size(); cc ++ )
  731. {
  732. cmCTestTestResult *result = &m_TestResults[cc];
  733. os << "\t<Test Status=\"";
  734. if ( result->m_Status == cmCTestTestHandler::COMPLETED )
  735. {
  736. os << "passed";
  737. }
  738. else if ( result->m_Status == cmCTestTestHandler::NOT_RUN )
  739. {
  740. os << "notrun";
  741. }
  742. else
  743. {
  744. os << "failed";
  745. }
  746. os << "\">\n"
  747. << "\t\t<Name>" << cmCTest::MakeXMLSafe(result->m_Name) << "</Name>\n"
  748. << "\t\t<Path>" << cmCTest::MakeXMLSafe(result->m_Path) << "</Path>\n"
  749. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(result->m_Path)
  750. << "/" << cmCTest::MakeXMLSafe(result->m_Name) << "</FullName>\n"
  751. << "\t\t<FullCommandLine>"
  752. << cmCTest::MakeXMLSafe(result->m_FullCommandLine)
  753. << "</FullCommandLine>\n"
  754. << "\t\t<Results>" << std::endl;
  755. if ( result->m_Status != cmCTestTestHandler::NOT_RUN )
  756. {
  757. if ( result->m_Status != cmCTestTestHandler::COMPLETED || result->m_ReturnValue )
  758. {
  759. os << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Code\"><Value>"
  760. << this->GetTestStatus(result->m_Status) << "</Value></NamedMeasurement>\n"
  761. << "\t\t\t<NamedMeasurement type=\"text/string\" name=\"Exit Value\"><Value>"
  762. << result->m_ReturnValue << "</Value></NamedMeasurement>" << std::endl;
  763. }
  764. os << result->m_RegressionImages;
  765. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  766. << "name=\"Execution Time\"><Value>"
  767. << result->m_ExecutionTime << "</Value></NamedMeasurement>\n";
  768. os
  769. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  770. << "name=\"Completion Status\"><Value>"
  771. << result->m_CompletionStatus << "</Value></NamedMeasurement>\n";
  772. }
  773. os
  774. << "\t\t\t<Measurement>\n"
  775. << "\t\t\t\t<Value>";
  776. size_t truncate = result->m_Output.size();
  777. if ( result->m_Status == cmCTestTestHandler::COMPLETED )
  778. {
  779. if ( result->m_Output.size() > m_MaximumPassedTestResultSize )
  780. {
  781. truncate = m_MaximumPassedTestResultSize;
  782. }
  783. }
  784. else
  785. {
  786. if ( result->m_Output.size() > m_MaximumFailedTestResultSize )
  787. {
  788. truncate = m_MaximumFailedTestResultSize;
  789. }
  790. }
  791. os << cmCTest::MakeXMLSafe(result->m_Output.substr(0, truncate));
  792. if ( truncate < result->m_Output.size() )
  793. {
  794. os << "...\n\nThe output was stirpped because it excedes maximum allowed size: "
  795. << truncate << std::endl;
  796. }
  797. os
  798. << "</Value>\n"
  799. << "\t\t\t</Measurement>\n"
  800. << "\t\t</Results>\n"
  801. << "\t</Test>" << std::endl;
  802. }
  803. os << "\t<EndDateTime>" << m_EndTest << "</EndDateTime>\n"
  804. << "<ElapsedMinutes>"
  805. << static_cast<int>(m_ElapsedTestingTime/6)/10.0
  806. << "</ElapsedMinutes>"
  807. << "</Testing>" << std::endl;
  808. m_CTest->EndXML(os);
  809. }
  810. bool cmCTestTestHandler::InitializeMemoryChecking()
  811. {
  812. // Setup the command
  813. if ( cmSystemTools::FileExists(m_CTest->GetDartConfiguration("MemoryCheckCommand").c_str()) )
  814. {
  815. m_MemoryTester
  816. = cmSystemTools::ConvertToOutputPath(m_CTest->GetDartConfiguration("MemoryCheckCommand").c_str());
  817. }
  818. else if ( cmSystemTools::FileExists(m_CTest->GetDartConfiguration("PurifyCommand").c_str()) )
  819. {
  820. m_MemoryTester
  821. = cmSystemTools::ConvertToOutputPath(m_CTest->GetDartConfiguration("PurifyCommand").c_str());
  822. }
  823. else if ( cmSystemTools::FileExists(m_CTest->GetDartConfiguration("ValgrindCommand").c_str()) )
  824. {
  825. m_MemoryTester
  826. = cmSystemTools::ConvertToOutputPath(m_CTest->GetDartConfiguration("ValgrindCommand").c_str());
  827. }
  828. else
  829. {
  830. std::cerr << "Memory checker (MemoryCheckCommand) not set, or cannot find the specified program."
  831. << std::endl;
  832. return false;
  833. }
  834. if ( m_MemoryTester[0] == '\"' && m_MemoryTester[m_MemoryTester.size()-1] == '\"' )
  835. {
  836. m_MemoryTester = m_MemoryTester.substr(1, m_MemoryTester.size()-2);
  837. }
  838. // Setup the options
  839. if ( m_CTest->GetDartConfiguration("MemoryCheckCommandOptions").size() )
  840. {
  841. m_MemoryTesterOptions = m_CTest->GetDartConfiguration("MemoryCheckCommandOptions");
  842. }
  843. else if ( m_CTest->GetDartConfiguration("ValgrindCommandOptions").size() )
  844. {
  845. m_MemoryTesterOptions = m_CTest->GetDartConfiguration("ValgrindCommandOptions");
  846. }
  847. m_MemoryTesterOutputFile = m_CTest->GetToplevelPath() + "/Testing/Temporary/MemoryChecker.log";
  848. m_MemoryTesterOutputFile = cmSystemTools::EscapeSpaces(m_MemoryTesterOutputFile.c_str());
  849. if ( m_MemoryTester.find("valgrind") != std::string::npos )
  850. {
  851. m_MemoryTesterStyle = cmCTestTestHandler::VALGRIND;
  852. if ( !m_MemoryTesterOptions.size() )
  853. {
  854. m_MemoryTesterOptions = "-q --skin=memcheck --leak-check=yes --show-reachable=yes --workaround-gcc296-bugs=yes --num-callers=100";
  855. }
  856. if ( m_CTest->GetDartConfiguration("MemoryCheckSuppressionFile").size() )
  857. {
  858. if ( !cmSystemTools::FileExists(m_CTest->GetDartConfiguration("MemoryCheckSuppressionFile").c_str()) )
  859. {
  860. std::cerr << "Cannot find memory checker suppression file: "
  861. << m_CTest->GetDartConfiguration("MemoryCheckSuppressionFile").c_str() << std::endl;
  862. return false;
  863. }
  864. m_MemoryTesterOptions += " --suppressions=" + cmSystemTools::EscapeSpaces(m_CTest->GetDartConfiguration("MemoryCheckSuppressionFile").c_str()) + "";
  865. }
  866. }
  867. else if ( m_MemoryTester.find("purify") != std::string::npos )
  868. {
  869. m_MemoryTesterStyle = cmCTestTestHandler::PURIFY;
  870. #ifdef _WIN32
  871. m_MemoryTesterOptions += " /SAVETEXTDATA=" + m_MemoryTesterOutputFile;
  872. #else
  873. m_MemoryTesterOptions += " -log-file=" + m_MemoryTesterOutputFile;
  874. #endif
  875. }
  876. else if ( m_MemoryTester.find("boundschecker") != std::string::npos )
  877. {
  878. m_MemoryTesterStyle = cmCTestTestHandler::BOUNDS_CHECKER;
  879. std::cerr << "Bounds checker not yet implemented" << std::endl;
  880. return false;
  881. }
  882. else
  883. {
  884. std::cerr << "Do not understand memory checker: " << m_MemoryTester.c_str() << std::endl;
  885. return false;
  886. }
  887. m_MemoryTesterOptionsParsed = cmSystemTools::ParseArguments(m_MemoryTesterOptions.c_str());
  888. std::vector<cmStdString>::size_type cc;
  889. for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  890. {
  891. m_MemoryTesterGlobalResults[cc] = 0;
  892. }
  893. return true;
  894. }
  895. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  896. {
  897. std::vector<cmStdString>::iterator it;
  898. for ( it = vec.begin(); it != vec.end(); ++it )
  899. {
  900. int retVal = 0;
  901. if ( m_Verbose )
  902. {
  903. std::cout << "Run command: " << *it << std::endl;
  904. }
  905. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true /*m_Verbose*/) ||
  906. retVal != 0 )
  907. {
  908. std::cerr << "Problem running command: " << *it << std::endl;
  909. return 0;
  910. }
  911. }
  912. return 1;
  913. }
  914. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  915. {
  916. std::string fullPath = "";
  917. std::string dir;
  918. std::string file;
  919. cmSystemTools::SplitProgramPath(exe, dir, file);
  920. if(m_CTest->GetConfigType() != "" &&
  921. ::TryExecutable(dir.c_str(), file.c_str(), &fullPath,
  922. m_CTest->GetConfigType().c_str()))
  923. {
  924. return fullPath;
  925. }
  926. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"."))
  927. {
  928. return fullPath;
  929. }
  930. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,""))
  931. {
  932. return fullPath;
  933. }
  934. if ( m_CTest->GetConfigType() == "" )
  935. {
  936. // No config type, so try to guess it
  937. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Release"))
  938. {
  939. return fullPath;
  940. }
  941. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"Debug"))
  942. {
  943. return fullPath;
  944. }
  945. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"MinSizeRel"))
  946. {
  947. return fullPath;
  948. }
  949. if (::TryExecutable(dir.c_str(),file.c_str(),&fullPath,"RelWithDebInfo"))
  950. {
  951. return fullPath;
  952. }
  953. }
  954. // if everything else failed, check the users path
  955. if (dir != "")
  956. {
  957. std::string path = cmSystemTools::FindProgram(file.c_str());
  958. if (path != "")
  959. {
  960. return path;
  961. }
  962. }
  963. if ( m_CTest->GetConfigType() != "" )
  964. {
  965. dir += "/";
  966. dir += m_CTest->GetConfigType();
  967. dir += "/";
  968. dir += file;
  969. cmSystemTools::Error("config type specified on the command line, but test executable not found.",
  970. dir.c_str());
  971. return "";
  972. }
  973. return fullPath;
  974. }
  975. void cmCTestTestHandler::GetListOfTests(tm_ListOfTests* testlist,
  976. bool memcheck)
  977. {
  978. // does the DartTestfile.txt exist ?
  979. if(!cmSystemTools::FileExists("DartTestfile.txt"))
  980. {
  981. return;
  982. }
  983. // parse the file
  984. std::ifstream fin("DartTestfile.txt");
  985. if(!fin)
  986. {
  987. return;
  988. }
  989. cmsys::RegularExpression ireg(this->m_IncludeRegExp.c_str());
  990. cmsys::RegularExpression ereg(this->m_ExcludeRegExp.c_str());
  991. cmListFileCache cache;
  992. cmListFile* listFile = cache.GetFileCache("DartTestfile.txt", false);
  993. for(std::vector<cmListFileFunction>::const_iterator f =
  994. listFile->m_Functions.begin(); f != listFile->m_Functions.end(); ++f)
  995. {
  996. const cmListFileFunction& lff = *f;
  997. const std::string& name = lff.m_Name;
  998. const tm_VectorOfListFileArgs& args = lff.m_Arguments;
  999. if (name == "SUBDIRS")
  1000. {
  1001. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  1002. for(tm_VectorOfListFileArgs::const_iterator j = args.begin();
  1003. j != args.end(); ++j)
  1004. {
  1005. std::string nwd = cwd + "/";
  1006. nwd += j->Value;
  1007. if (cmSystemTools::FileIsDirectory(nwd.c_str()))
  1008. {
  1009. cmSystemTools::ChangeDirectory(nwd.c_str());
  1010. this->GetListOfTests(testlist, memcheck);
  1011. }
  1012. }
  1013. // return to the original directory
  1014. cmSystemTools::ChangeDirectory(cwd.c_str());
  1015. }
  1016. if (name == "ADD_TEST")
  1017. {
  1018. const std::string& testname = args[0].Value;
  1019. if (this->m_UseExcludeRegExp &&
  1020. this->m_UseExcludeRegExpFirst &&
  1021. ereg.find(testname.c_str()))
  1022. {
  1023. continue;
  1024. }
  1025. if ( memcheck )
  1026. {
  1027. std::vector<cmStdString>::iterator it;
  1028. bool found = false;
  1029. for ( it = m_CustomMemCheckIgnore.begin();
  1030. it != m_CustomMemCheckIgnore.end(); ++ it )
  1031. {
  1032. if ( *it == testname )
  1033. {
  1034. found = true;
  1035. break;
  1036. }
  1037. }
  1038. if ( found )
  1039. {
  1040. if ( m_Verbose )
  1041. {
  1042. std::cout << "Ignore memcheck: " << *it << std::endl;
  1043. }
  1044. continue;
  1045. }
  1046. }
  1047. else
  1048. {
  1049. std::vector<cmStdString>::iterator it;
  1050. bool found = false;
  1051. for ( it = m_CustomTestsIgnore.begin();
  1052. it != m_CustomTestsIgnore.end(); ++ it )
  1053. {
  1054. if ( *it == testname )
  1055. {
  1056. found = true;
  1057. break;
  1058. }
  1059. }
  1060. if ( found )
  1061. {
  1062. if ( m_Verbose )
  1063. {
  1064. std::cout << "Ignore test: " << *it << std::endl;
  1065. }
  1066. continue;
  1067. }
  1068. }
  1069. if (this->m_UseIncludeRegExp && !ireg.find(testname.c_str()))
  1070. {
  1071. continue;
  1072. }
  1073. if (this->m_UseExcludeRegExp &&
  1074. !this->m_UseExcludeRegExpFirst &&
  1075. ereg.find(testname.c_str()))
  1076. {
  1077. continue;
  1078. }
  1079. cmCTestTestProperties test;
  1080. test.m_Name = testname;
  1081. test.m_Args = args;
  1082. test.m_Directory = cmSystemTools::GetCurrentWorkingDirectory();
  1083. testlist->push_back(test);
  1084. }
  1085. }
  1086. }
  1087. void cmCTestTestHandler::UseIncludeRegExp()
  1088. {
  1089. this->m_UseIncludeRegExp = true;
  1090. }
  1091. void cmCTestTestHandler::UseExcludeRegExp()
  1092. {
  1093. this->m_UseExcludeRegExp = true;
  1094. this->m_UseExcludeRegExpFirst = this->m_UseIncludeRegExp ? false : true;
  1095. }
  1096. const char* cmCTestTestHandler::GetTestStatus(int status)
  1097. {
  1098. static const char statuses[][100] = {
  1099. "Not Run",
  1100. "Timeout",
  1101. "SEGFAULT",
  1102. "ILLEGAL",
  1103. "INTERRUPT",
  1104. "NUMERICAL",
  1105. "OTHER_FAULT",
  1106. "Failed",
  1107. "BAD_COMMAND",
  1108. "Completed"
  1109. };
  1110. if ( status < cmCTestTestHandler::NOT_RUN ||
  1111. status > cmCTestTestHandler::COMPLETED )
  1112. {
  1113. return "No Status";
  1114. }
  1115. return statuses[status];
  1116. }
  1117. void cmCTestTestHandler::ExpandTestsToRunInformation(int numTests)
  1118. {
  1119. if (this->TestsToRunString.empty())
  1120. {
  1121. return;
  1122. }
  1123. int start;
  1124. int end = -1;
  1125. double stride = -1;
  1126. std::string::size_type pos = 0;
  1127. std::string::size_type pos2;
  1128. // read start
  1129. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1130. {
  1131. // read end
  1132. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1133. {
  1134. // read stride
  1135. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1136. {
  1137. int val =0;
  1138. // now read specific numbers
  1139. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1140. {
  1141. m_TestsToRun.push_back(val);
  1142. }
  1143. m_TestsToRun.push_back(val);
  1144. }
  1145. }
  1146. }
  1147. // if start is not specified then we assume we start at 1
  1148. if(start == -1)
  1149. {
  1150. start = 1;
  1151. }
  1152. // if end isnot specified then we assume we end with the last test
  1153. if(end == -1)
  1154. {
  1155. end = numTests;
  1156. }
  1157. // if the stride wasn't specified then it defaults to 1
  1158. if(stride == -1)
  1159. {
  1160. stride = 1;
  1161. }
  1162. // if we have a range then add it
  1163. if(end != -1 && start != -1 && stride > 0)
  1164. {
  1165. int i = 0;
  1166. while (i*stride + start <= end)
  1167. {
  1168. m_TestsToRun.push_back(static_cast<int>(i*stride+start));
  1169. ++i;
  1170. }
  1171. }
  1172. // sort the array
  1173. std::sort(m_TestsToRun.begin(), m_TestsToRun.end(), std::less<int>());
  1174. // remove duplicates
  1175. std::vector<int>::iterator new_end =
  1176. std::unique(m_TestsToRun.begin(), m_TestsToRun.end());
  1177. m_TestsToRun.erase(new_end, m_TestsToRun.end());
  1178. std::cout << "Running tests: ";
  1179. for(unsigned int i =0; i < m_TestsToRun.size(); ++i)
  1180. {
  1181. std::cout << m_TestsToRun[i] << " ";
  1182. }
  1183. std::cout << "\n";
  1184. }
  1185. #define SPACE_REGEX "[ \t\r\n]"
  1186. std::string cmCTestTestHandler::GenerateRegressionImages(
  1187. const std::string& xml)
  1188. {
  1189. cmsys::RegularExpression twoattributes(
  1190. "<DartMeasurement"
  1191. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1192. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1193. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1194. cmsys::RegularExpression threeattributes(
  1195. "<DartMeasurement"
  1196. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1197. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1198. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1199. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1200. cmsys::RegularExpression fourattributes(
  1201. "<DartMeasurement"
  1202. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1203. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1204. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1205. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1206. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1207. cmsys::RegularExpression measurementfile(
  1208. "<DartMeasurementFile"
  1209. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1210. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1211. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1212. cmOStringStream ostr;
  1213. bool done = false;
  1214. std::string cxml = xml;
  1215. while ( ! done )
  1216. {
  1217. if ( twoattributes.find(cxml) )
  1218. {
  1219. ostr
  1220. << "\t\t\t<NamedMeasurement"
  1221. << " " << twoattributes.match(1) << "=\"" << twoattributes.match(2) << "\""
  1222. << " " << twoattributes.match(3) << "=\"" << twoattributes.match(4) << "\""
  1223. << "><Value>" << twoattributes.match(5)
  1224. << "</Value></NamedMeasurement>"
  1225. << std::endl;
  1226. cxml.erase(twoattributes.start(), twoattributes.end() - twoattributes.start());
  1227. }
  1228. else if ( threeattributes.find(cxml) )
  1229. {
  1230. ostr
  1231. << "\t\t\t<NamedMeasurement"
  1232. << " " << threeattributes.match(1) << "=\"" << threeattributes.match(2) << "\""
  1233. << " " << threeattributes.match(3) << "=\"" << threeattributes.match(4) << "\""
  1234. << " " << threeattributes.match(5) << "=\"" << threeattributes.match(6) << "\""
  1235. << "><Value>" << threeattributes.match(7)
  1236. << "</Value></NamedMeasurement>"
  1237. << std::endl;
  1238. cxml.erase(threeattributes.start(), threeattributes.end() - threeattributes.start());
  1239. }
  1240. else if ( fourattributes.find(cxml) )
  1241. {
  1242. ostr
  1243. << "\t\t\t<NamedMeasurement"
  1244. << " " << fourattributes.match(1) << "=\"" << fourattributes.match(2) << "\""
  1245. << " " << fourattributes.match(3) << "=\"" << fourattributes.match(4) << "\""
  1246. << " " << fourattributes.match(5) << "=\"" << fourattributes.match(6) << "\""
  1247. << " " << fourattributes.match(7) << "=\"" << fourattributes.match(8) << "\""
  1248. << "><Value>" << fourattributes.match(9)
  1249. << "</Value></NamedMeasurement>"
  1250. << std::endl;
  1251. cxml.erase(fourattributes.start(), fourattributes.end() - fourattributes.start());
  1252. }
  1253. else if ( measurementfile.find(cxml) )
  1254. {
  1255. const std::string& filename =
  1256. cmCTest::CleanString(measurementfile.match(5));
  1257. if ( cmSystemTools::FileExists(filename.c_str()) )
  1258. {
  1259. long len = cmSystemTools::FileLength(filename.c_str());
  1260. if ( len == 0 )
  1261. {
  1262. std::string k1 = measurementfile.match(1);
  1263. std::string v1 = measurementfile.match(2);
  1264. std::string k2 = measurementfile.match(3);
  1265. std::string v2 = measurementfile.match(4);
  1266. if ( cmSystemTools::LowerCase(k1) == "type" )
  1267. {
  1268. v1 = "text/string";
  1269. }
  1270. if ( cmSystemTools::LowerCase(k2) == "type" )
  1271. {
  1272. v2 = "text/string";
  1273. }
  1274. ostr
  1275. << "\t\t\t<NamedMeasurement"
  1276. << " " << k1 << "=\"" << v1 << "\""
  1277. << " " << k2 << "=\"" << v2 << "\""
  1278. << " encoding=\"none\""
  1279. << "><Value>Image " << filename.c_str()
  1280. << " is empty</Value></NamedMeasurement>";
  1281. }
  1282. else
  1283. {
  1284. std::ifstream ifs(filename.c_str(), std::ios::in
  1285. #ifdef _WIN32
  1286. | std::ios::binary
  1287. #endif
  1288. );
  1289. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1290. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1291. unsigned char *encoded_buffer = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1292. unsigned long rlen = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1293. unsigned long cc;
  1294. ostr
  1295. << "\t\t\t<NamedMeasurement"
  1296. << " " << measurementfile.match(1) << "=\"" << measurementfile.match(2) << "\""
  1297. << " " << measurementfile.match(3) << "=\"" << measurementfile.match(4) << "\""
  1298. << " encoding=\"base64\""
  1299. << ">" << std::endl << "\t\t\t\t<Value>";
  1300. for ( cc = 0; cc < rlen; cc ++ )
  1301. {
  1302. ostr << encoded_buffer[cc];
  1303. if ( cc % 60 == 0 && cc )
  1304. {
  1305. ostr << std::endl;
  1306. }
  1307. }
  1308. ostr
  1309. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1310. << std::endl;
  1311. delete [] file_buffer;
  1312. delete [] encoded_buffer;
  1313. }
  1314. }
  1315. else
  1316. {
  1317. int idx = 4;
  1318. if ( measurementfile.match(1) == "name" )
  1319. {
  1320. idx = 2;
  1321. }
  1322. ostr
  1323. << "\t\t\t<NamedMeasurement"
  1324. << " name=\"" << measurementfile.match(idx) << "\""
  1325. << " text=\"text/string\""
  1326. << "><Value>File " << filename.c_str() << " not found</Value></NamedMeasurement>"
  1327. << std::endl;
  1328. std::cout << "File \"" << filename.c_str() << "\" not found." << std::endl;
  1329. }
  1330. cxml.erase(measurementfile.start(), measurementfile.end() - measurementfile.start());
  1331. }
  1332. else
  1333. {
  1334. done = true;
  1335. }
  1336. }
  1337. return ostr.str();
  1338. }
  1339. bool cmCTestTestHandler::ProcessMemCheckOutput(const std::string& str,
  1340. std::string& log, int* results)
  1341. {
  1342. std::string::size_type cc;
  1343. for ( cc = 0; cc < cmCTestTestHandler::NO_MEMORY_FAULT; cc ++ )
  1344. {
  1345. results[cc] = 0;
  1346. }
  1347. if ( m_MemoryTesterStyle == cmCTestTestHandler::VALGRIND )
  1348. {
  1349. return this->ProcessMemCheckValgrindOutput(str, log, results);
  1350. }
  1351. else if ( m_MemoryTesterStyle == cmCTestTestHandler::PURIFY )
  1352. {
  1353. return this->ProcessMemCheckPurifyOutput(str, log, results);
  1354. }
  1355. else if ( m_MemoryTesterStyle == cmCTestTestHandler::BOUNDS_CHECKER )
  1356. {
  1357. log.append("\nMemory checking style used was: ");
  1358. log.append("Bounds Checker");
  1359. }
  1360. else
  1361. {
  1362. log.append("\nMemory checking style used was: ");
  1363. log.append("None that I know");
  1364. log = str;
  1365. }
  1366. return true;
  1367. }
  1368. bool cmCTestTestHandler::ProcessMemCheckPurifyOutput(
  1369. const std::string&, std::string& log,
  1370. int* results)
  1371. {
  1372. if ( !cmSystemTools::FileExists(m_MemoryTesterOutputFile.c_str()) )
  1373. {
  1374. log = "Cannot find Purify output file: " + m_MemoryTesterOutputFile;
  1375. std::cerr << log.c_str() << std::endl;
  1376. return false;
  1377. }
  1378. std::ifstream ifs(m_MemoryTesterOutputFile.c_str());
  1379. if ( !ifs )
  1380. {
  1381. log = "Cannot read Purify output file: " + m_MemoryTesterOutputFile;
  1382. std::cerr << log.c_str() << std::endl;
  1383. return false;
  1384. }
  1385. cmOStringStream ostr;
  1386. log = "";
  1387. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  1388. int defects = 0;
  1389. std::string line;
  1390. while ( cmSystemTools::GetLineFromStream(ifs, line) )
  1391. {
  1392. int failure = cmCTestTestHandler::NO_MEMORY_FAULT;
  1393. if ( pfW.find(line) )
  1394. {
  1395. int cc;
  1396. for ( cc = 0; cc < cmCTestTestHandler::NO_MEMORY_FAULT; cc ++ )
  1397. {
  1398. if ( pfW.match(1) == cmCTestMemCheckResultStrings[cc] )
  1399. {
  1400. failure = cc;
  1401. break;
  1402. }
  1403. }
  1404. if ( cc == cmCTestTestHandler::NO_MEMORY_FAULT )
  1405. {
  1406. std::cerr<< "Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  1407. ostr << "*** Unknown Purify memory fault: " << pfW.match(1) << std::endl;
  1408. }
  1409. }
  1410. if ( failure != NO_MEMORY_FAULT )
  1411. {
  1412. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  1413. results[failure] ++;
  1414. defects ++;
  1415. }
  1416. ostr << cmCTest::MakeXMLSafe(line) << std::endl;
  1417. }
  1418. log = ostr.str();
  1419. if ( defects )
  1420. {
  1421. return false;
  1422. }
  1423. return true;
  1424. }
  1425. bool cmCTestTestHandler::ProcessMemCheckValgrindOutput(
  1426. const std::string& str, std::string& log,
  1427. int* results)
  1428. {
  1429. std::vector<cmStdString> lines;
  1430. cmSystemTools::Split(str.c_str(), lines);
  1431. std::string::size_type cc;
  1432. cmOStringStream ostr;
  1433. log = "";
  1434. int defects = 0;
  1435. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  1436. cmsys::RegularExpression vgFIM(
  1437. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  1438. cmsys::RegularExpression vgFMM(
  1439. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  1440. cmsys::RegularExpression vgMLK(
  1441. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are definitely lost"
  1442. " in loss record [0-9][0-9]* of [0-9]");
  1443. cmsys::RegularExpression vgPAR(
  1444. "== .*Syscall param .* contains unaddressable byte\\(s\\)");
  1445. cmsys::RegularExpression vgMPK1(
  1446. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are possibly lost in"
  1447. " loss record [0-9][0-9]* of [0-9]");
  1448. cmsys::RegularExpression vgMPK2(
  1449. "== .*[0-9][0-9]* bytes in [0-9][0-9]* blocks are still reachable"
  1450. " in loss record [0-9][0-9]* of [0-9]");
  1451. cmsys::RegularExpression vgUMC(
  1452. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  1453. cmsys::RegularExpression vgUMR1("== .*Use of uninitialised value of size [0-9][0-9]*");
  1454. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9][0-9]*");
  1455. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  1456. cmsys::RegularExpression vgUMR4(
  1457. "== .*Syscall param .* contains uninitialised or unaddressable byte\\(s\\)");
  1458. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9]");
  1459. cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is locked by a different thread");
  1460. //double sttime = cmSystemTools::GetTime();
  1461. //std::cout << "Start test: " << lines.size() << std::endl;
  1462. for ( cc = 0; cc < lines.size(); cc ++ )
  1463. {
  1464. if ( valgrindLine.find(lines[cc]) )
  1465. {
  1466. int failure = cmCTestTestHandler::NO_MEMORY_FAULT;
  1467. if ( vgFIM.find(lines[cc]) ) { failure = cmCTestTestHandler::FIM; }
  1468. else if ( vgFMM.find(lines[cc]) ) { failure = cmCTestTestHandler::FMM; }
  1469. else if ( vgMLK.find(lines[cc]) ) { failure = cmCTestTestHandler::MLK; }
  1470. else if ( vgPAR.find(lines[cc]) ) { failure = cmCTestTestHandler::PAR; }
  1471. else if ( vgMPK1.find(lines[cc]) ){ failure = cmCTestTestHandler::MPK; }
  1472. else if ( vgMPK2.find(lines[cc]) ){ failure = cmCTestTestHandler::MPK; }
  1473. else if ( vgUMC.find(lines[cc]) ) { failure = cmCTestTestHandler::UMC; }
  1474. else if ( vgUMR1.find(lines[cc]) ){ failure = cmCTestTestHandler::UMR; }
  1475. else if ( vgUMR2.find(lines[cc]) ){ failure = cmCTestTestHandler::UMR; }
  1476. else if ( vgUMR3.find(lines[cc]) ){ failure = cmCTestTestHandler::UMR; }
  1477. else if ( vgUMR4.find(lines[cc]) ){ failure = cmCTestTestHandler::UMR; }
  1478. else if ( vgIPW.find(lines[cc]) ) { failure = cmCTestTestHandler::IPW; }
  1479. else if ( vgABR.find(lines[cc]) ) { failure = cmCTestTestHandler::ABR; }
  1480. if ( failure != cmCTestTestHandler::NO_MEMORY_FAULT )
  1481. {
  1482. ostr << "<b>" << cmCTestMemCheckResultStrings[failure] << "</b> ";
  1483. results[failure] ++;
  1484. defects ++;
  1485. }
  1486. ostr << cmCTest::MakeXMLSafe(lines[cc]) << std::endl;
  1487. }
  1488. }
  1489. //std::cout << "End test (elapsed: " << (cmSystemTools::GetTime() - sttime) << std::endl;
  1490. log = ostr.str();
  1491. if ( defects )
  1492. {
  1493. return false;
  1494. }
  1495. return true;
  1496. }
  1497. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1498. {
  1499. m_IncludeRegExp = arg;
  1500. }
  1501. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1502. {
  1503. m_ExcludeRegExp = arg;
  1504. }
  1505. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1506. {
  1507. this->TestsToRunString = in;
  1508. // if the argument is a file, then read it and use the contents as the string
  1509. if(cmSystemTools::FileExists(in))
  1510. {
  1511. std::ifstream fin(in);
  1512. unsigned long filelen = cmSystemTools::FileLength(in);
  1513. char* buff = new char[filelen+1];
  1514. fin.getline(buff, filelen);
  1515. buff[fin.gcount()] = 0;
  1516. this->TestsToRunString = buff;
  1517. }
  1518. }