cmCTestTestHandler.cxx 67 KB

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