cmCTestTestHandler.cxx 66 KB

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