cmCTestTestHandler.cxx 76 KB

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