cmCTestTestHandler.cxx 77 KB

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