cmCTestTestHandler.cxx 67 KB

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