cmCTestTestHandler.cxx 78 KB

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