cmCTestTestHandler.cxx 76 KB

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