cmCTestMemCheckHandler.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCTestMemCheckHandler_h
  4. #define cmCTestMemCheckHandler_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmCTestTestHandler.h"
  7. #include <string>
  8. #include <vector>
  9. class cmMakefile;
  10. class cmXMLWriter;
  11. /** \class cmCTestMemCheckHandler
  12. * \brief A class that handles ctest -S invocations
  13. *
  14. */
  15. class cmCTestMemCheckHandler : public cmCTestTestHandler
  16. {
  17. friend class cmCTestRunTest;
  18. public:
  19. typedef cmCTestTestHandler Superclass;
  20. void PopulateCustomVectors(cmMakefile* mf) override;
  21. cmCTestMemCheckHandler();
  22. void Initialize() override;
  23. int GetDefectCount();
  24. protected:
  25. int PreProcessHandler() override;
  26. int PostProcessHandler() override;
  27. void GenerateTestCommand(std::vector<std::string>& args, int test) override;
  28. private:
  29. enum
  30. { // Memory checkers
  31. UNKNOWN = 0,
  32. VALGRIND,
  33. PURIFY,
  34. BOUNDS_CHECKER,
  35. // checkers after here do not use the standard error list
  36. ADDRESS_SANITIZER,
  37. LEAK_SANITIZER,
  38. THREAD_SANITIZER,
  39. MEMORY_SANITIZER,
  40. UB_SANITIZER
  41. };
  42. public:
  43. enum
  44. { // Memory faults
  45. ABR = 0,
  46. ABW,
  47. ABWL,
  48. COR,
  49. EXU,
  50. FFM,
  51. FIM,
  52. FMM,
  53. FMR,
  54. FMW,
  55. FUM,
  56. IPR,
  57. IPW,
  58. MAF,
  59. MLK,
  60. MPK,
  61. NPR,
  62. ODS,
  63. PAR,
  64. PLK,
  65. UMC,
  66. UMR,
  67. NO_MEMORY_FAULT
  68. };
  69. private:
  70. enum
  71. { // 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. int DefectCount;
  97. std::vector<int>::size_type FindOrAddWarning(const std::string& warning);
  98. // initialize the ResultStrings and ResultStringsLong for
  99. // this type of checker
  100. void InitializeResultsVectors();
  101. ///! Initialize memory checking subsystem.
  102. bool InitializeMemoryChecking();
  103. /**
  104. * Generate the Dart compatible output
  105. */
  106. void GenerateDartOutput(cmXMLWriter& xml) override;
  107. std::vector<std::string> CustomPreMemCheck;
  108. std::vector<std::string> CustomPostMemCheck;
  109. //! Parse Valgrind/Purify/Bounds Checker result out of the output
  110. // string. After running, log holds the output and results hold the
  111. // different memmory errors.
  112. bool ProcessMemCheckOutput(const std::string& str, std::string& log,
  113. std::vector<int>& results);
  114. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  115. std::vector<int>& results);
  116. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log,
  117. std::vector<int>& results);
  118. bool ProcessMemCheckSanitizerOutput(const std::string& str, std::string& log,
  119. std::vector<int>& results);
  120. bool ProcessMemCheckBoundsCheckerOutput(const std::string& str,
  121. std::string& log,
  122. std::vector<int>& results);
  123. void PostProcessTest(cmCTestTestResult& res, int test);
  124. void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
  125. ///! append MemoryTesterOutputFile to the test log
  126. void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
  127. std::string const& filename);
  128. ///! generate the output filename for the given test index
  129. void TestOutputFileNames(int test, std::vector<std::string>& files);
  130. };
  131. #endif