cmCTestMemCheckHandler.h 4.3 KB

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