cmCTestTestHandler.cxx 63 KB

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