cmCTestTestHandler.cxx 76 KB

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