cmCTestTestHandler.cxx 68 KB

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