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