cmCTestTestHandler.cxx 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  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 <memory> // auto_ptr
  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() { return "subdirs";}
  54. // Unused methods
  55. virtual const char* GetTerseDocumentation() { return ""; }
  56. virtual const char* GetFullDocumentation() { 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() { return "add_subdirectory";}
  147. // Unused methods
  148. virtual const char* GetTerseDocumentation() { return ""; }
  149. virtual const char* GetFullDocumentation() { 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() { return "ADD_TEST";}
  228. // Unused methods
  229. virtual const char* GetTerseDocumentation() { return ""; }
  230. virtual const char* GetFullDocumentation() { 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() { return "SET_TESTS_PROPERTIES";}
  269. // Unused methods
  270. virtual const char* GetTerseDocumentation() { return ""; }
  271. virtual const char* GetFullDocumentation() { 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. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  549. for(ftit = this->TestResults.begin();
  550. ftit != this->TestResults.end(); ++ftit)
  551. {
  552. if ( ftit->Status != cmCTestTestHandler::COMPLETED )
  553. {
  554. ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
  555. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
  556. << ftit->TestCount << " - "
  557. << ftit->Name.c_str() << " ("
  558. << this->GetTestStatus(ftit->Status) << ")"
  559. << std::endl);
  560. }
  561. }
  562. }
  563. }
  564. if ( this->CTest->GetProduceXML() )
  565. {
  566. cmGeneratedFileStream xmlfile;
  567. if( !this->StartResultingXML(
  568. (this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
  569. (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
  570. {
  571. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
  572. << (this->MemCheck ? "memory check" : "testing")
  573. << " XML file" << std::endl);
  574. this->LogFile = 0;
  575. return 1;
  576. }
  577. this->GenerateDartOutput(xmlfile);
  578. }
  579. if ( ! this->PostProcessHandler() )
  580. {
  581. this->LogFile = 0;
  582. return -1;
  583. }
  584. if ( !failed.empty() )
  585. {
  586. this->LogFile = 0;
  587. return -1;
  588. }
  589. this->LogFile = 0;
  590. return 0;
  591. }
  592. //----------------------------------------------------------------------
  593. void cmCTestTestHandler::PrintLabelSummary()
  594. {
  595. cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
  596. cmCTestTestHandler::TestResultsVector::iterator ri =
  597. this->TestResults.begin();
  598. std::map<cmStdString, double> labelTimes;
  599. std::set<cmStdString> labels;
  600. // initialize maps
  601. std::string::size_type maxlen = 0;
  602. for(; it != this->TestList.end(); ++it)
  603. {
  604. cmCTestTestProperties& p = *it;
  605. if(p.Labels.size() != 0)
  606. {
  607. for(std::vector<std::string>::iterator l = p.Labels.begin();
  608. l != p.Labels.end(); ++l)
  609. {
  610. if((*l).size() > maxlen)
  611. {
  612. maxlen = (*l).size();
  613. }
  614. labels.insert(*l);
  615. labelTimes[*l] = 0;
  616. }
  617. }
  618. }
  619. ri = this->TestResults.begin();
  620. // fill maps
  621. for(; ri != this->TestResults.end(); ++ri)
  622. {
  623. cmCTestTestResult &result = *ri;
  624. cmCTestTestProperties& p = *result.Properties;
  625. if(p.Labels.size() != 0)
  626. {
  627. for(std::vector<std::string>::iterator l = p.Labels.begin();
  628. l != p.Labels.end(); ++l)
  629. {
  630. labelTimes[*l] += result.ExecutionTime;
  631. }
  632. }
  633. }
  634. // now print times
  635. if(labels.size())
  636. {
  637. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nLabel Time Summary:");
  638. }
  639. for(std::set<cmStdString>::const_iterator i = labels.begin();
  640. i != labels.end(); ++i)
  641. {
  642. std::string label = *i;
  643. label.resize(maxlen +3, ' ');
  644. char buf[1024];
  645. sprintf(buf, "%6.2f sec", labelTimes[*i]);
  646. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\n"
  647. << label << " = " << buf );
  648. if ( this->LogFile )
  649. {
  650. *this->LogFile << "\n" << *i << " = "
  651. << buf << "\n";
  652. }
  653. }
  654. if(labels.size())
  655. {
  656. if(this->LogFile)
  657. {
  658. *this->LogFile << "\n";
  659. }
  660. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\n");
  661. }
  662. }
  663. //----------------------------------------------------------------------
  664. void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
  665. {
  666. // if not using Labels to filter then return
  667. if (!this->UseIncludeLabelRegExpFlag )
  668. {
  669. return;
  670. }
  671. // if there are no labels and we are filtering by labels
  672. // then exclude the test as it does not have the label
  673. if(it.Labels.size() == 0 )
  674. {
  675. it.IsInBasedOnREOptions = false;
  676. return;
  677. }
  678. // check to see if the label regular expression matches
  679. bool found = false; // assume it does not match
  680. // loop over all labels and look for match
  681. for(std::vector<std::string>::iterator l = it.Labels.begin();
  682. l != it.Labels.end(); ++l)
  683. {
  684. if(this->IncludeLabelRegularExpression.find(*l))
  685. {
  686. found = true;
  687. }
  688. }
  689. // if no match was found, exclude the test
  690. if(!found)
  691. {
  692. it.IsInBasedOnREOptions = false;
  693. }
  694. }
  695. //----------------------------------------------------------------------
  696. void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
  697. {
  698. // if not using Labels to filter then return
  699. if (!this->UseExcludeLabelRegExpFlag )
  700. {
  701. return;
  702. }
  703. // if there are no labels and we are excluding by labels
  704. // then do nothing as a no label can not be a match
  705. if(it.Labels.size() == 0 )
  706. {
  707. return;
  708. }
  709. // check to see if the label regular expression matches
  710. bool found = false; // assume it does not match
  711. // loop over all labels and look for match
  712. for(std::vector<std::string>::iterator l = it.Labels.begin();
  713. l != it.Labels.end(); ++l)
  714. {
  715. if(this->ExcludeLabelRegularExpression.find(*l))
  716. {
  717. found = true;
  718. }
  719. }
  720. // if match was found, exclude the test
  721. if(found)
  722. {
  723. it.IsInBasedOnREOptions = false;
  724. }
  725. }
  726. //----------------------------------------------------------------------
  727. void cmCTestTestHandler::CheckLabelFilter(cmCTestTestProperties& it)
  728. {
  729. this->CheckLabelFilterInclude(it);
  730. this->CheckLabelFilterExclude(it);
  731. }
  732. //----------------------------------------------------------------------
  733. void cmCTestTestHandler::ComputeTestList()
  734. {
  735. this->TestList.clear(); // clear list of test
  736. this->GetListOfTests();
  737. cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
  738. // how many tests are in based on RegExp?
  739. int inREcnt = 0;
  740. cmCTestTestHandler::ListOfTests::iterator it;
  741. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  742. {
  743. this->CheckLabelFilter(*it);
  744. if (it->IsInBasedOnREOptions)
  745. {
  746. inREcnt ++;
  747. }
  748. }
  749. // expand the test list based on the union flag
  750. if (this->UseUnion)
  751. {
  752. this->ExpandTestsToRunInformation((int)tmsize);
  753. }
  754. else
  755. {
  756. this->ExpandTestsToRunInformation(inREcnt);
  757. }
  758. // Now create a final list of tests to run
  759. int cnt = 0;
  760. inREcnt = 0;
  761. std::string last_directory = "";
  762. ListOfTests finalList;
  763. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  764. {
  765. cnt ++;
  766. if (it->IsInBasedOnREOptions)
  767. {
  768. inREcnt++;
  769. }
  770. if (this->UseUnion)
  771. {
  772. // if it is not in the list and not in the regexp then skip
  773. if ((this->TestsToRun.size() &&
  774. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
  775. == this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
  776. {
  777. continue;
  778. }
  779. }
  780. else
  781. {
  782. // is this test in the list of tests to run? If not then skip it
  783. if ((this->TestsToRun.size() &&
  784. std::find(this->TestsToRun.begin(),
  785. this->TestsToRun.end(), inREcnt)
  786. == this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
  787. {
  788. continue;
  789. }
  790. }
  791. it->Index = cnt; // save the index into the test list for this test
  792. finalList.push_back(*it);
  793. }
  794. // Save the total number of tests before exclusions
  795. this->TotalNumberOfTests = this->TestList.size();
  796. // Set the TestList to the final list of all test
  797. this->TestList = finalList;
  798. std::string::size_type max = this->CTest->GetMaxTestNameWidth();
  799. for (it = this->TestList.begin();
  800. it != this->TestList.end(); it ++ )
  801. {
  802. cmCTestTestProperties& p = *it;
  803. if(max < p.Name.size())
  804. {
  805. max = p.Name.size();
  806. }
  807. }
  808. if(static_cast<std::string::size_type>(this->CTest->GetMaxTestNameWidth())
  809. != max)
  810. {
  811. this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
  812. }
  813. }
  814. bool cmCTestTestHandler::GetValue(const char* tag,
  815. int& value,
  816. std::ifstream& fin)
  817. {
  818. std::string line;
  819. bool ret = true;
  820. cmSystemTools::GetLineFromStream(fin, line);
  821. if(line == tag)
  822. {
  823. fin >> value;
  824. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  825. }
  826. else
  827. {
  828. cmCTestLog(this->CTest, ERROR_MESSAGE,
  829. "parse error: missing tag: "
  830. << tag << " found [" << line << "]" << std::endl);
  831. ret = false;
  832. }
  833. return ret;
  834. }
  835. bool cmCTestTestHandler::GetValue(const char* tag,
  836. double& value,
  837. std::ifstream& fin)
  838. {
  839. std::string line;
  840. cmSystemTools::GetLineFromStream(fin, line);
  841. bool ret = true;
  842. if(line == tag)
  843. {
  844. fin >> value;
  845. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  846. }
  847. else
  848. {
  849. cmCTestLog(this->CTest, ERROR_MESSAGE,
  850. "parse error: missing tag: "
  851. << tag << " found [" << line << "]" << std::endl);
  852. ret = false;
  853. }
  854. return ret;
  855. }
  856. bool cmCTestTestHandler::GetValue(const char* tag,
  857. bool& value,
  858. std::ifstream& fin)
  859. {
  860. std::string line;
  861. cmSystemTools::GetLineFromStream(fin, line);
  862. bool ret = true;
  863. if(line == tag)
  864. {
  865. #ifdef __HAIKU__
  866. int tmp = 0;
  867. fin >> tmp;
  868. value = false;
  869. if(tmp)
  870. {
  871. value = true;
  872. }
  873. #else
  874. fin >> value;
  875. #endif
  876. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  877. }
  878. else
  879. {
  880. cmCTestLog(this->CTest, ERROR_MESSAGE,
  881. "parse error: missing tag: "
  882. << tag << " found [" << line << "]" << std::endl);
  883. ret = false;
  884. }
  885. return ret;
  886. }
  887. bool cmCTestTestHandler::GetValue(const char* tag,
  888. size_t& value,
  889. std::ifstream& fin)
  890. {
  891. std::string line;
  892. cmSystemTools::GetLineFromStream(fin, line);
  893. bool ret = true;
  894. if(line == tag)
  895. {
  896. fin >> value;
  897. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  898. }
  899. else
  900. {
  901. cmCTestLog(this->CTest, ERROR_MESSAGE,
  902. "parse error: missing tag: "
  903. << tag << " found [" << line.c_str() << "]" << std::endl);
  904. ret = false;
  905. }
  906. return ret;
  907. }
  908. bool cmCTestTestHandler::GetValue(const char* tag,
  909. std::string& value,
  910. std::ifstream& fin)
  911. {
  912. std::string line;
  913. cmSystemTools::GetLineFromStream(fin, line);
  914. bool ret = true;
  915. if(line == tag)
  916. {
  917. ret = cmSystemTools::GetLineFromStream(fin, value);
  918. }
  919. else
  920. {
  921. cmCTestLog(this->CTest, ERROR_MESSAGE,
  922. "parse error: missing tag: "
  923. << tag << " found [" << line << "]" << std::endl);
  924. ret = false;
  925. }
  926. return ret;
  927. }
  928. //---------------------------------------------------------------------
  929. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  930. std::vector<cmStdString> &failed)
  931. {
  932. this->ComputeTestList();
  933. this->StartTest = this->CTest->CurrentTime();
  934. this->StartTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  935. double elapsed_time_start = cmSystemTools::GetTime();
  936. cmCTestMultiProcessHandler* parallel = this->CTest->GetBatchJobs() ?
  937. new cmCTestBatchTestHandler : new cmCTestMultiProcessHandler;
  938. parallel->SetCTest(this->CTest);
  939. parallel->SetParallelLevel(this->CTest->GetParallelLevel());
  940. parallel->SetTestHandler(this);
  941. *this->LogFile << "Start testing: "
  942. << this->CTest->CurrentTime() << std::endl
  943. << "----------------------------------------------------------"
  944. << std::endl;
  945. cmCTestMultiProcessHandler::TestMap tests;
  946. cmCTestMultiProcessHandler::PropertiesMap properties;
  947. bool randomSchedule = this->CTest->GetScheduleType() == "Random";
  948. if(randomSchedule)
  949. {
  950. srand((unsigned)time(0));
  951. }
  952. for (ListOfTests::iterator it = this->TestList.begin();
  953. it != this->TestList.end(); ++it)
  954. {
  955. cmCTestTestProperties& p = *it;
  956. cmCTestMultiProcessHandler::TestSet depends;
  957. if(randomSchedule)
  958. {
  959. p.Cost = static_cast<float>(rand());
  960. }
  961. if(p.Timeout == 0 && this->CTest->GetGlobalTimeout() != 0)
  962. {
  963. p.Timeout = this->CTest->GetGlobalTimeout();
  964. }
  965. if(p.Depends.size())
  966. {
  967. for(std::vector<std::string>::iterator i = p.Depends.begin();
  968. i != p.Depends.end(); ++i)
  969. {
  970. for(ListOfTests::iterator it2 = this->TestList.begin();
  971. it2 != this->TestList.end(); ++it2)
  972. {
  973. if(it2->Name == *i)
  974. {
  975. depends.insert(it2->Index);
  976. break; // break out of test loop as name can only match 1
  977. }
  978. }
  979. }
  980. }
  981. tests[it->Index] = depends;
  982. properties[it->Index] = &*it;
  983. }
  984. parallel->SetTests(tests, properties);
  985. parallel->SetPassFailVectors(&passed, &failed);
  986. this->TestResults.clear();
  987. parallel->SetTestResults(&this->TestResults);
  988. if(this->CTest->ShouldPrintLabels())
  989. {
  990. parallel->PrintLabels();
  991. }
  992. else if(this->CTest->GetShowOnly())
  993. {
  994. parallel->PrintTestList();
  995. }
  996. else
  997. {
  998. parallel->RunTests();
  999. }
  1000. delete parallel;
  1001. this->EndTest = this->CTest->CurrentTime();
  1002. this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  1003. this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  1004. *this->LogFile << "End testing: "
  1005. << this->CTest->CurrentTime() << std::endl;
  1006. }
  1007. //----------------------------------------------------------------------
  1008. void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&)
  1009. {
  1010. }
  1011. //----------------------------------------------------------------------
  1012. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  1013. {
  1014. if ( !this->CTest->GetProduceXML() )
  1015. {
  1016. return;
  1017. }
  1018. this->CTest->StartXML(os, this->AppendXML);
  1019. os << "<Testing>\n"
  1020. << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
  1021. << "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
  1022. << "\t<TestList>\n";
  1023. cmCTestTestHandler::TestResultsVector::size_type cc;
  1024. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  1025. {
  1026. cmCTestTestResult *result = &this->TestResults[cc];
  1027. std::string testPath = result->Path + "/" + result->Name;
  1028. os << "\t\t<Test>" << cmXMLSafe(
  1029. this->CTest->GetShortPathToFile(testPath.c_str()))
  1030. << "</Test>" << std::endl;
  1031. }
  1032. os << "\t</TestList>\n";
  1033. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  1034. {
  1035. cmCTestTestResult *result = &this->TestResults[cc];
  1036. this->WriteTestResultHeader(os, result);
  1037. os << "\t\t<Results>" << std::endl;
  1038. if ( result->Status != cmCTestTestHandler::NOT_RUN )
  1039. {
  1040. if ( result->Status != cmCTestTestHandler::COMPLETED ||
  1041. result->ReturnValue )
  1042. {
  1043. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1044. "name=\"Exit Code\"><Value>"
  1045. << cmXMLSafe(this->GetTestStatus(result->Status))
  1046. << "</Value>"
  1047. "</NamedMeasurement>\n"
  1048. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1049. "name=\"Exit Value\"><Value>"
  1050. << result->ReturnValue
  1051. << "</Value></NamedMeasurement>"
  1052. << std::endl;
  1053. }
  1054. os << result->RegressionImages;
  1055. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1056. << "name=\"Execution Time\"><Value>"
  1057. << result->ExecutionTime
  1058. << "</Value></NamedMeasurement>\n";
  1059. if(result->Reason.size())
  1060. {
  1061. const char* reasonType = "Pass Reason";
  1062. if(result->Status != cmCTestTestHandler::COMPLETED &&
  1063. result->Status != cmCTestTestHandler::NOT_RUN)
  1064. {
  1065. reasonType = "Fail Reason";
  1066. }
  1067. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1068. << "name=\"" << reasonType << "\"><Value>"
  1069. << cmXMLSafe(result->Reason)
  1070. << "</Value></NamedMeasurement>\n";
  1071. }
  1072. os
  1073. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1074. << "name=\"Completion Status\"><Value>"
  1075. << cmXMLSafe(result->CompletionStatus)
  1076. << "</Value></NamedMeasurement>\n";
  1077. }
  1078. os
  1079. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1080. << "name=\"Command Line\"><Value>"
  1081. << cmXMLSafe(result->FullCommandLine)
  1082. << "</Value></NamedMeasurement>\n";
  1083. std::map<cmStdString,cmStdString>::iterator measureIt;
  1084. for ( measureIt = result->Properties->Measurements.begin();
  1085. measureIt != result->Properties->Measurements.end();
  1086. ++ measureIt )
  1087. {
  1088. os
  1089. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1090. << "name=\"" << measureIt->first.c_str() << "\"><Value>"
  1091. << cmXMLSafe(measureIt->second)
  1092. << "</Value></NamedMeasurement>\n";
  1093. }
  1094. os
  1095. << "\t\t\t<Measurement>\n"
  1096. << "\t\t\t\t<Value"
  1097. << (result->CompressOutput ?
  1098. " encoding=\"base64\" compression=\"gzip\">"
  1099. : ">");
  1100. os << cmXMLSafe(result->Output);
  1101. os
  1102. << "</Value>\n"
  1103. << "\t\t\t</Measurement>\n"
  1104. << "\t\t</Results>\n";
  1105. this->AttachFiles(os, result);
  1106. this->WriteTestResultFooter(os, result);
  1107. }
  1108. os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
  1109. << "\t<EndTestTime>" << this->EndTestTime << "</EndTestTime>\n"
  1110. << "<ElapsedMinutes>"
  1111. << static_cast<int>(this->ElapsedTestingTime/6)/10.0
  1112. << "</ElapsedMinutes>"
  1113. << "</Testing>" << std::endl;
  1114. this->CTest->EndXML(os);
  1115. }
  1116. //----------------------------------------------------------------------------
  1117. void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os,
  1118. cmCTestTestResult* result)
  1119. {
  1120. os << "\t<Test Status=\"";
  1121. if ( result->Status == cmCTestTestHandler::COMPLETED )
  1122. {
  1123. os << "passed";
  1124. }
  1125. else if ( result->Status == cmCTestTestHandler::NOT_RUN )
  1126. {
  1127. os << "notrun";
  1128. }
  1129. else
  1130. {
  1131. os << "failed";
  1132. }
  1133. std::string testPath = result->Path + "/" + result->Name;
  1134. os << "\">\n"
  1135. << "\t\t<Name>" << cmXMLSafe(result->Name) << "</Name>\n"
  1136. << "\t\t<Path>" << cmXMLSafe(
  1137. this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
  1138. << "\t\t<FullName>" << cmXMLSafe(
  1139. this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  1140. << "\t\t<FullCommandLine>"
  1141. << cmXMLSafe(result->FullCommandLine)
  1142. << "</FullCommandLine>\n";
  1143. }
  1144. //----------------------------------------------------------------------------
  1145. void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os,
  1146. cmCTestTestResult* result)
  1147. {
  1148. if(!result->Properties->Labels.empty())
  1149. {
  1150. os << "\t\t<Labels>\n";
  1151. std::vector<std::string> const& labels = result->Properties->Labels;
  1152. for(std::vector<std::string>::const_iterator li = labels.begin();
  1153. li != labels.end(); ++li)
  1154. {
  1155. os << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n";
  1156. }
  1157. os << "\t\t</Labels>\n";
  1158. }
  1159. os
  1160. << "\t</Test>" << std::endl;
  1161. }
  1162. //----------------------------------------------------------------------
  1163. void cmCTestTestHandler::AttachFiles(std::ostream& os,
  1164. cmCTestTestResult* result)
  1165. {
  1166. if(result->Status != cmCTestTestHandler::COMPLETED
  1167. && result->Properties->AttachOnFail.size())
  1168. {
  1169. result->Properties->AttachedFiles.insert(
  1170. result->Properties->AttachedFiles.end(),
  1171. result->Properties->AttachOnFail.begin(),
  1172. result->Properties->AttachOnFail.end());
  1173. }
  1174. for(std::vector<std::string>::const_iterator file =
  1175. result->Properties->AttachedFiles.begin();
  1176. file != result->Properties->AttachedFiles.end(); ++file)
  1177. {
  1178. std::string base64 = this->CTest->Base64GzipEncodeFile(*file);
  1179. std::string fname = cmSystemTools::GetFilenameName(*file);
  1180. os << "\t\t<NamedMeasurement name=\"Attached File\" encoding=\"base64\" "
  1181. "compression=\"tar/gzip\" filename=\"" << fname << "\" type=\"file\">"
  1182. "\n\t\t\t<Value>\n\t\t\t"
  1183. << base64
  1184. << "\n\t\t\t</Value>\n\t\t</NamedMeasurement>\n";
  1185. }
  1186. }
  1187. //----------------------------------------------------------------------
  1188. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  1189. {
  1190. std::vector<cmStdString>::iterator it;
  1191. for ( it = vec.begin(); it != vec.end(); ++it )
  1192. {
  1193. int retVal = 0;
  1194. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
  1195. << std::endl);
  1196. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
  1197. /*this->Verbose*/) || retVal != 0 )
  1198. {
  1199. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
  1200. << *it << std::endl);
  1201. return 0;
  1202. }
  1203. }
  1204. return 1;
  1205. }
  1206. //----------------------------------------------------------------------
  1207. // Find the appropriate executable to run for a test
  1208. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  1209. {
  1210. std::string resConfig;
  1211. std::vector<std::string> extraPaths;
  1212. std::vector<std::string> failedPaths;
  1213. if(strcmp(exe, "NOT_AVAILABLE") == 0)
  1214. {
  1215. return exe;
  1216. }
  1217. return cmCTestTestHandler::FindExecutable(this->CTest,
  1218. exe, resConfig,
  1219. extraPaths,
  1220. failedPaths);
  1221. }
  1222. // add additional configurations to the search path
  1223. void cmCTestTestHandler
  1224. ::AddConfigurations(cmCTest *ctest,
  1225. std::vector<std::string> &attempted,
  1226. std::vector<std::string> &attemptedConfigs,
  1227. std::string filepath,
  1228. std::string &filename)
  1229. {
  1230. std::string tempPath;
  1231. if (filepath.size() &&
  1232. filepath[filepath.size()-1] != '/')
  1233. {
  1234. filepath += "/";
  1235. }
  1236. tempPath = filepath + filename;
  1237. attempted.push_back(tempPath);
  1238. attemptedConfigs.push_back("");
  1239. if(ctest->GetConfigType().size())
  1240. {
  1241. tempPath = filepath;
  1242. tempPath += ctest->GetConfigType();
  1243. tempPath += "/";
  1244. tempPath += filename;
  1245. attempted.push_back(tempPath);
  1246. attemptedConfigs.push_back(ctest->GetConfigType());
  1247. // If the file is an OSX bundle then the configtyp
  1248. // will be at the start of the path
  1249. tempPath = ctest->GetConfigType();
  1250. tempPath += "/";
  1251. tempPath += filepath;
  1252. tempPath += filename;
  1253. attempted.push_back(tempPath);
  1254. attemptedConfigs.push_back(ctest->GetConfigType());
  1255. }
  1256. else
  1257. {
  1258. // no config specified to try some options
  1259. tempPath = filepath;
  1260. tempPath += "Release/";
  1261. tempPath += filename;
  1262. attempted.push_back(tempPath);
  1263. attemptedConfigs.push_back("Release");
  1264. tempPath = filepath;
  1265. tempPath += "Debug/";
  1266. tempPath += filename;
  1267. attempted.push_back(tempPath);
  1268. attemptedConfigs.push_back("Debug");
  1269. tempPath = filepath;
  1270. tempPath += "MinSizeRel/";
  1271. tempPath += filename;
  1272. attempted.push_back(tempPath);
  1273. attemptedConfigs.push_back("MinSizeRel");
  1274. tempPath = filepath;
  1275. tempPath += "RelWithDebInfo/";
  1276. tempPath += filename;
  1277. attempted.push_back(tempPath);
  1278. attemptedConfigs.push_back("RelWithDebInfo");
  1279. tempPath = filepath;
  1280. tempPath += "Deployment/";
  1281. tempPath += filename;
  1282. attempted.push_back(tempPath);
  1283. attemptedConfigs.push_back("Deployment");
  1284. tempPath = filepath;
  1285. tempPath += "Development/";
  1286. tempPath += filename;
  1287. attempted.push_back(tempPath);
  1288. attemptedConfigs.push_back("Deployment");
  1289. }
  1290. }
  1291. //----------------------------------------------------------------------
  1292. // Find the appropriate executable to run for a test
  1293. std::string cmCTestTestHandler
  1294. ::FindExecutable(cmCTest *ctest,
  1295. const char *testCommand,
  1296. std::string &resultingConfig,
  1297. std::vector<std::string> &extraPaths,
  1298. std::vector<std::string> &failed)
  1299. {
  1300. // now run the compiled test if we can find it
  1301. std::vector<std::string> attempted;
  1302. std::vector<std::string> attemptedConfigs;
  1303. std::string tempPath;
  1304. std::string filepath =
  1305. cmSystemTools::GetFilenamePath(testCommand);
  1306. std::string filename =
  1307. cmSystemTools::GetFilenameName(testCommand);
  1308. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1309. attemptedConfigs,
  1310. filepath,filename);
  1311. // even if a fullpath was specified also try it relative to the current
  1312. // directory
  1313. if (filepath.size() && filepath[0] == '/')
  1314. {
  1315. std::string localfilepath = filepath.substr(1,filepath.size()-1);
  1316. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1317. attemptedConfigs,
  1318. localfilepath,filename);
  1319. }
  1320. // if extraPaths are provided and we were not passed a full path, try them,
  1321. // try any extra paths
  1322. if (filepath.size() == 0)
  1323. {
  1324. for (unsigned int i = 0; i < extraPaths.size(); ++i)
  1325. {
  1326. std::string filepathExtra =
  1327. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1328. std::string filenameExtra =
  1329. cmSystemTools::GetFilenameName(extraPaths[i]);
  1330. cmCTestTestHandler::AddConfigurations(ctest,attempted,
  1331. attemptedConfigs,
  1332. filepathExtra,
  1333. filenameExtra);
  1334. }
  1335. }
  1336. // store the final location in fullPath
  1337. std::string fullPath;
  1338. // now look in the paths we specified above
  1339. for(unsigned int ai=0;
  1340. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1341. {
  1342. // first check without exe extension
  1343. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1344. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1345. {
  1346. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1347. resultingConfig = attemptedConfigs[ai];
  1348. }
  1349. // then try with the exe extension
  1350. else
  1351. {
  1352. failed.push_back(attempted[ai].c_str());
  1353. tempPath = attempted[ai];
  1354. tempPath += cmSystemTools::GetExecutableExtension();
  1355. if(cmSystemTools::FileExists(tempPath.c_str())
  1356. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1357. {
  1358. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1359. resultingConfig = attemptedConfigs[ai];
  1360. }
  1361. else
  1362. {
  1363. failed.push_back(tempPath.c_str());
  1364. }
  1365. }
  1366. }
  1367. // if everything else failed, check the users path, but only if a full path
  1368. // wasn't specified
  1369. if (fullPath.size() == 0 && filepath.size() == 0)
  1370. {
  1371. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1372. if (path != "")
  1373. {
  1374. resultingConfig = "";
  1375. return path;
  1376. }
  1377. }
  1378. if(fullPath.size() == 0)
  1379. {
  1380. cmCTestLog(ctest, HANDLER_OUTPUT,
  1381. "Could not find executable " << testCommand << "\n"
  1382. << "Looked in the following places:\n");
  1383. for(std::vector<std::string>::iterator i = failed.begin();
  1384. i != failed.end(); ++i)
  1385. {
  1386. cmCTestLog(ctest, HANDLER_OUTPUT,
  1387. i->c_str() << "\n");
  1388. }
  1389. }
  1390. return fullPath;
  1391. }
  1392. //----------------------------------------------------------------------
  1393. void cmCTestTestHandler::GetListOfTests()
  1394. {
  1395. if ( !this->IncludeLabelRegExp.empty() )
  1396. {
  1397. this->IncludeLabelRegularExpression.
  1398. compile(this->IncludeLabelRegExp.c_str());
  1399. }
  1400. if ( !this->IncludeLabelRegExp.empty() )
  1401. {
  1402. this->ExcludeLabelRegularExpression.
  1403. compile(this->ExcludeLabelRegExp.c_str());
  1404. }
  1405. if ( !this->IncludeRegExp.empty() )
  1406. {
  1407. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1408. }
  1409. if ( !this->ExcludeRegExp.empty() )
  1410. {
  1411. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1412. }
  1413. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1414. "Constructing a list of tests" << std::endl);
  1415. cmake cm;
  1416. cmGlobalGenerator gg;
  1417. gg.SetCMakeInstance(&cm);
  1418. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1419. cmMakefile *mf = lg->GetMakefile();
  1420. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1421. this->CTest->GetConfigType().c_str());
  1422. // Add handler for ADD_TEST
  1423. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1424. newCom1->TestHandler = this;
  1425. cm.AddCommand(newCom1);
  1426. // Add handler for SUBDIRS
  1427. cmCTestSubdirCommand* newCom2 =
  1428. new cmCTestSubdirCommand;
  1429. newCom2->TestHandler = this;
  1430. cm.AddCommand(newCom2);
  1431. // Add handler for ADD_SUBDIRECTORY
  1432. cmCTestAddSubdirectoryCommand* newCom3 =
  1433. new cmCTestAddSubdirectoryCommand;
  1434. newCom3->TestHandler = this;
  1435. cm.AddCommand(newCom3);
  1436. // Add handler for SET_SOURCE_FILES_PROPERTIES
  1437. cmCTestSetTestsPropertiesCommand* newCom4
  1438. = new cmCTestSetTestsPropertiesCommand;
  1439. newCom4->TestHandler = this;
  1440. cm.AddCommand(newCom4);
  1441. const char* testFilename;
  1442. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  1443. {
  1444. // does the CTestTestfile.cmake exist ?
  1445. testFilename = "CTestTestfile.cmake";
  1446. }
  1447. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  1448. {
  1449. // does the DartTestfile.txt exist ?
  1450. testFilename = "DartTestfile.txt";
  1451. }
  1452. else
  1453. {
  1454. return;
  1455. }
  1456. if ( !mf->ReadListFile(0, testFilename) )
  1457. {
  1458. return;
  1459. }
  1460. if ( cmSystemTools::GetErrorOccuredFlag() )
  1461. {
  1462. return;
  1463. }
  1464. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1465. "Done constructing a list of tests" << std::endl);
  1466. }
  1467. //----------------------------------------------------------------------
  1468. void cmCTestTestHandler::UseIncludeRegExp()
  1469. {
  1470. this->UseIncludeRegExpFlag = true;
  1471. }
  1472. //----------------------------------------------------------------------
  1473. void cmCTestTestHandler::UseExcludeRegExp()
  1474. {
  1475. this->UseExcludeRegExpFlag = true;
  1476. this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
  1477. }
  1478. //----------------------------------------------------------------------
  1479. const char* cmCTestTestHandler::GetTestStatus(int status)
  1480. {
  1481. static const char statuses[][100] = {
  1482. "Not Run",
  1483. "Timeout",
  1484. "SEGFAULT",
  1485. "ILLEGAL",
  1486. "INTERRUPT",
  1487. "NUMERICAL",
  1488. "OTHER_FAULT",
  1489. "Failed",
  1490. "BAD_COMMAND",
  1491. "Completed"
  1492. };
  1493. if ( status < cmCTestTestHandler::NOT_RUN ||
  1494. status > cmCTestTestHandler::COMPLETED )
  1495. {
  1496. return "No Status";
  1497. }
  1498. return statuses[status];
  1499. }
  1500. //----------------------------------------------------------------------
  1501. void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
  1502. {
  1503. if (this->TestsToRunString.empty())
  1504. {
  1505. return;
  1506. }
  1507. int start;
  1508. int end = -1;
  1509. double stride = -1;
  1510. std::string::size_type pos = 0;
  1511. std::string::size_type pos2;
  1512. // read start
  1513. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1514. {
  1515. // read end
  1516. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1517. {
  1518. // read stride
  1519. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1520. {
  1521. int val =0;
  1522. // now read specific numbers
  1523. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1524. {
  1525. this->TestsToRun.push_back(val);
  1526. }
  1527. this->TestsToRun.push_back(val);
  1528. }
  1529. }
  1530. }
  1531. // if start is not specified then we assume we start at 1
  1532. if(start == -1)
  1533. {
  1534. start = 1;
  1535. }
  1536. // if end isnot specified then we assume we end with the last test
  1537. if(end == -1)
  1538. {
  1539. end = static_cast<int>(numTests);
  1540. }
  1541. // if the stride wasn't specified then it defaults to 1
  1542. if(stride == -1)
  1543. {
  1544. stride = 1;
  1545. }
  1546. // if we have a range then add it
  1547. if(end != -1 && start != -1 && stride > 0)
  1548. {
  1549. int i = 0;
  1550. while (i*stride + start <= end)
  1551. {
  1552. this->TestsToRun.push_back(static_cast<int>(i*stride+start));
  1553. ++i;
  1554. }
  1555. }
  1556. // sort the array
  1557. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1558. std::less<int>());
  1559. // remove duplicates
  1560. std::vector<int>::iterator new_end =
  1561. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1562. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1563. }
  1564. //----------------------------------------------------------------------
  1565. // Just for convenience
  1566. #define SPACE_REGEX "[ \t\r\n]"
  1567. //----------------------------------------------------------------------
  1568. std::string cmCTestTestHandler::GenerateRegressionImages(
  1569. const std::string& xml)
  1570. {
  1571. cmsys::RegularExpression twoattributes(
  1572. "<DartMeasurement"
  1573. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1574. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1575. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1576. cmsys::RegularExpression threeattributes(
  1577. "<DartMeasurement"
  1578. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1579. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1580. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1581. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1582. cmsys::RegularExpression fourattributes(
  1583. "<DartMeasurement"
  1584. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1585. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1586. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1587. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1588. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1589. cmsys::RegularExpression cdatastart(
  1590. "<DartMeasurement"
  1591. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1592. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1593. SPACE_REGEX "*>"
  1594. SPACE_REGEX "*<!\\[CDATA\\[");
  1595. cmsys::RegularExpression cdataend(
  1596. "]]>"
  1597. SPACE_REGEX "*</DartMeasurement>");
  1598. cmsys::RegularExpression measurementfile(
  1599. "<DartMeasurementFile"
  1600. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1601. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1602. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1603. cmOStringStream ostr;
  1604. bool done = false;
  1605. std::string cxml = xml;
  1606. while ( ! done )
  1607. {
  1608. if ( twoattributes.find(cxml) )
  1609. {
  1610. ostr
  1611. << "\t\t\t<NamedMeasurement"
  1612. << " " << twoattributes.match(1) << "=\""
  1613. << twoattributes.match(2) << "\""
  1614. << " " << twoattributes.match(3) << "=\""
  1615. << twoattributes.match(4) << "\""
  1616. << "><Value>" << twoattributes.match(5)
  1617. << "</Value></NamedMeasurement>"
  1618. << std::endl;
  1619. cxml.erase(twoattributes.start(),
  1620. twoattributes.end() - twoattributes.start());
  1621. }
  1622. else if ( threeattributes.find(cxml) )
  1623. {
  1624. ostr
  1625. << "\t\t\t<NamedMeasurement"
  1626. << " " << threeattributes.match(1) << "=\""
  1627. << threeattributes.match(2) << "\""
  1628. << " " << threeattributes.match(3) << "=\""
  1629. << threeattributes.match(4) << "\""
  1630. << " " << threeattributes.match(5) << "=\""
  1631. << threeattributes.match(6) << "\""
  1632. << "><Value>" << threeattributes.match(7)
  1633. << "</Value></NamedMeasurement>"
  1634. << std::endl;
  1635. cxml.erase(threeattributes.start(),
  1636. threeattributes.end() - threeattributes.start());
  1637. }
  1638. else if ( fourattributes.find(cxml) )
  1639. {
  1640. ostr
  1641. << "\t\t\t<NamedMeasurement"
  1642. << " " << fourattributes.match(1) << "=\""
  1643. << fourattributes.match(2) << "\""
  1644. << " " << fourattributes.match(3) << "=\""
  1645. << fourattributes.match(4) << "\""
  1646. << " " << fourattributes.match(5) << "=\""
  1647. << fourattributes.match(6) << "\""
  1648. << " " << fourattributes.match(7) << "=\""
  1649. << fourattributes.match(8) << "\""
  1650. << "><Value>" << fourattributes.match(9)
  1651. << "</Value></NamedMeasurement>"
  1652. << std::endl;
  1653. cxml.erase(fourattributes.start(),
  1654. fourattributes.end() - fourattributes.start());
  1655. }
  1656. else if ( cdatastart.find(cxml) && cdataend.find(cxml) )
  1657. {
  1658. ostr
  1659. << "\t\t\t<NamedMeasurement"
  1660. << " " << cdatastart.match(1) << "=\""
  1661. << cdatastart.match(2) << "\""
  1662. << " " << cdatastart.match(3) << "=\""
  1663. << cdatastart.match(4) << "\""
  1664. << "><Value><![CDATA["
  1665. << cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())
  1666. << "]]></Value></NamedMeasurement>"
  1667. << std::endl;
  1668. cxml.erase(cdatastart.start(),
  1669. cdataend.end() - cdatastart.start());
  1670. }
  1671. else if ( measurementfile.find(cxml) )
  1672. {
  1673. const std::string& filename =
  1674. cmCTest::CleanString(measurementfile.match(5));
  1675. if ( cmSystemTools::FileExists(filename.c_str()) )
  1676. {
  1677. long len = cmSystemTools::FileLength(filename.c_str());
  1678. if ( len == 0 )
  1679. {
  1680. std::string k1 = measurementfile.match(1);
  1681. std::string v1 = measurementfile.match(2);
  1682. std::string k2 = measurementfile.match(3);
  1683. std::string v2 = measurementfile.match(4);
  1684. if ( cmSystemTools::LowerCase(k1) == "type" )
  1685. {
  1686. v1 = "text/string";
  1687. }
  1688. if ( cmSystemTools::LowerCase(k2) == "type" )
  1689. {
  1690. v2 = "text/string";
  1691. }
  1692. ostr
  1693. << "\t\t\t<NamedMeasurement"
  1694. << " " << k1 << "=\"" << v1 << "\""
  1695. << " " << k2 << "=\"" << v2 << "\""
  1696. << " encoding=\"none\""
  1697. << "><Value>Image " << filename.c_str()
  1698. << " is empty</Value></NamedMeasurement>";
  1699. }
  1700. else
  1701. {
  1702. std::ifstream ifs(filename.c_str(), std::ios::in
  1703. #ifdef _WIN32
  1704. | std::ios::binary
  1705. #endif
  1706. );
  1707. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1708. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1709. unsigned char *encoded_buffer
  1710. = new unsigned char [ static_cast<int>(
  1711. static_cast<double>(len) * 1.5 + 5.0) ];
  1712. unsigned long rlen
  1713. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1714. unsigned long cc;
  1715. ostr
  1716. << "\t\t\t<NamedMeasurement"
  1717. << " " << measurementfile.match(1) << "=\""
  1718. << measurementfile.match(2) << "\""
  1719. << " " << measurementfile.match(3) << "=\""
  1720. << measurementfile.match(4) << "\""
  1721. << " encoding=\"base64\""
  1722. << ">" << std::endl << "\t\t\t\t<Value>";
  1723. for ( cc = 0; cc < rlen; cc ++ )
  1724. {
  1725. ostr << encoded_buffer[cc];
  1726. if ( cc % 60 == 0 && cc )
  1727. {
  1728. ostr << std::endl;
  1729. }
  1730. }
  1731. ostr
  1732. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1733. << std::endl;
  1734. delete [] file_buffer;
  1735. delete [] encoded_buffer;
  1736. }
  1737. }
  1738. else
  1739. {
  1740. int idx = 4;
  1741. if ( measurementfile.match(1) == "name" )
  1742. {
  1743. idx = 2;
  1744. }
  1745. ostr
  1746. << "\t\t\t<NamedMeasurement"
  1747. << " name=\"" << measurementfile.match(idx) << "\""
  1748. << " text=\"text/string\""
  1749. << "><Value>File " << filename.c_str()
  1750. << " not found</Value></NamedMeasurement>"
  1751. << std::endl;
  1752. cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
  1753. << "\" not found." << std::endl);
  1754. }
  1755. cxml.erase(measurementfile.start(),
  1756. measurementfile.end() - measurementfile.start());
  1757. }
  1758. else
  1759. {
  1760. done = true;
  1761. }
  1762. }
  1763. return ostr.str();
  1764. }
  1765. //----------------------------------------------------------------------
  1766. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1767. {
  1768. this->IncludeRegExp = arg;
  1769. }
  1770. //----------------------------------------------------------------------
  1771. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1772. {
  1773. this->ExcludeRegExp = arg;
  1774. }
  1775. //----------------------------------------------------------------------
  1776. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1777. {
  1778. if ( !in )
  1779. {
  1780. return;
  1781. }
  1782. this->TestsToRunString = in;
  1783. // if the argument is a file, then read it and use the contents as the
  1784. // string
  1785. if(cmSystemTools::FileExists(in))
  1786. {
  1787. std::ifstream fin(in);
  1788. unsigned long filelen = cmSystemTools::FileLength(in);
  1789. char* buff = new char[filelen+1];
  1790. fin.getline(buff, filelen);
  1791. buff[fin.gcount()] = 0;
  1792. this->TestsToRunString = buff;
  1793. delete [] buff;
  1794. }
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length)
  1798. {
  1799. if(!length || length >= output.size() ||
  1800. output.find("CTEST_FULL_OUTPUT") != output.npos)
  1801. {
  1802. return true;
  1803. }
  1804. // Truncate at given length but do not break in the middle of a multi-byte
  1805. // UTF-8 encoding.
  1806. char const* const begin = output.c_str();
  1807. char const* const end = begin + output.size();
  1808. char const* const truncate = begin + length;
  1809. char const* current = begin;
  1810. while(current < truncate)
  1811. {
  1812. unsigned int ch;
  1813. if(const char* next = cm_utf8_decode_character(current, end, &ch))
  1814. {
  1815. if(next > truncate)
  1816. {
  1817. break;
  1818. }
  1819. current = next;
  1820. }
  1821. else // Bad byte will be handled by cmXMLSafe.
  1822. {
  1823. ++current;
  1824. }
  1825. }
  1826. output = output.substr(0, current - begin);
  1827. // Append truncation message.
  1828. cmOStringStream msg;
  1829. msg << "...\n"
  1830. "The rest of the test output was removed since it exceeds the threshold "
  1831. "of " << length << " bytes.\n";
  1832. output += msg.str();
  1833. return true;
  1834. }
  1835. //----------------------------------------------------------------------
  1836. bool cmCTestTestHandler::SetTestsProperties(
  1837. const std::vector<std::string>& args)
  1838. {
  1839. std::vector<std::string>::const_iterator it;
  1840. std::vector<cmStdString> tests;
  1841. bool found = false;
  1842. for ( it = args.begin(); it != args.end(); ++ it )
  1843. {
  1844. if ( *it == "PROPERTIES" )
  1845. {
  1846. found = true;
  1847. break;
  1848. }
  1849. tests.push_back(*it);
  1850. }
  1851. if ( !found )
  1852. {
  1853. return false;
  1854. }
  1855. ++ it; // skip PROPERTIES
  1856. for ( ; it != args.end(); ++ it )
  1857. {
  1858. std::string key = *it;
  1859. ++ it;
  1860. if ( it == args.end() )
  1861. {
  1862. break;
  1863. }
  1864. std::string val = *it;
  1865. std::vector<cmStdString>::const_iterator tit;
  1866. for ( tit = tests.begin(); tit != tests.end(); ++ tit )
  1867. {
  1868. cmCTestTestHandler::ListOfTests::iterator rtit;
  1869. for ( rtit = this->TestList.begin();
  1870. rtit != this->TestList.end();
  1871. ++ rtit )
  1872. {
  1873. if ( *tit == rtit->Name )
  1874. {
  1875. if ( key == "WILL_FAIL" )
  1876. {
  1877. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  1878. }
  1879. if ( key == "ATTACHED_FILES" )
  1880. {
  1881. std::vector<std::string> lval;
  1882. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1883. for(std::vector<std::string>::iterator f = lval.begin();
  1884. f != lval.end(); ++f)
  1885. {
  1886. rtit->AttachedFiles.push_back(*f);
  1887. }
  1888. }
  1889. if ( key == "ATTACHED_FILES_ON_FAIL" )
  1890. {
  1891. std::vector<std::string> lval;
  1892. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1893. for(std::vector<std::string>::iterator f = lval.begin();
  1894. f != lval.end(); ++f)
  1895. {
  1896. rtit->AttachOnFail.push_back(*f);
  1897. }
  1898. }
  1899. if ( key == "RESOURCE_LOCK" )
  1900. {
  1901. std::vector<std::string> lval;
  1902. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1903. for(std::vector<std::string>::iterator f = lval.begin();
  1904. f != lval.end(); ++f)
  1905. {
  1906. rtit->LockedResources.insert(*f);
  1907. }
  1908. }
  1909. if ( key == "TIMEOUT" )
  1910. {
  1911. rtit->Timeout = atof(val.c_str());
  1912. rtit->ExplicitTimeout = true;
  1913. }
  1914. if ( key == "COST" )
  1915. {
  1916. rtit->Cost = static_cast<float>(atof(val.c_str()));
  1917. }
  1918. if ( key == "REQUIRED_FILES" )
  1919. {
  1920. std::vector<std::string> lval;
  1921. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1922. for(std::vector<std::string>::iterator f = lval.begin();
  1923. f != lval.end(); ++f)
  1924. {
  1925. rtit->RequiredFiles.push_back(*f);
  1926. }
  1927. }
  1928. if ( key == "RUN_SERIAL" )
  1929. {
  1930. rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
  1931. }
  1932. if ( key == "FAIL_REGULAR_EXPRESSION" )
  1933. {
  1934. std::vector<std::string> lval;
  1935. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1936. std::vector<std::string>::iterator crit;
  1937. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1938. {
  1939. rtit->ErrorRegularExpressions.push_back(
  1940. std::pair<cmsys::RegularExpression, std::string>(
  1941. cmsys::RegularExpression(crit->c_str()),
  1942. std::string(crit->c_str())));
  1943. }
  1944. }
  1945. if ( key == "PROCESSORS" )
  1946. {
  1947. rtit->Processors = atoi(val.c_str());
  1948. if(rtit->Processors < 1)
  1949. {
  1950. rtit->Processors = 1;
  1951. }
  1952. }
  1953. if ( key == "DEPENDS" )
  1954. {
  1955. std::vector<std::string> lval;
  1956. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1957. std::vector<std::string>::iterator crit;
  1958. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1959. {
  1960. rtit->Depends.push_back(*crit);
  1961. }
  1962. }
  1963. if ( key == "ENVIRONMENT" )
  1964. {
  1965. std::vector<std::string> lval;
  1966. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1967. std::vector<std::string>::iterator crit;
  1968. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1969. {
  1970. rtit->Environment.push_back(*crit);
  1971. }
  1972. }
  1973. if ( key == "LABELS" )
  1974. {
  1975. std::vector<std::string> lval;
  1976. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  1977. std::vector<std::string>::iterator crit;
  1978. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  1979. {
  1980. rtit->Labels.push_back(*crit);
  1981. }
  1982. }
  1983. if ( key == "MEASUREMENT" )
  1984. {
  1985. size_t pos = val.find_first_of("=");
  1986. if ( pos != val.npos )
  1987. {
  1988. std::string mKey = val.substr(0, pos);
  1989. const char* mVal = val.c_str() + pos + 1;
  1990. rtit->Measurements[mKey] = mVal;
  1991. }
  1992. else
  1993. {
  1994. rtit->Measurements[val] = "1";
  1995. }
  1996. }
  1997. if ( key == "PASS_REGULAR_EXPRESSION" )
  1998. {
  1999. std::vector<std::string> lval;
  2000. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  2001. std::vector<std::string>::iterator crit;
  2002. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  2003. {
  2004. rtit->RequiredRegularExpressions.push_back(
  2005. std::pair<cmsys::RegularExpression, std::string>(
  2006. cmsys::RegularExpression(crit->c_str()),
  2007. std::string(crit->c_str())));
  2008. }
  2009. }
  2010. if ( key == "WORKING_DIRECTORY" )
  2011. {
  2012. rtit->Directory = val;
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. return true;
  2019. }
  2020. //----------------------------------------------------------------------
  2021. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  2022. {
  2023. const std::string& testname = args[0];
  2024. cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
  2025. if (this->UseExcludeRegExpFlag &&
  2026. this->UseExcludeRegExpFirst &&
  2027. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  2028. {
  2029. return true;
  2030. }
  2031. if ( this->MemCheck )
  2032. {
  2033. std::vector<cmStdString>::iterator it;
  2034. bool found = false;
  2035. for ( it = this->CustomTestsIgnore.begin();
  2036. it != this->CustomTestsIgnore.end(); ++ it )
  2037. {
  2038. if ( *it == testname )
  2039. {
  2040. found = true;
  2041. break;
  2042. }
  2043. }
  2044. if ( found )
  2045. {
  2046. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
  2047. << *it << std::endl);
  2048. return true;
  2049. }
  2050. }
  2051. else
  2052. {
  2053. std::vector<cmStdString>::iterator it;
  2054. bool found = false;
  2055. for ( it = this->CustomTestsIgnore.begin();
  2056. it != this->CustomTestsIgnore.end(); ++ it )
  2057. {
  2058. if ( *it == testname )
  2059. {
  2060. found = true;
  2061. break;
  2062. }
  2063. }
  2064. if ( found )
  2065. {
  2066. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
  2067. << *it << std::endl);
  2068. return true;
  2069. }
  2070. }
  2071. cmCTestTestProperties test;
  2072. test.Name = testname;
  2073. test.Args = args;
  2074. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  2075. cmCTestLog(this->CTest, DEBUG, "Set test directory: "
  2076. << test.Directory << std::endl);
  2077. test.IsInBasedOnREOptions = true;
  2078. test.WillFail = false;
  2079. test.RunSerial = false;
  2080. test.Timeout = 0;
  2081. test.ExplicitTimeout = false;
  2082. test.Cost = 0;
  2083. test.Processors = 1;
  2084. test.PreviousRuns = 0;
  2085. if (this->UseIncludeRegExpFlag &&
  2086. !this->IncludeTestsRegularExpression.find(testname.c_str()))
  2087. {
  2088. test.IsInBasedOnREOptions = false;
  2089. }
  2090. else if (this->UseExcludeRegExpFlag &&
  2091. !this->UseExcludeRegExpFirst &&
  2092. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  2093. {
  2094. test.IsInBasedOnREOptions = false;
  2095. }
  2096. this->TestList.push_back(test);
  2097. return true;
  2098. }