cmCTestTestHandler.cxx 77 KB

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