cmCTestTestHandler.cxx 66 KB

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