cmCTestTestHandler.cxx 69 KB

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