cmCTestTestHandler.cxx 79 KB

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