cmCTestTestHandler.cxx 82 KB

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