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