cmCTestTestHandler.cxx 77 KB

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