cmCTestMemCheckHandler.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc.
  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. #ifndef cmCTestMemCheckHandler_h
  11. #define cmCTestMemCheckHandler_h
  12. #include "cmCTestTestHandler.h"
  13. #include "cmStandardIncludes.h"
  14. #include "cmListFileCache.h"
  15. #include <vector>
  16. #include <string>
  17. class cmMakefile;
  18. /** \class cmCTestMemCheckHandler
  19. * \brief A class that handles ctest -S invocations
  20. *
  21. */
  22. class cmCTestMemCheckHandler : public cmCTestTestHandler
  23. {
  24. friend class cmCTestRunTest;
  25. public:
  26. cmTypeMacro(cmCTestMemCheckHandler, cmCTestTestHandler);
  27. void PopulateCustomVectors(cmMakefile *mf);
  28. cmCTestMemCheckHandler();
  29. void Initialize();
  30. protected:
  31. virtual int PreProcessHandler();
  32. virtual int PostProcessHandler();
  33. virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
  34. private:
  35. enum { // Memory checkers
  36. UNKNOWN = 0,
  37. VALGRIND,
  38. PURIFY,
  39. BOUNDS_CHECKER,
  40. // checkers after here do not use the standard error list
  41. THREAD_SANITIZER,
  42. ADDRESS_SANITIZER
  43. };
  44. public:
  45. enum { // Memory faults
  46. ABR = 0,
  47. ABW,
  48. ABWL,
  49. COR,
  50. EXU,
  51. FFM,
  52. FIM,
  53. FMM,
  54. FMR,
  55. FMW,
  56. FUM,
  57. IPR,
  58. IPW,
  59. MAF,
  60. MLK,
  61. MPK,
  62. NPR,
  63. ODS,
  64. PAR,
  65. PLK,
  66. UMC,
  67. UMR,
  68. NO_MEMORY_FAULT
  69. };
  70. private:
  71. enum { // Program statuses
  72. NOT_RUN = 0,
  73. TIMEOUT,
  74. SEGFAULT,
  75. ILLEGAL,
  76. INTERRUPT,
  77. NUMERICAL,
  78. OTHER_FAULT,
  79. FAILED,
  80. BAD_COMMAND,
  81. COMPLETED
  82. };
  83. std::string BoundsCheckerDPBDFile;
  84. std::string BoundsCheckerXMLFile;
  85. std::string MemoryTester;
  86. std::vector<std::string> MemoryTesterDynamicOptions;
  87. std::vector<std::string> MemoryTesterOptions;
  88. int MemoryTesterStyle;
  89. std::string MemoryTesterOutputFile;
  90. std::string MemoryTesterEnvironmentVariable;
  91. // these are used to store the types of errors that can show up
  92. std::vector<std::string> ResultStrings;
  93. std::vector<std::string> ResultStringsLong;
  94. std::vector<int> GlobalResults;
  95. bool LogWithPID; // does log file add pid
  96. std::vector<int>::size_type FindOrAddWarning(const std::string& warning);
  97. // initialize the ResultStrings and ResultStringsLong for
  98. // this type of checker
  99. void InitializeResultsVectors();
  100. ///! Initialize memory checking subsystem.
  101. bool InitializeMemoryChecking();
  102. /**
  103. * Generate the Dart compatible output
  104. */
  105. void GenerateDartOutput(std::ostream& os);
  106. std::vector<std::string> CustomPreMemCheck;
  107. std::vector<std::string> CustomPostMemCheck;
  108. //! Parse Valgrind/Purify/Bounds Checker result out of the output
  109. //string. After running, log holds the output and results hold the
  110. //different memmory errors.
  111. bool ProcessMemCheckOutput(const std::string& str,
  112. std::string& log, std::vector<int>& results);
  113. bool ProcessMemCheckValgrindOutput(const std::string& str,
  114. std::string& log,
  115. std::vector<int>& results);
  116. bool ProcessMemCheckPurifyOutput(const std::string& str,
  117. std::string& log,
  118. std::vector<int>& results);
  119. bool ProcessMemCheckSanitizerOutput(const std::string& str,
  120. std::string& log,
  121. std::vector<int>& results);
  122. bool ProcessMemCheckBoundsCheckerOutput(const std::string& str,
  123. std::string& log,
  124. std::vector<int>& results);
  125. void PostProcessTest(cmCTestTestResult& res, int test);
  126. void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
  127. ///! append MemoryTesterOutputFile to the test log
  128. void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
  129. std::string const& filename);
  130. ///! generate the output filename for the given test index
  131. void TestOutputFileNames(int test, std::vector<std::string>& files);
  132. };
  133. #endif