cmCTestMemCheckHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <string>
  7. #include <vector>
  8. #include "cmCTestTestHandler.h"
  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. using Superclass = cmCTestTestHandler;
  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. DRMEMORY,
  35. BOUNDS_CHECKER,
  36. // checkers after here do not use the standard error list
  37. CUDA_MEMCHECK,
  38. ADDRESS_SANITIZER,
  39. LEAK_SANITIZER,
  40. THREAD_SANITIZER,
  41. MEMORY_SANITIZER,
  42. UB_SANITIZER
  43. };
  44. public:
  45. enum
  46. { // Memory faults
  47. ABR = 0,
  48. ABW,
  49. ABWL,
  50. COR,
  51. EXU,
  52. FFM,
  53. FIM,
  54. FMM,
  55. FMR,
  56. FMW,
  57. FUM,
  58. IPR,
  59. IPW,
  60. MAF,
  61. MLK,
  62. MPK,
  63. NPR,
  64. ODS,
  65. PAR,
  66. PLK,
  67. UMC,
  68. UMR,
  69. NO_MEMORY_FAULT
  70. };
  71. private:
  72. enum
  73. { // Program statuses
  74. NOT_RUN = 0,
  75. TIMEOUT,
  76. SEGFAULT,
  77. ILLEGAL,
  78. INTERRUPT,
  79. NUMERICAL,
  80. OTHER_FAULT,
  81. FAILED,
  82. BAD_COMMAND,
  83. COMPLETED
  84. };
  85. std::string BoundsCheckerDPBDFile;
  86. std::string BoundsCheckerXMLFile;
  87. std::string MemoryTester;
  88. std::vector<std::string> MemoryTesterDynamicOptions;
  89. std::vector<std::string> MemoryTesterOptions;
  90. int MemoryTesterStyle;
  91. std::string MemoryTesterOutputFile;
  92. std::string MemoryTesterEnvironmentVariable;
  93. // these are used to store the types of errors that can show up
  94. std::vector<std::string> ResultStrings;
  95. std::vector<std::string> ResultStringsLong;
  96. std::vector<int> GlobalResults;
  97. bool LogWithPID; // does log file add pid
  98. int DefectCount;
  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) override;
  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 memory errors.
  114. bool ProcessMemCheckOutput(const std::string& str, std::string& log,
  115. std::vector<int>& results);
  116. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  117. std::vector<int>& results);
  118. bool ProcessMemCheckDrMemoryOutput(const std::string& str, std::string& log,
  119. std::vector<int>& results);
  120. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log,
  121. std::vector<int>& results);
  122. bool ProcessMemCheckCudaOutput(const std::string& str, std::string& log,
  123. std::vector<int>& results);
  124. bool ProcessMemCheckSanitizerOutput(const std::string& str, std::string& log,
  125. std::vector<int>& results);
  126. bool ProcessMemCheckBoundsCheckerOutput(const std::string& str,
  127. std::string& log,
  128. std::vector<int>& results);
  129. void PostProcessTest(cmCTestTestResult& res, int test);
  130. void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test);
  131. void PostProcessDrMemoryTest(cmCTestTestResult& res, int test);
  132. //! append MemoryTesterOutputFile to the test log
  133. void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
  134. std::string const& filename);
  135. //! generate the output filename for the given test index
  136. void TestOutputFileNames(int test, std::vector<std::string>& files);
  137. };
  138. #endif