cmCTestTestHandler.cxx 62 KB

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