cmCTestTestHandler.cxx 77 KB

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