cmCTestTestHandler.cxx 77 KB

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