cmCTestMemCheckHandler.cxx 28 KB

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