cmCTestTestHandler.cxx 67 KB

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