cmCTestTestHandler.cxx 62 KB

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