cmCTestMemCheckHandler.cxx 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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 "cmCTestMemCheckHandler.h"
  11. #include "cmCTest.h"
  12. #include "cmSystemTools.h"
  13. #include "cmXMLParser.h"
  14. #include "cmXMLWriter.h"
  15. #include <cmsys/FStream.hxx>
  16. #include <cmsys/Glob.hxx>
  17. #include <cmsys/RegularExpression.hxx>
  18. #include <iostream>
  19. #include <sstream>
  20. #include <string.h>
  21. struct CatToErrorType
  22. {
  23. const char* ErrorCategory;
  24. int ErrorCode;
  25. };
  26. static CatToErrorType cmCTestMemCheckBoundsChecker[] = {
  27. // Error tags
  28. { "Write Overrun", cmCTestMemCheckHandler::ABW },
  29. { "Read Overrun", cmCTestMemCheckHandler::ABR },
  30. { "Memory Overrun", cmCTestMemCheckHandler::ABW },
  31. { "Allocation Conflict", cmCTestMemCheckHandler::FMM },
  32. { "Bad Pointer Use", cmCTestMemCheckHandler::FMW },
  33. { "Dangling Pointer", cmCTestMemCheckHandler::FMR },
  34. { CM_NULLPTR, 0 }
  35. };
  36. static void xmlReportError(int line, const char* msg, void* data)
  37. {
  38. cmCTest* ctest = (cmCTest*)data;
  39. cmCTestLog(ctest, ERROR_MESSAGE, "Error parsing XML in stream at line "
  40. << line << ": " << msg << std::endl);
  41. }
  42. // parse the xml file containing the results of last BoundsChecker run
  43. class cmBoundsCheckerParser : public cmXMLParser
  44. {
  45. public:
  46. cmBoundsCheckerParser(cmCTest* c)
  47. {
  48. this->CTest = c;
  49. this->SetErrorCallback(xmlReportError, (void*)c);
  50. }
  51. void StartElement(const std::string& name, const char** atts) CM_OVERRIDE
  52. {
  53. if (name == "MemoryLeak" || name == "ResourceLeak") {
  54. this->Errors.push_back(cmCTestMemCheckHandler::MLK);
  55. } else if (name == "Error" || name == "Dangling Pointer") {
  56. this->ParseError(atts);
  57. }
  58. // Create the log
  59. std::ostringstream ostr;
  60. ostr << name << ":\n";
  61. int i = 0;
  62. for (; atts[i] != CM_NULLPTR; i += 2) {
  63. ostr << " " << atts[i] << " - " << atts[i + 1] << "\n";
  64. }
  65. ostr << "\n";
  66. this->Log += ostr.str();
  67. }
  68. void EndElement(const std::string& /*name*/) CM_OVERRIDE {}
  69. const char* GetAttribute(const char* name, const char** atts)
  70. {
  71. int i = 0;
  72. for (; atts[i] != CM_NULLPTR; ++i) {
  73. if (strcmp(name, atts[i]) == 0) {
  74. return atts[i + 1];
  75. }
  76. }
  77. return CM_NULLPTR;
  78. }
  79. void ParseError(const char** atts)
  80. {
  81. CatToErrorType* ptr = cmCTestMemCheckBoundsChecker;
  82. const char* cat = this->GetAttribute("ErrorCategory", atts);
  83. if (!cat) {
  84. this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know
  85. cmCTestLog(this->CTest, ERROR_MESSAGE,
  86. "No Category found in Bounds checker XML\n");
  87. return;
  88. }
  89. while (ptr->ErrorCategory && cat) {
  90. if (strcmp(ptr->ErrorCategory, cat) == 0) {
  91. this->Errors.push_back(ptr->ErrorCode);
  92. return; // found it we are done
  93. }
  94. ptr++;
  95. }
  96. if (ptr->ErrorCategory) {
  97. this->Errors.push_back(cmCTestMemCheckHandler::ABW); // do not know
  98. cmCTestLog(this->CTest, ERROR_MESSAGE,
  99. "Found unknown Bounds Checker error " << ptr->ErrorCategory
  100. << std::endl);
  101. }
  102. }
  103. cmCTest* CTest;
  104. std::vector<int> Errors;
  105. std::string Log;
  106. };
  107. #define BOUNDS_CHECKER_MARKER \
  108. "******######*****Begin BOUNDS CHECKER XML******######******"
  109. cmCTestMemCheckHandler::cmCTestMemCheckHandler()
  110. {
  111. this->MemCheck = true;
  112. this->CustomMaximumPassedTestOutputSize = 0;
  113. this->CustomMaximumFailedTestOutputSize = 0;
  114. this->LogWithPID = false;
  115. }
  116. void cmCTestMemCheckHandler::Initialize()
  117. {
  118. this->Superclass::Initialize();
  119. this->LogWithPID = false;
  120. this->CustomMaximumPassedTestOutputSize = 0;
  121. this->CustomMaximumFailedTestOutputSize = 0;
  122. this->MemoryTester = "";
  123. this->MemoryTesterDynamicOptions.clear();
  124. this->MemoryTesterOptions.clear();
  125. this->MemoryTesterStyle = UNKNOWN;
  126. this->MemoryTesterOutputFile = "";
  127. }
  128. int cmCTestMemCheckHandler::PreProcessHandler()
  129. {
  130. if (!this->InitializeMemoryChecking()) {
  131. return 0;
  132. }
  133. if (!this->ExecuteCommands(this->CustomPreMemCheck)) {
  134. cmCTestLog(this->CTest, ERROR_MESSAGE,
  135. "Problem executing pre-memcheck command(s)." << std::endl);
  136. return 0;
  137. }
  138. return 1;
  139. }
  140. int cmCTestMemCheckHandler::PostProcessHandler()
  141. {
  142. if (!this->ExecuteCommands(this->CustomPostMemCheck)) {
  143. cmCTestLog(this->CTest, ERROR_MESSAGE,
  144. "Problem executing post-memcheck command(s)." << std::endl);
  145. return 0;
  146. }
  147. return 1;
  148. }
  149. void cmCTestMemCheckHandler::GenerateTestCommand(
  150. std::vector<std::string>& args, int test)
  151. {
  152. std::vector<std::string>::size_type pp;
  153. std::string index;
  154. std::ostringstream stream;
  155. std::string memcheckcommand =
  156. cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str());
  157. stream << test;
  158. index = stream.str();
  159. for (pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp++) {
  160. std::string arg = this->MemoryTesterDynamicOptions[pp];
  161. std::string::size_type pos = arg.find("??");
  162. if (pos != std::string::npos) {
  163. arg.replace(pos, 2, index);
  164. }
  165. args.push_back(arg);
  166. memcheckcommand += " \"";
  167. memcheckcommand += arg;
  168. memcheckcommand += "\"";
  169. }
  170. // Create a copy of the memory tester environment variable.
  171. // This is used for memory testing programs that pass options
  172. // via environment varaibles.
  173. std::string memTesterEnvironmentVariable =
  174. this->MemoryTesterEnvironmentVariable;
  175. for (pp = 0; pp < this->MemoryTesterOptions.size(); pp++) {
  176. if (!memTesterEnvironmentVariable.empty()) {
  177. // If we are using env to pass options, append all the options to
  178. // this string with space separation.
  179. memTesterEnvironmentVariable += " " + this->MemoryTesterOptions[pp];
  180. }
  181. // for regular options just add them to args and memcheckcommand
  182. // which is just used for display
  183. else {
  184. args.push_back(this->MemoryTesterOptions[pp]);
  185. memcheckcommand += " \"";
  186. memcheckcommand += this->MemoryTesterOptions[pp];
  187. memcheckcommand += "\"";
  188. }
  189. }
  190. // if this is an env option type, then add the env string as a single
  191. // argument.
  192. if (!memTesterEnvironmentVariable.empty()) {
  193. std::string::size_type pos = memTesterEnvironmentVariable.find("??");
  194. if (pos != std::string::npos) {
  195. memTesterEnvironmentVariable.replace(pos, 2, index);
  196. }
  197. memcheckcommand += " " + memTesterEnvironmentVariable;
  198. args.push_back(memTesterEnvironmentVariable);
  199. }
  200. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  201. "Memory check command: " << memcheckcommand << std::endl,
  202. this->Quiet);
  203. }
  204. void cmCTestMemCheckHandler::InitializeResultsVectors()
  205. {
  206. // fill these members
  207. // cmsys::vector<std::string> ResultStrings;
  208. // cmsys::vector<std::string> ResultStringsLong;
  209. // cmsys::vector<int> GlobalResults;
  210. this->ResultStringsLong.clear();
  211. this->ResultStrings.clear();
  212. this->GlobalResults.clear();
  213. // If we are working with style checkers that dynamically fill
  214. // the results strings then return.
  215. if (this->MemoryTesterStyle > cmCTestMemCheckHandler::BOUNDS_CHECKER) {
  216. return;
  217. }
  218. // define the standard set of errors
  219. //----------------------------------------------------------------------
  220. static const char* cmCTestMemCheckResultStrings[] = {
  221. "ABR", "ABW", "ABWL", "COR", "EXU", "FFM", "FIM", "FMM",
  222. "FMR", "FMW", "FUM", "IPR", "IPW", "MAF", "MLK", "MPK",
  223. "NPR", "ODS", "PAR", "PLK", "UMC", "UMR", CM_NULLPTR
  224. };
  225. static const char* cmCTestMemCheckResultLongStrings[] = {
  226. "Threading Problem",
  227. "ABW",
  228. "ABWL",
  229. "COR",
  230. "EXU",
  231. "FFM",
  232. "FIM",
  233. "Mismatched deallocation",
  234. "FMR",
  235. "FMW",
  236. "FUM",
  237. "IPR",
  238. "IPW",
  239. "MAF",
  240. "Memory Leak",
  241. "Potential Memory Leak",
  242. "NPR",
  243. "ODS",
  244. "Invalid syscall param",
  245. "PLK",
  246. "Uninitialized Memory Conditional",
  247. "Uninitialized Memory Read",
  248. CM_NULLPTR
  249. };
  250. this->GlobalResults.clear();
  251. for (int i = 0; cmCTestMemCheckResultStrings[i] != CM_NULLPTR; ++i) {
  252. this->ResultStrings.push_back(cmCTestMemCheckResultStrings[i]);
  253. this->ResultStringsLong.push_back(cmCTestMemCheckResultLongStrings[i]);
  254. this->GlobalResults.push_back(0);
  255. }
  256. }
  257. void cmCTestMemCheckHandler::PopulateCustomVectors(cmMakefile* mf)
  258. {
  259. this->cmCTestTestHandler::PopulateCustomVectors(mf);
  260. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_PRE_MEMCHECK",
  261. this->CustomPreMemCheck);
  262. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_POST_MEMCHECK",
  263. this->CustomPostMemCheck);
  264. this->CTest->PopulateCustomVector(mf, "CTEST_CUSTOM_MEMCHECK_IGNORE",
  265. this->CustomTestsIgnore);
  266. std::string cmake = cmSystemTools::GetCMakeCommand();
  267. this->CTest->SetCTestConfiguration("CMakeCommand", cmake.c_str(),
  268. this->Quiet);
  269. }
  270. void cmCTestMemCheckHandler::GenerateDartOutput(cmXMLWriter& xml)
  271. {
  272. if (!this->CTest->GetProduceXML()) {
  273. return;
  274. }
  275. this->CTest->StartXML(xml, this->AppendXML);
  276. xml.StartElement("DynamicAnalysis");
  277. switch (this->MemoryTesterStyle) {
  278. case cmCTestMemCheckHandler::VALGRIND:
  279. xml.Attribute("Checker", "Valgrind");
  280. break;
  281. case cmCTestMemCheckHandler::PURIFY:
  282. xml.Attribute("Checker", "Purify");
  283. break;
  284. case cmCTestMemCheckHandler::BOUNDS_CHECKER:
  285. xml.Attribute("Checker", "BoundsChecker");
  286. break;
  287. case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
  288. xml.Attribute("Checker", "AddressSanitizer");
  289. break;
  290. case cmCTestMemCheckHandler::THREAD_SANITIZER:
  291. xml.Attribute("Checker", "ThreadSanitizer");
  292. break;
  293. case cmCTestMemCheckHandler::MEMORY_SANITIZER:
  294. xml.Attribute("Checker", "MemorySanitizer");
  295. break;
  296. case cmCTestMemCheckHandler::UB_SANITIZER:
  297. xml.Attribute("Checker", "UndefinedBehaviorSanitizer");
  298. break;
  299. default:
  300. xml.Attribute("Checker", "Unknown");
  301. }
  302. xml.Element("StartDateTime", this->StartTest);
  303. xml.Element("StartTestTime", this->StartTestTime);
  304. xml.StartElement("TestList");
  305. cmCTestMemCheckHandler::TestResultsVector::size_type cc;
  306. for (cc = 0; cc < this->TestResults.size(); cc++) {
  307. cmCTestTestResult* result = &this->TestResults[cc];
  308. std::string testPath = result->Path + "/" + result->Name;
  309. xml.Element("Test", this->CTest->GetShortPathToFile(testPath.c_str()));
  310. }
  311. xml.EndElement(); // TestList
  312. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  313. "-- Processing memory checking output: ", this->Quiet);
  314. size_t total = this->TestResults.size();
  315. size_t step = total / 10;
  316. size_t current = 0;
  317. for (cc = 0; cc < this->TestResults.size(); cc++) {
  318. cmCTestTestResult* result = &this->TestResults[cc];
  319. std::string memcheckstr;
  320. std::vector<int> memcheckresults(this->ResultStrings.size(), 0);
  321. bool res = this->ProcessMemCheckOutput(result->Output, memcheckstr,
  322. memcheckresults);
  323. if (res && result->Status == cmCTestMemCheckHandler::COMPLETED) {
  324. continue;
  325. }
  326. this->CleanTestOutput(
  327. memcheckstr,
  328. static_cast<size_t>(this->CustomMaximumFailedTestOutputSize));
  329. this->WriteTestResultHeader(xml, result);
  330. xml.StartElement("Results");
  331. for (std::vector<int>::size_type kk = 0; kk < memcheckresults.size();
  332. ++kk) {
  333. if (memcheckresults[kk]) {
  334. xml.StartElement("Defect");
  335. xml.Attribute("type", this->ResultStringsLong[kk]);
  336. xml.Content(memcheckresults[kk]);
  337. xml.EndElement(); // Defect
  338. }
  339. this->GlobalResults[kk] += memcheckresults[kk];
  340. }
  341. xml.EndElement(); // Results
  342. xml.StartElement("Log");
  343. if (this->CTest->ShouldCompressMemCheckOutput()) {
  344. this->CTest->CompressString(memcheckstr);
  345. xml.Attribute("compression", "gzip");
  346. xml.Attribute("encoding", "base64");
  347. }
  348. xml.Content(memcheckstr);
  349. xml.EndElement(); // Log
  350. this->WriteTestResultFooter(xml, result);
  351. if (current < cc) {
  352. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "#" << std::flush,
  353. this->Quiet);
  354. current += step;
  355. }
  356. }
  357. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, std::endl, this->Quiet);
  358. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  359. "Memory checking results:" << std::endl, this->Quiet);
  360. xml.StartElement("DefectList");
  361. for (cc = 0; cc < this->GlobalResults.size(); cc++) {
  362. if (this->GlobalResults[cc]) {
  363. #ifdef cerr
  364. #undef cerr
  365. #endif
  366. std::cerr.width(35);
  367. #define cerr no_cerr
  368. cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT,
  369. this->ResultStringsLong[cc]
  370. << " - " << this->GlobalResults[cc] << std::endl,
  371. this->Quiet);
  372. xml.StartElement("Defect");
  373. xml.Attribute("Type", this->ResultStringsLong[cc]);
  374. xml.EndElement();
  375. }
  376. }
  377. xml.EndElement(); // DefectList
  378. xml.Element("EndDateTime", this->EndTest);
  379. xml.Element("EndTestTime", this->EndTestTime);
  380. xml.Element("ElapsedMinutes",
  381. static_cast<int>(this->ElapsedTestingTime / 6) / 10.0);
  382. xml.EndElement(); // DynamicAnalysis
  383. this->CTest->EndXML(xml);
  384. }
  385. bool cmCTestMemCheckHandler::InitializeMemoryChecking()
  386. {
  387. this->MemoryTesterEnvironmentVariable = "";
  388. this->MemoryTester = "";
  389. // Setup the command
  390. if (cmSystemTools::FileExists(
  391. this->CTest->GetCTestConfiguration("MemoryCheckCommand").c_str())) {
  392. this->MemoryTester =
  393. this->CTest->GetCTestConfiguration("MemoryCheckCommand");
  394. std::string testerName =
  395. cmSystemTools::GetFilenameName(this->MemoryTester);
  396. // determine the checker type
  397. if (testerName.find("valgrind") != std::string::npos ||
  398. this->CTest->GetCTestConfiguration("MemoryCheckType") == "Valgrind") {
  399. this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
  400. } else if (testerName.find("purify") != std::string::npos) {
  401. this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
  402. } else if (testerName.find("BC") != std::string::npos) {
  403. this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
  404. } else {
  405. this->MemoryTesterStyle = cmCTestMemCheckHandler::UNKNOWN;
  406. }
  407. } else if (cmSystemTools::FileExists(
  408. this->CTest->GetCTestConfiguration("PurifyCommand").c_str())) {
  409. this->MemoryTester = this->CTest->GetCTestConfiguration("PurifyCommand");
  410. this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
  411. } else if (cmSystemTools::FileExists(
  412. this->CTest->GetCTestConfiguration("ValgrindCommand")
  413. .c_str())) {
  414. this->MemoryTester = this->CTest->GetCTestConfiguration("ValgrindCommand");
  415. this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
  416. } else if (cmSystemTools::FileExists(
  417. this->CTest->GetCTestConfiguration("BoundsCheckerCommand")
  418. .c_str())) {
  419. this->MemoryTester =
  420. this->CTest->GetCTestConfiguration("BoundsCheckerCommand");
  421. this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
  422. }
  423. if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
  424. "AddressSanitizer") {
  425. this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
  426. this->MemoryTesterStyle = cmCTestMemCheckHandler::ADDRESS_SANITIZER;
  427. this->LogWithPID = true; // even if we give the log file the pid is added
  428. }
  429. if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
  430. "ThreadSanitizer") {
  431. this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
  432. this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER;
  433. this->LogWithPID = true; // even if we give the log file the pid is added
  434. }
  435. if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
  436. "MemorySanitizer") {
  437. this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
  438. this->MemoryTesterStyle = cmCTestMemCheckHandler::MEMORY_SANITIZER;
  439. this->LogWithPID = true; // even if we give the log file the pid is added
  440. }
  441. if (this->CTest->GetCTestConfiguration("MemoryCheckType") ==
  442. "UndefinedBehaviorSanitizer") {
  443. this->MemoryTester = this->CTest->GetCTestConfiguration("CMakeCommand");
  444. this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER;
  445. this->LogWithPID = true; // even if we give the log file the pid is added
  446. }
  447. // Check the MemoryCheckType
  448. if (this->MemoryTesterStyle == cmCTestMemCheckHandler::UNKNOWN) {
  449. std::string checkType =
  450. this->CTest->GetCTestConfiguration("MemoryCheckType");
  451. if (checkType == "Purify") {
  452. this->MemoryTesterStyle = cmCTestMemCheckHandler::PURIFY;
  453. } else if (checkType == "BoundsChecker") {
  454. this->MemoryTesterStyle = cmCTestMemCheckHandler::BOUNDS_CHECKER;
  455. } else if (checkType == "Valgrind") {
  456. this->MemoryTesterStyle = cmCTestMemCheckHandler::VALGRIND;
  457. }
  458. }
  459. if (this->MemoryTester.empty()) {
  460. cmCTestOptionalLog(this->CTest, WARNING,
  461. "Memory checker (MemoryCheckCommand) "
  462. "not set, or cannot find the specified program."
  463. << std::endl,
  464. this->Quiet);
  465. return false;
  466. }
  467. // Setup the options
  468. std::string memoryTesterOptions;
  469. if (!this->CTest->GetCTestConfiguration("MemoryCheckCommandOptions")
  470. .empty()) {
  471. memoryTesterOptions =
  472. this->CTest->GetCTestConfiguration("MemoryCheckCommandOptions");
  473. } else if (!this->CTest->GetCTestConfiguration("ValgrindCommandOptions")
  474. .empty()) {
  475. memoryTesterOptions =
  476. this->CTest->GetCTestConfiguration("ValgrindCommandOptions");
  477. }
  478. this->MemoryTesterOptions =
  479. cmSystemTools::ParseArguments(memoryTesterOptions.c_str());
  480. this->MemoryTesterOutputFile =
  481. this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.??.log";
  482. switch (this->MemoryTesterStyle) {
  483. case cmCTestMemCheckHandler::VALGRIND: {
  484. if (this->MemoryTesterOptions.empty()) {
  485. this->MemoryTesterOptions.push_back("-q");
  486. this->MemoryTesterOptions.push_back("--tool=memcheck");
  487. this->MemoryTesterOptions.push_back("--leak-check=yes");
  488. this->MemoryTesterOptions.push_back("--show-reachable=yes");
  489. this->MemoryTesterOptions.push_back("--num-callers=50");
  490. }
  491. if (!this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
  492. .empty()) {
  493. if (!cmSystemTools::FileExists(
  494. this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
  495. .c_str())) {
  496. cmCTestLog(this->CTest, ERROR_MESSAGE,
  497. "Cannot find memory checker suppression file: "
  498. << this->CTest->GetCTestConfiguration(
  499. "MemoryCheckSuppressionFile")
  500. << std::endl);
  501. return false;
  502. }
  503. std::string suppressions = "--suppressions=" +
  504. this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
  505. this->MemoryTesterOptions.push_back(suppressions);
  506. }
  507. std::string outputFile = "--log-file=" + this->MemoryTesterOutputFile;
  508. this->MemoryTesterDynamicOptions.push_back(outputFile);
  509. break;
  510. }
  511. case cmCTestMemCheckHandler::PURIFY: {
  512. std::string outputFile;
  513. #ifdef _WIN32
  514. if (this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
  515. .size()) {
  516. if (!cmSystemTools::FileExists(
  517. this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile")
  518. .c_str())) {
  519. cmCTestLog(
  520. this->CTest, ERROR_MESSAGE,
  521. "Cannot find memory checker suppression file: "
  522. << this->CTest
  523. ->GetCTestConfiguration("MemoryCheckSuppressionFile")
  524. .c_str()
  525. << std::endl);
  526. return false;
  527. }
  528. std::string filterFiles = "/FilterFiles=" +
  529. this->CTest->GetCTestConfiguration("MemoryCheckSuppressionFile");
  530. this->MemoryTesterOptions.push_back(filterFiles);
  531. }
  532. outputFile = "/SAVETEXTDATA=";
  533. #else
  534. outputFile = "-log-file=";
  535. #endif
  536. outputFile += this->MemoryTesterOutputFile;
  537. this->MemoryTesterDynamicOptions.push_back(outputFile);
  538. break;
  539. }
  540. case cmCTestMemCheckHandler::BOUNDS_CHECKER: {
  541. this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile;
  542. std::string dpbdFile = this->CTest->GetBinaryDir() +
  543. "/Testing/Temporary/MemoryChecker.??.DPbd";
  544. this->BoundsCheckerDPBDFile = dpbdFile;
  545. this->MemoryTesterDynamicOptions.push_back("/B");
  546. this->MemoryTesterDynamicOptions.push_back(dpbdFile);
  547. this->MemoryTesterDynamicOptions.push_back("/X");
  548. this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile);
  549. this->MemoryTesterOptions.push_back("/M");
  550. break;
  551. }
  552. // these are almost the same but the env var used is different
  553. case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
  554. case cmCTestMemCheckHandler::THREAD_SANITIZER:
  555. case cmCTestMemCheckHandler::MEMORY_SANITIZER:
  556. case cmCTestMemCheckHandler::UB_SANITIZER: {
  557. // To pass arguments to ThreadSanitizer the environment variable
  558. // TSAN_OPTIONS is used. This is done with the cmake -E env command.
  559. // The MemoryTesterDynamicOptions is setup with the -E env
  560. // Then the MemoryTesterEnvironmentVariable gets the
  561. // TSAN_OPTIONS string with the log_path in it.
  562. this->MemoryTesterDynamicOptions.push_back("-E");
  563. this->MemoryTesterDynamicOptions.push_back("env");
  564. std::string envVar;
  565. std::string extraOptions =
  566. this->CTest->GetCTestConfiguration("MemoryCheckSanitizerOptions");
  567. if (this->MemoryTesterStyle ==
  568. cmCTestMemCheckHandler::ADDRESS_SANITIZER) {
  569. envVar = "ASAN_OPTIONS";
  570. extraOptions += " detect_leaks=1";
  571. } else if (this->MemoryTesterStyle ==
  572. cmCTestMemCheckHandler::THREAD_SANITIZER) {
  573. envVar = "TSAN_OPTIONS";
  574. } else if (this->MemoryTesterStyle ==
  575. cmCTestMemCheckHandler::MEMORY_SANITIZER) {
  576. envVar = "MSAN_OPTIONS";
  577. } else if (this->MemoryTesterStyle ==
  578. cmCTestMemCheckHandler::UB_SANITIZER) {
  579. envVar = "UBSAN_OPTIONS";
  580. }
  581. std::string outputFile =
  582. envVar + "=log_path=\"" + this->MemoryTesterOutputFile + "\" ";
  583. this->MemoryTesterEnvironmentVariable = outputFile + extraOptions;
  584. break;
  585. }
  586. default:
  587. cmCTestLog(this->CTest, ERROR_MESSAGE,
  588. "Do not understand memory checker: " << this->MemoryTester
  589. << std::endl);
  590. return false;
  591. }
  592. this->InitializeResultsVectors();
  593. // std::vector<std::string>::size_type cc;
  594. // for ( cc = 0; cmCTestMemCheckResultStrings[cc]; cc ++ )
  595. // {
  596. // this->MemoryTesterGlobalResults[cc] = 0;
  597. // }
  598. return true;
  599. }
  600. bool cmCTestMemCheckHandler::ProcessMemCheckOutput(const std::string& str,
  601. std::string& log,
  602. std::vector<int>& results)
  603. {
  604. switch (this->MemoryTesterStyle) {
  605. case cmCTestMemCheckHandler::VALGRIND:
  606. return this->ProcessMemCheckValgrindOutput(str, log, results);
  607. case cmCTestMemCheckHandler::PURIFY:
  608. return this->ProcessMemCheckPurifyOutput(str, log, results);
  609. case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
  610. case cmCTestMemCheckHandler::THREAD_SANITIZER:
  611. case cmCTestMemCheckHandler::MEMORY_SANITIZER:
  612. case cmCTestMemCheckHandler::UB_SANITIZER:
  613. return this->ProcessMemCheckSanitizerOutput(str, log, results);
  614. case cmCTestMemCheckHandler::BOUNDS_CHECKER:
  615. return this->ProcessMemCheckBoundsCheckerOutput(str, log, results);
  616. default:
  617. log.append("\nMemory checking style used was: ");
  618. log.append("None that I know");
  619. log = str;
  620. return true;
  621. }
  622. }
  623. std::vector<int>::size_type cmCTestMemCheckHandler::FindOrAddWarning(
  624. const std::string& warning)
  625. {
  626. for (std::vector<std::string>::size_type i = 0;
  627. i < this->ResultStrings.size(); ++i) {
  628. if (this->ResultStrings[i] == warning) {
  629. return i;
  630. }
  631. }
  632. this->GlobalResults.push_back(0); // this must stay the same size
  633. this->ResultStrings.push_back(warning);
  634. this->ResultStringsLong.push_back(warning);
  635. return this->ResultStrings.size() - 1;
  636. }
  637. bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput(
  638. const std::string& str, std::string& log, std::vector<int>& result)
  639. {
  640. std::string regex;
  641. switch (this->MemoryTesterStyle) {
  642. case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
  643. regex = "ERROR: AddressSanitizer: (.*) on.*";
  644. break;
  645. case cmCTestMemCheckHandler::THREAD_SANITIZER:
  646. regex = "WARNING: ThreadSanitizer: (.*) \\(pid=.*\\)";
  647. break;
  648. case cmCTestMemCheckHandler::MEMORY_SANITIZER:
  649. regex = "WARNING: MemorySanitizer: (.*)";
  650. break;
  651. case cmCTestMemCheckHandler::UB_SANITIZER:
  652. regex = "runtime error: (.*)";
  653. break;
  654. default:
  655. break;
  656. }
  657. cmsys::RegularExpression sanitizerWarning(regex);
  658. cmsys::RegularExpression leakWarning("(Direct|Indirect) leak of .*");
  659. int defects = 0;
  660. std::vector<std::string> lines;
  661. cmSystemTools::Split(str.c_str(), lines);
  662. std::ostringstream ostr;
  663. log = "";
  664. for (std::vector<std::string>::iterator i = lines.begin(); i != lines.end();
  665. ++i) {
  666. std::string resultFound;
  667. if (leakWarning.find(*i)) {
  668. resultFound = leakWarning.match(1) + " leak";
  669. } else if (sanitizerWarning.find(*i)) {
  670. resultFound = sanitizerWarning.match(1);
  671. }
  672. if (!resultFound.empty()) {
  673. std::vector<int>::size_type idx = this->FindOrAddWarning(resultFound);
  674. if (result.empty() || idx > result.size() - 1) {
  675. result.push_back(1);
  676. } else {
  677. result[idx]++;
  678. }
  679. defects++;
  680. ostr << "<b>" << this->ResultStrings[idx] << "</b> ";
  681. }
  682. ostr << *i << std::endl;
  683. }
  684. log = ostr.str();
  685. return defects == 0;
  686. }
  687. bool cmCTestMemCheckHandler::ProcessMemCheckPurifyOutput(
  688. const std::string& str, std::string& log, std::vector<int>& results)
  689. {
  690. std::vector<std::string> lines;
  691. cmSystemTools::Split(str.c_str(), lines);
  692. std::ostringstream ostr;
  693. log = "";
  694. cmsys::RegularExpression pfW("^\\[[WEI]\\] ([A-Z][A-Z][A-Z][A-Z]*): ");
  695. int defects = 0;
  696. for (std::vector<std::string>::iterator i = lines.begin(); i != lines.end();
  697. ++i) {
  698. std::vector<int>::size_type failure = this->ResultStrings.size();
  699. if (pfW.find(*i)) {
  700. std::vector<int>::size_type cc;
  701. for (cc = 0; cc < this->ResultStrings.size(); cc++) {
  702. if (pfW.match(1) == this->ResultStrings[cc]) {
  703. failure = cc;
  704. break;
  705. }
  706. }
  707. if (cc == this->ResultStrings.size()) {
  708. cmCTestLog(this->CTest, ERROR_MESSAGE, "Unknown Purify memory fault: "
  709. << pfW.match(1) << std::endl);
  710. ostr << "*** Unknown Purify memory fault: " << pfW.match(1)
  711. << std::endl;
  712. }
  713. }
  714. if (failure != this->ResultStrings.size()) {
  715. ostr << "<b>" << this->ResultStrings[failure] << "</b> ";
  716. results[failure]++;
  717. defects++;
  718. }
  719. ostr << *i << std::endl;
  720. }
  721. log = ostr.str();
  722. return defects == 0;
  723. }
  724. bool cmCTestMemCheckHandler::ProcessMemCheckValgrindOutput(
  725. const std::string& str, std::string& log, std::vector<int>& results)
  726. {
  727. std::vector<std::string> lines;
  728. cmSystemTools::Split(str.c_str(), lines);
  729. bool unlimitedOutput = false;
  730. if (str.find("CTEST_FULL_OUTPUT") != str.npos ||
  731. this->CustomMaximumFailedTestOutputSize == 0) {
  732. unlimitedOutput = true;
  733. }
  734. std::string::size_type cc;
  735. std::ostringstream ostr;
  736. log = "";
  737. int defects = 0;
  738. cmsys::RegularExpression valgrindLine("^==[0-9][0-9]*==");
  739. cmsys::RegularExpression vgFIM(
  740. "== .*Invalid free\\(\\) / delete / delete\\[\\]");
  741. cmsys::RegularExpression vgFMM(
  742. "== .*Mismatched free\\(\\) / delete / delete \\[\\]");
  743. cmsys::RegularExpression vgMLK1(
  744. "== .*[0-9,]+ bytes in [0-9,]+ blocks are definitely lost"
  745. " in loss record [0-9,]+ of [0-9,]+");
  746. cmsys::RegularExpression vgMLK2(
  747. "== .*[0-9,]+ \\([0-9,]+ direct, [0-9,]+ indirect\\)"
  748. " bytes in [0-9,]+ blocks are definitely lost"
  749. " in loss record [0-9,]+ of [0-9,]+");
  750. cmsys::RegularExpression vgPAR(
  751. "== .*Syscall param .* (contains|points to) unaddressable byte\\(s\\)");
  752. cmsys::RegularExpression vgMPK1(
  753. "== .*[0-9,]+ bytes in [0-9,]+ blocks are possibly lost in"
  754. " loss record [0-9,]+ of [0-9,]+");
  755. cmsys::RegularExpression vgMPK2(
  756. "== .*[0-9,]+ bytes in [0-9,]+ blocks are still reachable"
  757. " in loss record [0-9,]+ of [0-9,]+");
  758. cmsys::RegularExpression vgUMC(
  759. "== .*Conditional jump or move depends on uninitialised value\\(s\\)");
  760. cmsys::RegularExpression vgUMR1(
  761. "== .*Use of uninitialised value of size [0-9,]+");
  762. cmsys::RegularExpression vgUMR2("== .*Invalid read of size [0-9,]+");
  763. cmsys::RegularExpression vgUMR3("== .*Jump to the invalid address ");
  764. cmsys::RegularExpression vgUMR4(
  765. "== .*Syscall param .* contains "
  766. "uninitialised or unaddressable byte\\(s\\)");
  767. cmsys::RegularExpression vgUMR5("== .*Syscall param .* uninitialised");
  768. cmsys::RegularExpression vgIPW("== .*Invalid write of size [0-9,]+");
  769. cmsys::RegularExpression vgABR("== .*pthread_mutex_unlock: mutex is "
  770. "locked by a different thread");
  771. std::vector<std::string::size_type> nonValGrindOutput;
  772. double sttime = cmSystemTools::GetTime();
  773. cmCTestOptionalLog(this->CTest, DEBUG,
  774. "Start test: " << lines.size() << std::endl, this->Quiet);
  775. std::string::size_type totalOutputSize = 0;
  776. for (cc = 0; cc < lines.size(); cc++) {
  777. cmCTestOptionalLog(this->CTest, DEBUG,
  778. "test line " << lines[cc] << std::endl, this->Quiet);
  779. if (valgrindLine.find(lines[cc])) {
  780. cmCTestOptionalLog(this->CTest, DEBUG,
  781. "valgrind line " << lines[cc] << std::endl,
  782. this->Quiet);
  783. int failure = cmCTestMemCheckHandler::NO_MEMORY_FAULT;
  784. if (vgFIM.find(lines[cc])) {
  785. failure = cmCTestMemCheckHandler::FIM;
  786. } else if (vgFMM.find(lines[cc])) {
  787. failure = cmCTestMemCheckHandler::FMM;
  788. } else if (vgMLK1.find(lines[cc])) {
  789. failure = cmCTestMemCheckHandler::MLK;
  790. } else if (vgMLK2.find(lines[cc])) {
  791. failure = cmCTestMemCheckHandler::MLK;
  792. } else if (vgPAR.find(lines[cc])) {
  793. failure = cmCTestMemCheckHandler::PAR;
  794. } else if (vgMPK1.find(lines[cc])) {
  795. failure = cmCTestMemCheckHandler::MPK;
  796. } else if (vgMPK2.find(lines[cc])) {
  797. failure = cmCTestMemCheckHandler::MPK;
  798. } else if (vgUMC.find(lines[cc])) {
  799. failure = cmCTestMemCheckHandler::UMC;
  800. } else if (vgUMR1.find(lines[cc])) {
  801. failure = cmCTestMemCheckHandler::UMR;
  802. } else if (vgUMR2.find(lines[cc])) {
  803. failure = cmCTestMemCheckHandler::UMR;
  804. } else if (vgUMR3.find(lines[cc])) {
  805. failure = cmCTestMemCheckHandler::UMR;
  806. } else if (vgUMR4.find(lines[cc])) {
  807. failure = cmCTestMemCheckHandler::UMR;
  808. } else if (vgUMR5.find(lines[cc])) {
  809. failure = cmCTestMemCheckHandler::UMR;
  810. } else if (vgIPW.find(lines[cc])) {
  811. failure = cmCTestMemCheckHandler::IPW;
  812. } else if (vgABR.find(lines[cc])) {
  813. failure = cmCTestMemCheckHandler::ABR;
  814. }
  815. if (failure != cmCTestMemCheckHandler::NO_MEMORY_FAULT) {
  816. ostr << "<b>" << this->ResultStrings[failure] << "</b> ";
  817. results[failure]++;
  818. defects++;
  819. }
  820. totalOutputSize += lines[cc].size();
  821. ostr << lines[cc] << std::endl;
  822. } else {
  823. nonValGrindOutput.push_back(cc);
  824. }
  825. }
  826. // Now put all all the non valgrind output into the test output
  827. // This should be last in case it gets truncated by the output
  828. // limiting code
  829. for (std::vector<std::string::size_type>::iterator i =
  830. nonValGrindOutput.begin();
  831. i != nonValGrindOutput.end(); ++i) {
  832. totalOutputSize += lines[*i].size();
  833. ostr << lines[*i] << std::endl;
  834. if (!unlimitedOutput &&
  835. totalOutputSize >
  836. static_cast<size_t>(this->CustomMaximumFailedTestOutputSize)) {
  837. ostr << "....\n";
  838. ostr << "Test Output for this test has been truncated see testing"
  839. " machine logs for full output,\n";
  840. ostr << "or put CTEST_FULL_OUTPUT in the output of "
  841. "this test program.\n";
  842. break; // stop the copy of output if we are full
  843. }
  844. }
  845. cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
  846. << (cmSystemTools::GetTime() - sttime) << std::endl,
  847. this->Quiet);
  848. log = ostr.str();
  849. return defects == 0;
  850. }
  851. bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput(
  852. const std::string& str, std::string& log, std::vector<int>& results)
  853. {
  854. log = "";
  855. double sttime = cmSystemTools::GetTime();
  856. std::vector<std::string> lines;
  857. cmSystemTools::Split(str.c_str(), lines);
  858. cmCTestOptionalLog(this->CTest, DEBUG,
  859. "Start test: " << lines.size() << std::endl, this->Quiet);
  860. std::vector<std::string>::size_type cc;
  861. for (cc = 0; cc < lines.size(); cc++) {
  862. if (lines[cc] == BOUNDS_CHECKER_MARKER) {
  863. break;
  864. }
  865. }
  866. cmBoundsCheckerParser parser(this->CTest);
  867. parser.InitializeParser();
  868. if (cc < lines.size()) {
  869. for (cc++; cc < lines.size(); ++cc) {
  870. std::string& theLine = lines[cc];
  871. // check for command line arguments that are not escaped
  872. // correctly by BC
  873. if (theLine.find("TargetArgs=") != theLine.npos) {
  874. // skip this because BC gets it wrong and we can't parse it
  875. } else if (!parser.ParseChunk(theLine.c_str(), theLine.size())) {
  876. cmCTestLog(this->CTest, ERROR_MESSAGE,
  877. "Error in ParseChunk: " << theLine << std::endl);
  878. }
  879. }
  880. }
  881. int defects = 0;
  882. for (cc = 0; cc < parser.Errors.size(); ++cc) {
  883. results[parser.Errors[cc]]++;
  884. defects++;
  885. }
  886. cmCTestOptionalLog(this->CTest, DEBUG, "End test (elapsed: "
  887. << (cmSystemTools::GetTime() - sttime) << std::endl,
  888. this->Quiet);
  889. if (defects) {
  890. // only put the output of Bounds Checker if there were
  891. // errors or leaks detected
  892. log = parser.Log;
  893. return false;
  894. }
  895. return true;
  896. }
  897. // PostProcessTest memcheck results
  898. void cmCTestMemCheckHandler::PostProcessTest(cmCTestTestResult& res, int test)
  899. {
  900. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  901. "PostProcessTest memcheck results for : " << res.Name
  902. << std::endl,
  903. this->Quiet);
  904. if (this->MemoryTesterStyle == cmCTestMemCheckHandler::BOUNDS_CHECKER) {
  905. this->PostProcessBoundsCheckerTest(res, test);
  906. } else {
  907. std::vector<std::string> files;
  908. this->TestOutputFileNames(test, files);
  909. for (std::vector<std::string>::iterator i = files.begin();
  910. i != files.end(); ++i) {
  911. this->AppendMemTesterOutput(res, *i);
  912. }
  913. }
  914. }
  915. // This method puts the bounds checker output file into the output
  916. // for the test
  917. void cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(
  918. cmCTestTestResult& res, int test)
  919. {
  920. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  921. "PostProcessBoundsCheckerTest for : " << res.Name
  922. << std::endl,
  923. this->Quiet);
  924. std::vector<std::string> files;
  925. this->TestOutputFileNames(test, files);
  926. if (files.empty()) {
  927. return;
  928. }
  929. std::string ofile = files[0];
  930. if (ofile.empty()) {
  931. return;
  932. }
  933. // put a scope around this to close ifs so the file can be removed
  934. {
  935. cmsys::ifstream ifs(ofile.c_str());
  936. if (!ifs) {
  937. std::string log = "Cannot read memory tester output file: " + ofile;
  938. cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
  939. return;
  940. }
  941. res.Output += BOUNDS_CHECKER_MARKER;
  942. res.Output += "\n";
  943. std::string line;
  944. while (cmSystemTools::GetLineFromStream(ifs, line)) {
  945. res.Output += line;
  946. res.Output += "\n";
  947. }
  948. }
  949. cmSystemTools::Delay(1000);
  950. cmSystemTools::RemoveFile(this->BoundsCheckerDPBDFile);
  951. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  952. "Remove: " << this->BoundsCheckerDPBDFile << std::endl,
  953. this->Quiet);
  954. cmSystemTools::RemoveFile(this->BoundsCheckerXMLFile);
  955. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  956. "Remove: " << this->BoundsCheckerXMLFile << std::endl,
  957. this->Quiet);
  958. }
  959. void cmCTestMemCheckHandler::AppendMemTesterOutput(cmCTestTestResult& res,
  960. std::string const& ofile)
  961. {
  962. if (ofile.empty()) {
  963. return;
  964. }
  965. // put ifs in scope so file can be deleted if needed
  966. {
  967. cmsys::ifstream ifs(ofile.c_str());
  968. if (!ifs) {
  969. std::string log = "Cannot read memory tester output file: " + ofile;
  970. cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
  971. return;
  972. }
  973. std::string line;
  974. while (cmSystemTools::GetLineFromStream(ifs, line)) {
  975. res.Output += line;
  976. res.Output += "\n";
  977. }
  978. }
  979. if (this->LogWithPID) {
  980. cmSystemTools::RemoveFile(ofile);
  981. cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
  982. "Remove: " << ofile << "\n", this->Quiet);
  983. }
  984. }
  985. void cmCTestMemCheckHandler::TestOutputFileNames(
  986. int test, std::vector<std::string>& files)
  987. {
  988. std::string index;
  989. std::ostringstream stream;
  990. stream << test;
  991. index = stream.str();
  992. std::string ofile = this->MemoryTesterOutputFile;
  993. std::string::size_type pos = ofile.find("??");
  994. ofile.replace(pos, 2, index);
  995. if (this->LogWithPID) {
  996. ofile += ".*";
  997. cmsys::Glob g;
  998. g.FindFiles(ofile);
  999. if (g.GetFiles().empty()) {
  1000. std::string log = "Cannot find memory tester output file: " + ofile;
  1001. cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
  1002. ofile = "";
  1003. } else {
  1004. files = g.GetFiles();
  1005. return;
  1006. }
  1007. } else if (!cmSystemTools::FileExists(ofile.c_str())) {
  1008. std::string log = "Cannot find memory tester output file: " + ofile;
  1009. cmCTestLog(this->CTest, ERROR_MESSAGE, log << std::endl);
  1010. ofile = "";
  1011. }
  1012. files.push_back(ofile);
  1013. }