cmCTestTestHandler.cxx 80 KB

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