cmCTestTestHandler.cxx 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296
  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. xml.StartElement("Testing");
  1146. xml.Element("StartDateTime", this->StartTest);
  1147. xml.Element("StartTestTime", this->StartTestTime);
  1148. xml.StartElement("TestList");
  1149. cmCTestTestHandler::TestResultsVector::size_type cc;
  1150. for (cc = 0; cc < this->TestResults.size(); cc++) {
  1151. cmCTestTestResult* result = &this->TestResults[cc];
  1152. std::string testPath = result->Path + "/" + result->Name;
  1153. xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str()));
  1154. }
  1155. xml.EndElement(); // TestList
  1156. for (cc = 0; cc < this->TestResults.size(); cc++) {
  1157. cmCTestTestResult* result = &this->TestResults[cc];
  1158. this->WriteTestResultHeader(xml, result);
  1159. xml.StartElement("Results");
  1160. if (result->Status != cmCTestTestHandler::NOT_RUN) {
  1161. if (result->Status != cmCTestTestHandler::COMPLETED ||
  1162. result->ReturnValue) {
  1163. xml.StartElement("NamedMeasurement");
  1164. xml.Attribute("type", "text/string");
  1165. xml.Attribute("name", "Exit Code");
  1166. xml.Element("Value", this->GetTestStatus(result->Status));
  1167. xml.EndElement(); // NamedMeasurement
  1168. xml.StartElement("NamedMeasurement");
  1169. xml.Attribute("type", "text/string");
  1170. xml.Attribute("name", "Exit Value");
  1171. xml.Element("Value", result->ReturnValue);
  1172. xml.EndElement(); // NamedMeasurement
  1173. }
  1174. this->GenerateRegressionImages(xml, result->DartString);
  1175. xml.StartElement("NamedMeasurement");
  1176. xml.Attribute("type", "numeric/double");
  1177. xml.Attribute("name", "Execution Time");
  1178. xml.Element("Value", result->ExecutionTime);
  1179. xml.EndElement(); // NamedMeasurement
  1180. if (!result->Reason.empty()) {
  1181. const char* reasonType = "Pass Reason";
  1182. if (result->Status != cmCTestTestHandler::COMPLETED) {
  1183. reasonType = "Fail Reason";
  1184. }
  1185. xml.StartElement("NamedMeasurement");
  1186. xml.Attribute("type", "text/string");
  1187. xml.Attribute("name", reasonType);
  1188. xml.Element("Value", result->Reason);
  1189. xml.EndElement(); // NamedMeasurement
  1190. }
  1191. }
  1192. xml.StartElement("NamedMeasurement");
  1193. xml.Attribute("type", "text/string");
  1194. xml.Attribute("name", "Completion Status");
  1195. xml.Element("Value", result->CompletionStatus);
  1196. xml.EndElement(); // NamedMeasurement
  1197. xml.StartElement("NamedMeasurement");
  1198. xml.Attribute("type", "text/string");
  1199. xml.Attribute("name", "Command Line");
  1200. xml.Element("Value", result->FullCommandLine);
  1201. xml.EndElement(); // NamedMeasurement
  1202. std::map<std::string, std::string>::iterator measureIt;
  1203. for (measureIt = result->Properties->Measurements.begin();
  1204. measureIt != result->Properties->Measurements.end(); ++measureIt) {
  1205. xml.StartElement("NamedMeasurement");
  1206. xml.Attribute("type", "text/string");
  1207. xml.Attribute("name", measureIt->first);
  1208. xml.Element("Value", measureIt->second);
  1209. xml.EndElement(); // NamedMeasurement
  1210. }
  1211. xml.StartElement("Measurement");
  1212. xml.StartElement("Value");
  1213. if (result->CompressOutput) {
  1214. xml.Attribute("encoding", "base64");
  1215. xml.Attribute("compression", "gzip");
  1216. }
  1217. xml.Content(result->Output);
  1218. xml.EndElement(); // Value
  1219. xml.EndElement(); // Measurement
  1220. xml.EndElement(); // Results
  1221. this->AttachFiles(xml, result);
  1222. this->WriteTestResultFooter(xml, result);
  1223. }
  1224. xml.Element("EndDateTime", this->EndTest);
  1225. xml.Element("EndTestTime", this->EndTestTime);
  1226. xml.Element("ElapsedMinutes",
  1227. static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
  1228. xml.EndElement(); // Testing
  1229. this->CTest->EndXML(xml);
  1230. }
  1231. void cmCTestTestHandler::WriteTestResultHeader(cmXMLWriter& xml,
  1232. cmCTestTestResult* result)
  1233. {
  1234. xml.StartElement("Test");
  1235. if (result->Status == cmCTestTestHandler::COMPLETED) {
  1236. xml.Attribute("Status", "passed");
  1237. } else if (result->Status == cmCTestTestHandler::NOT_RUN) {
  1238. xml.Attribute("Status", "notrun");
  1239. } else {
  1240. xml.Attribute("Status", "failed");
  1241. }
  1242. std::string testPath = result->Path + "/" + result->Name;
  1243. xml.Element("Name", result->Name);
  1244. xml.Element("Path", this->CTest->GetShortPathToFile(result->Path.c_str()));
  1245. xml.Element("FullName", this->CTest->GetShortPathToFile(testPath.c_str()));
  1246. xml.Element("FullCommandLine", result->FullCommandLine);
  1247. }
  1248. void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml,
  1249. cmCTestTestResult* result)
  1250. {
  1251. if (!result->Properties->Labels.empty()) {
  1252. xml.StartElement("Labels");
  1253. std::vector<std::string> const& labels = result->Properties->Labels;
  1254. for (std::vector<std::string>::const_iterator li = labels.begin();
  1255. li != labels.end(); ++li) {
  1256. xml.Element("Label", *li);
  1257. }
  1258. xml.EndElement(); // Labels
  1259. }
  1260. xml.EndElement(); // Test
  1261. }
  1262. void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml,
  1263. cmCTestTestResult* result)
  1264. {
  1265. if (result->Status != cmCTestTestHandler::COMPLETED &&
  1266. !result->Properties->AttachOnFail.empty()) {
  1267. result->Properties->AttachedFiles.insert(
  1268. result->Properties->AttachedFiles.end(),
  1269. result->Properties->AttachOnFail.begin(),
  1270. result->Properties->AttachOnFail.end());
  1271. }
  1272. for (std::vector<std::string>::const_iterator file =
  1273. result->Properties->AttachedFiles.begin();
  1274. file != result->Properties->AttachedFiles.end(); ++file) {
  1275. const std::string& base64 = this->CTest->Base64GzipEncodeFile(*file);
  1276. std::string fname = cmSystemTools::GetFilenameName(*file);
  1277. xml.StartElement("NamedMeasurement");
  1278. xml.Attribute("name", "Attached File");
  1279. xml.Attribute("encoding", "base64");
  1280. xml.Attribute("compression", "tar/gzip");
  1281. xml.Attribute("filename", fname);
  1282. xml.Attribute("type", "file");
  1283. xml.Element("Value", base64);
  1284. xml.EndElement(); // NamedMeasurement
  1285. }
  1286. }
  1287. int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
  1288. {
  1289. std::vector<std::string>::iterator it;
  1290. for (it = vec.begin(); it != vec.end(); ++it) {
  1291. int retVal = 0;
  1292. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1293. "Run command: " << *it << std::endl, this->Quiet);
  1294. if (!cmSystemTools::RunSingleCommand(it->c_str(), CM_NULLPTR, CM_NULLPTR,
  1295. &retVal, CM_NULLPTR,
  1296. cmSystemTools::OUTPUT_MERGE
  1297. /*this->Verbose*/) ||
  1298. retVal != 0) {
  1299. cmCTestLog(this->CTest, ERROR_MESSAGE,
  1300. "Problem running command: " << *it << std::endl);
  1301. return 0;
  1302. }
  1303. }
  1304. return 1;
  1305. }
  1306. // Find the appropriate executable to run for a test
  1307. std::string cmCTestTestHandler::FindTheExecutable(const char* exe)
  1308. {
  1309. std::string resConfig;
  1310. std::vector<std::string> extraPaths;
  1311. std::vector<std::string> failedPaths;
  1312. if (strcmp(exe, "NOT_AVAILABLE") == 0) {
  1313. return exe;
  1314. }
  1315. return cmCTestTestHandler::FindExecutable(this->CTest, exe, resConfig,
  1316. extraPaths, failedPaths);
  1317. }
  1318. // add additional configurations to the search path
  1319. void cmCTestTestHandler::AddConfigurations(
  1320. cmCTest* ctest, std::vector<std::string>& attempted,
  1321. std::vector<std::string>& attemptedConfigs, std::string filepath,
  1322. std::string& filename)
  1323. {
  1324. std::string tempPath;
  1325. if (!filepath.empty() && filepath[filepath.size() - 1] != '/') {
  1326. filepath += "/";
  1327. }
  1328. tempPath = filepath + filename;
  1329. attempted.push_back(tempPath);
  1330. attemptedConfigs.push_back("");
  1331. if (!ctest->GetConfigType().empty()) {
  1332. tempPath = filepath;
  1333. tempPath += ctest->GetConfigType();
  1334. tempPath += "/";
  1335. tempPath += filename;
  1336. attempted.push_back(tempPath);
  1337. attemptedConfigs.push_back(ctest->GetConfigType());
  1338. // If the file is an OSX bundle then the configtype
  1339. // will be at the start of the path
  1340. tempPath = ctest->GetConfigType();
  1341. tempPath += "/";
  1342. tempPath += filepath;
  1343. tempPath += filename;
  1344. attempted.push_back(tempPath);
  1345. attemptedConfigs.push_back(ctest->GetConfigType());
  1346. } else {
  1347. // no config specified - try some options...
  1348. tempPath = filepath;
  1349. tempPath += "Release/";
  1350. tempPath += filename;
  1351. attempted.push_back(tempPath);
  1352. attemptedConfigs.push_back("Release");
  1353. tempPath = filepath;
  1354. tempPath += "Debug/";
  1355. tempPath += filename;
  1356. attempted.push_back(tempPath);
  1357. attemptedConfigs.push_back("Debug");
  1358. tempPath = filepath;
  1359. tempPath += "MinSizeRel/";
  1360. tempPath += filename;
  1361. attempted.push_back(tempPath);
  1362. attemptedConfigs.push_back("MinSizeRel");
  1363. tempPath = filepath;
  1364. tempPath += "RelWithDebInfo/";
  1365. tempPath += filename;
  1366. attempted.push_back(tempPath);
  1367. attemptedConfigs.push_back("RelWithDebInfo");
  1368. tempPath = filepath;
  1369. tempPath += "Deployment/";
  1370. tempPath += filename;
  1371. attempted.push_back(tempPath);
  1372. attemptedConfigs.push_back("Deployment");
  1373. tempPath = filepath;
  1374. tempPath += "Development/";
  1375. tempPath += filename;
  1376. attempted.push_back(tempPath);
  1377. attemptedConfigs.push_back("Deployment");
  1378. }
  1379. }
  1380. // Find the appropriate executable to run for a test
  1381. std::string cmCTestTestHandler::FindExecutable(
  1382. cmCTest* ctest, const char* testCommand, std::string& resultingConfig,
  1383. std::vector<std::string>& extraPaths, std::vector<std::string>& failed)
  1384. {
  1385. // now run the compiled test if we can find it
  1386. std::vector<std::string> attempted;
  1387. std::vector<std::string> attemptedConfigs;
  1388. std::string tempPath;
  1389. std::string filepath = cmSystemTools::GetFilenamePath(testCommand);
  1390. std::string filename = cmSystemTools::GetFilenameName(testCommand);
  1391. cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
  1392. filepath, filename);
  1393. // even if a fullpath was specified also try it relative to the current
  1394. // directory
  1395. if (!filepath.empty() && filepath[0] == '/') {
  1396. std::string localfilepath = filepath.substr(1, filepath.size() - 1);
  1397. cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
  1398. localfilepath, filename);
  1399. }
  1400. // if extraPaths are provided and we were not passed a full path, try them,
  1401. // try any extra paths
  1402. if (filepath.empty()) {
  1403. for (unsigned int i = 0; i < extraPaths.size(); ++i) {
  1404. std::string filepathExtra =
  1405. cmSystemTools::GetFilenamePath(extraPaths[i]);
  1406. std::string filenameExtra =
  1407. cmSystemTools::GetFilenameName(extraPaths[i]);
  1408. cmCTestTestHandler::AddConfigurations(ctest, attempted, attemptedConfigs,
  1409. filepathExtra, filenameExtra);
  1410. }
  1411. }
  1412. // store the final location in fullPath
  1413. std::string fullPath;
  1414. // now look in the paths we specified above
  1415. for (unsigned int ai = 0; ai < attempted.size() && fullPath.empty(); ++ai) {
  1416. // first check without exe extension
  1417. if (cmSystemTools::FileExists(attempted[ai].c_str()) &&
  1418. !cmSystemTools::FileIsDirectory(attempted[ai])) {
  1419. fullPath = cmSystemTools::CollapseFullPath(attempted[ai]);
  1420. resultingConfig = attemptedConfigs[ai];
  1421. }
  1422. // then try with the exe extension
  1423. else {
  1424. failed.push_back(attempted[ai]);
  1425. tempPath = attempted[ai];
  1426. tempPath += cmSystemTools::GetExecutableExtension();
  1427. if (cmSystemTools::FileExists(tempPath.c_str()) &&
  1428. !cmSystemTools::FileIsDirectory(tempPath)) {
  1429. fullPath = cmSystemTools::CollapseFullPath(tempPath);
  1430. resultingConfig = attemptedConfigs[ai];
  1431. } else {
  1432. failed.push_back(tempPath);
  1433. }
  1434. }
  1435. }
  1436. // if everything else failed, check the users path, but only if a full path
  1437. // wasn't specified
  1438. if (fullPath.empty() && filepath.empty()) {
  1439. std::string path = cmSystemTools::FindProgram(filename.c_str());
  1440. if (path != "") {
  1441. resultingConfig = "";
  1442. return path;
  1443. }
  1444. }
  1445. if (fullPath.empty()) {
  1446. cmCTestLog(ctest, HANDLER_OUTPUT, "Could not find executable "
  1447. << testCommand << "\n"
  1448. << "Looked in the following places:\n");
  1449. for (std::vector<std::string>::iterator i = failed.begin();
  1450. i != failed.end(); ++i) {
  1451. cmCTestLog(ctest, HANDLER_OUTPUT, *i << "\n");
  1452. }
  1453. }
  1454. return fullPath;
  1455. }
  1456. void cmCTestTestHandler::GetListOfTests()
  1457. {
  1458. if (!this->IncludeLabelRegExp.empty()) {
  1459. this->IncludeLabelRegularExpression.compile(
  1460. this->IncludeLabelRegExp.c_str());
  1461. }
  1462. if (!this->ExcludeLabelRegExp.empty()) {
  1463. this->ExcludeLabelRegularExpression.compile(
  1464. this->ExcludeLabelRegExp.c_str());
  1465. }
  1466. if (!this->IncludeRegExp.empty()) {
  1467. this->IncludeTestsRegularExpression.compile(this->IncludeRegExp.c_str());
  1468. }
  1469. if (!this->ExcludeRegExp.empty()) {
  1470. this->ExcludeTestsRegularExpression.compile(this->ExcludeRegExp.c_str());
  1471. }
  1472. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1473. "Constructing a list of tests" << std::endl, this->Quiet);
  1474. cmake cm(cmake::RoleScript);
  1475. cm.SetHomeDirectory("");
  1476. cm.SetHomeOutputDirectory("");
  1477. cm.GetCurrentSnapshot().SetDefaultDefinitions();
  1478. cmGlobalGenerator gg(&cm);
  1479. CM_AUTO_PTR<cmMakefile> mf(new cmMakefile(&gg, cm.GetCurrentSnapshot()));
  1480. mf->AddDefinition("CTEST_CONFIGURATION_TYPE",
  1481. this->CTest->GetConfigType().c_str());
  1482. // Add handler for ADD_TEST
  1483. cmCTestAddTestCommand* newCom1 = new cmCTestAddTestCommand;
  1484. newCom1->TestHandler = this;
  1485. cm.GetState()->AddBuiltinCommand("add_test", newCom1);
  1486. // Add handler for SUBDIRS
  1487. cmCTestSubdirCommand* newCom2 = new cmCTestSubdirCommand;
  1488. newCom2->TestHandler = this;
  1489. cm.GetState()->AddBuiltinCommand("subdirs", newCom2);
  1490. // Add handler for ADD_SUBDIRECTORY
  1491. cmCTestAddSubdirectoryCommand* newCom3 = new cmCTestAddSubdirectoryCommand;
  1492. newCom3->TestHandler = this;
  1493. cm.GetState()->AddBuiltinCommand("add_subdirectory", newCom3);
  1494. // Add handler for SET_TESTS_PROPERTIES
  1495. cmCTestSetTestsPropertiesCommand* newCom4 =
  1496. new cmCTestSetTestsPropertiesCommand;
  1497. newCom4->TestHandler = this;
  1498. cm.GetState()->AddBuiltinCommand("set_tests_properties", newCom4);
  1499. const char* testFilename;
  1500. if (cmSystemTools::FileExists("CTestTestfile.cmake")) {
  1501. // does the CTestTestfile.cmake exist ?
  1502. testFilename = "CTestTestfile.cmake";
  1503. } else if (cmSystemTools::FileExists("DartTestfile.txt")) {
  1504. // does the DartTestfile.txt exist ?
  1505. testFilename = "DartTestfile.txt";
  1506. } else {
  1507. return;
  1508. }
  1509. if (!mf->ReadListFile(testFilename)) {
  1510. return;
  1511. }
  1512. if (cmSystemTools::GetErrorOccuredFlag()) {
  1513. return;
  1514. }
  1515. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1516. "Done constructing a list of tests" << std::endl,
  1517. this->Quiet);
  1518. }
  1519. void cmCTestTestHandler::UseIncludeRegExp()
  1520. {
  1521. this->UseIncludeRegExpFlag = true;
  1522. }
  1523. void cmCTestTestHandler::UseExcludeRegExp()
  1524. {
  1525. this->UseExcludeRegExpFlag = true;
  1526. this->UseExcludeRegExpFirst = !this->UseIncludeRegExpFlag;
  1527. }
  1528. const char* cmCTestTestHandler::GetTestStatus(int status)
  1529. {
  1530. static const char* statuses[] = { "Not Run", "Timeout", "SEGFAULT",
  1531. "ILLEGAL", "INTERRUPT", "NUMERICAL",
  1532. "OTHER_FAULT", "Failed", "BAD_COMMAND",
  1533. "Completed" };
  1534. if (status < cmCTestTestHandler::NOT_RUN ||
  1535. status > cmCTestTestHandler::COMPLETED) {
  1536. return "No Status";
  1537. }
  1538. return statuses[status];
  1539. }
  1540. void cmCTestTestHandler::ExpandTestsToRunInformation(size_t numTests)
  1541. {
  1542. if (this->TestsToRunString.empty()) {
  1543. return;
  1544. }
  1545. int start;
  1546. int end = -1;
  1547. double stride = -1;
  1548. std::string::size_type pos = 0;
  1549. std::string::size_type pos2;
  1550. // read start
  1551. if (GetNextNumber(this->TestsToRunString, start, pos, pos2)) {
  1552. // read end
  1553. if (GetNextNumber(this->TestsToRunString, end, pos, pos2)) {
  1554. // read stride
  1555. if (GetNextRealNumber(this->TestsToRunString, stride, pos, pos2)) {
  1556. int val = 0;
  1557. // now read specific numbers
  1558. while (GetNextNumber(this->TestsToRunString, val, pos, pos2)) {
  1559. this->TestsToRun.push_back(val);
  1560. }
  1561. this->TestsToRun.push_back(val);
  1562. }
  1563. }
  1564. }
  1565. // if start is not specified then we assume we start at 1
  1566. if (start == -1) {
  1567. start = 1;
  1568. }
  1569. // if end isnot specified then we assume we end with the last test
  1570. if (end == -1) {
  1571. end = static_cast<int>(numTests);
  1572. }
  1573. // if the stride wasn't specified then it defaults to 1
  1574. if (stride == -1) {
  1575. stride = 1;
  1576. }
  1577. // if we have a range then add it
  1578. if (end != -1 && start != -1 && stride > 0) {
  1579. int i = 0;
  1580. while (i * stride + start <= end) {
  1581. this->TestsToRun.push_back(static_cast<int>(i * stride + start));
  1582. ++i;
  1583. }
  1584. }
  1585. // sort the array
  1586. std::sort(this->TestsToRun.begin(), this->TestsToRun.end(),
  1587. std::less<int>());
  1588. // remove duplicates
  1589. std::vector<int>::iterator new_end =
  1590. std::unique(this->TestsToRun.begin(), this->TestsToRun.end());
  1591. this->TestsToRun.erase(new_end, this->TestsToRun.end());
  1592. }
  1593. void cmCTestTestHandler::ExpandTestsToRunInformationForRerunFailed()
  1594. {
  1595. std::string dirName = this->CTest->GetBinaryDir() + "/Testing/Temporary";
  1596. cmsys::Directory directory;
  1597. if (directory.Load(dirName) == 0) {
  1598. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unable to read the contents of "
  1599. << dirName << std::endl);
  1600. return;
  1601. }
  1602. int numFiles =
  1603. static_cast<int>(cmsys::Directory::GetNumberOfFilesInDirectory(dirName));
  1604. std::string pattern = "LastTestsFailed";
  1605. std::string logName;
  1606. for (int i = 0; i < numFiles; ++i) {
  1607. std::string fileName = directory.GetFile(i);
  1608. // bcc crashes if we attempt a normal substring comparison,
  1609. // hence the following workaround
  1610. std::string fileNameSubstring = fileName.substr(0, pattern.length());
  1611. if (fileNameSubstring != pattern) {
  1612. continue;
  1613. }
  1614. if (logName == "") {
  1615. logName = fileName;
  1616. } else {
  1617. // if multiple matching logs were found we use the most recently
  1618. // modified one.
  1619. int res;
  1620. cmSystemTools::FileTimeCompare(logName, fileName, &res);
  1621. if (res == -1) {
  1622. logName = fileName;
  1623. }
  1624. }
  1625. }
  1626. std::string lastTestsFailedLog =
  1627. this->CTest->GetBinaryDir() + "/Testing/Temporary/" + logName;
  1628. if (!cmSystemTools::FileExists(lastTestsFailedLog.c_str())) {
  1629. if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) {
  1630. cmCTestLog(this->CTest, ERROR_MESSAGE, lastTestsFailedLog
  1631. << " does not exist!" << std::endl);
  1632. }
  1633. return;
  1634. }
  1635. // parse the list of tests to rerun from LastTestsFailed.log
  1636. cmsys::ifstream ifs(lastTestsFailedLog.c_str());
  1637. if (ifs) {
  1638. std::string line;
  1639. std::string::size_type pos;
  1640. while (cmSystemTools::GetLineFromStream(ifs, line)) {
  1641. pos = line.find(':', 0);
  1642. if (pos == std::string::npos) {
  1643. continue;
  1644. }
  1645. int val = atoi(line.substr(0, pos).c_str());
  1646. this->TestsToRun.push_back(val);
  1647. }
  1648. ifs.close();
  1649. } else if (!this->CTest->GetShowOnly() &&
  1650. !this->CTest->ShouldPrintLabels()) {
  1651. cmCTestLog(this->CTest, ERROR_MESSAGE, "Problem reading file: "
  1652. << lastTestsFailedLog
  1653. << " while generating list of previously failed tests."
  1654. << std::endl);
  1655. }
  1656. }
  1657. // Just for convenience
  1658. #define SPACE_REGEX "[ \t\r\n]"
  1659. void cmCTestTestHandler::GenerateRegressionImages(cmXMLWriter& xml,
  1660. const std::string& dart)
  1661. {
  1662. cmsys::RegularExpression twoattributes(
  1663. "<DartMeasurement" SPACE_REGEX
  1664. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1665. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1666. "*>([^<]*)</DartMeasurement>");
  1667. cmsys::RegularExpression threeattributes(
  1668. "<DartMeasurement" SPACE_REGEX
  1669. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1670. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1671. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1672. "*>([^<]*)</DartMeasurement>");
  1673. cmsys::RegularExpression fourattributes(
  1674. "<DartMeasurement" SPACE_REGEX
  1675. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1676. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1677. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1678. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1679. "*>([^<]*)</DartMeasurement>");
  1680. cmsys::RegularExpression cdatastart(
  1681. "<DartMeasurement" SPACE_REGEX
  1682. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1683. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1684. "*>" SPACE_REGEX "*<!\\[CDATA\\[");
  1685. cmsys::RegularExpression cdataend("]]>" SPACE_REGEX "*</DartMeasurement>");
  1686. cmsys::RegularExpression measurementfile(
  1687. "<DartMeasurementFile" SPACE_REGEX
  1688. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1689. "*(name|type|encoding|compression)=\"([^\"]*)\"" SPACE_REGEX
  1690. "*>([^<]*)</DartMeasurementFile>");
  1691. bool done = false;
  1692. std::string cxml = dart;
  1693. while (!done) {
  1694. if (twoattributes.find(cxml)) {
  1695. xml.StartElement("NamedMeasurement");
  1696. xml.Attribute(twoattributes.match(1).c_str(), twoattributes.match(2));
  1697. xml.Attribute(twoattributes.match(3).c_str(), twoattributes.match(4));
  1698. xml.Element("Value", twoattributes.match(5));
  1699. xml.EndElement();
  1700. cxml.erase(twoattributes.start(),
  1701. twoattributes.end() - twoattributes.start());
  1702. } else if (threeattributes.find(cxml)) {
  1703. xml.StartElement("NamedMeasurement");
  1704. xml.Attribute(threeattributes.match(1).c_str(),
  1705. threeattributes.match(2));
  1706. xml.Attribute(threeattributes.match(3).c_str(),
  1707. threeattributes.match(4));
  1708. xml.Attribute(threeattributes.match(5).c_str(),
  1709. threeattributes.match(6));
  1710. xml.Element("Value", twoattributes.match(7));
  1711. xml.EndElement();
  1712. cxml.erase(threeattributes.start(),
  1713. threeattributes.end() - threeattributes.start());
  1714. } else if (fourattributes.find(cxml)) {
  1715. xml.StartElement("NamedMeasurement");
  1716. xml.Attribute(fourattributes.match(1).c_str(), fourattributes.match(2));
  1717. xml.Attribute(fourattributes.match(3).c_str(), fourattributes.match(4));
  1718. xml.Attribute(fourattributes.match(5).c_str(), fourattributes.match(6));
  1719. xml.Attribute(fourattributes.match(7).c_str(), fourattributes.match(8));
  1720. xml.Element("Value", twoattributes.match(9));
  1721. xml.EndElement();
  1722. cxml.erase(fourattributes.start(),
  1723. fourattributes.end() - fourattributes.start());
  1724. } else if (cdatastart.find(cxml) && cdataend.find(cxml)) {
  1725. xml.StartElement("NamedMeasurement");
  1726. xml.Attribute(cdatastart.match(1).c_str(), cdatastart.match(2));
  1727. xml.Attribute(cdatastart.match(3).c_str(), cdatastart.match(4));
  1728. xml.StartElement("Value");
  1729. xml.CData(
  1730. cxml.substr(cdatastart.end(), cdataend.start() - cdatastart.end()));
  1731. xml.EndElement(); // Value
  1732. xml.EndElement(); // NamedMeasurement
  1733. cxml.erase(cdatastart.start(), cdataend.end() - cdatastart.start());
  1734. } else if (measurementfile.find(cxml)) {
  1735. const std::string& filename =
  1736. cmCTest::CleanString(measurementfile.match(5));
  1737. if (cmSystemTools::FileExists(filename.c_str())) {
  1738. long len = cmSystemTools::FileLength(filename);
  1739. if (len == 0) {
  1740. std::string k1 = measurementfile.match(1);
  1741. std::string v1 = measurementfile.match(2);
  1742. std::string k2 = measurementfile.match(3);
  1743. std::string v2 = measurementfile.match(4);
  1744. if (cmSystemTools::LowerCase(k1) == "type") {
  1745. v1 = "text/string";
  1746. }
  1747. if (cmSystemTools::LowerCase(k2) == "type") {
  1748. v2 = "text/string";
  1749. }
  1750. xml.StartElement("NamedMeasurement");
  1751. xml.Attribute(k1.c_str(), v1);
  1752. xml.Attribute(k2.c_str(), v2);
  1753. xml.Attribute("encoding", "none");
  1754. xml.Element("Value", "Image " + filename + " is empty");
  1755. xml.EndElement();
  1756. } else {
  1757. cmsys::ifstream ifs(filename.c_str(), std::ios::in
  1758. #ifdef _WIN32
  1759. | std::ios::binary
  1760. #endif
  1761. );
  1762. unsigned char* file_buffer = new unsigned char[len + 1];
  1763. ifs.read(reinterpret_cast<char*>(file_buffer), len);
  1764. unsigned char* encoded_buffer = new unsigned char[static_cast<int>(
  1765. static_cast<double>(len) * 1.5 + 5.0)];
  1766. size_t rlen =
  1767. cmsysBase64_Encode(file_buffer, len, encoded_buffer, 1);
  1768. xml.StartElement("NamedMeasurement");
  1769. xml.Attribute(measurementfile.match(1).c_str(),
  1770. measurementfile.match(2));
  1771. xml.Attribute(measurementfile.match(3).c_str(),
  1772. measurementfile.match(4));
  1773. xml.Attribute("encoding", "base64");
  1774. std::ostringstream ostr;
  1775. for (size_t cc = 0; cc < rlen; cc++) {
  1776. ostr << encoded_buffer[cc];
  1777. if (cc % 60 == 0 && cc) {
  1778. ostr << std::endl;
  1779. }
  1780. }
  1781. xml.Element("Value", ostr.str());
  1782. xml.EndElement(); // NamedMeasurement
  1783. delete[] file_buffer;
  1784. delete[] encoded_buffer;
  1785. }
  1786. } else {
  1787. int idx = 4;
  1788. if (measurementfile.match(1) == "name") {
  1789. idx = 2;
  1790. }
  1791. xml.StartElement("NamedMeasurement");
  1792. xml.Attribute("name", measurementfile.match(idx));
  1793. xml.Attribute("text", "text/string");
  1794. xml.Element("Value", "File " + filename + " not found");
  1795. xml.EndElement();
  1796. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "File \""
  1797. << filename << "\" not found." << std::endl,
  1798. this->Quiet);
  1799. }
  1800. cxml.erase(measurementfile.start(),
  1801. measurementfile.end() - measurementfile.start());
  1802. } else {
  1803. done = true;
  1804. }
  1805. }
  1806. }
  1807. void cmCTestTestHandler::SetIncludeRegExp(const char* arg)
  1808. {
  1809. this->IncludeRegExp = arg;
  1810. }
  1811. void cmCTestTestHandler::SetExcludeRegExp(const char* arg)
  1812. {
  1813. this->ExcludeRegExp = arg;
  1814. }
  1815. void cmCTestTestHandler::SetTestsToRunInformation(const char* in)
  1816. {
  1817. if (!in) {
  1818. return;
  1819. }
  1820. this->TestsToRunString = in;
  1821. // if the argument is a file, then read it and use the contents as the
  1822. // string
  1823. if (cmSystemTools::FileExists(in)) {
  1824. cmsys::ifstream fin(in);
  1825. unsigned long filelen = cmSystemTools::FileLength(in);
  1826. char* buff = new char[filelen + 1];
  1827. fin.getline(buff, filelen);
  1828. buff[fin.gcount()] = 0;
  1829. this->TestsToRunString = buff;
  1830. delete[] buff;
  1831. }
  1832. }
  1833. bool cmCTestTestHandler::CleanTestOutput(std::string& output, size_t length)
  1834. {
  1835. if (!length || length >= output.size() ||
  1836. output.find("CTEST_FULL_OUTPUT") != std::string::npos) {
  1837. return true;
  1838. }
  1839. // Truncate at given length but do not break in the middle of a multi-byte
  1840. // UTF-8 encoding.
  1841. char const* const begin = output.c_str();
  1842. char const* const end = begin + output.size();
  1843. char const* const truncate = begin + length;
  1844. char const* current = begin;
  1845. while (current < truncate) {
  1846. unsigned int ch;
  1847. if (const char* next = cm_utf8_decode_character(current, end, &ch)) {
  1848. if (next > truncate) {
  1849. break;
  1850. }
  1851. current = next;
  1852. } else // Bad byte will be handled by cmXMLWriter.
  1853. {
  1854. ++current;
  1855. }
  1856. }
  1857. output = output.substr(0, current - begin);
  1858. // Append truncation message.
  1859. std::ostringstream msg;
  1860. msg << "...\n"
  1861. "The rest of the test output was removed since it exceeds the "
  1862. "threshold "
  1863. "of "
  1864. << length << " bytes.\n";
  1865. output += msg.str();
  1866. return true;
  1867. }
  1868. bool cmCTestTestHandler::SetTestsProperties(
  1869. const std::vector<std::string>& args)
  1870. {
  1871. std::vector<std::string>::const_iterator it;
  1872. std::vector<std::string> tests;
  1873. bool found = false;
  1874. for (it = args.begin(); it != args.end(); ++it) {
  1875. if (*it == "PROPERTIES") {
  1876. found = true;
  1877. break;
  1878. }
  1879. tests.push_back(*it);
  1880. }
  1881. if (!found) {
  1882. return false;
  1883. }
  1884. ++it; // skip PROPERTIES
  1885. for (; it != args.end(); ++it) {
  1886. std::string key = *it;
  1887. ++it;
  1888. if (it == args.end()) {
  1889. break;
  1890. }
  1891. std::string val = *it;
  1892. std::vector<std::string>::const_iterator tit;
  1893. for (tit = tests.begin(); tit != tests.end(); ++tit) {
  1894. cmCTestTestHandler::ListOfTests::iterator rtit;
  1895. for (rtit = this->TestList.begin(); rtit != this->TestList.end();
  1896. ++rtit) {
  1897. if (*tit == rtit->Name) {
  1898. if (key == "WILL_FAIL") {
  1899. rtit->WillFail = cmSystemTools::IsOn(val.c_str());
  1900. }
  1901. if (key == "DISABLED") {
  1902. rtit->Disabled = cmSystemTools::IsOn(val.c_str());
  1903. }
  1904. if (key == "ATTACHED_FILES") {
  1905. cmSystemTools::ExpandListArgument(val, rtit->AttachedFiles);
  1906. }
  1907. if (key == "ATTACHED_FILES_ON_FAIL") {
  1908. cmSystemTools::ExpandListArgument(val, rtit->AttachOnFail);
  1909. }
  1910. if (key == "RESOURCE_LOCK") {
  1911. std::vector<std::string> lval;
  1912. cmSystemTools::ExpandListArgument(val, lval);
  1913. rtit->LockedResources.insert(lval.begin(), lval.end());
  1914. }
  1915. if (key == "FIXTURES_SETUP") {
  1916. std::vector<std::string> lval;
  1917. cmSystemTools::ExpandListArgument(val, lval);
  1918. rtit->FixturesSetup.insert(lval.begin(), lval.end());
  1919. }
  1920. if (key == "FIXTURES_CLEANUP") {
  1921. std::vector<std::string> lval;
  1922. cmSystemTools::ExpandListArgument(val, lval);
  1923. rtit->FixturesCleanup.insert(lval.begin(), lval.end());
  1924. }
  1925. if (key == "FIXTURES_REQUIRED") {
  1926. std::vector<std::string> lval;
  1927. cmSystemTools::ExpandListArgument(val, lval);
  1928. rtit->FixturesRequired.insert(lval.begin(), lval.end());
  1929. }
  1930. if (key == "TIMEOUT") {
  1931. rtit->Timeout = atof(val.c_str());
  1932. rtit->ExplicitTimeout = true;
  1933. }
  1934. if (key == "COST") {
  1935. rtit->Cost = static_cast<float>(atof(val.c_str()));
  1936. }
  1937. if (key == "REQUIRED_FILES") {
  1938. cmSystemTools::ExpandListArgument(val, rtit->RequiredFiles);
  1939. }
  1940. if (key == "RUN_SERIAL") {
  1941. rtit->RunSerial = cmSystemTools::IsOn(val.c_str());
  1942. }
  1943. if (key == "FAIL_REGULAR_EXPRESSION") {
  1944. std::vector<std::string> lval;
  1945. cmSystemTools::ExpandListArgument(val, lval);
  1946. std::vector<std::string>::iterator crit;
  1947. for (crit = lval.begin(); crit != lval.end(); ++crit) {
  1948. rtit->ErrorRegularExpressions.push_back(
  1949. std::pair<cmsys::RegularExpression, std::string>(
  1950. cmsys::RegularExpression(crit->c_str()),
  1951. std::string(*crit)));
  1952. }
  1953. }
  1954. if (key == "PROCESSORS") {
  1955. rtit->Processors = atoi(val.c_str());
  1956. if (rtit->Processors < 1) {
  1957. rtit->Processors = 1;
  1958. }
  1959. }
  1960. if (key == "SKIP_RETURN_CODE") {
  1961. rtit->SkipReturnCode = atoi(val.c_str());
  1962. if (rtit->SkipReturnCode < 0 || rtit->SkipReturnCode > 255) {
  1963. rtit->SkipReturnCode = -1;
  1964. }
  1965. }
  1966. if (key == "DEPENDS") {
  1967. cmSystemTools::ExpandListArgument(val, rtit->Depends);
  1968. }
  1969. if (key == "ENVIRONMENT") {
  1970. cmSystemTools::ExpandListArgument(val, rtit->Environment);
  1971. }
  1972. if (key == "LABELS") {
  1973. cmSystemTools::ExpandListArgument(val, rtit->Labels);
  1974. }
  1975. if (key == "MEASUREMENT") {
  1976. size_t pos = val.find_first_of('=');
  1977. if (pos != std::string::npos) {
  1978. std::string mKey = val.substr(0, pos);
  1979. const char* mVal = val.c_str() + pos + 1;
  1980. rtit->Measurements[mKey] = mVal;
  1981. } else {
  1982. rtit->Measurements[val] = "1";
  1983. }
  1984. }
  1985. if (key == "PASS_REGULAR_EXPRESSION") {
  1986. std::vector<std::string> lval;
  1987. cmSystemTools::ExpandListArgument(val, lval);
  1988. std::vector<std::string>::iterator crit;
  1989. for (crit = lval.begin(); crit != lval.end(); ++crit) {
  1990. rtit->RequiredRegularExpressions.push_back(
  1991. std::pair<cmsys::RegularExpression, std::string>(
  1992. cmsys::RegularExpression(crit->c_str()),
  1993. std::string(*crit)));
  1994. }
  1995. }
  1996. if (key == "WORKING_DIRECTORY") {
  1997. rtit->Directory = val;
  1998. }
  1999. if (key == "TIMEOUT_AFTER_MATCH") {
  2000. std::vector<std::string> propArgs;
  2001. cmSystemTools::ExpandListArgument(val, propArgs);
  2002. if (propArgs.size() != 2) {
  2003. cmCTestLog(this->CTest, WARNING,
  2004. "TIMEOUT_AFTER_MATCH expects two arguments, found "
  2005. << propArgs.size() << std::endl);
  2006. } else {
  2007. rtit->AlternateTimeout = atof(propArgs[0].c_str());
  2008. std::vector<std::string> lval;
  2009. cmSystemTools::ExpandListArgument(propArgs[1], lval);
  2010. std::vector<std::string>::iterator crit;
  2011. for (crit = lval.begin(); crit != lval.end(); ++crit) {
  2012. rtit->TimeoutRegularExpressions.push_back(
  2013. std::pair<cmsys::RegularExpression, std::string>(
  2014. cmsys::RegularExpression(crit->c_str()),
  2015. std::string(*crit)));
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. }
  2022. }
  2023. return true;
  2024. }
  2025. bool cmCTestTestHandler::AddTest(const std::vector<std::string>& args)
  2026. {
  2027. const std::string& testname = args[0];
  2028. cmCTestOptionalLog(this->CTest, DEBUG, "Add test: " << args[0] << std::endl,
  2029. this->Quiet);
  2030. if (this->UseExcludeRegExpFlag && this->UseExcludeRegExpFirst &&
  2031. this->ExcludeTestsRegularExpression.find(testname.c_str())) {
  2032. return true;
  2033. }
  2034. if (this->MemCheck) {
  2035. std::vector<std::string>::iterator it;
  2036. bool found = false;
  2037. for (it = this->CustomTestsIgnore.begin();
  2038. it != this->CustomTestsIgnore.end(); ++it) {
  2039. if (*it == testname) {
  2040. found = true;
  2041. break;
  2042. }
  2043. }
  2044. if (found) {
  2045. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  2046. "Ignore memcheck: " << *it << std::endl, this->Quiet);
  2047. return true;
  2048. }
  2049. } else {
  2050. std::vector<std::string>::iterator it;
  2051. bool found = false;
  2052. for (it = this->CustomTestsIgnore.begin();
  2053. it != this->CustomTestsIgnore.end(); ++it) {
  2054. if (*it == testname) {
  2055. found = true;
  2056. break;
  2057. }
  2058. }
  2059. if (found) {
  2060. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  2061. "Ignore test: " << *it << std::endl, this->Quiet);
  2062. return true;
  2063. }
  2064. }
  2065. cmCTestTestProperties test;
  2066. test.Name = testname;
  2067. test.Args = args;
  2068. test.Directory = cmSystemTools::GetCurrentWorkingDirectory();
  2069. cmCTestOptionalLog(this->CTest, DEBUG,
  2070. "Set test directory: " << test.Directory << std::endl,
  2071. this->Quiet);
  2072. test.IsInBasedOnREOptions = true;
  2073. test.WillFail = false;
  2074. test.Disabled = false;
  2075. test.RunSerial = false;
  2076. test.Timeout = 0;
  2077. test.ExplicitTimeout = false;
  2078. test.Cost = 0;
  2079. test.Processors = 1;
  2080. test.SkipReturnCode = -1;
  2081. test.PreviousRuns = 0;
  2082. if (this->UseIncludeRegExpFlag &&
  2083. !this->IncludeTestsRegularExpression.find(testname.c_str())) {
  2084. test.IsInBasedOnREOptions = false;
  2085. } else if (this->UseExcludeRegExpFlag && !this->UseExcludeRegExpFirst &&
  2086. this->ExcludeTestsRegularExpression.find(testname.c_str())) {
  2087. test.IsInBasedOnREOptions = false;
  2088. }
  2089. this->TestList.push_back(test);
  2090. return true;
  2091. }