cmCTestTestHandler.cxx 68 KB

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