cmCTestTestHandler.cxx 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCTestTestHandler.h"
  14. #include "cmCTest.h"
  15. #include "cmake.h"
  16. #include "cmGeneratedFileStream.h"
  17. #include <cmsys/Process.h>
  18. #include <cmsys/RegularExpression.hxx>
  19. #include <cmsys/Base64.h>
  20. #include "cmMakefile.h"
  21. #include "cmGlobalGenerator.h"
  22. #include "cmLocalGenerator.h"
  23. #include "cmCommand.h"
  24. #include "cmSystemTools.h"
  25. #include <stdlib.h>
  26. #include <math.h>
  27. #include <float.h>
  28. #include <memory> // auto_ptr
  29. //----------------------------------------------------------------------
  30. class cmCTestSubdirCommand : public cmCommand
  31. {
  32. public:
  33. /**
  34. * This is a virtual constructor for the command.
  35. */
  36. virtual cmCommand* Clone()
  37. {
  38. cmCTestSubdirCommand* c = new cmCTestSubdirCommand;
  39. c->TestHandler = this->TestHandler;
  40. return c;
  41. }
  42. /**
  43. * This is called when the command is first encountered in
  44. * the CMakeLists.txt file.
  45. */
  46. virtual bool InitialPass(std::vector<std::string> const& args,
  47. cmExecutionStatus &);
  48. /**
  49. * The name of the command as specified in CMakeList.txt.
  50. */
  51. virtual const char* GetName() { return "subdirs";}
  52. // Unused methods
  53. virtual const char* GetTerseDocumentation() { return ""; }
  54. virtual const char* GetFullDocumentation() { return ""; }
  55. cmTypeMacro(cmCTestSubdirCommand, cmCommand);
  56. cmCTestTestHandler* TestHandler;
  57. };
  58. //----------------------------------------------------------------------
  59. bool cmCTestSubdirCommand
  60. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  61. {
  62. if(args.size() < 1 )
  63. {
  64. this->SetError("called with incorrect number of arguments");
  65. return false;
  66. }
  67. std::vector<std::string>::const_iterator it;
  68. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  69. for ( it = args.begin(); it != args.end(); ++ it )
  70. {
  71. cmSystemTools::ChangeDirectory(cwd.c_str());
  72. std::string fname = cwd;
  73. fname += "/";
  74. fname += *it;
  75. if ( !cmSystemTools::FileExists(fname.c_str()) )
  76. {
  77. // No subdirectory? So what...
  78. continue;
  79. }
  80. cmSystemTools::ChangeDirectory(fname.c_str());
  81. const char* testFilename;
  82. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  83. {
  84. // does the CTestTestfile.cmake exist ?
  85. testFilename = "CTestTestfile.cmake";
  86. }
  87. else
  88. {
  89. // No CTestTestfile? Who cares...
  90. cmSystemTools::ChangeDirectory(cwd.c_str());
  91. continue;
  92. }
  93. fname += "/";
  94. fname += testFilename;
  95. bool readit =
  96. this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
  97. fname.c_str());
  98. cmSystemTools::ChangeDirectory(cwd.c_str());
  99. if(!readit)
  100. {
  101. std::string m = "Could not find include file: ";
  102. m += fname;
  103. this->SetError(m.c_str());
  104. return false;
  105. }
  106. }
  107. return true;
  108. }
  109. //----------------------------------------------------------------------
  110. class cmCTestAddSubdirectoryCommand : public cmCommand
  111. {
  112. public:
  113. /**
  114. * This is a virtual constructor for the command.
  115. */
  116. virtual cmCommand* Clone()
  117. {
  118. cmCTestAddSubdirectoryCommand* c = new cmCTestAddSubdirectoryCommand;
  119. c->TestHandler = this->TestHandler;
  120. return c;
  121. }
  122. /**
  123. * This is called when the command is first encountered in
  124. * the CMakeLists.txt file.
  125. */
  126. virtual bool InitialPass(std::vector<std::string> const& args,
  127. cmExecutionStatus &);
  128. /**
  129. * The name of the command as specified in CMakeList.txt.
  130. */
  131. virtual const char* GetName() { return "add_subdirectory";}
  132. // Unused methods
  133. virtual const char* GetTerseDocumentation() { return ""; }
  134. virtual const char* GetFullDocumentation() { return ""; }
  135. cmTypeMacro(cmCTestAddSubdirectoryCommand, cmCommand);
  136. cmCTestTestHandler* TestHandler;
  137. };
  138. //----------------------------------------------------------------------
  139. bool cmCTestAddSubdirectoryCommand
  140. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  141. {
  142. if(args.size() < 1 )
  143. {
  144. this->SetError("called with incorrect number of arguments");
  145. return false;
  146. }
  147. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  148. cmSystemTools::ChangeDirectory(cwd.c_str());
  149. std::string fname = cwd;
  150. fname += "/";
  151. fname += args[1];
  152. if ( !cmSystemTools::FileExists(fname.c_str()) )
  153. {
  154. // No subdirectory? So what...
  155. return true;
  156. }
  157. cmSystemTools::ChangeDirectory(fname.c_str());
  158. const char* testFilename;
  159. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  160. {
  161. // does the CTestTestfile.cmake exist ?
  162. testFilename = "CTestTestfile.cmake";
  163. }
  164. else
  165. {
  166. // No CTestTestfile? Who cares...
  167. cmSystemTools::ChangeDirectory(cwd.c_str());
  168. return true;
  169. }
  170. fname += "/";
  171. fname += testFilename;
  172. bool readit =
  173. this->Makefile->ReadListFile(this->Makefile->GetCurrentListFile(),
  174. fname.c_str());
  175. cmSystemTools::ChangeDirectory(cwd.c_str());
  176. if(!readit)
  177. {
  178. std::string m = "Could not find include file: ";
  179. m += fname;
  180. this->SetError(m.c_str());
  181. return false;
  182. }
  183. return true;
  184. }
  185. //----------------------------------------------------------------------
  186. class cmCTestAddTestCommand : public cmCommand
  187. {
  188. public:
  189. /**
  190. * This is a virtual constructor for the command.
  191. */
  192. virtual cmCommand* Clone()
  193. {
  194. cmCTestAddTestCommand* c = new cmCTestAddTestCommand;
  195. c->TestHandler = this->TestHandler;
  196. return c;
  197. }
  198. /**
  199. * This is called when the command is first encountered in
  200. * the CMakeLists.txt file.
  201. */
  202. virtual bool InitialPass(std::vector<std::string> const&,
  203. cmExecutionStatus &);
  204. /**
  205. * The name of the command as specified in CMakeList.txt.
  206. */
  207. virtual const char* GetName() { return "ADD_TEST";}
  208. // Unused methods
  209. virtual const char* GetTerseDocumentation() { return ""; }
  210. virtual const char* GetFullDocumentation() { return ""; }
  211. cmTypeMacro(cmCTestAddTestCommand, cmCommand);
  212. cmCTestTestHandler* TestHandler;
  213. };
  214. //----------------------------------------------------------------------
  215. bool cmCTestAddTestCommand
  216. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  217. {
  218. if ( args.size() < 2 )
  219. {
  220. this->SetError("called with incorrect number of arguments");
  221. return false;
  222. }
  223. return this->TestHandler->AddTest(args);
  224. }
  225. //----------------------------------------------------------------------
  226. class cmCTestSetTestsPropertiesCommand : public cmCommand
  227. {
  228. public:
  229. /**
  230. * This is a virtual constructor for the command.
  231. */
  232. virtual cmCommand* Clone()
  233. {
  234. cmCTestSetTestsPropertiesCommand* c
  235. = new cmCTestSetTestsPropertiesCommand;
  236. c->TestHandler = this->TestHandler;
  237. return c;
  238. }
  239. /**
  240. * This is called when the command is first encountered in
  241. * the CMakeLists.txt file.
  242. */
  243. virtual bool InitialPass(std::vector<std::string> const&,
  244. cmExecutionStatus &);
  245. /**
  246. * The name of the command as specified in CMakeList.txt.
  247. */
  248. virtual const char* GetName() { return "SET_TESTS_PROPERTIES";}
  249. // Unused methods
  250. virtual const char* GetTerseDocumentation() { return ""; }
  251. virtual const char* GetFullDocumentation() { return ""; }
  252. cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
  253. cmCTestTestHandler* TestHandler;
  254. };
  255. //----------------------------------------------------------------------
  256. bool cmCTestSetTestsPropertiesCommand
  257. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  258. {
  259. return this->TestHandler->SetTestsProperties(args);
  260. }
  261. //----------------------------------------------------------------------
  262. // get the next number in a string with numbers separated by ,
  263. // pos is the start of the search and pos2 is the end of the search
  264. // pos becomes pos2 after a call to GetNextNumber.
  265. // -1 is returned at the end of the list.
  266. inline int GetNextNumber(std::string const& in,
  267. int& val,
  268. std::string::size_type& pos,
  269. std::string::size_type& pos2)
  270. {
  271. pos2 = in.find(',', pos);
  272. if(pos2 != in.npos)
  273. {
  274. if(pos2-pos == 0)
  275. {
  276. val = -1;
  277. }
  278. else
  279. {
  280. val = atoi(in.substr(pos, pos2-pos).c_str());
  281. }
  282. pos = pos2+1;
  283. return 1;
  284. }
  285. else
  286. {
  287. if(in.size()-pos == 0)
  288. {
  289. val = -1;
  290. }
  291. else
  292. {
  293. val = atoi(in.substr(pos, in.size()-pos).c_str());
  294. }
  295. return 0;
  296. }
  297. }
  298. //----------------------------------------------------------------------
  299. // get the next number in a string with numbers separated by ,
  300. // pos is the start of the search and pos2 is the end of the search
  301. // pos becomes pos2 after a call to GetNextNumber.
  302. // -1 is returned at the end of the list.
  303. inline int GetNextRealNumber(std::string const& in,
  304. double& val,
  305. std::string::size_type& pos,
  306. std::string::size_type& pos2)
  307. {
  308. pos2 = in.find(',', pos);
  309. if(pos2 != in.npos)
  310. {
  311. if(pos2-pos == 0)
  312. {
  313. val = -1;
  314. }
  315. else
  316. {
  317. val = atof(in.substr(pos, pos2-pos).c_str());
  318. }
  319. pos = pos2+1;
  320. return 1;
  321. }
  322. else
  323. {
  324. if(in.size()-pos == 0)
  325. {
  326. val = -1;
  327. }
  328. else
  329. {
  330. val = atof(in.substr(pos, in.size()-pos).c_str());
  331. }
  332. return 0;
  333. }
  334. }
  335. //----------------------------------------------------------------------
  336. cmCTestTestHandler::cmCTestTestHandler()
  337. {
  338. this->UseUnion = false;
  339. this->UseIncludeRegExpFlag = false;
  340. this->UseExcludeRegExpFlag = false;
  341. this->UseExcludeRegExpFirst = false;
  342. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  343. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  344. this->MemCheck = false;
  345. this->LogFile = 0;
  346. this->DartStuff.compile("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  347. }
  348. //----------------------------------------------------------------------
  349. void cmCTestTestHandler::Initialize()
  350. {
  351. this->Superclass::Initialize();
  352. this->ElapsedTestingTime = -1;
  353. this->TestResults.clear();
  354. this->CustomTestsIgnore.clear();
  355. this->StartTest = "";
  356. this->EndTest = "";
  357. this->CustomPreTest.clear();
  358. this->CustomPostTest.clear();
  359. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  360. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  361. this->TestsToRun.clear();
  362. this->UseIncludeRegExpFlag = false;
  363. this->UseExcludeRegExpFlag = false;
  364. this->UseExcludeRegExpFirst = false;
  365. this->IncludeRegExp = "";
  366. this->ExcludeRegExp = "";
  367. TestsToRunString = "";
  368. this->UseUnion = false;
  369. this->TestList.clear();
  370. }
  371. //----------------------------------------------------------------------
  372. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile *mf)
  373. {
  374. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  375. this->CustomPreTest);
  376. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  377. this->CustomPostTest);
  378. this->CTest->PopulateCustomVector(mf,
  379. "CTEST_CUSTOM_TESTS_IGNORE",
  380. this->CustomTestsIgnore);
  381. this->CTest->PopulateCustomInteger(mf,
  382. "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
  383. this->CustomMaximumPassedTestOutputSize);
  384. this->CTest->PopulateCustomInteger(mf,
  385. "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
  386. this->CustomMaximumFailedTestOutputSize);
  387. }
  388. //----------------------------------------------------------------------
  389. int cmCTestTestHandler::PreProcessHandler()
  390. {
  391. if ( !this->ExecuteCommands(this->CustomPreTest) )
  392. {
  393. cmCTestLog(this->CTest, ERROR_MESSAGE,
  394. "Problem executing pre-test command(s)." << std::endl);
  395. return 0;
  396. }
  397. return 1;
  398. }
  399. //----------------------------------------------------------------------
  400. int cmCTestTestHandler::PostProcessHandler()
  401. {
  402. if ( !this->ExecuteCommands(this->CustomPostTest) )
  403. {
  404. cmCTestLog(this->CTest, ERROR_MESSAGE,
  405. "Problem executing post-test command(s)." << std::endl);
  406. return 0;
  407. }
  408. return 1;
  409. }
  410. //----------------------------------------------------------------------
  411. //clearly it would be nice if this were broken up into a few smaller
  412. //functions and commented...
  413. int cmCTestTestHandler::ProcessHandler()
  414. {
  415. // Update internal data structure from generic one
  416. this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
  417. this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
  418. const char* val;
  419. val = this->GetOption("IncludeRegularExpression");
  420. if ( val )
  421. {
  422. this->UseIncludeRegExp();
  423. this->SetIncludeRegExp(val);
  424. }
  425. val = this->GetOption("ExcludeRegularExpression");
  426. if ( val )
  427. {
  428. this->UseExcludeRegExp();
  429. this->SetExcludeRegExp(val);
  430. }
  431. this->TestResults.clear();
  432. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  433. (this->MemCheck ? "Memory check" : "Test")
  434. << " project " << cmSystemTools::GetCurrentWorkingDirectory()
  435. << std::endl);
  436. if ( ! this->PreProcessHandler() )
  437. {
  438. return -1;
  439. }
  440. cmGeneratedFileStream mLogFile;
  441. this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
  442. this->LogFile = &mLogFile;
  443. std::vector<cmStdString> passed;
  444. std::vector<cmStdString> failed;
  445. int total;
  446. this->ProcessDirectory(passed, failed);
  447. total = int(passed.size()) + int(failed.size());
  448. if (total == 0)
  449. {
  450. if ( !this->CTest->GetShowOnly() )
  451. {
  452. cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
  453. << std::endl);
  454. }
  455. }
  456. else
  457. {
  458. if (this->HandlerVerbose && passed.size() &&
  459. (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag))
  460. {
  461. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  462. << "The following tests passed:" << std::endl);
  463. for(std::vector<cmStdString>::iterator j = passed.begin();
  464. j != passed.end(); ++j)
  465. {
  466. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j
  467. << std::endl);
  468. }
  469. }
  470. float percent = float(passed.size()) * 100.0f / total;
  471. if ( failed.size() > 0 && percent > 99)
  472. {
  473. percent = 99;
  474. }
  475. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
  476. << static_cast<int>(percent + .5) << "% tests passed, "
  477. << failed.size() << " tests failed out of " << total << std::endl);
  478. //fprintf(stderr,"\n%.0f%% tests passed, %i tests failed out of %i\n",
  479. // percent, int(failed.size()), total);
  480. if (failed.size())
  481. {
  482. cmGeneratedFileStream ofs;
  483. cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
  484. << "The following tests FAILED:" << std::endl);
  485. this->StartLogFile("TestsFailed", ofs);
  486. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  487. for(ftit = this->TestResults.begin();
  488. ftit != this->TestResults.end(); ++ftit)
  489. {
  490. if ( ftit->Status != cmCTestTestHandler::COMPLETED )
  491. {
  492. ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
  493. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
  494. << ftit->TestCount << " - " << ftit->Name.c_str() << " ("
  495. << this->GetTestStatus(ftit->Status) << ")" << std::endl);
  496. }
  497. }
  498. }
  499. }
  500. if ( this->CTest->GetProduceXML() )
  501. {
  502. cmGeneratedFileStream xmlfile;
  503. if( !this->StartResultingXML(
  504. (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
  505. {
  506. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
  507. << (this->MemCheck ? "memory check" : "testing")
  508. << " XML file" << std::endl);
  509. this->LogFile = 0;
  510. return 1;
  511. }
  512. this->GenerateDartOutput(xmlfile);
  513. }
  514. if ( ! this->PostProcessHandler() )
  515. {
  516. this->LogFile = 0;
  517. return -1;
  518. }
  519. if ( !failed.empty() )
  520. {
  521. this->LogFile = 0;
  522. return -1;
  523. }
  524. this->LogFile = 0;
  525. return 0;
  526. }
  527. //----------------------------------------------------------------------
  528. void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it,
  529. std::vector<cmStdString> &passed,
  530. std::vector<cmStdString> &failed,
  531. int cnt, int tmsize)
  532. {
  533. const std::string& testname = it->Name;
  534. std::vector<std::string>& args = it->Args;
  535. cmCTestTestResult cres;
  536. cres.Properties = &*it;
  537. cres.ExecutionTime = 0;
  538. cres.ReturnValue = -1;
  539. cres.Status = cmCTestTestHandler::NOT_RUN;
  540. cres.TestCount = cnt;
  541. cres.Name = testname;
  542. cres.Path = it->Directory.c_str();
  543. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
  544. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " ");
  545. if ( this->MemCheck )
  546. {
  547. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Memory Check");
  548. }
  549. else
  550. {
  551. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Testing");
  552. }
  553. cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
  554. std::string outname = testname;
  555. outname.resize(30, ' ');
  556. *this->LogFile << cnt << "/" << tmsize << " Testing: " << testname
  557. << std::endl;
  558. if ( this->CTest->GetShowOnly() )
  559. {
  560. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str() << std::endl);
  561. }
  562. else
  563. {
  564. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
  565. }
  566. cmCTestLog(this->CTest, DEBUG, "Testing " << args[0].c_str() << " ... ");
  567. // find the test executable
  568. std::string actualCommand = this->FindTheExecutable(args[1].c_str());
  569. std::string testCommand
  570. = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  571. // continue if we did not find the executable
  572. if (testCommand == "")
  573. {
  574. *this->LogFile << "Unable to find executable: " << args[1].c_str()
  575. << std::endl;
  576. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
  577. << args[1].c_str() << std::endl);
  578. cres.Output = "Unable to find executable: " + args[1];
  579. if ( !this->CTest->GetShowOnly() )
  580. {
  581. cres.FullCommandLine = actualCommand;
  582. this->TestResults.push_back( cres );
  583. failed.push_back(testname);
  584. return;
  585. }
  586. }
  587. // add the arguments
  588. std::vector<std::string>::const_iterator j = args.begin();
  589. ++j;
  590. ++j;
  591. std::vector<const char*> arguments;
  592. this->GenerateTestCommand(arguments);
  593. arguments.push_back(actualCommand.c_str());
  594. for(;j != args.end(); ++j)
  595. {
  596. testCommand += " ";
  597. testCommand += cmSystemTools::EscapeSpaces(j->c_str());
  598. arguments.push_back(j->c_str());
  599. }
  600. arguments.push_back(0);
  601. /**
  602. * Run an executable command and put the stdout in output.
  603. */
  604. std::string output;
  605. int retVal = 0;
  606. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  607. << (this->MemCheck?"MemCheck":"Test")
  608. << " command: " << testCommand
  609. << std::endl);
  610. *this->LogFile << cnt << "/" << tmsize
  611. << " Test: " << testname.c_str() << std::endl;
  612. *this->LogFile << "Command: ";
  613. std::vector<cmStdString>::size_type ll;
  614. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  615. {
  616. *this->LogFile << "\"" << arguments[ll] << "\" ";
  617. }
  618. *this->LogFile
  619. << std::endl
  620. << "Directory: " << it->Directory << std::endl
  621. << "\"" << testname.c_str() << "\" start time: "
  622. << this->CTest->CurrentTime() << std::endl
  623. << "Output:" << std::endl
  624. << "----------------------------------------------------------"
  625. << std::endl;
  626. int res = 0;
  627. double clock_start, clock_finish;
  628. clock_start = cmSystemTools::GetTime();
  629. if ( !this->CTest->GetShowOnly() )
  630. {
  631. res = this->CTest->RunTest(arguments, &output, &retVal, this->LogFile,
  632. it->Timeout);
  633. }
  634. clock_finish = cmSystemTools::GetTime();
  635. if ( this->LogFile )
  636. {
  637. double ttime = clock_finish - clock_start;
  638. int hours = static_cast<int>(ttime / (60 * 60));
  639. int minutes = static_cast<int>(ttime / 60) % 60;
  640. int seconds = static_cast<int>(ttime) % 60;
  641. char buffer[100];
  642. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  643. *this->LogFile
  644. << "----------------------------------------------------------"
  645. << std::endl
  646. << "\"" << testname.c_str() << "\" end time: "
  647. << this->CTest->CurrentTime() << std::endl
  648. << "\"" << testname.c_str() << "\" time elapsed: "
  649. << buffer << std::endl
  650. << "----------------------------------------------------------"
  651. << std::endl << std::endl;
  652. }
  653. cres.ExecutionTime = (double)(clock_finish - clock_start);
  654. cres.FullCommandLine = testCommand;
  655. std::string reason;
  656. if ( !this->CTest->GetShowOnly() )
  657. {
  658. bool testFailed = false;
  659. std::vector<std::pair<cmsys::RegularExpression,
  660. std::string> >::iterator passIt;
  661. bool forceFail = false;
  662. if ( it->RequiredRegularExpressions.size() > 0 )
  663. {
  664. bool found = false;
  665. for ( passIt = it->RequiredRegularExpressions.begin();
  666. passIt != it->RequiredRegularExpressions.end();
  667. ++ passIt )
  668. {
  669. if ( passIt->first.find(output.c_str()) )
  670. {
  671. found = true;
  672. }
  673. }
  674. if ( !found )
  675. {
  676. reason = "Required regular expression not found.";
  677. reason += "Regex=[";
  678. for ( passIt = it->RequiredRegularExpressions.begin();
  679. passIt != it->RequiredRegularExpressions.end();
  680. ++ passIt )
  681. {
  682. reason += passIt->second;
  683. reason += "\n";
  684. }
  685. reason += "]";
  686. forceFail = true;
  687. }
  688. }
  689. if ( it->ErrorRegularExpressions.size() > 0 )
  690. {
  691. for ( passIt = it->ErrorRegularExpressions.begin();
  692. passIt != it->ErrorRegularExpressions.end();
  693. ++ passIt )
  694. {
  695. if ( passIt->first.find(output.c_str()) )
  696. {
  697. reason = "Error regular expression found in output.";
  698. reason += " Regex=[";
  699. reason += passIt->second;
  700. reason += "]";
  701. forceFail = true;
  702. }
  703. }
  704. }
  705. if (res == cmsysProcess_State_Exited &&
  706. (retVal == 0 || it->RequiredRegularExpressions.size()) &&
  707. !forceFail)
  708. {
  709. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed");
  710. if ( it->WillFail )
  711. {
  712. cmCTestLog(this->CTest, HANDLER_OUTPUT, " - But it should fail!");
  713. cres.Status = cmCTestTestHandler::FAILED;
  714. testFailed = true;
  715. }
  716. else
  717. {
  718. cres.Status = cmCTestTestHandler::COMPLETED;
  719. }
  720. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  721. }
  722. else
  723. {
  724. testFailed = true;
  725. cres.Status = cmCTestTestHandler::FAILED;
  726. if ( res == cmsysProcess_State_Expired )
  727. {
  728. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout" << std::endl);
  729. cres.Status = cmCTestTestHandler::TIMEOUT;
  730. }
  731. else if ( res == cmsysProcess_State_Exception )
  732. {
  733. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
  734. switch ( retVal )
  735. {
  736. case cmsysProcess_Exception_Fault:
  737. cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
  738. cres.Status = cmCTestTestHandler::SEGFAULT;
  739. break;
  740. case cmsysProcess_Exception_Illegal:
  741. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
  742. cres.Status = cmCTestTestHandler::ILLEGAL;
  743. break;
  744. case cmsysProcess_Exception_Interrupt:
  745. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
  746. cres.Status = cmCTestTestHandler::INTERRUPT;
  747. break;
  748. case cmsysProcess_Exception_Numerical:
  749. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
  750. cres.Status = cmCTestTestHandler::NUMERICAL;
  751. break;
  752. default:
  753. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
  754. cres.Status = cmCTestTestHandler::OTHER_FAULT;
  755. }
  756. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  757. }
  758. else if ( res == cmsysProcess_State_Error )
  759. {
  760. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Bad command " << res
  761. << std::endl);
  762. cres.Status = cmCTestTestHandler::BAD_COMMAND;
  763. }
  764. else
  765. {
  766. // Force fail will also be here?
  767. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Failed " << reason);
  768. if ( it->WillFail )
  769. {
  770. cres.Status = cmCTestTestHandler::COMPLETED;
  771. cmCTestLog(this->CTest, HANDLER_OUTPUT, " - supposed to fail");
  772. testFailed = false;
  773. }
  774. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl);
  775. }
  776. }
  777. if ( testFailed )
  778. {
  779. failed.push_back(testname);
  780. }
  781. else
  782. {
  783. passed.push_back(testname);
  784. }
  785. if (!output.empty() && output.find("<DartMeasurement") != output.npos)
  786. {
  787. if (this->DartStuff.find(output.c_str()))
  788. {
  789. std::string dartString = this->DartStuff.match(1);
  790. cmSystemTools::ReplaceString(output, dartString.c_str(),"");
  791. cres.RegressionImages
  792. = this->GenerateRegressionImages(dartString);
  793. }
  794. }
  795. }
  796. // if this is doing MemCheck then all the output needs to be put into
  797. // Output since that it what is parsed to by cmCTestMemCheckHandler
  798. if(!this->MemCheck)
  799. {
  800. if ( cres.Status == cmCTestTestHandler::COMPLETED )
  801. {
  802. this->CleanTestOutput(output, static_cast<size_t>
  803. (this->CustomMaximumPassedTestOutputSize));
  804. }
  805. else
  806. {
  807. this->CleanTestOutput(output, static_cast<size_t>
  808. (this->CustomMaximumFailedTestOutputSize));
  809. }
  810. }
  811. cres.Output = output;
  812. cres.ReturnValue = retVal;
  813. cres.CompletionStatus = "Completed";
  814. this->TestResults.push_back( cres );
  815. }
  816. //----------------------------------------------------------------------
  817. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  818. std::vector<cmStdString> &failed)
  819. {
  820. std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory();
  821. this->TestList.clear();
  822. this->GetListOfTests();
  823. cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
  824. this->StartTest = this->CTest->CurrentTime();
  825. double elapsed_time_start = cmSystemTools::GetTime();
  826. *this->LogFile << "Start testing: " << this->StartTest << std::endl
  827. << "----------------------------------------------------------"
  828. << std::endl;
  829. // how many tests are in based on RegExp?
  830. int inREcnt = 0;
  831. cmCTestTestHandler::ListOfTests::iterator it;
  832. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  833. {
  834. if (it->IsInBasedOnREOptions)
  835. {
  836. inREcnt ++;
  837. }
  838. }
  839. // expand the test list based on the union flag
  840. if (this->UseUnion)
  841. {
  842. this->ExpandTestsToRunInformation((int)tmsize);
  843. }
  844. else
  845. {
  846. this->ExpandTestsToRunInformation(inREcnt);
  847. }
  848. int cnt = 0;
  849. inREcnt = 0;
  850. std::string last_directory = "";
  851. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  852. {
  853. cnt ++;
  854. if (it->IsInBasedOnREOptions)
  855. {
  856. inREcnt++;
  857. }
  858. // if we are out of time then skip this test, we leave two minutes
  859. // to submit results
  860. if (this->CTest->GetRemainingTimeAllowed() - 120 <= 0)
  861. {
  862. continue;
  863. }
  864. if (!(last_directory == it->Directory))
  865. {
  866. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  867. "Changing directory into " << it->Directory.c_str() << "\n");
  868. *this->LogFile << "Changing directory into: " << it->Directory.c_str()
  869. << std::endl;
  870. last_directory = it->Directory;
  871. cmSystemTools::ChangeDirectory(it->Directory.c_str());
  872. }
  873. if (this->UseUnion)
  874. {
  875. // if it is not in the list and not in the regexp then skip
  876. if ((this->TestsToRun.size() &&
  877. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
  878. == this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
  879. {
  880. continue;
  881. }
  882. }
  883. else
  884. {
  885. // is this test in the list of tests to run? If not then skip it
  886. if ((this->TestsToRun.size() &&
  887. std::find(this->TestsToRun.begin(),
  888. this->TestsToRun.end(), inREcnt)
  889. == this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
  890. {
  891. continue;
  892. }
  893. }
  894. // process this one test
  895. this->ProcessOneTest(&(*it), passed, failed, cnt,
  896. static_cast<int>(tmsize));
  897. }
  898. this->EndTest = this->CTest->CurrentTime();
  899. this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  900. if ( this->LogFile )
  901. {
  902. *this->LogFile << "End testing: " << this->EndTest << std::endl;
  903. }
  904. cmSystemTools::ChangeDirectory(current_dir.c_str());
  905. }
  906. //----------------------------------------------------------------------
  907. void cmCTestTestHandler::GenerateTestCommand(std::vector<const char*>&)
  908. {
  909. }
  910. //----------------------------------------------------------------------
  911. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  912. {
  913. if ( !this->CTest->GetProduceXML() )
  914. {
  915. return;
  916. }
  917. this->CTest->StartXML(os);
  918. os << "<Testing>\n"
  919. << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
  920. << "\t<TestList>\n";
  921. cmCTestTestHandler::TestResultsVector::size_type cc;
  922. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  923. {
  924. cmCTestTestResult *result = &this->TestResults[cc];
  925. std::string testPath = result->Path + "/" + result->Name;
  926. os << "\t\t<Test>" << cmCTest::MakeXMLSafe(
  927. this->CTest->GetShortPathToFile(testPath.c_str()))
  928. << "</Test>" << std::endl;
  929. }
  930. os << "\t</TestList>\n";
  931. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  932. {
  933. cmCTestTestResult *result = &this->TestResults[cc];
  934. os << "\t<Test Status=\"";
  935. if ( result->Status == cmCTestTestHandler::COMPLETED )
  936. {
  937. os << "passed";
  938. }
  939. else if ( result->Status == cmCTestTestHandler::NOT_RUN )
  940. {
  941. os << "notrun";
  942. }
  943. else
  944. {
  945. os << "failed";
  946. }
  947. std::string testPath = result->Path + "/" + result->Name;
  948. os << "\">\n"
  949. << "\t\t<Name>" << cmCTest::MakeXMLSafe(result->Name) << "</Name>\n"
  950. << "\t\t<Path>" << cmCTest::MakeXMLSafe(
  951. this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
  952. << "\t\t<FullName>" << cmCTest::MakeXMLSafe(
  953. this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  954. << "\t\t<FullCommandLine>"
  955. << cmCTest::MakeXMLSafe(result->FullCommandLine)
  956. << "</FullCommandLine>\n"
  957. << "\t\t<Results>" << std::endl;
  958. if ( result->Status != cmCTestTestHandler::NOT_RUN )
  959. {
  960. if ( result->Status != cmCTestTestHandler::COMPLETED ||
  961. result->ReturnValue )
  962. {
  963. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  964. "name=\"Exit Code\"><Value>"
  965. << this->GetTestStatus(result->Status) << "</Value>"
  966. "</NamedMeasurement>\n"
  967. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  968. "name=\"Exit Value\"><Value>"
  969. << result->ReturnValue << "</Value></NamedMeasurement>"
  970. << std::endl;
  971. }
  972. os << result->RegressionImages;
  973. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  974. << "name=\"Execution Time\"><Value>"
  975. << result->ExecutionTime << "</Value></NamedMeasurement>\n";
  976. os
  977. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  978. << "name=\"Completion Status\"><Value>"
  979. << result->CompletionStatus << "</Value></NamedMeasurement>\n";
  980. }
  981. os
  982. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  983. << "name=\"Command Line\"><Value>"
  984. << result->FullCommandLine << "</Value></NamedMeasurement>\n";
  985. std::map<cmStdString,cmStdString>::iterator measureIt;
  986. for ( measureIt = result->Properties->Measurements.begin();
  987. measureIt != result->Properties->Measurements.end();
  988. ++ measureIt )
  989. {
  990. os
  991. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  992. << "name=\"" << measureIt->first.c_str() << "\"><Value>"
  993. << measureIt->second.c_str() << "</Value></NamedMeasurement>\n";
  994. }
  995. os
  996. << "\t\t\t<Measurement>\n"
  997. << "\t\t\t\t<Value>";
  998. os << cmCTest::MakeXMLSafe(result->Output);
  999. os
  1000. << "</Value>\n"
  1001. << "\t\t\t</Measurement>\n"
  1002. << "\t\t</Results>\n"
  1003. << "\t</Test>" << std::endl;
  1004. }
  1005. os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
  1006. << "<ElapsedMinutes>"
  1007. << static_cast<int>(this->ElapsedTestingTime/6)/10.0
  1008. << "</ElapsedMinutes>"
  1009. << "</Testing>" << std::endl;
  1010. this->CTest->EndXML(os);
  1011. }
  1012. //----------------------------------------------------------------------
  1013. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  1014. {
  1015. std::vector<cmStdString>::iterator it;
  1016. for ( it = vec.begin(); it != vec.end(); ++it )
  1017. {
  1018. int retVal = 0;
  1019. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
  1020. << std::endl);
  1021. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
  1022. /*this->Verbose*/) || retVal != 0 )
  1023. {
  1024. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
  1025. << *it << std::endl);
  1026. return 0;
  1027. }
  1028. }
  1029. return 1;
  1030. }
  1031. //----------------------------------------------------------------------
  1032. // Find the appropriate executable to run for a test
  1033. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  1034. {
  1035. std::string resConfig;
  1036. std::vector<std::string> extraPaths;
  1037. std::vector<std::string> failedPaths;
  1038. return cmCTestTestHandler::FindExecutable(this->CTest,
  1039. exe, resConfig,
  1040. extraPaths,
  1041. failedPaths);
  1042. }
  1043. // add additional configuraitons to the search path
  1044. void cmCTestTestHandler
  1045. ::AddConfigurations(cmCTest *ctest,
  1046. std::vector<std::string> &attempted,
  1047. std::vector<std::string> &attemptedConfigs,
  1048. std::string filepath,
  1049. std::string &filename)
  1050. {
  1051. std::string tempPath;
  1052. if (filepath.size())
  1053. {
  1054. filepath += "/";
  1055. }
  1056. tempPath = filepath + filename;
  1057. attempted.push_back(tempPath);
  1058. attemptedConfigs.push_back("");
  1059. if(ctest->GetConfigType().size())
  1060. {
  1061. tempPath = filepath;
  1062. tempPath += ctest->GetConfigType();
  1063. tempPath += "/";
  1064. tempPath += filename;
  1065. attempted.push_back(tempPath);
  1066. attemptedConfigs.push_back(ctest->GetConfigType());
  1067. // If the file is an OSX bundle then the configtyp
  1068. // will be at the start of the path
  1069. tempPath = ctest->GetConfigType();
  1070. tempPath += "/";
  1071. tempPath += filepath;
  1072. tempPath += filename;
  1073. attempted.push_back(tempPath);
  1074. attemptedConfigs.push_back(ctest->GetConfigType());
  1075. }
  1076. else
  1077. {
  1078. // no config specified to try some options
  1079. tempPath = filepath;
  1080. tempPath += "Release/";
  1081. tempPath += filename;
  1082. attempted.push_back(tempPath);
  1083. attemptedConfigs.push_back("Release");
  1084. tempPath = filepath;
  1085. tempPath += "Debug/";
  1086. tempPath += filename;
  1087. attempted.push_back(tempPath);
  1088. attemptedConfigs.push_back("Debug");
  1089. tempPath = filepath;
  1090. tempPath += "MinSizeRel/";
  1091. tempPath += filename;
  1092. attempted.push_back(tempPath);
  1093. attemptedConfigs.push_back("MinSizeRel");
  1094. tempPath = filepath;
  1095. tempPath += "RelWithDebInfo/";
  1096. tempPath += filename;
  1097. attempted.push_back(tempPath);
  1098. attemptedConfigs.push_back("RelWithDebInfo");
  1099. tempPath = filepath;
  1100. tempPath += "Deployment/";
  1101. tempPath += filename;
  1102. attempted.push_back(tempPath);
  1103. attemptedConfigs.push_back("Deployment");
  1104. tempPath = filepath;
  1105. tempPath += "Development/";
  1106. tempPath += filename;
  1107. attempted.push_back(tempPath);
  1108. attemptedConfigs.push_back("Deployment");
  1109. }
  1110. }
  1111. //----------------------------------------------------------------------
  1112. // Find the appropriate executable to run for a test
  1113. std::string cmCTestTestHandler
  1114. ::FindExecutable(cmCTest *ctest,
  1115. const char *testCommand,
  1116. std::string &resultingConfig,
  1117. std::vector<std::string> &extraPaths,
  1118. std::vector<std::string> &failed)
  1119. {
  1120. // now run the compiled test if we can find it
  1121. std::vector<std::string> attempted;
  1122. std::vector<std::string> attemptedConfigs;
  1123. std::string tempPath;
  1124. std::string filepath =
  1125. cmSystemTools::GetFilenamePath(testCommand);
  1126. std::string filename =
  1127. cmSystemTools::GetFilenameName(testCommand);
  1128. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1129. attemptedConfigs,
  1130. filepath,filename);
  1131. // if extraPaths are provided and we were not passed a full path, try them,
  1132. // try any extra paths
  1133. if (filepath.size() == 0)
  1134. {
  1135. for (unsigned int i = 0; i < extraPaths.size(); ++i)
  1136. {
  1137. std::string filepathExtra =
  1138. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1139. std::string filenameExtra =
  1140. cmSystemTools::GetFilenameName(extraPaths[i]);
  1141. cmCTestTestHandler::AddConfigurations(ctest,attempted,
  1142. attemptedConfigs,
  1143. filepathExtra,
  1144. filenameExtra);
  1145. }
  1146. }
  1147. // store the final location in fullPath
  1148. std::string fullPath;
  1149. // now look in the paths we specified above
  1150. for(unsigned int ai=0;
  1151. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1152. {
  1153. // first check without exe extension
  1154. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1155. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1156. {
  1157. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1158. resultingConfig = attemptedConfigs[ai];
  1159. }
  1160. // then try with the exe extension
  1161. else
  1162. {
  1163. failed.push_back(attempted[ai].c_str());
  1164. tempPath = attempted[ai];
  1165. tempPath += cmSystemTools::GetExecutableExtension();
  1166. if(cmSystemTools::FileExists(tempPath.c_str())
  1167. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1168. {
  1169. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1170. resultingConfig = attemptedConfigs[ai];
  1171. }
  1172. else
  1173. {
  1174. failed.push_back(tempPath.c_str());
  1175. }
  1176. }
  1177. }
  1178. // if everything else failed, check the users path, but only if a full path
  1179. // wasn't specified
  1180. if (fullPath.size() == 0 && filepath.size() == 0)
  1181. {
  1182. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1183. if (path != "")
  1184. {
  1185. resultingConfig = "";
  1186. return path;
  1187. }
  1188. }
  1189. if(fullPath.size() == 0)
  1190. {
  1191. cmCTestLog(ctest, HANDLER_OUTPUT,
  1192. "Could not find executable " << testCommand << "\n"
  1193. << "Looked in the following places:\n");
  1194. for(std::vector<std::string>::iterator i = failed.begin();
  1195. i != failed.end(); ++i)
  1196. {
  1197. cmCTestLog(ctest, HANDLER_OUTPUT,
  1198. i->c_str() << "\n");
  1199. }
  1200. }
  1201. return fullPath;
  1202. }
  1203. //----------------------------------------------------------------------
  1204. void cmCTestTestHandler::GetListOfTests()
  1205. {
  1206. if ( !this->IncludeRegExp.empty() )
  1207. {
  1208. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1209. }
  1210. if ( !this->ExcludeRegExp.empty() )
  1211. {
  1212. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1213. }
  1214. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1215. "Constructing a list of tests" << std::endl);
  1216. cmake cm;
  1217. cmGlobalGenerator gg;
  1218. gg.SetCMakeInstance(&cm);
  1219. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1220. lg->SetGlobalGenerator(&gg);
  1221. cmMakefile *mf = lg->GetMakefile();
  1222. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1223. this->CTest->GetConfigType().c_str());
  1224. // Add handler for ADD_TEST
  1225. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1226. newCom1->TestHandler = this;
  1227. cm.AddCommand(newCom1);
  1228. // Add handler for SUBDIRS
  1229. cmCTestSubdirCommand* newCom2 =
  1230. new cmCTestSubdirCommand;
  1231. newCom2->TestHandler = this;
  1232. cm.AddCommand(newCom2);
  1233. // Add handler for ADD_SUBDIRECTORY
  1234. cmCTestAddSubdirectoryCommand* newCom3 =
  1235. new cmCTestAddSubdirectoryCommand;
  1236. newCom3->TestHandler = this;
  1237. cm.AddCommand(newCom3);
  1238. // Add handler for SET_SOURCE_FILES_PROPERTIES
  1239. cmCTestSetTestsPropertiesCommand* newCom4
  1240. = new cmCTestSetTestsPropertiesCommand;
  1241. newCom4->TestHandler = this;
  1242. cm.AddCommand(newCom4);
  1243. const char* testFilename;
  1244. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  1245. {
  1246. // does the CTestTestfile.cmake exist ?
  1247. testFilename = "CTestTestfile.cmake";
  1248. }
  1249. else
  1250. {
  1251. return;
  1252. }
  1253. if ( !mf->ReadListFile(0, testFilename) )
  1254. {
  1255. return;
  1256. }
  1257. if ( cmSystemTools::GetErrorOccuredFlag() )
  1258. {
  1259. return;
  1260. }
  1261. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1262. "Done constructing a list of tests" << std::endl);
  1263. }
  1264. //----------------------------------------------------------------------
  1265. void cmCTestTestHandler::UseIncludeRegExp()
  1266. {
  1267. this->UseIncludeRegExpFlag = true;
  1268. }
  1269. //----------------------------------------------------------------------
  1270. void cmCTestTestHandler::UseExcludeRegExp()
  1271. {
  1272. this->UseExcludeRegExpFlag = true;
  1273. this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
  1274. }
  1275. //----------------------------------------------------------------------
  1276. const char* cmCTestTestHandler::GetTestStatus(int status)
  1277. {
  1278. static const char statuses[][100] = {
  1279. "Not Run",
  1280. "Timeout",
  1281. "SEGFAULT",
  1282. "ILLEGAL",
  1283. "INTERRUPT",
  1284. "NUMERICAL",
  1285. "OTHER_FAULT",
  1286. "Failed",
  1287. "BAD_COMMAND",
  1288. "Completed"
  1289. };
  1290. if ( status < cmCTestTestHandler::NOT_RUN ||
  1291. status > cmCTestTestHandler::COMPLETED )
  1292. {
  1293. return "No Status";
  1294. }
  1295. return statuses[status];
  1296. }
  1297. //----------------------------------------------------------------------
  1298. void cmCTestTestHandler::ExpandTestsToRunInformation(int numTests)
  1299. {
  1300. if (this->TestsToRunString.empty())
  1301. {
  1302. return;
  1303. }
  1304. int start;
  1305. int end = -1;
  1306. double stride = -1;
  1307. std::string::size_type pos = 0;
  1308. std::string::size_type pos2;
  1309. // read start
  1310. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1311. {
  1312. // read end
  1313. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1314. {
  1315. // read stride
  1316. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1317. {
  1318. int val =0;
  1319. // now read specific numbers
  1320. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1321. {
  1322. this->TestsToRun.push_back(val);
  1323. }
  1324. this->TestsToRun.push_back(val);
  1325. }
  1326. }
  1327. }
  1328. // if start is not specified then we assume we start at 1
  1329. if(start == -1)
  1330. {
  1331. start = 1;
  1332. }
  1333. // if end isnot specified then we assume we end with the last test
  1334. if(end == -1)
  1335. {
  1336. end = numTests;
  1337. }
  1338. // if the stride wasn't specified then it defaults to 1
  1339. if(stride == -1)
  1340. {
  1341. stride = 1;
  1342. }
  1343. // if we have a range then add it
  1344. if(end != -1 && start != -1 && stride > 0)
  1345. {
  1346. int i = 0;
  1347. while (i*stride + start <= end)
  1348. {
  1349. this->TestsToRun.push_back(static_cast<int>(i*stride+start));
  1350. ++i;
  1351. }
  1352. }
  1353. // sort the array
  1354. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1355. std::less<int>());
  1356. // remove duplicates
  1357. std::vector<int>::iterator new_end =
  1358. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1359. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1360. }
  1361. //----------------------------------------------------------------------
  1362. // Just for convenience
  1363. #define SPACE_REGEX "[ \t\r\n]"
  1364. //----------------------------------------------------------------------
  1365. std::string cmCTestTestHandler::GenerateRegressionImages(
  1366. const std::string& xml)
  1367. {
  1368. cmsys::RegularExpression twoattributes(
  1369. "<DartMeasurement"
  1370. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1371. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1372. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1373. cmsys::RegularExpression threeattributes(
  1374. "<DartMeasurement"
  1375. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1376. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1377. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1378. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1379. cmsys::RegularExpression fourattributes(
  1380. "<DartMeasurement"
  1381. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1382. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1383. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1384. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1385. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1386. cmsys::RegularExpression measurementfile(
  1387. "<DartMeasurementFile"
  1388. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1389. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1390. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1391. cmOStringStream ostr;
  1392. bool done = false;
  1393. std::string cxml = xml;
  1394. while ( ! done )
  1395. {
  1396. if ( twoattributes.find(cxml) )
  1397. {
  1398. ostr
  1399. << "\t\t\t<NamedMeasurement"
  1400. << " " << twoattributes.match(1) << "=\""
  1401. << twoattributes.match(2) << "\""
  1402. << " " << twoattributes.match(3) << "=\""
  1403. << twoattributes.match(4) << "\""
  1404. << "><Value>" << twoattributes.match(5)
  1405. << "</Value></NamedMeasurement>"
  1406. << std::endl;
  1407. cxml.erase(twoattributes.start(),
  1408. twoattributes.end() - twoattributes.start());
  1409. }
  1410. else if ( threeattributes.find(cxml) )
  1411. {
  1412. ostr
  1413. << "\t\t\t<NamedMeasurement"
  1414. << " " << threeattributes.match(1) << "=\""
  1415. << threeattributes.match(2) << "\""
  1416. << " " << threeattributes.match(3) << "=\""
  1417. << threeattributes.match(4) << "\""
  1418. << " " << threeattributes.match(5) << "=\""
  1419. << threeattributes.match(6) << "\""
  1420. << "><Value>" << threeattributes.match(7)
  1421. << "</Value></NamedMeasurement>"
  1422. << std::endl;
  1423. cxml.erase(threeattributes.start(),
  1424. threeattributes.end() - threeattributes.start());
  1425. }
  1426. else if ( fourattributes.find(cxml) )
  1427. {
  1428. ostr
  1429. << "\t\t\t<NamedMeasurement"
  1430. << " " << fourattributes.match(1) << "=\""
  1431. << fourattributes.match(2) << "\""
  1432. << " " << fourattributes.match(3) << "=\""
  1433. << fourattributes.match(4) << "\""
  1434. << " " << fourattributes.match(5) << "=\""
  1435. << fourattributes.match(6) << "\""
  1436. << " " << fourattributes.match(7) << "=\""
  1437. << fourattributes.match(8) << "\""
  1438. << "><Value>" << fourattributes.match(9)
  1439. << "</Value></NamedMeasurement>"
  1440. << std::endl;
  1441. cxml.erase(fourattributes.start(),
  1442. fourattributes.end() - fourattributes.start());
  1443. }
  1444. else if ( measurementfile.find(cxml) )
  1445. {
  1446. const std::string& filename =
  1447. cmCTest::CleanString(measurementfile.match(5));
  1448. if ( cmSystemTools::FileExists(filename.c_str()) )
  1449. {
  1450. long len = cmSystemTools::FileLength(filename.c_str());
  1451. if ( len == 0 )
  1452. {
  1453. std::string k1 = measurementfile.match(1);
  1454. std::string v1 = measurementfile.match(2);
  1455. std::string k2 = measurementfile.match(3);
  1456. std::string v2 = measurementfile.match(4);
  1457. if ( cmSystemTools::LowerCase(k1) == "type" )
  1458. {
  1459. v1 = "text/string";
  1460. }
  1461. if ( cmSystemTools::LowerCase(k2) == "type" )
  1462. {
  1463. v2 = "text/string";
  1464. }
  1465. ostr
  1466. << "\t\t\t<NamedMeasurement"
  1467. << " " << k1 << "=\"" << v1 << "\""
  1468. << " " << k2 << "=\"" << v2 << "\""
  1469. << " encoding=\"none\""
  1470. << "><Value>Image " << filename.c_str()
  1471. << " is empty</Value></NamedMeasurement>";
  1472. }
  1473. else
  1474. {
  1475. std::ifstream ifs(filename.c_str(), std::ios::in
  1476. #ifdef _WIN32
  1477. | std::ios::binary
  1478. #endif
  1479. );
  1480. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1481. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1482. unsigned char *encoded_buffer
  1483. = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1484. unsigned long rlen
  1485. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1486. unsigned long cc;
  1487. ostr
  1488. << "\t\t\t<NamedMeasurement"
  1489. << " " << measurementfile.match(1) << "=\""
  1490. << measurementfile.match(2) << "\""
  1491. << " " << measurementfile.match(3) << "=\""
  1492. << measurementfile.match(4) << "\""
  1493. << " encoding=\"base64\""
  1494. << ">" << std::endl << "\t\t\t\t<Value>";
  1495. for ( cc = 0; cc < rlen; cc ++ )
  1496. {
  1497. ostr << encoded_buffer[cc];
  1498. if ( cc % 60 == 0 && cc )
  1499. {
  1500. ostr << std::endl;
  1501. }
  1502. }
  1503. ostr
  1504. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1505. << std::endl;
  1506. delete [] file_buffer;
  1507. delete [] encoded_buffer;
  1508. }
  1509. }
  1510. else
  1511. {
  1512. int idx = 4;
  1513. if ( measurementfile.match(1) == "name" )
  1514. {
  1515. idx = 2;
  1516. }
  1517. ostr
  1518. << "\t\t\t<NamedMeasurement"
  1519. << " name=\"" << measurementfile.match(idx) << "\""
  1520. << " text=\"text/string\""
  1521. << "><Value>File " << filename.c_str()
  1522. << " not found</Value></NamedMeasurement>"
  1523. << std::endl;
  1524. cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
  1525. << "\" not found." << std::endl);
  1526. }
  1527. cxml.erase(measurementfile.start(),
  1528. measurementfile.end() - measurementfile.start());
  1529. }
  1530. else
  1531. {
  1532. done = true;
  1533. }
  1534. }
  1535. return ostr.str();
  1536. }
  1537. //----------------------------------------------------------------------
  1538. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1539. {
  1540. this->IncludeRegExp = arg;
  1541. }
  1542. //----------------------------------------------------------------------
  1543. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1544. {
  1545. this->ExcludeRegExp = arg;
  1546. }
  1547. //----------------------------------------------------------------------
  1548. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1549. {
  1550. if ( !in )
  1551. {
  1552. return;
  1553. }
  1554. this->TestsToRunString = in;
  1555. // if the argument is a file, then read it and use the contents as the
  1556. // string
  1557. if(cmSystemTools::FileExists(in))
  1558. {
  1559. std::ifstream fin(in);
  1560. unsigned long filelen = cmSystemTools::FileLength(in);
  1561. char* buff = new char[filelen+1];
  1562. fin.getline(buff, filelen);
  1563. buff[fin.gcount()] = 0;
  1564. this->TestsToRunString = buff;
  1565. }
  1566. }
  1567. //----------------------------------------------------------------------
  1568. bool cmCTestTestHandler::CleanTestOutput(std::string& output,
  1569. size_t remove_threshold)
  1570. {
  1571. if ( remove_threshold == 0 )
  1572. {
  1573. return true;
  1574. }
  1575. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  1576. {
  1577. return true;
  1578. }
  1579. cmOStringStream ostr;
  1580. std::string::size_type cc;
  1581. std::string::size_type skipsize = 0;
  1582. int inTag = 0;
  1583. int skipped = 0;
  1584. for ( cc = 0; cc < output.size(); cc ++ )
  1585. {
  1586. int ch = output[cc];
  1587. if ( ch < 0 || ch > 255 )
  1588. {
  1589. break;
  1590. }
  1591. if ( ch == '<' )
  1592. {
  1593. inTag = 1;
  1594. }
  1595. if ( !inTag )
  1596. {
  1597. int notskip = 0;
  1598. // Skip
  1599. if ( skipsize < remove_threshold )
  1600. {
  1601. ostr << static_cast<char>(ch);
  1602. notskip = 1;
  1603. }
  1604. skipsize ++;
  1605. if ( notskip && skipsize >= remove_threshold )
  1606. {
  1607. skipped = 1;
  1608. }
  1609. }
  1610. else
  1611. {
  1612. ostr << static_cast<char>(ch);
  1613. }
  1614. if ( ch == '>' )
  1615. {
  1616. inTag = 0;
  1617. }
  1618. }
  1619. if ( skipped )
  1620. {
  1621. ostr << "..." << std::endl << "The rest of the test output was removed "
  1622. "since it exceeds the threshold of "
  1623. << remove_threshold << " characters." << std::endl;
  1624. }
  1625. output = ostr.str();
  1626. return true;
  1627. }
  1628. //----------------------------------------------------------------------
  1629. bool cmCTestTestHandler::SetTestsProperties(
  1630. const std::vector<std::string>& args)
  1631. {
  1632. std::vector<std::string>::const_iterator it;
  1633. std::vector<cmStdString> tests;
  1634. bool found = false;
  1635. for ( it = args.begin(); it != args.end(); ++ it )
  1636. {
  1637. if ( *it == "PROPERTIES" )
  1638. {
  1639. found = true;
  1640. break;
  1641. }
  1642. tests.push_back(*it);
  1643. }
  1644. if ( !found )
  1645. {
  1646. return false;
  1647. }
  1648. ++ it; // skip PROPERTIES
  1649. for ( ; it != args.end(); ++ it )
  1650. {
  1651. std::string key = *it;
  1652. ++ it;
  1653. if ( it == args.end() )
  1654. {
  1655. break;
  1656. }
  1657. std::string val = *it;
  1658. std::vector<cmStdString>::const_iterator tit;
  1659. for ( tit = tests.begin(); tit != tests.end(); ++ tit )
  1660. {
  1661. cmCTestTestHandler::ListOfTests::iterator rtit;
  1662. for ( rtit = this->TestList.begin();
  1663. rtit != this->TestList.end();
  1664. ++ rtit )
  1665. {
  1666. if ( *tit == rtit->Name )
  1667. {
  1668. if ( key == "WILL_FAIL" )
  1669. {
  1670. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  1671. }
  1672. if ( key == "TIMEOUT" )
  1673. {
  1674. rtit->Timeout = atof(val.c_str());
  1675. }
  1676. if ( key == "FAIL_REGULAR_EXPRESSION" )
  1677. {
  1678. std::vector<std::string> lval;
  1679. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1680. std::vector<std::string>::iterator crit;
  1681. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1682. {
  1683. rtit->ErrorRegularExpressions.push_back(
  1684. std::pair<cmsys::RegularExpression, std::string>(
  1685. cmsys::RegularExpression(crit->c_str()),
  1686. std::string(crit->c_str())));
  1687. }
  1688. }
  1689. if ( key == "MEASUREMENT" )
  1690. {
  1691. size_t pos = val.find_first_of("=");
  1692. if ( pos != val.npos )
  1693. {
  1694. std::string mKey = val.substr(0, pos);
  1695. const char* mVal = val.c_str() + pos + 1;
  1696. rtit->Measurements[mKey] = mVal;
  1697. }
  1698. else
  1699. {
  1700. rtit->Measurements[val] = "1";
  1701. }
  1702. }
  1703. if ( key == "PASS_REGULAR_EXPRESSION" )
  1704. {
  1705. std::vector<std::string> lval;
  1706. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1707. std::vector<std::string>::iterator crit;
  1708. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1709. {
  1710. rtit->RequiredRegularExpressions.push_back(
  1711. std::pair<cmsys::RegularExpression, std::string>(
  1712. cmsys::RegularExpression(crit->c_str()),
  1713. std::string(crit->c_str())));
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. return true;
  1721. }
  1722. //----------------------------------------------------------------------
  1723. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  1724. {
  1725. const std::string& testname = args[0];
  1726. cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
  1727. if (this->UseExcludeRegExpFlag &&
  1728. this->UseExcludeRegExpFirst &&
  1729. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1730. {
  1731. return true;
  1732. }
  1733. if ( this->MemCheck )
  1734. {
  1735. std::vector<cmStdString>::iterator it;
  1736. bool found = false;
  1737. for ( it = this->CustomTestsIgnore.begin();
  1738. it != this->CustomTestsIgnore.end(); ++ it )
  1739. {
  1740. if ( *it == testname )
  1741. {
  1742. found = true;
  1743. break;
  1744. }
  1745. }
  1746. if ( found )
  1747. {
  1748. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
  1749. << *it << std::endl);
  1750. return true;
  1751. }
  1752. }
  1753. else
  1754. {
  1755. std::vector<cmStdString>::iterator it;
  1756. bool found = false;
  1757. for ( it = this->CustomTestsIgnore.begin();
  1758. it != this->CustomTestsIgnore.end(); ++ it )
  1759. {
  1760. if ( *it == testname )
  1761. {
  1762. found = true;
  1763. break;
  1764. }
  1765. }
  1766. if ( found )
  1767. {
  1768. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
  1769. << *it << std::endl);
  1770. return true;
  1771. }
  1772. }
  1773. cmCTestTestProperties test;
  1774. test.Name = testname;
  1775. test.Args = args;
  1776. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  1777. cmCTestLog(this->CTest, DEBUG, "Set test directory: "
  1778. << test.Directory << std::endl);
  1779. test.IsInBasedOnREOptions = true;
  1780. test.WillFail = false;
  1781. test.Timeout = 0;
  1782. if (this->UseIncludeRegExpFlag &&
  1783. !this->IncludeTestsRegularExpression.find(testname.c_str()))
  1784. {
  1785. test.IsInBasedOnREOptions = false;
  1786. }
  1787. else if (this->UseExcludeRegExpFlag &&
  1788. !this->UseExcludeRegExpFirst &&
  1789. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  1790. {
  1791. test.IsInBasedOnREOptions = false;
  1792. }
  1793. this->TestList.push_back(test);
  1794. return true;
  1795. }