cmCTestTestHandler.cxx 77 KB

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