cmCTestTestHandler.cxx 47 KB

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