cmCTestTestHandler.cxx 64 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. cmCommand* Clone() CM_OVERRIDE
  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. bool InitialPass(std::vector<std::string> const& args,
  49. cmExecutionStatus& /*unused*/) CM_OVERRIDE;
  50. /**
  51. * The name of the command as specified in CMakeList.txt.
  52. */
  53. std::string GetName() const CM_OVERRIDE { return "subdirs"; }
  54. cmTypeMacro(cmCTestSubdirCommand, cmCommand);
  55. cmCTestTestHandler* TestHandler;
  56. };
  57. bool cmCTestSubdirCommand::InitialPass(std::vector<std::string> const& args,
  58. cmExecutionStatus& /*unused*/)
  59. {
  60. if (args.empty()) {
  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. cmCommand* Clone() CM_OVERRIDE
  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. bool InitialPass(std::vector<std::string> const& args,
  122. cmExecutionStatus& /*unused*/) CM_OVERRIDE;
  123. /**
  124. * The name of the command as specified in CMakeList.txt.
  125. */
  126. std::string GetName() const CM_OVERRIDE { return "add_subdirectory"; }
  127. cmTypeMacro(cmCTestAddSubdirectoryCommand, cmCommand);
  128. cmCTestTestHandler* TestHandler;
  129. };
  130. bool cmCTestAddSubdirectoryCommand::InitialPass(
  131. std::vector<std::string> const& args, cmExecutionStatus& /*unused*/)
  132. {
  133. if (args.empty()) {
  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. 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. cmTypeMacro(cmCTestAddTestCommand, cmCommand);
  194. cmCTestTestHandler* TestHandler;
  195. };
  196. bool cmCTestAddTestCommand::InitialPass(std::vector<std::string> const& args,
  197. cmExecutionStatus& /*unused*/)
  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. cmCommand* Clone() CM_OVERRIDE
  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. bool InitialPass(std::vector<std::string> const& /*args*/,
  222. cmExecutionStatus& /*unused*/) CM_OVERRIDE;
  223. /**
  224. * The name of the command as specified in CMakeList.txt.
  225. */
  226. std::string GetName() const CM_OVERRIDE { return "set_tests_properties"; }
  227. cmTypeMacro(cmCTestSetTestsPropertiesCommand, cmCommand);
  228. cmCTestTestHandler* TestHandler;
  229. };
  230. bool cmCTestSetTestsPropertiesCommand::InitialPass(
  231. std::vector<std::string> const& args, cmExecutionStatus& /*unused*/)
  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. }
  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. // get the next number in a string with numbers separated by ,
  261. // pos is the start of the search and pos2 is the end of the search
  262. // pos becomes pos2 after a call to GetNextNumber.
  263. // -1 is returned at the end of the list.
  264. inline int GetNextRealNumber(std::string const& in, double& val,
  265. std::string::size_type& pos,
  266. std::string::size_type& pos2)
  267. {
  268. pos2 = in.find(',', pos);
  269. if (pos2 != in.npos) {
  270. if (pos2 - pos == 0) {
  271. val = -1;
  272. } else {
  273. val = atof(in.substr(pos, pos2 - pos).c_str());
  274. }
  275. pos = pos2 + 1;
  276. return 1;
  277. }
  278. if (in.size() - pos == 0) {
  279. val = -1;
  280. } else {
  281. val = atof(in.substr(pos, in.size() - pos).c_str());
  282. }
  283. return 0;
  284. }
  285. cmCTestTestHandler::cmCTestTestHandler()
  286. {
  287. this->UseUnion = false;
  288. this->UseIncludeLabelRegExpFlag = false;
  289. this->UseExcludeLabelRegExpFlag = false;
  290. this->UseIncludeRegExpFlag = false;
  291. this->UseExcludeRegExpFlag = false;
  292. this->UseExcludeRegExpFirst = false;
  293. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  294. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  295. this->MemCheck = false;
  296. this->LogFile = CM_NULLPTR;
  297. // regex to detect <DartMeasurement>...</DartMeasurement>
  298. this->DartStuff.compile("(<DartMeasurement.*/DartMeasurement[a-zA-Z]*>)");
  299. // regex to detect each individual <DartMeasurement>...</DartMeasurement>
  300. this->DartStuff1.compile(
  301. "(<DartMeasurement[^<]*</DartMeasurement[a-zA-Z]*>)");
  302. }
  303. void cmCTestTestHandler::Initialize()
  304. {
  305. this->Superclass::Initialize();
  306. this->ElapsedTestingTime = -1;
  307. this->TestResults.clear();
  308. this->CustomTestsIgnore.clear();
  309. this->StartTest = "";
  310. this->EndTest = "";
  311. this->CustomPreTest.clear();
  312. this->CustomPostTest.clear();
  313. this->CustomMaximumPassedTestOutputSize = 1 * 1024;
  314. this->CustomMaximumFailedTestOutputSize = 300 * 1024;
  315. this->TestsToRun.clear();
  316. this->UseIncludeLabelRegExpFlag = false;
  317. this->UseExcludeLabelRegExpFlag = false;
  318. this->UseIncludeRegExpFlag = false;
  319. this->UseExcludeRegExpFlag = false;
  320. this->UseExcludeRegExpFirst = false;
  321. this->IncludeLabelRegularExpression = "";
  322. this->ExcludeLabelRegularExpression = "";
  323. this->IncludeRegExp = "";
  324. this->ExcludeRegExp = "";
  325. TestsToRunString = "";
  326. this->UseUnion = false;
  327. this->TestList.clear();
  328. }
  329. void cmCTestTestHandler::PopulateCustomVectors(cmMakefile* mf)
  330. {
  331. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_TEST",
  332. this->CustomPreTest);
  333. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_TEST",
  334. this->CustomPostTest);
  335. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_TESTS_IGNORE",
  336. this->CustomTestsIgnore);
  337. this->CTest->PopulateCustomInteger(
  338. mf, "CTEST_CUSTOM_MAXIMUM_PASSED_TEST_OUTPUT_SIZE",
  339. this->CustomMaximumPassedTestOutputSize);
  340. this->CTest->PopulateCustomInteger(
  341. mf, "CTEST_CUSTOM_MAXIMUM_FAILED_TEST_OUTPUT_SIZE",
  342. this->CustomMaximumFailedTestOutputSize);
  343. }
  344. int cmCTestTestHandler::PreProcessHandler()
  345. {
  346. if (!this->ExecuteCommands(this->CustomPreTest)) {
  347. cmCTestLog(this->CTest, ERROR_MESSAGE,
  348. "Problem executing pre-test command(s)." << std::endl);
  349. return 0;
  350. }
  351. return 1;
  352. }
  353. int cmCTestTestHandler::PostProcessHandler()
  354. {
  355. if (!this->ExecuteCommands(this->CustomPostTest)) {
  356. cmCTestLog(this->CTest, ERROR_MESSAGE,
  357. "Problem executing post-test command(s)." << std::endl);
  358. return 0;
  359. }
  360. return 1;
  361. }
  362. // clearly it would be nice if this were broken up into a few smaller
  363. // functions and commented...
  364. int cmCTestTestHandler::ProcessHandler()
  365. {
  366. // Update internal data structure from generic one
  367. this->SetTestsToRunInformation(this->GetOption("TestsToRunInformation"));
  368. this->SetUseUnion(cmSystemTools::IsOn(this->GetOption("UseUnion")));
  369. if (cmSystemTools::IsOn(this->GetOption("ScheduleRandom"))) {
  370. this->CTest->SetScheduleType("Random");
  371. }
  372. if (this->GetOption("ParallelLevel")) {
  373. this->CTest->SetParallelLevel(atoi(this->GetOption("ParallelLevel")));
  374. }
  375. const char* val;
  376. val = this->GetOption("LabelRegularExpression");
  377. if (val) {
  378. this->UseIncludeLabelRegExpFlag = true;
  379. this->IncludeLabelRegExp = val;
  380. }
  381. val = this->GetOption("ExcludeLabelRegularExpression");
  382. if (val) {
  383. this->UseExcludeLabelRegExpFlag = true;
  384. this->ExcludeLabelRegExp = val;
  385. }
  386. val = this->GetOption("IncludeRegularExpression");
  387. if (val) {
  388. this->UseIncludeRegExp();
  389. this->SetIncludeRegExp(val);
  390. }
  391. val = this->GetOption("ExcludeRegularExpression");
  392. if (val) {
  393. this->UseExcludeRegExp();
  394. this->SetExcludeRegExp(val);
  395. }
  396. this->SetRerunFailed(cmSystemTools::IsOn(this->GetOption("RerunFailed")));
  397. this->TestResults.clear();
  398. cmCTestOptionalLog(
  399. this->CTest, HANDLER_OUTPUT, (this->MemCheck ? "Memory check" : "Test")
  400. << " project " << cmSystemTools::GetCurrentWorkingDirectory()
  401. << std::endl,
  402. this->Quiet);
  403. if (!this->PreProcessHandler()) {
  404. return -1;
  405. }
  406. cmGeneratedFileStream mLogFile;
  407. this->StartLogFile((this->MemCheck ? "DynamicAnalysis" : "Test"), mLogFile);
  408. this->LogFile = &mLogFile;
  409. std::vector<std::string> passed;
  410. std::vector<std::string> failed;
  411. int total;
  412. // start the real time clock
  413. double clock_start, clock_finish;
  414. clock_start = cmSystemTools::GetTime();
  415. this->ProcessDirectory(passed, failed);
  416. clock_finish = cmSystemTools::GetTime();
  417. total = int(passed.size()) + int(failed.size());
  418. if (total == 0) {
  419. if (!this->CTest->GetShowOnly() && !this->CTest->ShouldPrintLabels()) {
  420. cmCTestLog(this->CTest, ERROR_MESSAGE, "No tests were found!!!"
  421. << std::endl);
  422. }
  423. } else {
  424. if (this->HandlerVerbose && !passed.empty() &&
  425. (this->UseIncludeRegExpFlag || this->UseExcludeRegExpFlag)) {
  426. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT, std::endl
  427. << "The following tests passed:" << std::endl,
  428. this->Quiet);
  429. for (std::vector<std::string>::iterator j = passed.begin();
  430. j != passed.end(); ++j) {
  431. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  432. "\t" << *j << std::endl, this->Quiet);
  433. }
  434. }
  435. float percent = float(passed.size()) * 100.0f / float(total);
  436. if (!failed.empty() && percent > 99) {
  437. percent = 99;
  438. }
  439. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
  440. << static_cast<int>(percent + .5f) << "% tests passed, "
  441. << failed.size() << " tests failed out of " << total
  442. << std::endl);
  443. if (this->CTest->GetLabelSummary()) {
  444. this->PrintLabelSummary();
  445. }
  446. char realBuf[1024];
  447. sprintf(realBuf, "%6.2f sec", (double)(clock_finish - clock_start));
  448. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  449. "\nTotal Test time (real) = " << realBuf << "\n",
  450. this->Quiet);
  451. if (!failed.empty()) {
  452. cmGeneratedFileStream ofs;
  453. cmCTestLog(this->CTest, HANDLER_OUTPUT, std::endl
  454. << "The following tests FAILED:" << std::endl);
  455. this->StartLogFile("TestsFailed", ofs);
  456. typedef std::set<cmCTestTestHandler::cmCTestTestResult,
  457. cmCTestTestResultLess>
  458. SetOfTests;
  459. SetOfTests resultsSet(this->TestResults.begin(),
  460. this->TestResults.end());
  461. for (SetOfTests::iterator ftit = resultsSet.begin();
  462. ftit != resultsSet.end(); ++ftit) {
  463. if (ftit->Status != cmCTestTestHandler::COMPLETED) {
  464. ofs << ftit->TestCount << ":" << ftit->Name << std::endl;
  465. cmCTestLog(
  466. this->CTest, HANDLER_OUTPUT, "\t"
  467. << std::setw(3) << ftit->TestCount << " - " << ftit->Name << " ("
  468. << this->GetTestStatus(ftit->Status) << ")" << std::endl);
  469. }
  470. }
  471. }
  472. }
  473. if (this->CTest->GetProduceXML()) {
  474. cmGeneratedFileStream xmlfile;
  475. if (!this->StartResultingXML(
  476. (this->MemCheck ? cmCTest::PartMemCheck : cmCTest::PartTest),
  477. (this->MemCheck ? "DynamicAnalysis" : "Test"), xmlfile)) {
  478. cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot create "
  479. << (this->MemCheck ? "memory check" : "testing")
  480. << " XML file" << std::endl);
  481. this->LogFile = CM_NULLPTR;
  482. return 1;
  483. }
  484. cmXMLWriter xml(xmlfile);
  485. this->GenerateDartOutput(xml);
  486. }
  487. if (!this->PostProcessHandler()) {
  488. this->LogFile = CM_NULLPTR;
  489. return -1;
  490. }
  491. if (!failed.empty()) {
  492. this->LogFile = CM_NULLPTR;
  493. return -1;
  494. }
  495. this->LogFile = CM_NULLPTR;
  496. return 0;
  497. }
  498. void cmCTestTestHandler::PrintLabelSummary()
  499. {
  500. cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
  501. std::map<std::string, double> labelTimes;
  502. std::map<std::string, int> labelCounts;
  503. std::set<std::string> labels;
  504. // initialize maps
  505. std::string::size_type maxlen = 0;
  506. for (; it != this->TestList.end(); ++it) {
  507. cmCTestTestProperties& p = *it;
  508. if (!p.Labels.empty()) {
  509. for (std::vector<std::string>::iterator l = p.Labels.begin();
  510. l != p.Labels.end(); ++l) {
  511. if ((*l).size() > maxlen) {
  512. maxlen = (*l).size();
  513. }
  514. labels.insert(*l);
  515. labelTimes[*l] = 0;
  516. labelCounts[*l] = 0;
  517. }
  518. }
  519. }
  520. cmCTestTestHandler::TestResultsVector::iterator ri =
  521. this->TestResults.begin();
  522. // fill maps
  523. for (; ri != this->TestResults.end(); ++ri) {
  524. cmCTestTestResult& result = *ri;
  525. cmCTestTestProperties& p = *result.Properties;
  526. if (!p.Labels.empty()) {
  527. for (std::vector<std::string>::iterator l = p.Labels.begin();
  528. l != p.Labels.end(); ++l) {
  529. labelTimes[*l] += result.ExecutionTime;
  530. ++labelCounts[*l];
  531. }
  532. }
  533. }
  534. // now print times
  535. if (!labels.empty()) {
  536. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\nLabel Time Summary:",
  537. this->Quiet);
  538. }
  539. for (std::set<std::string>::const_iterator i = labels.begin();
  540. i != labels.end(); ++i) {
  541. std::string label = *i;
  542. label.resize(maxlen + 3, ' ');
  543. char buf[1024];
  544. sprintf(buf, "%6.2f sec", labelTimes[*i]);
  545. std::ostringstream labelCountStr;
  546. labelCountStr << "(" << labelCounts[*i] << " test";
  547. if (labelCounts[*i] > 1) {
  548. labelCountStr << "s";
  549. }
  550. labelCountStr << ")";
  551. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n"
  552. << label << " = " << buf << " "
  553. << labelCountStr.str(),
  554. this->Quiet);
  555. if (this->LogFile) {
  556. *this->LogFile << "\n" << *i << " = " << buf << "\n";
  557. }
  558. }
  559. if (!labels.empty()) {
  560. if (this->LogFile) {
  561. *this->LogFile << "\n";
  562. }
  563. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "\n", this->Quiet);
  564. }
  565. }
  566. void cmCTestTestHandler::CheckLabelFilterInclude(cmCTestTestProperties& it)
  567. {
  568. // if not using Labels to filter then return
  569. if (!this->UseIncludeLabelRegExpFlag) {
  570. return;
  571. }
  572. // if there are no labels and we are filtering by labels
  573. // then exclude the test as it does not have the label
  574. if (it.Labels.empty()) {
  575. it.IsInBasedOnREOptions = false;
  576. return;
  577. }
  578. // check to see if the label regular expression matches
  579. bool found = false; // assume it does not match
  580. // loop over all labels and look for match
  581. for (std::vector<std::string>::iterator l = it.Labels.begin();
  582. l != it.Labels.end(); ++l) {
  583. if (this->IncludeLabelRegularExpression.find(*l)) {
  584. found = true;
  585. }
  586. }
  587. // if no match was found, exclude the test
  588. if (!found) {
  589. it.IsInBasedOnREOptions = false;
  590. }
  591. }
  592. void cmCTestTestHandler::CheckLabelFilterExclude(cmCTestTestProperties& it)
  593. {
  594. // if not using Labels to filter then return
  595. if (!this->UseExcludeLabelRegExpFlag) {
  596. return;
  597. }
  598. // if there are no labels and we are excluding by labels
  599. // then do nothing as a no label can not be a match
  600. if (it.Labels.empty()) {
  601. return;
  602. }
  603. // check to see if the label regular expression matches
  604. bool found = false; // assume it does not match
  605. // loop over all labels and look for match
  606. for (std::vector<std::string>::iterator l = it.Labels.begin();
  607. l != it.Labels.end(); ++l) {
  608. if (this->ExcludeLabelRegularExpression.find(*l)) {
  609. found = true;
  610. }
  611. }
  612. // if match was found, exclude the test
  613. if (found) {
  614. it.IsInBasedOnREOptions = false;
  615. }
  616. }
  617. void cmCTestTestHandler::CheckLabelFilter(cmCTestTestProperties& it)
  618. {
  619. this->CheckLabelFilterInclude(it);
  620. this->CheckLabelFilterExclude(it);
  621. }
  622. void cmCTestTestHandler::ComputeTestList()
  623. {
  624. this->TestList.clear(); // clear list of test
  625. this->GetListOfTests();
  626. if (this->RerunFailed) {
  627. this->ComputeTestListForRerunFailed();
  628. return;
  629. }
  630. cmCTestTestHandler::ListOfTests::size_type tmsize = this->TestList.size();
  631. // how many tests are in based on RegExp?
  632. int inREcnt = 0;
  633. cmCTestTestHandler::ListOfTests::iterator it;
  634. for (it = this->TestList.begin(); it != this->TestList.end(); it++) {
  635. this->CheckLabelFilter(*it);
  636. if (it->IsInBasedOnREOptions) {
  637. inREcnt++;
  638. }
  639. }
  640. // expand the test list based on the union flag
  641. if (this->UseUnion) {
  642. this->ExpandTestsToRunInformation((int)tmsize);
  643. } else {
  644. this->ExpandTestsToRunInformation(inREcnt);
  645. }
  646. // Now create a final list of tests to run
  647. int cnt = 0;
  648. inREcnt = 0;
  649. std::string last_directory = "";
  650. ListOfTests finalList;
  651. for (it = this->TestList.begin(); it != this->TestList.end(); it++) {
  652. cnt++;
  653. if (it->IsInBasedOnREOptions) {
  654. inREcnt++;
  655. }
  656. if (this->UseUnion) {
  657. // if it is not in the list and not in the regexp then skip
  658. if ((!this->TestsToRun.empty() &&
  659. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt) ==
  660. this->TestsToRun.end()) &&
  661. !it->IsInBasedOnREOptions) {
  662. continue;
  663. }
  664. } else {
  665. // is this test in the list of tests to run? If not then skip it
  666. if ((!this->TestsToRun.empty() &&
  667. std::find(this->TestsToRun.begin(), this->TestsToRun.end(),
  668. inREcnt) == this->TestsToRun.end()) ||
  669. !it->IsInBasedOnREOptions) {
  670. continue;
  671. }
  672. }
  673. it->Index = cnt; // save the index into the test list for this test
  674. finalList.push_back(*it);
  675. }
  676. // Save the total number of tests before exclusions
  677. this->TotalNumberOfTests = this->TestList.size();
  678. // Set the TestList to the final list of all test
  679. this->TestList = finalList;
  680. this->UpdateMaxTestNameWidth();
  681. }
  682. void cmCTestTestHandler::ComputeTestListForRerunFailed()
  683. {
  684. this->ExpandTestsToRunInformationForRerunFailed();
  685. cmCTestTestHandler::ListOfTests::iterator it;
  686. ListOfTests finalList;
  687. int cnt = 0;
  688. for (it = this->TestList.begin(); it != this->TestList.end(); it++) {
  689. cnt++;
  690. // if this test is not in our list of tests to run, then skip it.
  691. if ((!this->TestsToRun.empty() &&
  692. std::find(this->TestsToRun.begin(), this->TestsToRun.end(), cnt) ==
  693. this->TestsToRun.end())) {
  694. continue;
  695. }
  696. it->Index = cnt;
  697. finalList.push_back(*it);
  698. }
  699. // Save the total number of tests before exclusions
  700. this->TotalNumberOfTests = this->TestList.size();
  701. // Set the TestList to the list of failed tests to rerun
  702. this->TestList = finalList;
  703. this->UpdateMaxTestNameWidth();
  704. }
  705. void cmCTestTestHandler::UpdateMaxTestNameWidth()
  706. {
  707. std::string::size_type max = this->CTest->GetMaxTestNameWidth();
  708. for (cmCTestTestHandler::ListOfTests::iterator it = this->TestList.begin();
  709. it != this->TestList.end(); it++) {
  710. cmCTestTestProperties& p = *it;
  711. if (max < p.Name.size()) {
  712. max = p.Name.size();
  713. }
  714. }
  715. if (static_cast<std::string::size_type>(
  716. this->CTest->GetMaxTestNameWidth()) != max) {
  717. this->CTest->SetMaxTestNameWidth(static_cast<int>(max));
  718. }
  719. }
  720. bool cmCTestTestHandler::GetValue(const char* tag, int& value,
  721. std::istream& fin)
  722. {
  723. std::string line;
  724. bool ret = true;
  725. cmSystemTools::GetLineFromStream(fin, line);
  726. if (line == tag) {
  727. fin >> value;
  728. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  729. } else {
  730. cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: "
  731. << tag << " found [" << line << "]" << std::endl);
  732. ret = false;
  733. }
  734. return ret;
  735. }
  736. bool cmCTestTestHandler::GetValue(const char* tag, double& value,
  737. std::istream& fin)
  738. {
  739. std::string line;
  740. cmSystemTools::GetLineFromStream(fin, line);
  741. bool ret = true;
  742. if (line == tag) {
  743. fin >> value;
  744. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  745. } else {
  746. cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: "
  747. << tag << " found [" << line << "]" << std::endl);
  748. ret = false;
  749. }
  750. return ret;
  751. }
  752. bool cmCTestTestHandler::GetValue(const char* tag, bool& value,
  753. std::istream& fin)
  754. {
  755. std::string line;
  756. cmSystemTools::GetLineFromStream(fin, line);
  757. bool ret = true;
  758. if (line == tag) {
  759. #ifdef __HAIKU__
  760. int tmp = 0;
  761. fin >> tmp;
  762. value = false;
  763. if (tmp) {
  764. value = true;
  765. }
  766. #else
  767. fin >> value;
  768. #endif
  769. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  770. } else {
  771. cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: "
  772. << tag << " found [" << line << "]" << std::endl);
  773. ret = false;
  774. }
  775. return ret;
  776. }
  777. bool cmCTestTestHandler::GetValue(const char* tag, size_t& value,
  778. std::istream& fin)
  779. {
  780. std::string line;
  781. cmSystemTools::GetLineFromStream(fin, line);
  782. bool ret = true;
  783. if (line == tag) {
  784. fin >> value;
  785. ret = cmSystemTools::GetLineFromStream(fin, line); // read blank line
  786. } else {
  787. cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: "
  788. << tag << " found [" << line << "]" << std::endl);
  789. ret = false;
  790. }
  791. return ret;
  792. }
  793. bool cmCTestTestHandler::GetValue(const char* tag, std::string& value,
  794. std::istream& fin)
  795. {
  796. std::string line;
  797. cmSystemTools::GetLineFromStream(fin, line);
  798. bool ret = true;
  799. if (line == tag) {
  800. ret = cmSystemTools::GetLineFromStream(fin, value);
  801. } else {
  802. cmCTestLog(this->CTest, ERROR_MESSAGE, "parse error: missing tag: "
  803. << tag << " found [" << line << "]" << std::endl);
  804. ret = false;
  805. }
  806. return ret;
  807. }
  808. void cmCTestTestHandler::ProcessDirectory(std::vector<std::string>& passed,
  809. std::vector<std::string>& failed)
  810. {
  811. this->ComputeTestList();
  812. this->StartTest = this->CTest->CurrentTime();
  813. this->StartTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  814. double elapsed_time_start = cmSystemTools::GetTime();
  815. cmCTestMultiProcessHandler* parallel = this->CTest->GetBatchJobs()
  816. ? new cmCTestBatchTestHandler
  817. : new cmCTestMultiProcessHandler;
  818. parallel->SetCTest(this->CTest);
  819. parallel->SetParallelLevel(this->CTest->GetParallelLevel());
  820. parallel->SetTestHandler(this);
  821. parallel->SetQuiet(this->Quiet);
  822. if (this->TestLoad > 0) {
  823. parallel->SetTestLoad(this->TestLoad);
  824. } else {
  825. parallel->SetTestLoad(this->CTest->GetTestLoad());
  826. }
  827. *this->LogFile
  828. << "Start testing: " << this->CTest->CurrentTime() << std::endl
  829. << "----------------------------------------------------------"
  830. << std::endl;
  831. cmCTestMultiProcessHandler::TestMap tests;
  832. cmCTestMultiProcessHandler::PropertiesMap properties;
  833. bool randomSchedule = this->CTest->GetScheduleType() == "Random";
  834. if (randomSchedule) {
  835. srand((unsigned)time(CM_NULLPTR));
  836. }
  837. for (ListOfTests::iterator it = this->TestList.begin();
  838. it != this->TestList.end(); ++it) {
  839. cmCTestTestProperties& p = *it;
  840. cmCTestMultiProcessHandler::TestSet depends;
  841. if (randomSchedule) {
  842. p.Cost = static_cast<float>(rand());
  843. }
  844. if (p.Timeout == 0 && this->CTest->GetGlobalTimeout() != 0) {
  845. p.Timeout = this->CTest->GetGlobalTimeout();
  846. }
  847. if (!p.Depends.empty()) {
  848. for (std::vector<std::string>::iterator i = p.Depends.begin();
  849. i != p.Depends.end(); ++i) {
  850. for (ListOfTests::iterator it2 = this->TestList.begin();
  851. it2 != this->TestList.end(); ++it2) {
  852. if (it2->Name == *i) {
  853. depends.insert(it2->Index);
  854. break; // break out of test loop as name can only match 1
  855. }
  856. }
  857. }
  858. }
  859. tests[it->Index] = depends;
  860. properties[it->Index] = &*it;
  861. }
  862. parallel->SetTests(tests, properties);
  863. parallel->SetPassFailVectors(&passed, &failed);
  864. this->TestResults.clear();
  865. parallel->SetTestResults(&this->TestResults);
  866. if (this->CTest->ShouldPrintLabels()) {
  867. parallel->PrintLabels();
  868. } else if (this->CTest->GetShowOnly()) {
  869. parallel->PrintTestList();
  870. } else {
  871. parallel->RunTests();
  872. }
  873. delete parallel;
  874. this->EndTest = this->CTest->CurrentTime();
  875. this->EndTestTime = static_cast<unsigned int>(cmSystemTools::GetTime());
  876. this->ElapsedTestingTime = cmSystemTools::GetTime() - elapsed_time_start;
  877. *this->LogFile << "End testing: " << this->CTest->CurrentTime() << std::endl;
  878. }
  879. void cmCTestTestHandler::GenerateTestCommand(
  880. std::vector<std::string>& /*unused*/, int /*unused*/)
  881. {
  882. }
  883. void cmCTestTestHandler::GenerateDartOutput(cmXMLWriter& xml)
  884. {
  885. if (!this->CTest->GetProduceXML()) {
  886. return;
  887. }
  888. this->CTest->StartXML(xml, this->AppendXML);
  889. xml.StartElement("Testing");
  890. xml.Element("StartDateTime", this->StartTest);
  891. xml.Element("StartTestTime", this->StartTestTime);
  892. xml.StartElement("TestList");
  893. cmCTestTestHandler::TestResultsVector::size_type cc;
  894. for (cc = 0; cc < this->TestResults.size(); cc++) {
  895. cmCTestTestResult* result = &this->TestResults[cc];
  896. std::string testPath = result->Path + "/" + result->Name;
  897. xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str()));
  898. }
  899. xml.EndElement(); // TestList
  900. for (cc = 0; cc < this->TestResults.size(); cc++) {
  901. cmCTestTestResult* result = &this->TestResults[cc];
  902. this->WriteTestResultHeader(xml, result);
  903. xml.StartElement("Results");
  904. if (result->Status != cmCTestTestHandler::NOT_RUN) {
  905. if (result->Status != cmCTestTestHandler::COMPLETED ||
  906. result->ReturnValue) {
  907. xml.StartElement("NamedMeasurement");
  908. xml.Attribute("type", "text/string");
  909. xml.Attribute("name", "Exit Code");
  910. xml.Element("Value", this->GetTestStatus(result->Status));
  911. xml.EndElement(); // NamedMeasurement
  912. xml.StartElement("NamedMeasurement");
  913. xml.Attribute("type", "text/string");
  914. xml.Attribute("name", "Exit Value");
  915. xml.Element("Value", result->ReturnValue);
  916. xml.EndElement(); // NamedMeasurement
  917. }
  918. this->GenerateRegressionImages(xml, result->DartString);
  919. xml.StartElement("NamedMeasurement");
  920. xml.Attribute("type", "numeric/double");
  921. xml.Attribute("name", "Execution Time");
  922. xml.Element("Value", result->ExecutionTime);
  923. xml.EndElement(); // NamedMeasurement
  924. if (!result->Reason.empty()) {
  925. const char* reasonType = "Pass Reason";
  926. if (result->Status != cmCTestTestHandler::COMPLETED &&
  927. result->Status != cmCTestTestHandler::NOT_RUN) {
  928. reasonType = "Fail Reason";
  929. }
  930. xml.StartElement("NamedMeasurement");
  931. xml.Attribute("type", "text/string");
  932. xml.Attribute("name", reasonType);
  933. xml.Element("Value", result->Reason);
  934. xml.EndElement(); // NamedMeasurement
  935. }
  936. xml.StartElement("NamedMeasurement");
  937. xml.Attribute("type", "text/string");
  938. xml.Attribute("name", "Completion Status");
  939. xml.Element("Value", result->CompletionStatus);
  940. xml.EndElement(); // NamedMeasurement
  941. }
  942. xml.StartElement("NamedMeasurement");
  943. xml.Attribute("type", "text/string");
  944. xml.Attribute("name", "Command Line");
  945. xml.Element("Value", result->FullCommandLine);
  946. xml.EndElement(); // NamedMeasurement
  947. std::map<std::string, std::string>::iterator measureIt;
  948. for (measureIt = result->Properties->Measurements.begin();
  949. measureIt != result->Properties->Measurements.end(); ++measureIt) {
  950. xml.StartElement("NamedMeasurement");
  951. xml.Attribute("type", "text/string");
  952. xml.Attribute("name", measureIt->first);
  953. xml.Element("Value", measureIt->second);
  954. xml.EndElement(); // NamedMeasurement
  955. }
  956. xml.StartElement("Measurement");
  957. xml.StartElement("Value");
  958. if (result->CompressOutput) {
  959. xml.Attribute("encoding", "base64");
  960. xml.Attribute("compression", "gzip");
  961. }
  962. xml.Content(result->Output);
  963. xml.EndElement(); // Value
  964. xml.EndElement(); // Measurement
  965. xml.EndElement(); // Results
  966. this->AttachFiles(xml, result);
  967. this->WriteTestResultFooter(xml, result);
  968. }
  969. xml.Element("EndDateTime", this->EndTest);
  970. xml.Element("EndTestTime", this->EndTestTime);
  971. xml.Element("ElapsedMinutes",
  972. static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
  973. xml.EndElement(); // Testing
  974. this->CTest->EndXML(xml);
  975. }
  976. void cmCTestTestHandler::WriteTestResultHeader(cmXMLWriter& xml,
  977. cmCTestTestResult* result)
  978. {
  979. xml.StartElement("Test");
  980. if (result->Status == cmCTestTestHandler::COMPLETED) {
  981. xml.Attribute("Status", "passed");
  982. } else if (result->Status == cmCTestTestHandler::NOT_RUN) {
  983. xml.Attribute("Status", "notrun");
  984. } else {
  985. xml.Attribute("Status", "failed");
  986. }
  987. std::string testPath = result->Path + "/" + result->Name;
  988. xml.Element("Name", result->Name);
  989. xml.Element("Path", this->CTest->GetShortPathToFile(result->Path.c_str()));
  990. xml.Element("FullName", this->CTest->GetShortPathToFile(testPath.c_str()));
  991. xml.Element("FullCommandLine", result->FullCommandLine);
  992. }
  993. void cmCTestTestHandler::WriteTestResultFooter(cmXMLWriter& xml,
  994. cmCTestTestResult* result)
  995. {
  996. if (!result->Properties->Labels.empty()) {
  997. xml.StartElement("Labels");
  998. std::vector<std::string> const& labels = result->Properties->Labels;
  999. for (std::vector<std::string>::const_iterator li = labels.begin();
  1000. li != labels.end(); ++li) {
  1001. xml.Element("Label", *li);
  1002. }
  1003. xml.EndElement(); // Labels
  1004. }
  1005. xml.EndElement(); // Test
  1006. }
  1007. void cmCTestTestHandler::AttachFiles(cmXMLWriter& xml,
  1008. cmCTestTestResult* result)
  1009. {
  1010. if (result->Status != cmCTestTestHandler::COMPLETED &&
  1011. !result->Properties->AttachOnFail.empty()) {
  1012. result->Properties->AttachedFiles.insert(
  1013. result->Properties->AttachedFiles.end(),
  1014. result->Properties->AttachOnFail.begin(),
  1015. result->Properties->AttachOnFail.end());
  1016. }
  1017. for (std::vector<std::string>::const_iterator file =
  1018. result->Properties->AttachedFiles.begin();
  1019. file != result->Properties->AttachedFiles.end(); ++file) {
  1020. const std::string& base64 = this->CTest->Base64GzipEncodeFile(*file);
  1021. std::string fname = cmSystemTools::GetFilenameName(*file);
  1022. xml.StartElement("NamedMeasurement");
  1023. xml.Attribute("name", "Attached File");
  1024. xml.Attribute("encoding", "base64");
  1025. xml.Attribute("compression", "tar/gzip");
  1026. xml.Attribute("filename", fname);
  1027. xml.Attribute("type", "file");
  1028. xml.Element("Value", base64);
  1029. xml.EndElement(); // NamedMeasurement
  1030. }
  1031. }
  1032. int cmCTestTestHandler::ExecuteCommands(std::vector<std::string>& vec)
  1033. {
  1034. std::vector<std::string>::iterator it;
  1035. for (it = vec.begin(); it != vec.end(); ++it) {
  1036. int retVal = 0;
  1037. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  1038. "Run command: " << *it << std::endl, this->Quiet);
  1039. if (!cmSystemTools::RunSingleCommand(it->c_str(), CM_NULLPTR, CM_NULLPTR,
  1040. &retVal, CM_NULLPTR,
  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 << "\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. CM_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;
  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::ostringstream 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. }