cmCTestTestHandler.cxx 77 KB

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