cmCTestMemCheckHandler.h 4.5 KB

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