cmCTestTestHandler.cxx 58 KB

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