cmCTestTestHandler.cxx 63 KB

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