cmCTestTestHandler.cxx 67 KB

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