cmCTestTestHandler.cxx 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481
  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 = 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 = nullptr;
  537. return 1;
  538. }
  539. cmXMLWriter xml(xmlfile);
  540. this->GenerateDartOutput(xml);
  541. }
  542. if (!this->PostProcessHandler()) {
  543. this->LogFile = nullptr;
  544. return -1;
  545. }
  546. if (!failed.empty()) {
  547. this->LogFile = nullptr;
  548. return -1;
  549. }
  550. this->LogFile = 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(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", "numeric/double");
  1298. xml.Attribute("name", "Processors");
  1299. xml.Element("Value", result->Properties->Processors);
  1300. xml.EndElement(); // NamedMeasurement
  1301. xml.StartElement("NamedMeasurement");
  1302. xml.Attribute("type", "text/string");
  1303. xml.Attribute("name", "Completion Status");
  1304. xml.Element("Value", result->CompletionStatus);
  1305. xml.EndElement(); // NamedMeasurement
  1306. xml.StartElement("NamedMeasurement");
  1307. xml.Attribute("type", "text/string");
  1308. xml.Attribute("name", "Command Line");
  1309. xml.Element("Value", result->FullCommandLine);
  1310. xml.EndElement(); // NamedMeasurement
  1311. std::map<std::string, std::string>::iterator measureIt;
  1312. for (measureIt = result->Properties->Measurements.begin();
  1313. measureIt != result->Properties->Measurements.end(); ++measureIt) {
  1314. xml.StartElement("NamedMeasurement");
  1315. xml.Attribute("type", "text/string");
  1316. xml.Attribute("name", measureIt->first);
  1317. xml.Element("Value", measureIt->second);
  1318. xml.EndElement(); // NamedMeasurement
  1319. }
  1320. xml.StartElement("Measurement");
  1321. xml.StartElement("Value");
  1322. if (result->CompressOutput) {
  1323. xml.Attribute("encoding", "base64");
  1324. xml.Attribute("compression", "gzip");
  1325. }
  1326. xml.Content(result->Output);
  1327. xml.EndElement(); // Value
  1328. xml.EndElement(); // Measurement
  1329. xml.EndElement(); // Results
  1330. this->AttachFiles(xml, result);
  1331. this->WriteTestResultFooter(xml, result);
  1332. }
  1333. xml.Element("EndDateTime", this->EndTest);
  1334. xml.Element("EndTestTime", this->EndTestTime);
  1335. xml.Element("ElapsedMinutes",
  1336. static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
  1337. xml.EndElement(); // Testing
  1338. this->CTest->EndXML(xml);
  1339. }
  1340. void cmCTestTestHandler::WriteTestResultHeader(cmXMLWriter& xml,
  1341. cmCTestTestResult* result)
  1342. {
  1343. xml.StartElement("Test");
  1344. if (result->Status == cmCTestTestHandler::COMPLETED) {
  1345. xml.Attribute("Status", "passed");
  1346. } else if (result->Status == cmCTestTestHandler::NOT_RUN) {
  1347. xml.Attribute("Status", "notrun");
  1348. } else {
  1349. xml.Attribute("Status", "failed");
  1350. }
  1351. std::string testPath = result->Path + "/" + result->Name;
  1352. xml.Element("Name", result->Name);
  1353. xml.Element("Path", this->CTest->GetShortPathToFile(result->Path.c_str()));
  1354. xml.Element("FullName", this->CTest->GetShortPathToFile(testPath.c_str()));
  1355. xml.Element("FullCommandLine", result->FullCommandLine);
  1356. }
  1357. void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml,
  1358. cmCTestTestResult* result)
  1359. {
  1360. if (!result->Properties->Labels.empty()) {
  1361. xml.StartElement("Labels");
  1362. std::vector<std::string> const& labels = result->Properties->Labels;
  1363. for (std::vector<std::string>::const_iterator li = labels.begin();
  1364. li != labels.end(); ++li) {
  1365. xml.Element("Label", *li);
  1366. }
  1367. xml.EndElement(); // Labels
  1368. }
  1369. xml.EndElement(); // Test
  1370. }
  1371. void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml,
  1372. cmCTestTestResult* result)
  1373. {
  1374. if (result->Status != cmCTestTestHandler::COMPLETED &&
  1375. !result->Properties->AttachOnFail.empty()) {
  1376. result->Properties->AttachedFiles.insert(
  1377. result->Properties->AttachedFiles.end(),
  1378. result->Properties->AttachOnFail.begin(),
  1379. result->Properties->AttachOnFail.end());
  1380. }
  1381. for (std::vector<std::string>::const_iterator file =
  1382. result->Properties->AttachedFiles.begin();
  1383. file != result->Properties->AttachedFiles.end(); ++file) {
  1384. const std::string& base64 = this->CTest->Base64GzipEncodeFile(*file);
  1385. std::string fname = cmSystemTools::GetFilenameName(*file);
  1386. xml.StartElement("NamedMeasurement");
  1387. xml.Attribute("name", "Attached File");
  1388. xml.Attribute("encoding", "base64");
  1389. xml.Attribute("compression", "tar/gzip");
  1390. xml.Attribute("filename", fname);
  1391. xml.Attribute("type", "file");
  1392. xml.Element("Value", base64);
  1393. xml.EndElement(); // NamedMeasurement
  1394. }
  1395. }
  1396. int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
  1397. {
  1398. std::vector<std::string>::iterator it;
  1399. for (it = vec.begin(); it != vec.end(); ++it) {
  1400. int retVal = 0;
  1401. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1402. "Run command: " << *it << std::endl, this->Quiet);
  1403. if (!cmSystemTools::RunSingleCommand(it->c_str(), nullptr, nullptr,
  1404. &retVal, nullptr,
  1405. cmSystemTools::OUTPUT_MERGE
  1406. /*this->Verbose*/) ||
  1407. retVal != 0) {
  1408. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1409. "Problem running command: " << *it << std::endl);
  1410. return 0;
  1411. }
  1412. }
  1413. return 1;
  1414. }
  1415. // Find the appropriate executable to run for a test
  1416. std::string cmCTestTestHandler::FindTheExecutable(const char* exe)
  1417. {
  1418. std::string resConfig;
  1419. std::vector<std::string> extraPaths;
  1420. std::vector<std::string> failedPaths;
  1421. if (strcmp(exe, "NOT_AVAILABLE") == 0) {
  1422. return exe;
  1423. }
  1424. return cmCTestTestHandler::FindExecutable(this->CTest, exe, resConfig,
  1425. extraPaths, failedPaths);
  1426. }
  1427. // add additional configurations to the search path
  1428. void cmCTestTestHandler::AddConfigurations(
  1429. cmCTest* ctest, std::vector<std::string>& attempted,
  1430. std::vector<std::string>& attemptedConfigs, std::string filepath,
  1431. std::string& filename)
  1432. {
  1433. std::string tempPath;
  1434. if (!filepath.empty() && filepath[filepath.size() - 1] != '/') {
  1435. filepath += "/";
  1436. }
  1437. tempPath = filepath + filename;
  1438. attempted.push_back(tempPath);
  1439. attemptedConfigs.push_back("");
  1440. if (!ctest->GetConfigType().empty()) {
  1441. tempPath = filepath;
  1442. tempPath += ctest->GetConfigType();
  1443. tempPath += "/";
  1444. tempPath += filename;
  1445. attempted.push_back(tempPath);
  1446. attemptedConfigs.push_back(ctest->GetConfigType());
  1447. // If the file is an OSX bundle then the configtype
  1448. // will be at the start of the path
  1449. tempPath = ctest->GetConfigType();
  1450. tempPath += "/";
  1451. tempPath += filepath;
  1452. tempPath += filename;
  1453. attempted.push_back(tempPath);
  1454. attemptedConfigs.push_back(ctest->GetConfigType());
  1455. } else {
  1456. // no config specified - try some options...
  1457. tempPath = filepath;
  1458. tempPath += "Release/";
  1459. tempPath += filename;
  1460. attempted.push_back(tempPath);
  1461. attemptedConfigs.push_back("Release");
  1462. tempPath = filepath;
  1463. tempPath += "Debug/";
  1464. tempPath += filename;
  1465. attempted.push_back(tempPath);
  1466. attemptedConfigs.push_back("Debug");
  1467. tempPath = filepath;
  1468. tempPath += "MinSizeRel/";
  1469. tempPath += filename;
  1470. attempted.push_back(tempPath);
  1471. attemptedConfigs.push_back("MinSizeRel");
  1472. tempPath = filepath;
  1473. tempPath += "RelWithDebInfo/";
  1474. tempPath += filename;
  1475. attempted.push_back(tempPath);
  1476. attemptedConfigs.push_back("RelWithDebInfo");
  1477. tempPath = filepath;
  1478. tempPath += "Deployment/";
  1479. tempPath += filename;
  1480. attempted.push_back(tempPath);
  1481. attemptedConfigs.push_back("Deployment");
  1482. tempPath = filepath;
  1483. tempPath += "Development/";
  1484. tempPath += filename;
  1485. attempted.push_back(tempPath);
  1486. attemptedConfigs.push_back("Deployment");
  1487. }
  1488. }
  1489. // Find the appropriate executable to run for a test
  1490. std::string cmCTestTestHandler::FindExecutable(
  1491. cmCTest* ctest, const char* testCommand, std::string& resultingConfig,
  1492. std::vector<std::string>& extraPaths, std::vector<std::string>& failed)
  1493. {
  1494. // now run the compiled test if we can find it
  1495. std::vector<std::string> attempted;
  1496. std::vector<std::string> attemptedConfigs;
  1497. std::string tempPath;
  1498. std::string filepath = cmSystemTools::GetFilenamePath(testCommand);
  1499. std::string filename = cmSystemTools::GetFilenameName(testCommand);
  1500. cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
  1501. filepath, filename);
  1502. // even if a fullpath was specified also try it relative to the current
  1503. // directory
  1504. if (!filepath.empty() && filepath[0] == '/') {
  1505. std::string localfilepath = filepath.substr(1, filepath.size() - 1);
  1506. cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
  1507. localfilepath, filename);
  1508. }
  1509. // if extraPaths are provided and we were not passed a full path, try them,
  1510. // try any extra paths
  1511. if (filepath.empty()) {
  1512. for (unsigned int i = 0; i < extraPaths.size(); ++i) {
  1513. std::string filepathExtra =
  1514. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1515. std::string filenameExtra =
  1516. cmSystemTools::GetFilenameName(extraPaths[i]);
  1517. cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
  1518. filepathExtra, filenameExtra);
  1519. }
  1520. }
  1521. // store the final location in fullPath
  1522. std::string fullPath;
  1523. // now look in the paths we specified above
  1524. for (unsigned int ai = 0; ai < attempted.size() && fullPath.empty(); ++ai) {
  1525. // first check without exe extension
  1526. if (cmSystemTools::FileExists(attempted[ai].c_str()) &&
  1527. !cmSystemTools::FileIsDirectory(attempted[ai])) {
  1528. fullPath = cmSystemTools::CollapseFullPath(attempted[ai]);
  1529. resultingConfig = attemptedConfigs[ai];
  1530. }
  1531. // then try with the exe extension
  1532. else {
  1533. failed.push_back(attempted[ai]);
  1534. tempPath = attempted[ai];
  1535. tempPath += cmSystemTools::GetExecutableExtension();
  1536. if (cmSystemTools::FileExists(tempPath.c_str()) &&
  1537. !cmSystemTools::FileIsDirectory(tempPath)) {
  1538. fullPath = cmSystemTools::CollapseFullPath(tempPath);
  1539. resultingConfig = attemptedConfigs[ai];
  1540. } else {
  1541. failed.push_back(tempPath);
  1542. }
  1543. }
  1544. }
  1545. // if everything else failed, check the users path, but only if a full path
  1546. // wasn't specified
  1547. if (fullPath.empty() && filepath.empty()) {
  1548. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1549. if (path != "") {
  1550. resultingConfig = "";
  1551. return path;
  1552. }
  1553. }
  1554. if (fullPath.empty()) {
  1555. cmCTestLog(ctest, HANDLER_OUTPUT, "Could not find executable "
  1556. << testCommand << "\n"
  1557. << "Looked in the following places:\n");
  1558. for (std::vector<std::string>::iterator i = failed.begin();
  1559. i != failed.end(); ++i) {
  1560. cmCTestLog(ctest, HANDLER_OUTPUT, *i << "\n");
  1561. }
  1562. }
  1563. return fullPath;
  1564. }
  1565. void cmCTestTestHandler::GetListOfTests()
  1566. {
  1567. if (!this->IncludeLabelRegExp.empty()) {
  1568. this->IncludeLabelRegularExpression.compile(
  1569. this->IncludeLabelRegExp.c_str());
  1570. }
  1571. if (!this->ExcludeLabelRegExp.empty()) {
  1572. this->ExcludeLabelRegularExpression.compile(
  1573. this->ExcludeLabelRegExp.c_str());
  1574. }
  1575. if (!this->IncludeRegExp.empty()) {
  1576. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1577. }
  1578. if (!this->ExcludeRegExp.empty()) {
  1579. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1580. }
  1581. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1582. "Constructing a list of tests" << std::endl, this->Quiet);
  1583. cmake cm(cmake::RoleScript);
  1584. cm.SetHomeDirectory("");
  1585. cm.SetHomeOutputDirectory("");
  1586. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  1587. cmGlobalGenerator gg(&cm);
  1588. CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
  1589. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1590. this->CTest->GetConfigType().c_str());
  1591. // Add handler for ADD_TEST
  1592. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1593. newCom1->TestHandler = this;
  1594. cm.GetState()->AddBuiltinCommand("add_test", newCom1);
  1595. // Add handler for SUBDIRS
  1596. cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
  1597. newCom2->TestHandler = this;
  1598. cm.GetState()->AddBuiltinCommand("subdirs", newCom2);
  1599. // Add handler for ADD_SUBDIRECTORY
  1600. cmCTestAddSubdirectoryCommand* newCom3 = new cmCTestAddSubdirectoryCommand;
  1601. newCom3->TestHandler = this;
  1602. cm.GetState()->AddBuiltinCommand("add_subdirectory", newCom3);
  1603. // Add handler for SET_TESTS_PROPERTIES
  1604. cmCTestSetTestsPropertiesCommand* newCom4 =
  1605. new cmCTestSetTestsPropertiesCommand;
  1606. newCom4->TestHandler = this;
  1607. cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4);
  1608. // Add handler for SET_DIRECTORY_PROPERTIES
  1609. cmCTestSetDirectoryPropertiesCommand* newCom5 =
  1610. new cmCTestSetDirectoryPropertiesCommand;
  1611. newCom5->TestHandler = this;
  1612. cm.GetState()->AddBuiltinCommand("set_directory_properties", newCom5);
  1613. const char* testFilename;
  1614. if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
  1615. // does the CTestTestfile.cmake exist ?
  1616. testFilename = "CTestTestfile.cmake";
  1617. } else if (cmSystemTools::FileExists("DartTestfile.txt")) {
  1618. // does the DartTestfile.txt exist ?
  1619. testFilename = "DartTestfile.txt";
  1620. } else {
  1621. return;
  1622. }
  1623. if (!mf->ReadListFile(testFilename)) {
  1624. return;
  1625. }
  1626. if (cmSystemTools::GetErrorOccuredFlag()) {
  1627. return;
  1628. }
  1629. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1630. "Done constructing a list of tests" << std::endl,
  1631. this->Quiet);
  1632. }
  1633. void cmCTestTestHandler::UseIncludeRegExp()
  1634. {
  1635. this->UseIncludeRegExpFlag = true;
  1636. }
  1637. void cmCTestTestHandler::UseExcludeRegExp()
  1638. {
  1639. this->UseExcludeRegExpFlag = true;
  1640. this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag;
  1641. }
  1642. const char* cmCTestTestHandler::GetTestStatus(const cmCTestTestResult* result)
  1643. {
  1644. static const char* statuses[] = { "Not Run", "Timeout", "SEGFAULT",
  1645. "ILLEGAL", "INTERRUPT", "NUMERICAL",
  1646. "OTHER_FAULT", "Failed", "BAD_COMMAND",
  1647. "Completed" };
  1648. int status = result->Status;
  1649. if (status < cmCTestTestHandler::NOT_RUN ||
  1650. status > cmCTestTestHandler::COMPLETED) {
  1651. return "No Status";
  1652. }
  1653. if (status == cmCTestTestHandler::OTHER_FAULT) {
  1654. return result->ExceptionStatus.c_str();
  1655. }
  1656. return statuses[status];
  1657. }
  1658. void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
  1659. {
  1660. if (this->TestsToRunString.empty()) {
  1661. return;
  1662. }
  1663. int start;
  1664. int end = -1;
  1665. double stride = -1;
  1666. std::string::size_type pos = 0;
  1667. std::string::size_type pos2;
  1668. // read start
  1669. if (GetNextNumber(this->TestsToRunString, start, pos, pos2)) {
  1670. // read end
  1671. if (GetNextNumber(this->TestsToRunString, end, pos, pos2)) {
  1672. // read stride
  1673. if (GetNextRealNumber(this->TestsToRunString, stride, pos, pos2)) {
  1674. int val = 0;
  1675. // now read specific numbers
  1676. while (GetNextNumber(this->TestsToRunString, val, pos, pos2)) {
  1677. this->TestsToRun.push_back(val);
  1678. }
  1679. this->TestsToRun.push_back(val);
  1680. }
  1681. }
  1682. }
  1683. // if start is not specified then we assume we start at 1
  1684. if (start == -1) {
  1685. start = 1;
  1686. }
  1687. // if end isnot specified then we assume we end with the last test
  1688. if (end == -1) {
  1689. end = static_cast<int>(numTests);
  1690. }
  1691. // if the stride wasn't specified then it defaults to 1
  1692. if (stride == -1) {
  1693. stride = 1;
  1694. }
  1695. // if we have a range then add it
  1696. if (end != -1 && start != -1 && stride > 0) {
  1697. int i = 0;
  1698. while (i * stride + start <= end) {
  1699. this->TestsToRun.push_back(static_cast<int>(i * stride + start));
  1700. ++i;
  1701. }
  1702. }
  1703. // sort the array
  1704. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1705. std::less<int>());
  1706. // remove duplicates
  1707. std::vector<int>::iterator new_end =
  1708. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1709. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1710. }
  1711. void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
  1712. {
  1713. std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
  1714. cmsys::Directory directory;
  1715. if (directory.Load(dirName) == 0) {
  1716. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of "
  1717. << dirName << std::endl);
  1718. return;
  1719. }
  1720. int numFiles =
  1721. static_cast<int>(cmsys::Directory::GetNumberOfFilesInDirectory(dirName));
  1722. std::string pattern = "LastTestsFailed";
  1723. std::string logName;
  1724. for (int i = 0; i < numFiles; ++i) {
  1725. std::string fileName = directory.GetFile(i);
  1726. // bcc crashes if we attempt a normal substring comparison,
  1727. // hence the following workaround
  1728. std::string fileNameSubstring = fileName.substr(0, pattern.length());
  1729. if (fileNameSubstring != pattern) {
  1730. continue;
  1731. }
  1732. if (logName == "") {
  1733. logName = fileName;
  1734. } else {
  1735. // if multiple matching logs were found we use the most recently
  1736. // modified one.
  1737. int res;
  1738. cmSystemTools::FileTimeCompare(logName, fileName, &res);
  1739. if (res == -1) {
  1740. logName = fileName;
  1741. }
  1742. }
  1743. }
  1744. std::string lastTestsFailedLog =
  1745. this->CTest->GetBinaryDir() + "/Testing/Temporary/" + logName;
  1746. if (!cmSystemTools::FileExists(lastTestsFailedLog.c_str())) {
  1747. if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) {
  1748. cmCTestLog(this->CTest, ERROR_MESSAGE, lastTestsFailedLog
  1749. << " does not exist!" << std::endl);
  1750. }
  1751. return;
  1752. }
  1753. // parse the list of tests to rerun from LastTestsFailed.log
  1754. cmsys::ifstream ifs(lastTestsFailedLog.c_str());
  1755. if (ifs) {
  1756. std::string line;
  1757. std::string::size_type pos;
  1758. while (cmSystemTools::GetLineFromStream(ifs, line)) {
  1759. pos = line.find(':', 0);
  1760. if (pos == std::string::npos) {
  1761. continue;
  1762. }
  1763. int val = atoi(line.substr(0, pos).c_str());
  1764. this->TestsToRun.push_back(val);
  1765. }
  1766. ifs.close();
  1767. } else if (!this->CTest->GetShowOnly() &&
  1768. !this->CTest->ShouldPrintLabels()) {
  1769. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem reading file: "
  1770. << lastTestsFailedLog
  1771. << " while generating list of previously failed tests."
  1772. << std::endl);
  1773. }
  1774. }
  1775. // Just for convenience
  1776. #define SPACE_REGEX "[ \t\r\n]"
  1777. void cmCTestTestHandler::GenerateRegressionImages(cmXMLWriter& xml,
  1778. const std::string& dart)
  1779. {
  1780. cmsys::RegularExpression twoattributes(
  1781. "<DartMeasurement" SPACE_REGEX
  1782. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1783. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1784. "*>([^<]*)</DartMeasurement>");
  1785. cmsys::RegularExpression threeattributes(
  1786. "<DartMeasurement" SPACE_REGEX
  1787. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1788. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1789. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1790. "*>([^<]*)</DartMeasurement>");
  1791. cmsys::RegularExpression fourattributes(
  1792. "<DartMeasurement" SPACE_REGEX
  1793. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1794. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1795. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1796. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1797. "*>([^<]*)</DartMeasurement>");
  1798. cmsys::RegularExpression cdatastart(
  1799. "<DartMeasurement" SPACE_REGEX
  1800. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1801. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1802. "*>" SPACE_REGEX "*<!\\[CDATA\\[");
  1803. cmsys::RegularExpression cdataend("]]>" SPACE_REGEX "*</DartMeasurement>");
  1804. cmsys::RegularExpression measurementfile(
  1805. "<DartMeasurementFile" SPACE_REGEX
  1806. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1807. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1808. "*>([^<]*)</DartMeasurementFile>");
  1809. bool done = false;
  1810. std::string cxml = dart;
  1811. while (!done) {
  1812. if (twoattributes.find(cxml)) {
  1813. xml.StartElement("NamedMeasurement");
  1814. xml.Attribute(twoattributes.match(1).c_str(), twoattributes.match(2));
  1815. xml.Attribute(twoattributes.match(3).c_str(), twoattributes.match(4));
  1816. xml.Element("Value", twoattributes.match(5));
  1817. xml.EndElement();
  1818. cxml.erase(twoattributes.start(),
  1819. twoattributes.end() - twoattributes.start());
  1820. } else if (threeattributes.find(cxml)) {
  1821. xml.StartElement("NamedMeasurement");
  1822. xml.Attribute(threeattributes.match(1).c_str(),
  1823. threeattributes.match(2));
  1824. xml.Attribute(threeattributes.match(3).c_str(),
  1825. threeattributes.match(4));
  1826. xml.Attribute(threeattributes.match(5).c_str(),
  1827. threeattributes.match(6));
  1828. xml.Element("Value", twoattributes.match(7));
  1829. xml.EndElement();
  1830. cxml.erase(threeattributes.start(),
  1831. threeattributes.end() - threeattributes.start());
  1832. } else if (fourattributes.find(cxml)) {
  1833. xml.StartElement("NamedMeasurement");
  1834. xml.Attribute(fourattributes.match(1).c_str(), fourattributes.match(2));
  1835. xml.Attribute(fourattributes.match(3).c_str(), fourattributes.match(4));
  1836. xml.Attribute(fourattributes.match(5).c_str(), fourattributes.match(6));
  1837. xml.Attribute(fourattributes.match(7).c_str(), fourattributes.match(8));
  1838. xml.Element("Value", twoattributes.match(9));
  1839. xml.EndElement();
  1840. cxml.erase(fourattributes.start(),
  1841. fourattributes.end() - fourattributes.start());
  1842. } else if (cdatastart.find(cxml) && cdataend.find(cxml)) {
  1843. xml.StartElement("NamedMeasurement");
  1844. xml.Attribute(cdatastart.match(1).c_str(), cdatastart.match(2));
  1845. xml.Attribute(cdatastart.match(3).c_str(), cdatastart.match(4));
  1846. xml.StartElement("Value");
  1847. xml.CData(
  1848. cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end()));
  1849. xml.EndElement(); // Value
  1850. xml.EndElement(); // NamedMeasurement
  1851. cxml.erase(cdatastart.start(), cdataend.end() - cdatastart.start());
  1852. } else if (measurementfile.find(cxml)) {
  1853. const std::string& filename =
  1854. cmCTest::CleanString(measurementfile.match(5));
  1855. if (cmSystemTools::FileExists(filename.c_str())) {
  1856. long len = cmSystemTools::FileLength(filename);
  1857. if (len == 0) {
  1858. std::string k1 = measurementfile.match(1);
  1859. std::string v1 = measurementfile.match(2);
  1860. std::string k2 = measurementfile.match(3);
  1861. std::string v2 = measurementfile.match(4);
  1862. if (cmSystemTools::LowerCase(k1) == "type") {
  1863. v1 = "text/string";
  1864. }
  1865. if (cmSystemTools::LowerCase(k2) == "type") {
  1866. v2 = "text/string";
  1867. }
  1868. xml.StartElement("NamedMeasurement");
  1869. xml.Attribute(k1.c_str(), v1);
  1870. xml.Attribute(k2.c_str(), v2);
  1871. xml.Attribute("encoding", "none");
  1872. xml.Element("Value", "Image " + filename + " is empty");
  1873. xml.EndElement();
  1874. } else {
  1875. cmsys::ifstream ifs(filename.c_str(), std::ios::in
  1876. #ifdef _WIN32
  1877. | std::ios::binary
  1878. #endif
  1879. );
  1880. unsigned char* file_buffer = new unsigned char[len + 1];
  1881. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1882. unsigned char* encoded_buffer = new unsigned char[static_cast<int>(
  1883. static_cast<double>(len) * 1.5 + 5.0)];
  1884. size_t rlen =
  1885. cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1886. xml.StartElement("NamedMeasurement");
  1887. xml.Attribute(measurementfile.match(1).c_str(),
  1888. measurementfile.match(2));
  1889. xml.Attribute(measurementfile.match(3).c_str(),
  1890. measurementfile.match(4));
  1891. xml.Attribute("encoding", "base64");
  1892. std::ostringstream ostr;
  1893. for (size_t cc = 0; cc < rlen; cc++) {
  1894. ostr << encoded_buffer[cc];
  1895. if (cc % 60 == 0 && cc) {
  1896. ostr << std::endl;
  1897. }
  1898. }
  1899. xml.Element("Value", ostr.str());
  1900. xml.EndElement(); // NamedMeasurement
  1901. delete[] file_buffer;
  1902. delete[] encoded_buffer;
  1903. }
  1904. } else {
  1905. int idx = 4;
  1906. if (measurementfile.match(1) == "name") {
  1907. idx = 2;
  1908. }
  1909. xml.StartElement("NamedMeasurement");
  1910. xml.Attribute("name", measurementfile.match(idx));
  1911. xml.Attribute("text", "text/string");
  1912. xml.Element("Value", "File " + filename + " not found");
  1913. xml.EndElement();
  1914. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "File \""
  1915. << filename << "\" not found." << std::endl,
  1916. this->Quiet);
  1917. }
  1918. cxml.erase(measurementfile.start(),
  1919. measurementfile.end() - measurementfile.start());
  1920. } else {
  1921. done = true;
  1922. }
  1923. }
  1924. }
  1925. void cmCTestTestHandler::SetIncludeRegExp(const char* arg)
  1926. {
  1927. this->IncludeRegExp = arg;
  1928. }
  1929. void cmCTestTestHandler::SetExcludeRegExp(const char* arg)
  1930. {
  1931. this->ExcludeRegExp = arg;
  1932. }
  1933. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1934. {
  1935. if (!in) {
  1936. return;
  1937. }
  1938. this->TestsToRunString = in;
  1939. // if the argument is a file, then read it and use the contents as the
  1940. // string
  1941. if (cmSystemTools::FileExists(in)) {
  1942. cmsys::ifstream fin(in);
  1943. unsigned long filelen = cmSystemTools::FileLength(in);
  1944. char* buff = new char[filelen + 1];
  1945. fin.getline(buff, filelen);
  1946. buff[fin.gcount()] = 0;
  1947. this->TestsToRunString = buff;
  1948. delete[] buff;
  1949. }
  1950. }
  1951. bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length)
  1952. {
  1953. if (!length || length >= output.size() ||
  1954. output.find("CTEST_FULL_OUTPUT") != std::string::npos) {
  1955. return true;
  1956. }
  1957. // Truncate at given length but do not break in the middle of a multi-byte
  1958. // UTF-8 encoding.
  1959. char const* const begin = output.c_str();
  1960. char const* const end = begin + output.size();
  1961. char const* const truncate = begin + length;
  1962. char const* current = begin;
  1963. while (current < truncate) {
  1964. unsigned int ch;
  1965. if (const char* next = cm_utf8_decode_character(current, end, &ch)) {
  1966. if (next > truncate) {
  1967. break;
  1968. }
  1969. current = next;
  1970. } else // Bad byte will be handled by cmXMLWriter.
  1971. {
  1972. ++current;
  1973. }
  1974. }
  1975. output = output.substr(0, current - begin);
  1976. // Append truncation message.
  1977. std::ostringstream msg;
  1978. msg << "...\n"
  1979. "The rest of the test output was removed since it exceeds the "
  1980. "threshold "
  1981. "of "
  1982. << length << " bytes.\n";
  1983. output += msg.str();
  1984. return true;
  1985. }
  1986. bool cmCTestTestHandler::SetTestsProperties(
  1987. const std::vector<std::string>& args)
  1988. {
  1989. std::vector<std::string>::const_iterator it;
  1990. std::vector<std::string> tests;
  1991. bool found = false;
  1992. for (it = args.begin(); it != args.end(); ++it) {
  1993. if (*it == "PROPERTIES") {
  1994. found = true;
  1995. break;
  1996. }
  1997. tests.push_back(*it);
  1998. }
  1999. if (!found) {
  2000. return false;
  2001. }
  2002. ++it; // skip PROPERTIES
  2003. for (; it != args.end(); ++it) {
  2004. std::string key = *it;
  2005. ++it;
  2006. if (it == args.end()) {
  2007. break;
  2008. }
  2009. std::string val = *it;
  2010. std::vector<std::string>::const_iterator tit;
  2011. for (tit = tests.begin(); tit != tests.end(); ++tit) {
  2012. cmCTestTestHandler::ListOfTests::iterator rtit;
  2013. for (rtit = this->TestList.begin(); rtit != this->TestList.end();
  2014. ++rtit) {
  2015. if (*tit == rtit->Name) {
  2016. if (key == "WILL_FAIL") {
  2017. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  2018. }
  2019. if (key == "DISABLED") {
  2020. rtit->Disabled = cmSystemTools::IsOn(val.c_str());
  2021. }
  2022. if (key == "ATTACHED_FILES") {
  2023. cmSystemTools::ExpandListArgument(val, rtit->AttachedFiles);
  2024. }
  2025. if (key == "ATTACHED_FILES_ON_FAIL") {
  2026. cmSystemTools::ExpandListArgument(val, rtit->AttachOnFail);
  2027. }
  2028. if (key == "RESOURCE_LOCK") {
  2029. std::vector<std::string> lval;
  2030. cmSystemTools::ExpandListArgument(val, lval);
  2031. rtit->LockedResources.insert(lval.begin(), lval.end());
  2032. }
  2033. if (key == "FIXTURES_SETUP") {
  2034. std::vector<std::string> lval;
  2035. cmSystemTools::ExpandListArgument(val, lval);
  2036. rtit->FixturesSetup.insert(lval.begin(), lval.end());
  2037. }
  2038. if (key == "FIXTURES_CLEANUP") {
  2039. std::vector<std::string> lval;
  2040. cmSystemTools::ExpandListArgument(val, lval);
  2041. rtit->FixturesCleanup.insert(lval.begin(), lval.end());
  2042. }
  2043. if (key == "FIXTURES_REQUIRED") {
  2044. std::vector<std::string> lval;
  2045. cmSystemTools::ExpandListArgument(val, lval);
  2046. rtit->FixturesRequired.insert(lval.begin(), lval.end());
  2047. }
  2048. if (key == "TIMEOUT") {
  2049. rtit->Timeout = atof(val.c_str());
  2050. rtit->ExplicitTimeout = true;
  2051. }
  2052. if (key == "COST") {
  2053. rtit->Cost = static_cast<float>(atof(val.c_str()));
  2054. }
  2055. if (key == "REQUIRED_FILES") {
  2056. cmSystemTools::ExpandListArgument(val, rtit->RequiredFiles);
  2057. }
  2058. if (key == "RUN_SERIAL") {
  2059. rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
  2060. }
  2061. if (key == "FAIL_REGULAR_EXPRESSION") {
  2062. std::vector<std::string> lval;
  2063. cmSystemTools::ExpandListArgument(val, lval);
  2064. std::vector<std::string>::iterator crit;
  2065. for (crit = lval.begin(); crit != lval.end(); ++crit) {
  2066. rtit->ErrorRegularExpressions.push_back(
  2067. std::pair<cmsys::RegularExpression, std::string>(
  2068. cmsys::RegularExpression(crit->c_str()),
  2069. std::string(*crit)));
  2070. }
  2071. }
  2072. if (key == "PROCESSORS") {
  2073. rtit->Processors = atoi(val.c_str());
  2074. if (rtit->Processors < 1) {
  2075. rtit->Processors = 1;
  2076. }
  2077. }
  2078. if (key == "SKIP_RETURN_CODE") {
  2079. rtit->SkipReturnCode = atoi(val.c_str());
  2080. if (rtit->SkipReturnCode < 0 || rtit->SkipReturnCode > 255) {
  2081. rtit->SkipReturnCode = -1;
  2082. }
  2083. }
  2084. if (key == "DEPENDS") {
  2085. cmSystemTools::ExpandListArgument(val, rtit->Depends);
  2086. }
  2087. if (key == "ENVIRONMENT") {
  2088. cmSystemTools::ExpandListArgument(val, rtit->Environment);
  2089. }
  2090. if (key == "LABELS") {
  2091. std::vector<std::string> Labels;
  2092. cmSystemTools::ExpandListArgument(val, Labels);
  2093. rtit->Labels.insert(rtit->Labels.end(), Labels.begin(),
  2094. Labels.end());
  2095. // sort the array
  2096. std::sort(rtit->Labels.begin(), rtit->Labels.end());
  2097. // remove duplicates
  2098. std::vector<std::string>::iterator new_end =
  2099. std::unique(rtit->Labels.begin(), rtit->Labels.end());
  2100. rtit->Labels.erase(new_end, rtit->Labels.end());
  2101. }
  2102. if (key == "MEASUREMENT") {
  2103. size_t pos = val.find_first_of('=');
  2104. if (pos != std::string::npos) {
  2105. std::string mKey = val.substr(0, pos);
  2106. const char* mVal = val.c_str() + pos + 1;
  2107. rtit->Measurements[mKey] = mVal;
  2108. } else {
  2109. rtit->Measurements[val] = "1";
  2110. }
  2111. }
  2112. if (key == "PASS_REGULAR_EXPRESSION") {
  2113. std::vector<std::string> lval;
  2114. cmSystemTools::ExpandListArgument(val, lval);
  2115. std::vector<std::string>::iterator crit;
  2116. for (crit = lval.begin(); crit != lval.end(); ++crit) {
  2117. rtit->RequiredRegularExpressions.push_back(
  2118. std::pair<cmsys::RegularExpression, std::string>(
  2119. cmsys::RegularExpression(crit->c_str()),
  2120. std::string(*crit)));
  2121. }
  2122. }
  2123. if (key == "WORKING_DIRECTORY") {
  2124. rtit->Directory = val;
  2125. }
  2126. if (key == "TIMEOUT_AFTER_MATCH") {
  2127. std::vector<std::string> propArgs;
  2128. cmSystemTools::ExpandListArgument(val, propArgs);
  2129. if (propArgs.size() != 2) {
  2130. cmCTestLog(this->CTest, WARNING,
  2131. "TIMEOUT_AFTER_MATCH expects two arguments, found "
  2132. << propArgs.size() << std::endl);
  2133. } else {
  2134. rtit->AlternateTimeout = atof(propArgs[0].c_str());
  2135. std::vector<std::string> lval;
  2136. cmSystemTools::ExpandListArgument(propArgs[1], lval);
  2137. std::vector<std::string>::iterator crit;
  2138. for (crit = lval.begin(); crit != lval.end(); ++crit) {
  2139. rtit->TimeoutRegularExpressions.push_back(
  2140. std::pair<cmsys::RegularExpression, std::string>(
  2141. cmsys::RegularExpression(crit->c_str()),
  2142. std::string(*crit)));
  2143. }
  2144. }
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. return true;
  2151. }
  2152. bool cmCTestTestHandler::SetDirectoryProperties(
  2153. const std::vector<std::string>& args)
  2154. {
  2155. std::vector<std::string>::const_iterator it;
  2156. std::vector<std::string> tests;
  2157. bool found = false;
  2158. for (it = args.begin(); it != args.end(); ++it) {
  2159. if (*it == "PROPERTIES") {
  2160. found = true;
  2161. break;
  2162. }
  2163. tests.push_back(*it);
  2164. }
  2165. if (!found) {
  2166. return false;
  2167. }
  2168. ++it; // skip PROPERTIES
  2169. for (; it != args.end(); ++it) {
  2170. std::string key = *it;
  2171. ++it;
  2172. if (it == args.end()) {
  2173. break;
  2174. }
  2175. std::string val = *it;
  2176. cmCTestTestHandler::ListOfTests::iterator rtit;
  2177. for (rtit = this->TestList.begin(); rtit != this->TestList.end(); ++rtit) {
  2178. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  2179. if (cwd == rtit->Directory) {
  2180. if (key == "LABELS") {
  2181. std::vector<std::string> DirectoryLabels;
  2182. cmSystemTools::ExpandListArgument(val, DirectoryLabels);
  2183. rtit->Labels.insert(rtit->Labels.end(), DirectoryLabels.begin(),
  2184. DirectoryLabels.end());
  2185. // sort the array
  2186. std::sort(rtit->Labels.begin(), rtit->Labels.end());
  2187. // remove duplicates
  2188. std::vector<std::string>::iterator new_end =
  2189. std::unique(rtit->Labels.begin(), rtit->Labels.end());
  2190. rtit->Labels.erase(new_end, rtit->Labels.end());
  2191. }
  2192. }
  2193. }
  2194. }
  2195. return true;
  2196. }
  2197. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  2198. {
  2199. const std::string& testname = args[0];
  2200. cmCTestOptionalLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl,
  2201. this->Quiet);
  2202. if (this->UseExcludeRegExpFlag && this->UseExcludeRegExpFirst &&
  2203. this->ExcludeTestsRegularExpression.find(testname.c_str())) {
  2204. return true;
  2205. }
  2206. if (this->MemCheck) {
  2207. std::vector<std::string>::iterator it;
  2208. bool found = false;
  2209. for (it = this->CustomTestsIgnore.begin();
  2210. it != this->CustomTestsIgnore.end(); ++it) {
  2211. if (*it == testname) {
  2212. found = true;
  2213. break;
  2214. }
  2215. }
  2216. if (found) {
  2217. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  2218. "Ignore memcheck: " << *it << std::endl, this->Quiet);
  2219. return true;
  2220. }
  2221. } else {
  2222. std::vector<std::string>::iterator it;
  2223. bool found = false;
  2224. for (it = this->CustomTestsIgnore.begin();
  2225. it != this->CustomTestsIgnore.end(); ++it) {
  2226. if (*it == testname) {
  2227. found = true;
  2228. break;
  2229. }
  2230. }
  2231. if (found) {
  2232. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  2233. "Ignore test: " << *it << std::endl, this->Quiet);
  2234. return true;
  2235. }
  2236. }
  2237. cmCTestTestProperties test;
  2238. test.Name = testname;
  2239. test.Args = args;
  2240. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  2241. cmCTestOptionalLog(this->CTest, DEBUG,
  2242. "Set test directory: " << test.Directory << std::endl,
  2243. this->Quiet);
  2244. test.IsInBasedOnREOptions = true;
  2245. test.WillFail = false;
  2246. test.Disabled = false;
  2247. test.RunSerial = false;
  2248. test.Timeout = 0;
  2249. test.ExplicitTimeout = false;
  2250. test.Cost = 0;
  2251. test.Processors = 1;
  2252. test.SkipReturnCode = -1;
  2253. test.PreviousRuns = 0;
  2254. if (this->UseIncludeRegExpFlag &&
  2255. !this->IncludeTestsRegularExpression.find(testname.c_str())) {
  2256. test.IsInBasedOnREOptions = false;
  2257. } else if (this->UseExcludeRegExpFlag && !this->UseExcludeRegExpFirst &&
  2258. this->ExcludeTestsRegularExpression.find(testname.c_str())) {
  2259. test.IsInBasedOnREOptions = false;
  2260. }
  2261. this->TestList.push_back(test);
  2262. return true;
  2263. }