cmCTestTestHandler.cxx 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430
  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. const char* val;
  441. val = this->GetOption("LabelRegularExpression");
  442. if ( val )
  443. {
  444. this->UseIncludeLabelRegExpFlag = true;
  445. this->IncludeLabelRegExp = val;
  446. }
  447. val = this->GetOption("ExcludeLabelRegularExpression");
  448. if ( val )
  449. {
  450. this->UseExcludeLabelRegExpFlag = true;
  451. this->ExcludeLabelRegularExpression = val;
  452. }
  453. val = this->GetOption("IncludeRegularExpression");
  454. if ( val )
  455. {
  456. this->UseIncludeRegExp();
  457. this->SetIncludeRegExp(val);
  458. }
  459. val = this->GetOption("ExcludeRegularExpression");
  460. if ( val )
  461. {
  462. this->UseExcludeRegExp();
  463. this->SetExcludeRegExp(val);
  464. }
  465. this->TestResults.clear();
  466. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  467. (this->MemCheck ? "Memory check" : "Test")
  468. << " project " << cmSystemTools::GetCurrentWorkingDirectory()
  469. << std::endl);
  470. if ( ! this->PreProcessHandler() )
  471. {
  472. return -1;
  473. }
  474. cmGeneratedFileStream mLogFile;
  475. this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
  476. this->LogFile = &mLogFile;
  477. std::vector<cmStdString> passed;
  478. std::vector<cmStdString> failed;
  479. int total;
  480. //start the real time clock
  481. double clock_start, clock_finish;
  482. clock_start = cmSystemTools::GetTime();
  483. this->ProcessDirectory(passed, failed);
  484. clock_finish = cmSystemTools::GetTime();
  485. total = int(passed.size()) + int(failed.size());
  486. if (total == 0)
  487. {
  488. if ( !this->CTest->GetShowOnly() )
  489. {
  490. cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
  491. << std::endl);
  492. }
  493. }
  494. else
  495. {
  496. if (this->HandlerVerbose && passed.size() &&
  497. (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag))
  498. {
  499. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  500. << "The following tests passed:" << std::endl);
  501. for(std::vector<cmStdString>::iterator j = passed.begin();
  502. j != passed.end(); ++j)
  503. {
  504. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "\t" << *j
  505. << std::endl);
  506. }
  507. }
  508. float percent = float(passed.size()) * 100.0f / total;
  509. if ( failed.size() > 0 && percent > 99)
  510. {
  511. percent = 99;
  512. }
  513. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
  514. << static_cast<int>(percent + .5) << "% tests passed, "
  515. << failed.size() << " tests failed out of "
  516. << total << std::endl);
  517. double totalTestTime = 0;
  518. for(cmCTestTestHandler::TestResultsVector::size_type cc = 0;
  519. cc < this->TestResults.size(); cc ++ )
  520. {
  521. cmCTestTestResult *result = &this->TestResults[cc];
  522. totalTestTime += result->ExecutionTime;
  523. }
  524. char realBuf[1024];
  525. sprintf(realBuf, "%6.2f sec", (double)(clock_finish - clock_start));
  526. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (real) = "
  527. << realBuf << "\n" );
  528. char totalBuf[1024];
  529. sprintf(totalBuf, "%6.2f sec", totalTestTime);
  530. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTotal Test time (parallel) = "
  531. << totalBuf << "\n" );
  532. if (failed.size())
  533. {
  534. cmGeneratedFileStream ofs;
  535. cmCTestLog(this->CTest, ERROR_MESSAGE, std::endl
  536. << "The following tests FAILED:" << std::endl);
  537. this->StartLogFile("TestsFailed", ofs);
  538. std::vector<cmCTestTestHandler::cmCTestTestResult>::iterator ftit;
  539. for(ftit = this->TestResults.begin();
  540. ftit != this->TestResults.end(); ++ftit)
  541. {
  542. if ( ftit->Status != cmCTestTestHandler::COMPLETED )
  543. {
  544. ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
  545. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\t" << std::setw(3)
  546. << ftit->TestCount << " - "
  547. << ftit->Name.c_str() << " ("
  548. << this->GetTestStatus(ftit->Status) << ")"
  549. << std::endl);
  550. }
  551. }
  552. }
  553. }
  554. if ( this->CTest->GetProduceXML() )
  555. {
  556. cmGeneratedFileStream xmlfile;
  557. if( !this->StartResultingXML(
  558. (this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
  559. (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile) )
  560. {
  561. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
  562. << (this->MemCheck ? "memory check" : "testing")
  563. << " XML file" << std::endl);
  564. this->LogFile = 0;
  565. return 1;
  566. }
  567. this->GenerateDartOutput(xmlfile);
  568. }
  569. if ( ! this->PostProcessHandler() )
  570. {
  571. this->LogFile = 0;
  572. return -1;
  573. }
  574. if ( !failed.empty() )
  575. {
  576. this->LogFile = 0;
  577. return -1;
  578. }
  579. this->LogFile = 0;
  580. return 0;
  581. }
  582. //----------------------------------------------------------------------
  583. void cmCTestTestHandler::PrintLabelSummary()
  584. {
  585. cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
  586. cmCTestTestHandler::TestResultsVector::iterator ri =
  587. this->TestResults.begin();
  588. std::map<cmStdString, double> labelTimes;
  589. std::set<cmStdString> labels;
  590. // initialize maps
  591. for(; it != this->TestList.end(); ++it)
  592. {
  593. cmCTestTestProperties& p = *it;
  594. if(p.Labels.size() != 0)
  595. {
  596. for(std::vector<std::string>::iterator l = p.Labels.begin();
  597. l != p.Labels.end(); ++l)
  598. {
  599. labels.insert(*l);
  600. labelTimes[*l] = 0;
  601. }
  602. }
  603. }
  604. it = this->TestList.begin();
  605. ri = this->TestResults.begin();
  606. // fill maps
  607. for(; it != this->TestList.end(); ++it, ++ri)
  608. {
  609. cmCTestTestProperties& p = *it;
  610. cmCTestTestResult &result = *ri;
  611. if(p.Labels.size() != 0)
  612. {
  613. for(std::vector<std::string>::iterator l = p.Labels.begin();
  614. l != p.Labels.end(); ++l)
  615. {
  616. labelTimes[*l] += result.ExecutionTime;
  617. }
  618. }
  619. }
  620. // now print times
  621. for(std::set<cmStdString>::const_iterator i = labels.begin();
  622. i != labels.end(); ++i)
  623. {
  624. cmCTestLog(this->CTest, HANDLER_OUTPUT, "\nTime in "
  625. << *i << " = " << labelTimes[*i] << " sec" );
  626. if ( this->LogFile )
  627. {
  628. *this->LogFile << "\nTime in " << *i << " = "
  629. << labelTimes[*i] << " sec" << std::endl;
  630. }
  631. }
  632. }
  633. /*
  634. //----------------------------------------------------------------------
  635. void cmCTestTestHandler::ProcessOneTest(cmCTestTestProperties *it,
  636. std::vector<cmStdString> &passed,
  637. std::vector<cmStdString> &failed,
  638. int cnt, int tmsize)
  639. {
  640. const std::string& testname = it->Name;
  641. std::vector<std::string>& args = it->Args;
  642. cmCTestTestResult cres;
  643. cres.Properties = &*it;
  644. cres.ExecutionTime = 0;
  645. cres.ReturnValue = -1;
  646. cres.Status = cmCTestTestHandler::NOT_RUN;
  647. cres.TestCount = cnt;
  648. cres.Name = testname;
  649. cres.Path = it->Directory.c_str();
  650. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << cnt << "/");
  651. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::setw(3) << tmsize << " ");
  652. if ( this->MemCheck )
  653. {
  654. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Memory Check");
  655. }
  656. else
  657. {
  658. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Testing");
  659. }
  660. cmCTestLog(this->CTest, HANDLER_OUTPUT, " ");
  661. const int maxTestNameWidth = this->CTest->GetMaxTestNameWidth();
  662. std::string outname = testname + " ";
  663. outname.resize(maxTestNameWidth, '.');
  664. *this->LogFile << cnt << "/" << tmsize << " Testing: " << testname
  665. << std::endl;
  666. if ( this->CTest->GetShowOnly() )
  667. {
  668. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str() << std::endl);
  669. }
  670. else
  671. {
  672. cmCTestLog(this->CTest, HANDLER_OUTPUT, outname.c_str());
  673. }
  674. cmCTestLog(this->CTest, DEBUG, "Testing " << args[0].c_str() << " ... ");
  675. // find the test executable
  676. std::string actualCommand = this->FindTheExecutable(args[1].c_str());
  677. std::string testCommand
  678. = cmSystemTools::ConvertToOutputPath(actualCommand.c_str());
  679. // continue if we did not find the executable
  680. if (testCommand == "")
  681. {
  682. *this->LogFile << "Unable to find executable: " << args[1].c_str()
  683. << std::endl;
  684. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to find executable: "
  685. << args[1].c_str() << std::endl);
  686. cres.Output = "Unable to find executable: " + args[1];
  687. if ( !this->CTest->GetShowOnly() )
  688. {
  689. cres.FullCommandLine = actualCommand;
  690. this->TestResults.push_back( cres );
  691. failed.push_back(testname);
  692. return;
  693. }
  694. }
  695. // add the arguments
  696. std::vector<std::string>::const_iterator j = args.begin();
  697. ++j; // skip test name
  698. ++j; // skip command as it is in actualCommand
  699. std::vector<const char*> arguments;
  700. this->GenerateTestCommand(arguments);
  701. arguments.push_back(actualCommand.c_str());
  702. for(;j != args.end(); ++j)
  703. {
  704. testCommand += " ";
  705. testCommand += cmSystemTools::EscapeSpaces(j->c_str());
  706. arguments.push_back(j->c_str());
  707. }
  708. arguments.push_back(0);
  709. std::string output;
  710. int retVal = 0;
  711. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  712. << (this->MemCheck?"MemCheck":"Test")
  713. << " command: " << testCommand
  714. << std::endl);
  715. *this->LogFile << cnt << "/" << tmsize
  716. << " Test: " << testname.c_str() << std::endl;
  717. *this->LogFile << "Command: ";
  718. std::vector<cmStdString>::size_type ll;
  719. for ( ll = 0; ll < arguments.size()-1; ll ++ )
  720. {
  721. *this->LogFile << "\"" << arguments[ll] << "\" ";
  722. }
  723. *this->LogFile
  724. << std::endl
  725. << "Directory: " << it->Directory << std::endl
  726. << "\"" << testname.c_str() << "\" start time: "
  727. << this->CTest->CurrentTime() << std::endl
  728. << "Output:" << std::endl
  729. << "----------------------------------------------------------"
  730. << std::endl;
  731. int res = 0;
  732. double clock_start, clock_finish;
  733. clock_start = cmSystemTools::GetTime();
  734. if ( !this->CTest->GetShowOnly() )
  735. {
  736. res = this->CTest->RunTest(arguments, &output, &retVal, this->LogFile,
  737. it->Timeout, &it->Environment);
  738. }
  739. clock_finish = cmSystemTools::GetTime();
  740. cres.ExecutionTime = (double)(clock_finish - clock_start);
  741. cres.FullCommandLine = testCommand;
  742. std::string reason;
  743. if ( !this->CTest->GetShowOnly() )
  744. {
  745. std::vector<std::pair<cmsys::RegularExpression,
  746. std::string> >::iterator passIt;
  747. bool forceFail = false;
  748. if ( it->RequiredRegularExpressions.size() > 0 )
  749. {
  750. bool found = false;
  751. for ( passIt = it->RequiredRegularExpressions.begin();
  752. passIt != it->RequiredRegularExpressions.end();
  753. ++ passIt )
  754. {
  755. if ( passIt->first.find(output.c_str()) )
  756. {
  757. found = true;
  758. reason = "Required regular expression found.";
  759. }
  760. }
  761. if ( !found )
  762. {
  763. reason = "Required regular expression not found.";
  764. forceFail = true;
  765. }
  766. reason += "Regex=[";
  767. for ( passIt = it->RequiredRegularExpressions.begin();
  768. passIt != it->RequiredRegularExpressions.end();
  769. ++ passIt )
  770. {
  771. reason += passIt->second;
  772. reason += "\n";
  773. }
  774. reason += "]";
  775. }
  776. if ( it->ErrorRegularExpressions.size() > 0 )
  777. {
  778. for ( passIt = it->ErrorRegularExpressions.begin();
  779. passIt != it->ErrorRegularExpressions.end();
  780. ++ passIt )
  781. {
  782. if ( passIt->first.find(output.c_str()) )
  783. {
  784. reason = "Error regular expression found in output.";
  785. reason += " Regex=[";
  786. reason += passIt->second;
  787. reason += "]";
  788. forceFail = true;
  789. }
  790. }
  791. }
  792. if (res == cmsysProcess_State_Exited)
  793. {
  794. bool success =
  795. !forceFail && (retVal == 0 || it->RequiredRegularExpressions.size());
  796. if((success && !it->WillFail) || (!success && it->WillFail))
  797. {
  798. cres.Status = cmCTestTestHandler::COMPLETED;
  799. cmCTestLog(this->CTest, HANDLER_OUTPUT, " Passed " );
  800. }
  801. else
  802. {
  803. cres.Status = cmCTestTestHandler::FAILED;
  804. cmCTestLog(this->CTest, HANDLER_OUTPUT,
  805. "***Failed " << reason );
  806. }
  807. }
  808. else if ( res == cmsysProcess_State_Expired )
  809. {
  810. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Timeout");
  811. cres.Status = cmCTestTestHandler::TIMEOUT;
  812. }
  813. else if ( res == cmsysProcess_State_Exception )
  814. {
  815. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Exception: ");
  816. switch ( retVal )
  817. {
  818. case cmsysProcess_Exception_Fault:
  819. cmCTestLog(this->CTest, HANDLER_OUTPUT, "SegFault");
  820. cres.Status = cmCTestTestHandler::SEGFAULT;
  821. break;
  822. case cmsysProcess_Exception_Illegal:
  823. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Illegal");
  824. cres.Status = cmCTestTestHandler::ILLEGAL;
  825. break;
  826. case cmsysProcess_Exception_Interrupt:
  827. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Interrupt");
  828. cres.Status = cmCTestTestHandler::INTERRUPT;
  829. break;
  830. case cmsysProcess_Exception_Numerical:
  831. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Numerical");
  832. cres.Status = cmCTestTestHandler::NUMERICAL;
  833. break;
  834. default:
  835. cmCTestLog(this->CTest, HANDLER_OUTPUT, "Other");
  836. cres.Status = cmCTestTestHandler::OTHER_FAULT;
  837. }
  838. }
  839. else // if ( res == cmsysProcess_State_Error )
  840. {
  841. cmCTestLog(this->CTest, HANDLER_OUTPUT, "***Bad command " << res );
  842. cres.Status = cmCTestTestHandler::BAD_COMMAND;
  843. }
  844. if(cres.Status == cmCTestTestHandler::COMPLETED)
  845. {
  846. passed.push_back(testname);
  847. }
  848. else
  849. {
  850. failed.push_back(testname);
  851. }
  852. char buf[1024];
  853. sprintf(buf, "%6.2f sec", cres.ExecutionTime);
  854. cmCTestLog(this->CTest, HANDLER_OUTPUT, buf << "\n" );
  855. if (!output.empty() && output.find("<DartMeasurement") != output.npos)
  856. {
  857. if (this->DartStuff.find(output.c_str()))
  858. {
  859. std::string dartString = this->DartStuff.match(1);
  860. // keep searching and replacing until none are left
  861. while (this->DartStuff1.find(output.c_str()))
  862. {
  863. // replace the exact match for the string
  864. cmSystemTools::ReplaceString(output,
  865. this->DartStuff1.match(1).c_str(), "");
  866. }
  867. cres.RegressionImages
  868. = this->GenerateRegressionImages(dartString);
  869. }
  870. }
  871. }
  872. // if this is doing MemCheck then all the output needs to be put into
  873. // Output since that it what is parsed to by cmCTestMemCheckHandler
  874. if(!this->MemCheck)
  875. {
  876. if ( cres.Status == cmCTestTestHandler::COMPLETED )
  877. {
  878. this->CleanTestOutput(output, static_cast<size_t>
  879. (this->CustomMaximumPassedTestOutputSize));
  880. }
  881. else
  882. {
  883. this->CleanTestOutput(output, static_cast<size_t>
  884. (this->CustomMaximumFailedTestOutputSize));
  885. }
  886. }
  887. cres.Reason = reason;
  888. if ( this->LogFile )
  889. {
  890. bool pass = true;
  891. const char* reasonType = "Test Pass Reason";
  892. if(cres.Status != cmCTestTestHandler::COMPLETED &&
  893. cres.Status != cmCTestTestHandler::NOT_RUN)
  894. {
  895. reasonType = "Test Fail Reason";
  896. pass = false;
  897. }
  898. double ttime = clock_finish - clock_start;
  899. int hours = static_cast<int>(ttime / (60 * 60));
  900. int minutes = static_cast<int>(ttime / 60) % 60;
  901. int seconds = static_cast<int>(ttime) % 60;
  902. char buffer[100];
  903. sprintf(buffer, "%02d:%02d:%02d", hours, minutes, seconds);
  904. *this->LogFile
  905. << "----------------------------------------------------------"
  906. << std::endl;
  907. if(cres.Reason.size())
  908. {
  909. *this->LogFile << reasonType << ":\n" << cres.Reason << "\n";
  910. }
  911. else
  912. {
  913. if(pass)
  914. {
  915. *this->LogFile << "Test Passed.\n";
  916. }
  917. else
  918. {
  919. *this->LogFile << "Test Failed.\n";
  920. }
  921. }
  922. *this->LogFile << "\"" << testname.c_str() << "\" end time: "
  923. << this->CTest->CurrentTime() << std::endl
  924. << "\"" << testname.c_str() << "\" time elapsed: "
  925. << buffer << std::endl
  926. << "----------------------------------------------------------"
  927. << std::endl << std::endl;
  928. }
  929. cres.Output = output;
  930. cres.ReturnValue = retVal;
  931. cres.CompletionStatus = "Completed";
  932. this->TestResults.push_back( cres );
  933. }
  934. */
  935. //----------------------------------------------------------------------
  936. void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
  937. {
  938. // if not using Labels to filter then return
  939. if (!this->UseIncludeLabelRegExpFlag )
  940. {
  941. return;
  942. }
  943. // if there are no labels and we are filtering by labels
  944. // then exclude the test as it does not have the label
  945. if(it.Labels.size() == 0 )
  946. {
  947. it.IsInBasedOnREOptions = false;
  948. return;
  949. }
  950. // check to see if the label regular expression matches
  951. bool found = false; // assume it does not match
  952. // loop over all labels and look for match
  953. for(std::vector<std::string>::iterator l = it.Labels.begin();
  954. l != it.Labels.end(); ++l)
  955. {
  956. if(this->IncludeLabelRegularExpression.find(*l))
  957. {
  958. found = true;
  959. }
  960. }
  961. // if no match was found, exclude the test
  962. if(!found)
  963. {
  964. it.IsInBasedOnREOptions = false;
  965. }
  966. }
  967. //----------------------------------------------------------------------
  968. void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
  969. {
  970. // if not using Labels to filter then return
  971. if (!this->UseExcludeLabelRegExpFlag )
  972. {
  973. return;
  974. }
  975. // if there are no labels and we are excluding by labels
  976. // then do nothing as a no label can not be a match
  977. if(it.Labels.size() == 0 )
  978. {
  979. return;
  980. }
  981. // check to see if the label regular expression matches
  982. bool found = false; // assume it does not match
  983. // loop over all labels and look for match
  984. for(std::vector<std::string>::iterator l = it.Labels.begin();
  985. l != it.Labels.end(); ++l)
  986. {
  987. if(this->ExcludeLabelRegularExpression.find(*l))
  988. {
  989. found = true;
  990. }
  991. }
  992. // if match was found, exclude the test
  993. if(found)
  994. {
  995. it.IsInBasedOnREOptions = false;
  996. }
  997. }
  998. //----------------------------------------------------------------------
  999. void cmCTestTestHandler::CheckLabelFilter(cmCTestTestProperties& it)
  1000. {
  1001. this->CheckLabelFilterInclude(it);
  1002. this->CheckLabelFilterExclude(it);
  1003. }
  1004. //----------------------------------------------------------------------
  1005. void cmCTestTestHandler::ComputeTestList()
  1006. {
  1007. this->TestList.clear(); // clear list of test
  1008. this->GetListOfTests();
  1009. cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
  1010. // how many tests are in based on RegExp?
  1011. int inREcnt = 0;
  1012. cmCTestTestHandler::ListOfTests::iterator it;
  1013. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  1014. {
  1015. this->CheckLabelFilter(*it);
  1016. if (it->IsInBasedOnREOptions)
  1017. {
  1018. inREcnt ++;
  1019. }
  1020. }
  1021. // expand the test list based on the union flag
  1022. if (this->UseUnion)
  1023. {
  1024. this->ExpandTestsToRunInformation((int)tmsize);
  1025. }
  1026. else
  1027. {
  1028. this->ExpandTestsToRunInformation(inREcnt);
  1029. }
  1030. // Now create a final list of tests to run
  1031. int cnt = 0;
  1032. inREcnt = 0;
  1033. std::string last_directory = "";
  1034. ListOfTests finalList;
  1035. for ( it = this->TestList.begin(); it != this->TestList.end(); it ++ )
  1036. {
  1037. cnt ++;
  1038. if (it->IsInBasedOnREOptions)
  1039. {
  1040. inREcnt++;
  1041. }
  1042. if (this->UseUnion)
  1043. {
  1044. // if it is not in the list and not in the regexp then skip
  1045. if ((this->TestsToRun.size() &&
  1046. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt)
  1047. == this->TestsToRun.end()) && !it->IsInBasedOnREOptions)
  1048. {
  1049. continue;
  1050. }
  1051. }
  1052. else
  1053. {
  1054. // is this test in the list of tests to run? If not then skip it
  1055. if ((this->TestsToRun.size() &&
  1056. std::find(this->TestsToRun.begin(),
  1057. this->TestsToRun.end(), inREcnt)
  1058. == this->TestsToRun.end()) || !it->IsInBasedOnREOptions)
  1059. {
  1060. continue;
  1061. }
  1062. }
  1063. it->Index = cnt; // save the index into the test list for this test
  1064. finalList.push_back(*it);
  1065. }
  1066. // Save the total number of tests before exclusions
  1067. this->TotalNumberOfTests = this->TestList.size();
  1068. // Set the TestList to the final list of all test
  1069. this->TestList = finalList;
  1070. std::string::size_type max = this->CTest->GetMaxTestNameWidth();
  1071. for (it = this->TestList.begin();
  1072. it != this->TestList.end(); it ++ )
  1073. {
  1074. cmCTestTestProperties& p = *it;
  1075. if(max < p.Name.size())
  1076. {
  1077. max = p.Name.size();
  1078. }
  1079. }
  1080. if(static_cast<std::string::size_type>(this->CTest->GetMaxTestNameWidth())
  1081. != max)
  1082. {
  1083. this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
  1084. }
  1085. }
  1086. bool cmCTestTestHandler::GetValue(const char* tag,
  1087. int& value,
  1088. std::ifstream& fin)
  1089. {
  1090. std::string line;
  1091. bool ret = true;
  1092. cmSystemTools::GetLineFromStream(fin, line);
  1093. if(line == tag)
  1094. {
  1095. fin >> value;
  1096. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  1097. }
  1098. else
  1099. {
  1100. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1101. "parse error: missing tag: "
  1102. << tag << " found [" << line << "]" << std::endl);
  1103. ret = false;
  1104. }
  1105. return ret;
  1106. }
  1107. bool cmCTestTestHandler::GetValue(const char* tag,
  1108. double& value,
  1109. std::ifstream& fin)
  1110. {
  1111. std::string line;
  1112. cmSystemTools::GetLineFromStream(fin, line);
  1113. bool ret = true;
  1114. if(line == tag)
  1115. {
  1116. fin >> value;
  1117. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  1118. }
  1119. else
  1120. {
  1121. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1122. "parse error: missing tag: "
  1123. << tag << " found [" << line << "]" << std::endl);
  1124. ret = false;
  1125. }
  1126. return ret;
  1127. }
  1128. bool cmCTestTestHandler::GetValue(const char* tag,
  1129. bool& value,
  1130. std::ifstream& fin)
  1131. {
  1132. std::string line;
  1133. cmSystemTools::GetLineFromStream(fin, line);
  1134. bool ret = true;
  1135. if(line == tag)
  1136. {
  1137. #ifdef __HAIKU__
  1138. int tmp = 0;
  1139. fin >> tmp;
  1140. value = false;
  1141. if(tmp)
  1142. {
  1143. value = true;
  1144. }
  1145. #else
  1146. fin >> value;
  1147. #endif
  1148. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  1149. }
  1150. else
  1151. {
  1152. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1153. "parse error: missing tag: "
  1154. << tag << " found [" << line << "]" << std::endl);
  1155. ret = false;
  1156. }
  1157. return ret;
  1158. }
  1159. bool cmCTestTestHandler::GetValue(const char* tag,
  1160. size_t& value,
  1161. std::ifstream& fin)
  1162. {
  1163. std::string line;
  1164. cmSystemTools::GetLineFromStream(fin, line);
  1165. bool ret = true;
  1166. if(line == tag)
  1167. {
  1168. fin >> value;
  1169. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  1170. }
  1171. else
  1172. {
  1173. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1174. "parse error: missing tag: "
  1175. << tag << " found [" << line.c_str() << "]" << std::endl);
  1176. ret = false;
  1177. }
  1178. return ret;
  1179. }
  1180. bool cmCTestTestHandler::GetValue(const char* tag,
  1181. std::string& value,
  1182. std::ifstream& fin)
  1183. {
  1184. std::string line;
  1185. cmSystemTools::GetLineFromStream(fin, line);
  1186. bool ret = true;
  1187. if(line == tag)
  1188. {
  1189. ret = cmSystemTools::GetLineFromStream(fin, value);
  1190. }
  1191. else
  1192. {
  1193. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1194. "parse error: missing tag: "
  1195. << tag << " found [" << line << "]" << std::endl);
  1196. ret = false;
  1197. }
  1198. return ret;
  1199. }
  1200. //---------------------------------------------------------------------
  1201. void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed,
  1202. std::vector<cmStdString> &failed)
  1203. {
  1204. this->ComputeTestList();
  1205. cmCTestMultiProcessHandler parallel;
  1206. parallel.SetCTest(this->CTest);
  1207. parallel.SetParallelLevel(this->CTest->GetParallelLevel());
  1208. parallel.SetTestHandler(this);
  1209. *this->LogFile << "Start testing: "
  1210. << this->CTest->CurrentTime() << std::endl
  1211. << "----------------------------------------------------------"
  1212. << std::endl;
  1213. cmCTestMultiProcessHandler::TestSet depends;
  1214. cmCTestMultiProcessHandler::TestMap tests;
  1215. cmCTestMultiProcessHandler::PropertiesMap properties;
  1216. for (ListOfTests::iterator it = this->TestList.begin();
  1217. it != this->TestList.end(); it ++ )
  1218. {
  1219. cmCTestTestProperties& p = *it;
  1220. if(p.Depends.size())
  1221. {
  1222. for(std::vector<std::string>::iterator i = p.Depends.begin();
  1223. i != p.Depends.end(); ++i)
  1224. {
  1225. for(ListOfTests::iterator it2 = this->TestList.begin();
  1226. it2 != this->TestList.end(); it2 ++ )
  1227. {
  1228. if(it2->Name == *i)
  1229. {
  1230. depends.insert(it2->Index);
  1231. break; // break out of test loop as name can only match 1
  1232. }
  1233. }
  1234. }
  1235. }
  1236. tests[it->Index] = depends;
  1237. properties[it->Index] = &*it;
  1238. }
  1239. parallel.SetTests(tests, properties);
  1240. parallel.SetPassFailVectors(&passed, &failed);
  1241. this->TestResults.clear();
  1242. parallel.SetTestResults(&this->TestResults);
  1243. if(this->CTest->GetShowOnly())
  1244. {
  1245. parallel.PrintTestList();
  1246. }
  1247. else
  1248. {
  1249. parallel.RunTests();
  1250. }
  1251. *this->LogFile << "End testing: "
  1252. << this->CTest->CurrentTime() << std::endl;
  1253. }
  1254. //----------------------------------------------------------------------
  1255. void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&)
  1256. {
  1257. }
  1258. //----------------------------------------------------------------------
  1259. void cmCTestTestHandler::GenerateDartOutput(std::ostream& os)
  1260. {
  1261. if ( !this->CTest->GetProduceXML() )
  1262. {
  1263. return;
  1264. }
  1265. this->CTest->StartXML(os, this->AppendXML);
  1266. os << "<Testing>\n"
  1267. << "\t<StartDateTime>" << this->StartTest << "</StartDateTime>\n"
  1268. << "\t<StartTestTime>" << this->StartTestTime << "</StartTestTime>\n"
  1269. << "\t<TestList>\n";
  1270. cmCTestTestHandler::TestResultsVector::size_type cc;
  1271. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  1272. {
  1273. cmCTestTestResult *result = &this->TestResults[cc];
  1274. std::string testPath = result->Path + "/" + result->Name;
  1275. os << "\t\t<Test>" << cmXMLSafe(
  1276. this->CTest->GetShortPathToFile(testPath.c_str()))
  1277. << "</Test>" << std::endl;
  1278. }
  1279. os << "\t</TestList>\n";
  1280. for ( cc = 0; cc < this->TestResults.size(); cc ++ )
  1281. {
  1282. cmCTestTestResult *result = &this->TestResults[cc];
  1283. this->WriteTestResultHeader(os, result);
  1284. os << "\t\t<Results>" << std::endl;
  1285. if ( result->Status != cmCTestTestHandler::NOT_RUN )
  1286. {
  1287. if ( result->Status != cmCTestTestHandler::COMPLETED ||
  1288. result->ReturnValue )
  1289. {
  1290. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1291. "name=\"Exit Code\"><Value>"
  1292. << cmXMLSafe(this->GetTestStatus(result->Status))
  1293. << "</Value>"
  1294. "</NamedMeasurement>\n"
  1295. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1296. "name=\"Exit Value\"><Value>"
  1297. << result->ReturnValue
  1298. << "</Value></NamedMeasurement>"
  1299. << std::endl;
  1300. }
  1301. os << result->RegressionImages;
  1302. os << "\t\t\t<NamedMeasurement type=\"numeric/double\" "
  1303. << "name=\"Execution Time\"><Value>"
  1304. << result->ExecutionTime
  1305. << "</Value></NamedMeasurement>\n";
  1306. if(result->Reason.size())
  1307. {
  1308. const char* reasonType = "Pass Reason";
  1309. if(result->Status != cmCTestTestHandler::COMPLETED &&
  1310. result->Status != cmCTestTestHandler::NOT_RUN)
  1311. {
  1312. reasonType = "Fail Reason";
  1313. }
  1314. os << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1315. << "name=\"" << reasonType << "\"><Value>"
  1316. << cmXMLSafe(result->Reason)
  1317. << "</Value></NamedMeasurement>\n";
  1318. }
  1319. os
  1320. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1321. << "name=\"Completion Status\"><Value>"
  1322. << cmXMLSafe(result->CompletionStatus)
  1323. << "</Value></NamedMeasurement>\n";
  1324. }
  1325. os
  1326. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1327. << "name=\"Command Line\"><Value>"
  1328. << cmXMLSafe(result->FullCommandLine)
  1329. << "</Value></NamedMeasurement>\n";
  1330. std::map<cmStdString,cmStdString>::iterator measureIt;
  1331. for ( measureIt = result->Properties->Measurements.begin();
  1332. measureIt != result->Properties->Measurements.end();
  1333. ++ measureIt )
  1334. {
  1335. os
  1336. << "\t\t\t<NamedMeasurement type=\"text/string\" "
  1337. << "name=\"" << measureIt->first.c_str() << "\"><Value>"
  1338. << cmXMLSafe(measureIt->second)
  1339. << "</Value></NamedMeasurement>\n";
  1340. }
  1341. os
  1342. << "\t\t\t<Measurement>\n"
  1343. << "\t\t\t\t<Value>";
  1344. os << cmXMLSafe(result->Output);
  1345. os
  1346. << "</Value>\n"
  1347. << "\t\t\t</Measurement>\n"
  1348. << "\t\t</Results>\n";
  1349. this->WriteTestResultFooter(os, result);
  1350. }
  1351. os << "\t<EndDateTime>" << this->EndTest << "</EndDateTime>\n"
  1352. << "\t<EndTestTime>" << this->EndTestTime << "</EndTestTime>\n"
  1353. << "<ElapsedMinutes>"
  1354. << static_cast<int>(this->ElapsedTestingTime/6)/10.0
  1355. << "</ElapsedMinutes>"
  1356. << "</Testing>" << std::endl;
  1357. this->CTest->EndXML(os);
  1358. }
  1359. //----------------------------------------------------------------------------
  1360. void cmCTestTestHandler::WriteTestResultHeader(std::ostream& os,
  1361. cmCTestTestResult* result)
  1362. {
  1363. os << "\t<Test Status=\"";
  1364. if ( result->Status == cmCTestTestHandler::COMPLETED )
  1365. {
  1366. os << "passed";
  1367. }
  1368. else if ( result->Status == cmCTestTestHandler::NOT_RUN )
  1369. {
  1370. os << "notrun";
  1371. }
  1372. else
  1373. {
  1374. os << "failed";
  1375. }
  1376. std::string testPath = result->Path + "/" + result->Name;
  1377. os << "\">\n"
  1378. << "\t\t<Name>" << cmXMLSafe(result->Name) << "</Name>\n"
  1379. << "\t\t<Path>" << cmXMLSafe(
  1380. this->CTest->GetShortPathToFile(result->Path.c_str())) << "</Path>\n"
  1381. << "\t\t<FullName>" << cmXMLSafe(
  1382. this->CTest->GetShortPathToFile(testPath.c_str())) << "</FullName>\n"
  1383. << "\t\t<FullCommandLine>"
  1384. << cmXMLSafe(result->FullCommandLine)
  1385. << "</FullCommandLine>\n";
  1386. }
  1387. //----------------------------------------------------------------------------
  1388. void cmCTestTestHandler::WriteTestResultFooter(std::ostream& os,
  1389. cmCTestTestResult* result)
  1390. {
  1391. if(!result->Properties->Labels.empty())
  1392. {
  1393. os << "\t\t<Labels>\n";
  1394. std::vector<std::string> const& labels = result->Properties->Labels;
  1395. for(std::vector<std::string>::const_iterator li = labels.begin();
  1396. li != labels.end(); ++li)
  1397. {
  1398. os << "\t\t\t<Label>" << cmXMLSafe(*li) << "</Label>\n";
  1399. }
  1400. os << "\t\t</Labels>\n";
  1401. }
  1402. os
  1403. << "\t</Test>" << std::endl;
  1404. }
  1405. //----------------------------------------------------------------------
  1406. int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec)
  1407. {
  1408. std::vector<cmStdString>::iterator it;
  1409. for ( it = vec.begin(); it != vec.end(); ++it )
  1410. {
  1411. int retVal = 0;
  1412. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it
  1413. << std::endl);
  1414. if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, true
  1415. /*this->Verbose*/) || retVal != 0 )
  1416. {
  1417. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem running command: "
  1418. << *it << std::endl);
  1419. return 0;
  1420. }
  1421. }
  1422. return 1;
  1423. }
  1424. //----------------------------------------------------------------------
  1425. // Find the appropriate executable to run for a test
  1426. std::string cmCTestTestHandler::FindTheExecutable(const char *exe)
  1427. {
  1428. std::string resConfig;
  1429. std::vector<std::string> extraPaths;
  1430. std::vector<std::string> failedPaths;
  1431. return cmCTestTestHandler::FindExecutable(this->CTest,
  1432. exe, resConfig,
  1433. extraPaths,
  1434. failedPaths);
  1435. }
  1436. // add additional configurations to the search path
  1437. void cmCTestTestHandler
  1438. ::AddConfigurations(cmCTest *ctest,
  1439. std::vector<std::string> &attempted,
  1440. std::vector<std::string> &attemptedConfigs,
  1441. std::string filepath,
  1442. std::string &filename)
  1443. {
  1444. std::string tempPath;
  1445. if (filepath.size() &&
  1446. filepath[filepath.size()-1] != '/')
  1447. {
  1448. filepath += "/";
  1449. }
  1450. tempPath = filepath + filename;
  1451. attempted.push_back(tempPath);
  1452. attemptedConfigs.push_back("");
  1453. if(ctest->GetConfigType().size())
  1454. {
  1455. tempPath = filepath;
  1456. tempPath += ctest->GetConfigType();
  1457. tempPath += "/";
  1458. tempPath += filename;
  1459. attempted.push_back(tempPath);
  1460. attemptedConfigs.push_back(ctest->GetConfigType());
  1461. // If the file is an OSX bundle then the configtyp
  1462. // will be at the start of the path
  1463. tempPath = ctest->GetConfigType();
  1464. tempPath += "/";
  1465. tempPath += filepath;
  1466. tempPath += filename;
  1467. attempted.push_back(tempPath);
  1468. attemptedConfigs.push_back(ctest->GetConfigType());
  1469. }
  1470. else
  1471. {
  1472. // no config specified to try some options
  1473. tempPath = filepath;
  1474. tempPath += "Release/";
  1475. tempPath += filename;
  1476. attempted.push_back(tempPath);
  1477. attemptedConfigs.push_back("Release");
  1478. tempPath = filepath;
  1479. tempPath += "Debug/";
  1480. tempPath += filename;
  1481. attempted.push_back(tempPath);
  1482. attemptedConfigs.push_back("Debug");
  1483. tempPath = filepath;
  1484. tempPath += "MinSizeRel/";
  1485. tempPath += filename;
  1486. attempted.push_back(tempPath);
  1487. attemptedConfigs.push_back("MinSizeRel");
  1488. tempPath = filepath;
  1489. tempPath += "RelWithDebInfo/";
  1490. tempPath += filename;
  1491. attempted.push_back(tempPath);
  1492. attemptedConfigs.push_back("RelWithDebInfo");
  1493. tempPath = filepath;
  1494. tempPath += "Deployment/";
  1495. tempPath += filename;
  1496. attempted.push_back(tempPath);
  1497. attemptedConfigs.push_back("Deployment");
  1498. tempPath = filepath;
  1499. tempPath += "Development/";
  1500. tempPath += filename;
  1501. attempted.push_back(tempPath);
  1502. attemptedConfigs.push_back("Deployment");
  1503. }
  1504. }
  1505. //----------------------------------------------------------------------
  1506. // Find the appropriate executable to run for a test
  1507. std::string cmCTestTestHandler
  1508. ::FindExecutable(cmCTest *ctest,
  1509. const char *testCommand,
  1510. std::string &resultingConfig,
  1511. std::vector<std::string> &extraPaths,
  1512. std::vector<std::string> &failed)
  1513. {
  1514. // now run the compiled test if we can find it
  1515. std::vector<std::string> attempted;
  1516. std::vector<std::string> attemptedConfigs;
  1517. std::string tempPath;
  1518. std::string filepath =
  1519. cmSystemTools::GetFilenamePath(testCommand);
  1520. std::string filename =
  1521. cmSystemTools::GetFilenameName(testCommand);
  1522. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1523. attemptedConfigs,
  1524. filepath,filename);
  1525. // even if a fullpath was specified also try it relative to the current
  1526. // directory
  1527. if (filepath.size() && filepath[0] == '/')
  1528. {
  1529. std::string localfilepath = filepath.substr(1,filepath.size()-1);
  1530. cmCTestTestHandler::AddConfigurations(ctest, attempted,
  1531. attemptedConfigs,
  1532. localfilepath,filename);
  1533. }
  1534. // if extraPaths are provided and we were not passed a full path, try them,
  1535. // try any extra paths
  1536. if (filepath.size() == 0)
  1537. {
  1538. for (unsigned int i = 0; i < extraPaths.size(); ++i)
  1539. {
  1540. std::string filepathExtra =
  1541. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1542. std::string filenameExtra =
  1543. cmSystemTools::GetFilenameName(extraPaths[i]);
  1544. cmCTestTestHandler::AddConfigurations(ctest,attempted,
  1545. attemptedConfigs,
  1546. filepathExtra,
  1547. filenameExtra);
  1548. }
  1549. }
  1550. // store the final location in fullPath
  1551. std::string fullPath;
  1552. // now look in the paths we specified above
  1553. for(unsigned int ai=0;
  1554. ai < attempted.size() && fullPath.size() == 0; ++ai)
  1555. {
  1556. // first check without exe extension
  1557. if(cmSystemTools::FileExists(attempted[ai].c_str())
  1558. && !cmSystemTools::FileIsDirectory(attempted[ai].c_str()))
  1559. {
  1560. fullPath = cmSystemTools::CollapseFullPath(attempted[ai].c_str());
  1561. resultingConfig = attemptedConfigs[ai];
  1562. }
  1563. // then try with the exe extension
  1564. else
  1565. {
  1566. failed.push_back(attempted[ai].c_str());
  1567. tempPath = attempted[ai];
  1568. tempPath += cmSystemTools::GetExecutableExtension();
  1569. if(cmSystemTools::FileExists(tempPath.c_str())
  1570. && !cmSystemTools::FileIsDirectory(tempPath.c_str()))
  1571. {
  1572. fullPath = cmSystemTools::CollapseFullPath(tempPath.c_str());
  1573. resultingConfig = attemptedConfigs[ai];
  1574. }
  1575. else
  1576. {
  1577. failed.push_back(tempPath.c_str());
  1578. }
  1579. }
  1580. }
  1581. // if everything else failed, check the users path, but only if a full path
  1582. // wasn't specified
  1583. if (fullPath.size() == 0 && filepath.size() == 0)
  1584. {
  1585. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1586. if (path != "")
  1587. {
  1588. resultingConfig = "";
  1589. return path;
  1590. }
  1591. }
  1592. if(fullPath.size() == 0)
  1593. {
  1594. cmCTestLog(ctest, HANDLER_OUTPUT,
  1595. "Could not find executable " << testCommand << "\n"
  1596. << "Looked in the following places:\n");
  1597. for(std::vector<std::string>::iterator i = failed.begin();
  1598. i != failed.end(); ++i)
  1599. {
  1600. cmCTestLog(ctest, HANDLER_OUTPUT,
  1601. i->c_str() << "\n");
  1602. }
  1603. }
  1604. return fullPath;
  1605. }
  1606. //----------------------------------------------------------------------
  1607. void cmCTestTestHandler::GetListOfTests()
  1608. {
  1609. if ( !this->IncludeLabelRegExp.empty() )
  1610. {
  1611. this->IncludeLabelRegularExpression.
  1612. compile(this->IncludeLabelRegExp.c_str());
  1613. }
  1614. if ( !this->IncludeLabelRegExp.empty() )
  1615. {
  1616. this->ExcludeLabelRegularExpression.
  1617. compile(this->ExcludeLabelRegExp.c_str());
  1618. }
  1619. if ( !this->IncludeRegExp.empty() )
  1620. {
  1621. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1622. }
  1623. if ( !this->ExcludeRegExp.empty() )
  1624. {
  1625. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1626. }
  1627. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1628. "Constructing a list of tests" << std::endl);
  1629. cmake cm;
  1630. cmGlobalGenerator gg;
  1631. gg.SetCMakeInstance(&cm);
  1632. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  1633. cmMakefile *mf = lg->GetMakefile();
  1634. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1635. this->CTest->GetConfigType().c_str());
  1636. // Add handler for ADD_TEST
  1637. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1638. newCom1->TestHandler = this;
  1639. cm.AddCommand(newCom1);
  1640. // Add handler for SUBDIRS
  1641. cmCTestSubdirCommand* newCom2 =
  1642. new cmCTestSubdirCommand;
  1643. newCom2->TestHandler = this;
  1644. cm.AddCommand(newCom2);
  1645. // Add handler for ADD_SUBDIRECTORY
  1646. cmCTestAddSubdirectoryCommand* newCom3 =
  1647. new cmCTestAddSubdirectoryCommand;
  1648. newCom3->TestHandler = this;
  1649. cm.AddCommand(newCom3);
  1650. // Add handler for SET_SOURCE_FILES_PROPERTIES
  1651. cmCTestSetTestsPropertiesCommand* newCom4
  1652. = new cmCTestSetTestsPropertiesCommand;
  1653. newCom4->TestHandler = this;
  1654. cm.AddCommand(newCom4);
  1655. const char* testFilename;
  1656. if( cmSystemTools::FileExists("CTestTestfile.cmake") )
  1657. {
  1658. // does the CTestTestfile.cmake exist ?
  1659. testFilename = "CTestTestfile.cmake";
  1660. }
  1661. else if( cmSystemTools::FileExists("DartTestfile.txt") )
  1662. {
  1663. // does the DartTestfile.txt exist ?
  1664. testFilename = "DartTestfile.txt";
  1665. }
  1666. else
  1667. {
  1668. return;
  1669. }
  1670. if ( !mf->ReadListFile(0, testFilename) )
  1671. {
  1672. return;
  1673. }
  1674. if ( cmSystemTools::GetErrorOccuredFlag() )
  1675. {
  1676. return;
  1677. }
  1678. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1679. "Done constructing a list of tests" << std::endl);
  1680. }
  1681. //----------------------------------------------------------------------
  1682. void cmCTestTestHandler::UseIncludeRegExp()
  1683. {
  1684. this->UseIncludeRegExpFlag = true;
  1685. }
  1686. //----------------------------------------------------------------------
  1687. void cmCTestTestHandler::UseExcludeRegExp()
  1688. {
  1689. this->UseExcludeRegExpFlag = true;
  1690. this->UseExcludeRegExpFirst = this->UseIncludeRegExpFlag ? false : true;
  1691. }
  1692. //----------------------------------------------------------------------
  1693. const char* cmCTestTestHandler::GetTestStatus(int status)
  1694. {
  1695. static const char statuses[][100] = {
  1696. "Not Run",
  1697. "Timeout",
  1698. "SEGFAULT",
  1699. "ILLEGAL",
  1700. "INTERRUPT",
  1701. "NUMERICAL",
  1702. "OTHER_FAULT",
  1703. "Failed",
  1704. "BAD_COMMAND",
  1705. "Completed"
  1706. };
  1707. if ( status < cmCTestTestHandler::NOT_RUN ||
  1708. status > cmCTestTestHandler::COMPLETED )
  1709. {
  1710. return "No Status";
  1711. }
  1712. return statuses[status];
  1713. }
  1714. //----------------------------------------------------------------------
  1715. void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
  1716. {
  1717. if (this->TestsToRunString.empty())
  1718. {
  1719. return;
  1720. }
  1721. int start;
  1722. int end = -1;
  1723. double stride = -1;
  1724. std::string::size_type pos = 0;
  1725. std::string::size_type pos2;
  1726. // read start
  1727. if(GetNextNumber(this->TestsToRunString, start, pos, pos2))
  1728. {
  1729. // read end
  1730. if(GetNextNumber(this->TestsToRunString, end, pos, pos2))
  1731. {
  1732. // read stride
  1733. if(GetNextRealNumber(this->TestsToRunString, stride, pos, pos2))
  1734. {
  1735. int val =0;
  1736. // now read specific numbers
  1737. while(GetNextNumber(this->TestsToRunString, val, pos, pos2))
  1738. {
  1739. this->TestsToRun.push_back(val);
  1740. }
  1741. this->TestsToRun.push_back(val);
  1742. }
  1743. }
  1744. }
  1745. // if start is not specified then we assume we start at 1
  1746. if(start == -1)
  1747. {
  1748. start = 1;
  1749. }
  1750. // if end isnot specified then we assume we end with the last test
  1751. if(end == -1)
  1752. {
  1753. end = static_cast<int>(numTests);
  1754. }
  1755. // if the stride wasn't specified then it defaults to 1
  1756. if(stride == -1)
  1757. {
  1758. stride = 1;
  1759. }
  1760. // if we have a range then add it
  1761. if(end != -1 && start != -1 && stride > 0)
  1762. {
  1763. int i = 0;
  1764. while (i*stride + start <= end)
  1765. {
  1766. this->TestsToRun.push_back(static_cast<int>(i*stride+start));
  1767. ++i;
  1768. }
  1769. }
  1770. // sort the array
  1771. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1772. std::less<int>());
  1773. // remove duplicates
  1774. std::vector<int>::iterator new_end =
  1775. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1776. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1777. }
  1778. //----------------------------------------------------------------------
  1779. // Just for convenience
  1780. #define SPACE_REGEX "[ \t\r\n]"
  1781. //----------------------------------------------------------------------
  1782. std::string cmCTestTestHandler::GenerateRegressionImages(
  1783. const std::string& xml)
  1784. {
  1785. cmsys::RegularExpression twoattributes(
  1786. "<DartMeasurement"
  1787. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1788. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1789. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1790. cmsys::RegularExpression threeattributes(
  1791. "<DartMeasurement"
  1792. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1793. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1794. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1795. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1796. cmsys::RegularExpression fourattributes(
  1797. "<DartMeasurement"
  1798. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1799. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1800. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1801. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1802. SPACE_REGEX "*>([^<]*)</DartMeasurement>");
  1803. cmsys::RegularExpression cdatastart(
  1804. "<DartMeasurement"
  1805. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1806. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1807. SPACE_REGEX "*>"
  1808. SPACE_REGEX "*<!\\[CDATA\\[");
  1809. cmsys::RegularExpression cdataend(
  1810. "]]>"
  1811. SPACE_REGEX "*</DartMeasurement>");
  1812. cmsys::RegularExpression measurementfile(
  1813. "<DartMeasurementFile"
  1814. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1815. SPACE_REGEX "*(name|type|encoding|compression)=\"([^\"]*)\""
  1816. SPACE_REGEX "*>([^<]*)</DartMeasurementFile>");
  1817. cmOStringStream ostr;
  1818. bool done = false;
  1819. std::string cxml = xml;
  1820. while ( ! done )
  1821. {
  1822. if ( twoattributes.find(cxml) )
  1823. {
  1824. ostr
  1825. << "\t\t\t<NamedMeasurement"
  1826. << " " << twoattributes.match(1) << "=\""
  1827. << twoattributes.match(2) << "\""
  1828. << " " << twoattributes.match(3) << "=\""
  1829. << twoattributes.match(4) << "\""
  1830. << "><Value>" << twoattributes.match(5)
  1831. << "</Value></NamedMeasurement>"
  1832. << std::endl;
  1833. cxml.erase(twoattributes.start(),
  1834. twoattributes.end() - twoattributes.start());
  1835. }
  1836. else if ( threeattributes.find(cxml) )
  1837. {
  1838. ostr
  1839. << "\t\t\t<NamedMeasurement"
  1840. << " " << threeattributes.match(1) << "=\""
  1841. << threeattributes.match(2) << "\""
  1842. << " " << threeattributes.match(3) << "=\""
  1843. << threeattributes.match(4) << "\""
  1844. << " " << threeattributes.match(5) << "=\""
  1845. << threeattributes.match(6) << "\""
  1846. << "><Value>" << threeattributes.match(7)
  1847. << "</Value></NamedMeasurement>"
  1848. << std::endl;
  1849. cxml.erase(threeattributes.start(),
  1850. threeattributes.end() - threeattributes.start());
  1851. }
  1852. else if ( fourattributes.find(cxml) )
  1853. {
  1854. ostr
  1855. << "\t\t\t<NamedMeasurement"
  1856. << " " << fourattributes.match(1) << "=\""
  1857. << fourattributes.match(2) << "\""
  1858. << " " << fourattributes.match(3) << "=\""
  1859. << fourattributes.match(4) << "\""
  1860. << " " << fourattributes.match(5) << "=\""
  1861. << fourattributes.match(6) << "\""
  1862. << " " << fourattributes.match(7) << "=\""
  1863. << fourattributes.match(8) << "\""
  1864. << "><Value>" << fourattributes.match(9)
  1865. << "</Value></NamedMeasurement>"
  1866. << std::endl;
  1867. cxml.erase(fourattributes.start(),
  1868. fourattributes.end() - fourattributes.start());
  1869. }
  1870. else if ( cdatastart.find(cxml) && cdataend.find(cxml) )
  1871. {
  1872. ostr
  1873. << "\t\t\t<NamedMeasurement"
  1874. << " " << cdatastart.match(1) << "=\""
  1875. << cdatastart.match(2) << "\""
  1876. << " " << cdatastart.match(3) << "=\""
  1877. << cdatastart.match(4) << "\""
  1878. << "><Value><![CDATA["
  1879. << cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end())
  1880. << "]]></Value></NamedMeasurement>"
  1881. << std::endl;
  1882. cxml.erase(cdatastart.start(),
  1883. cdataend.end() - cdatastart.start());
  1884. }
  1885. else if ( measurementfile.find(cxml) )
  1886. {
  1887. const std::string& filename =
  1888. cmCTest::CleanString(measurementfile.match(5));
  1889. if ( cmSystemTools::FileExists(filename.c_str()) )
  1890. {
  1891. long len = cmSystemTools::FileLength(filename.c_str());
  1892. if ( len == 0 )
  1893. {
  1894. std::string k1 = measurementfile.match(1);
  1895. std::string v1 = measurementfile.match(2);
  1896. std::string k2 = measurementfile.match(3);
  1897. std::string v2 = measurementfile.match(4);
  1898. if ( cmSystemTools::LowerCase(k1) == "type" )
  1899. {
  1900. v1 = "text/string";
  1901. }
  1902. if ( cmSystemTools::LowerCase(k2) == "type" )
  1903. {
  1904. v2 = "text/string";
  1905. }
  1906. ostr
  1907. << "\t\t\t<NamedMeasurement"
  1908. << " " << k1 << "=\"" << v1 << "\""
  1909. << " " << k2 << "=\"" << v2 << "\""
  1910. << " encoding=\"none\""
  1911. << "><Value>Image " << filename.c_str()
  1912. << " is empty</Value></NamedMeasurement>";
  1913. }
  1914. else
  1915. {
  1916. std::ifstream ifs(filename.c_str(), std::ios::in
  1917. #ifdef _WIN32
  1918. | std::ios::binary
  1919. #endif
  1920. );
  1921. unsigned char *file_buffer = new unsigned char [ len + 1 ];
  1922. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1923. unsigned char *encoded_buffer
  1924. = new unsigned char [ static_cast<int>(len * 1.5 + 5) ];
  1925. unsigned long rlen
  1926. = cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1927. unsigned long cc;
  1928. ostr
  1929. << "\t\t\t<NamedMeasurement"
  1930. << " " << measurementfile.match(1) << "=\""
  1931. << measurementfile.match(2) << "\""
  1932. << " " << measurementfile.match(3) << "=\""
  1933. << measurementfile.match(4) << "\""
  1934. << " encoding=\"base64\""
  1935. << ">" << std::endl << "\t\t\t\t<Value>";
  1936. for ( cc = 0; cc < rlen; cc ++ )
  1937. {
  1938. ostr << encoded_buffer[cc];
  1939. if ( cc % 60 == 0 && cc )
  1940. {
  1941. ostr << std::endl;
  1942. }
  1943. }
  1944. ostr
  1945. << "</Value>" << std::endl << "\t\t\t</NamedMeasurement>"
  1946. << std::endl;
  1947. delete [] file_buffer;
  1948. delete [] encoded_buffer;
  1949. }
  1950. }
  1951. else
  1952. {
  1953. int idx = 4;
  1954. if ( measurementfile.match(1) == "name" )
  1955. {
  1956. idx = 2;
  1957. }
  1958. ostr
  1959. << "\t\t\t<NamedMeasurement"
  1960. << " name=\"" << measurementfile.match(idx) << "\""
  1961. << " text=\"text/string\""
  1962. << "><Value>File " << filename.c_str()
  1963. << " not found</Value></NamedMeasurement>"
  1964. << std::endl;
  1965. cmCTestLog(this->CTest, HANDLER_OUTPUT, "File \"" << filename.c_str()
  1966. << "\" not found." << std::endl);
  1967. }
  1968. cxml.erase(measurementfile.start(),
  1969. measurementfile.end() - measurementfile.start());
  1970. }
  1971. else
  1972. {
  1973. done = true;
  1974. }
  1975. }
  1976. return ostr.str();
  1977. }
  1978. //----------------------------------------------------------------------
  1979. void cmCTestTestHandler::SetIncludeRegExp(const char *arg)
  1980. {
  1981. this->IncludeRegExp = arg;
  1982. }
  1983. //----------------------------------------------------------------------
  1984. void cmCTestTestHandler::SetExcludeRegExp(const char *arg)
  1985. {
  1986. this->ExcludeRegExp = arg;
  1987. }
  1988. //----------------------------------------------------------------------
  1989. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1990. {
  1991. if ( !in )
  1992. {
  1993. return;
  1994. }
  1995. this->TestsToRunString = in;
  1996. // if the argument is a file, then read it and use the contents as the
  1997. // string
  1998. if(cmSystemTools::FileExists(in))
  1999. {
  2000. std::ifstream fin(in);
  2001. unsigned long filelen = cmSystemTools::FileLength(in);
  2002. char* buff = new char[filelen+1];
  2003. fin.getline(buff, filelen);
  2004. buff[fin.gcount()] = 0;
  2005. this->TestsToRunString = buff;
  2006. }
  2007. }
  2008. //----------------------------------------------------------------------
  2009. bool cmCTestTestHandler::CleanTestOutput(std::string& output,
  2010. size_t remove_threshold)
  2011. {
  2012. if ( remove_threshold == 0 )
  2013. {
  2014. return true;
  2015. }
  2016. if ( output.find("CTEST_FULL_OUTPUT") != output.npos )
  2017. {
  2018. return true;
  2019. }
  2020. cmOStringStream ostr;
  2021. std::string::size_type cc;
  2022. std::string::size_type skipsize = 0;
  2023. int inTag = 0;
  2024. int skipped = 0;
  2025. for ( cc = 0; cc < output.size(); cc ++ )
  2026. {
  2027. int ch = output[cc];
  2028. if ( ch < 0 || ch > 255 )
  2029. {
  2030. break;
  2031. }
  2032. if ( ch == '<' )
  2033. {
  2034. inTag = 1;
  2035. }
  2036. if ( !inTag )
  2037. {
  2038. int notskip = 0;
  2039. // Skip
  2040. if ( skipsize < remove_threshold )
  2041. {
  2042. ostr << static_cast<char>(ch);
  2043. notskip = 1;
  2044. }
  2045. skipsize ++;
  2046. if ( notskip && skipsize >= remove_threshold )
  2047. {
  2048. skipped = 1;
  2049. }
  2050. }
  2051. else
  2052. {
  2053. ostr << static_cast<char>(ch);
  2054. }
  2055. if ( ch == '>' )
  2056. {
  2057. inTag = 0;
  2058. }
  2059. }
  2060. if ( skipped )
  2061. {
  2062. ostr << "..." << std::endl << "The rest of the test output was removed "
  2063. "since it exceeds the threshold of "
  2064. << remove_threshold << " characters." << std::endl;
  2065. }
  2066. output = ostr.str();
  2067. return true;
  2068. }
  2069. //----------------------------------------------------------------------
  2070. bool cmCTestTestHandler::SetTestsProperties(
  2071. const std::vector<std::string>& args)
  2072. {
  2073. std::vector<std::string>::const_iterator it;
  2074. std::vector<cmStdString> tests;
  2075. bool found = false;
  2076. for ( it = args.begin(); it != args.end(); ++ it )
  2077. {
  2078. if ( *it == "PROPERTIES" )
  2079. {
  2080. found = true;
  2081. break;
  2082. }
  2083. tests.push_back(*it);
  2084. }
  2085. if ( !found )
  2086. {
  2087. return false;
  2088. }
  2089. ++ it; // skip PROPERTIES
  2090. for ( ; it != args.end(); ++ it )
  2091. {
  2092. std::string key = *it;
  2093. ++ it;
  2094. if ( it == args.end() )
  2095. {
  2096. break;
  2097. }
  2098. std::string val = *it;
  2099. std::vector<cmStdString>::const_iterator tit;
  2100. for ( tit = tests.begin(); tit != tests.end(); ++ tit )
  2101. {
  2102. cmCTestTestHandler::ListOfTests::iterator rtit;
  2103. for ( rtit = this->TestList.begin();
  2104. rtit != this->TestList.end();
  2105. ++ rtit )
  2106. {
  2107. if ( *tit == rtit->Name )
  2108. {
  2109. if ( key == "WILL_FAIL" )
  2110. {
  2111. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  2112. }
  2113. if ( key == "TIMEOUT" )
  2114. {
  2115. rtit->Timeout = atof(val.c_str());
  2116. }
  2117. if ( key == "FAIL_REGULAR_EXPRESSION" )
  2118. {
  2119. std::vector<std::string> lval;
  2120. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  2121. std::vector<std::string>::iterator crit;
  2122. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  2123. {
  2124. rtit->ErrorRegularExpressions.push_back(
  2125. std::pair<cmsys::RegularExpression, std::string>(
  2126. cmsys::RegularExpression(crit->c_str()),
  2127. std::string(crit->c_str())));
  2128. }
  2129. }
  2130. if ( key == "DEPENDS" )
  2131. {
  2132. std::vector<std::string> lval;
  2133. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  2134. std::vector<std::string>::iterator crit;
  2135. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  2136. {
  2137. rtit->Depends.push_back(*crit);
  2138. }
  2139. }
  2140. if ( key == "ENVIRONMENT" )
  2141. {
  2142. std::vector<std::string> lval;
  2143. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  2144. std::vector<std::string>::iterator crit;
  2145. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  2146. {
  2147. rtit->Environment.push_back(*crit);
  2148. }
  2149. }
  2150. if ( key == "LABELS" )
  2151. {
  2152. std::vector<std::string> lval;
  2153. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  2154. std::vector<std::string>::iterator crit;
  2155. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  2156. {
  2157. rtit->Labels.push_back(*crit);
  2158. }
  2159. }
  2160. if ( key == "MEASUREMENT" )
  2161. {
  2162. size_t pos = val.find_first_of("=");
  2163. if ( pos != val.npos )
  2164. {
  2165. std::string mKey = val.substr(0, pos);
  2166. const char* mVal = val.c_str() + pos + 1;
  2167. rtit->Measurements[mKey] = mVal;
  2168. }
  2169. else
  2170. {
  2171. rtit->Measurements[val] = "1";
  2172. }
  2173. }
  2174. if ( key == "PASS_REGULAR_EXPRESSION" )
  2175. {
  2176. std::vector<std::string> lval;
  2177. cmSystemTools::ExpandListArgument(val.c_str(), lval);
  2178. std::vector<std::string>::iterator crit;
  2179. for ( crit = lval.begin(); crit != lval.end(); ++ crit )
  2180. {
  2181. rtit->RequiredRegularExpressions.push_back(
  2182. std::pair<cmsys::RegularExpression, std::string>(
  2183. cmsys::RegularExpression(crit->c_str()),
  2184. std::string(crit->c_str())));
  2185. }
  2186. }
  2187. }
  2188. }
  2189. }
  2190. }
  2191. return true;
  2192. }
  2193. //----------------------------------------------------------------------
  2194. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  2195. {
  2196. const std::string& testname = args[0];
  2197. cmCTestLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl);
  2198. if (this->UseExcludeRegExpFlag &&
  2199. this->UseExcludeRegExpFirst &&
  2200. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  2201. {
  2202. return true;
  2203. }
  2204. if ( this->MemCheck )
  2205. {
  2206. std::vector<cmStdString>::iterator it;
  2207. bool found = false;
  2208. for ( it = this->CustomTestsIgnore.begin();
  2209. it != this->CustomTestsIgnore.end(); ++ it )
  2210. {
  2211. if ( *it == testname )
  2212. {
  2213. found = true;
  2214. break;
  2215. }
  2216. }
  2217. if ( found )
  2218. {
  2219. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore memcheck: "
  2220. << *it << std::endl);
  2221. return true;
  2222. }
  2223. }
  2224. else
  2225. {
  2226. std::vector<cmStdString>::iterator it;
  2227. bool found = false;
  2228. for ( it = this->CustomTestsIgnore.begin();
  2229. it != this->CustomTestsIgnore.end(); ++ it )
  2230. {
  2231. if ( *it == testname )
  2232. {
  2233. found = true;
  2234. break;
  2235. }
  2236. }
  2237. if ( found )
  2238. {
  2239. cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Ignore test: "
  2240. << *it << std::endl);
  2241. return true;
  2242. }
  2243. }
  2244. cmCTestTestProperties test;
  2245. test.Name = testname;
  2246. test.Args = args;
  2247. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  2248. cmCTestLog(this->CTest, DEBUG, "Set test directory: "
  2249. << test.Directory << std::endl);
  2250. test.IsInBasedOnREOptions = true;
  2251. test.WillFail = false;
  2252. test.Timeout = 0;
  2253. if (this->UseIncludeRegExpFlag &&
  2254. !this->IncludeTestsRegularExpression.find(testname.c_str()))
  2255. {
  2256. test.IsInBasedOnREOptions = false;
  2257. }
  2258. else if (this->UseExcludeRegExpFlag &&
  2259. !this->UseExcludeRegExpFirst &&
  2260. this->ExcludeTestsRegularExpression.find(testname.c_str()))
  2261. {
  2262. test.IsInBasedOnREOptions = false;
  2263. }
  2264. this->TestList.push_back(test);
  2265. return true;
  2266. }