cmCTestTestHandler.cxx 77 KB

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