cmCTestMemCheckHandler.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <string>
  6. #include <vector>
  7. #include "cmCTestTestHandler.h"
  8. class cmMakefile;
  9. class cmXMLWriter;
  10. /** \class cmCTestMemCheckHandler
  11. * \brief A class that handles ctest -S invocations
  12. *
  13. */
  14. class cmCTestMemCheckHandler : public cmCTestTestHandler
  15. {
  16. friend class cmCTestRunTest;
  17. public:
  18. using Superclass = cmCTestTestHandler;
  19. void PopulateCustomVectors(cmMakefile* mf) override;
  20. cmCTestMemCheckHandler();
  21. void Initialize() override;
  22. int GetDefectCount();
  23. protected:
  24. int PreProcessHandler() override;
  25. int PostProcessHandler() override;
  26. void GenerateTestCommand(std::vector<std::string>& args, int test) override;
  27. private:
  28. enum
  29. { // Memory checkers
  30. UNKNOWN = 0,
  31. VALGRIND,
  32. PURIFY,
  33. DRMEMORY,
  34. BOUNDS_CHECKER,
  35. // checkers after here do not use the standard error list
  36. CUDA_MEMCHECK,
  37. ADDRESS_SANITIZER,
  38. LEAK_SANITIZER,
  39. THREAD_SANITIZER,
  40. MEMORY_SANITIZER,
  41. UB_SANITIZER
  42. };
  43. public:
  44. enum
  45. { // 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
  72. { // Program statuses
  73. NOT_RUN = 0,
  74. TIMEOUT,
  75. SEGFAULT,
  76. ILLEGAL,
  77. INTERRUPT,
  78. NUMERICAL,
  79. OTHER_FAULT,
  80. FAILED,
  81. BAD_COMMAND,
  82. COMPLETED
  83. };
  84. std::string BoundsCheckerDPBDFile;
  85. std::string BoundsCheckerXMLFile;
  86. std::string MemoryTester;
  87. std::vector<std::string> MemoryTesterDynamicOptions;
  88. std::vector<std::string> MemoryTesterOptions;
  89. int MemoryTesterStyle;
  90. std::string MemoryTesterOutputFile;
  91. std::string MemoryTesterEnvironmentVariable;
  92. // these are used to store the types of errors that can show up
  93. std::vector<std::string> ResultStrings;
  94. std::vector<std::string> ResultStringsLong;
  95. std::vector<int> GlobalResults;
  96. bool LogWithPID; // does log file add pid
  97. int DefectCount;
  98. std::vector<int>::size_type FindOrAddWarning(const std::string& warning);
  99. // initialize the ResultStrings and ResultStringsLong for
  100. // this type of checker
  101. void InitializeResultsVectors();
  102. //! Initialize memory checking subsystem.
  103. bool InitializeMemoryChecking();
  104. /**
  105. * Generate the Dart compatible output
  106. */
  107. void GenerateDartOutput(cmXMLWriter& xml) override;
  108. std::vector<std::string> CustomPreMemCheck;
  109. std::vector<std::string> CustomPostMemCheck;
  110. //! Parse Valgrind/Purify/Bounds Checker result out of the output
  111. // string. After running, log holds the output and results hold the
  112. // different memory errors.
  113. bool ProcessMemCheckOutput(const std::string& str, std::string& log,
  114. std::vector<int>& results);
  115. bool ProcessMemCheckValgrindOutput(const std::string& str, std::string& log,
  116. std::vector<int>& results);
  117. bool ProcessMemCheckDrMemoryOutput(const std::string& str, std::string& log,
  118. std::vector<int>& results);
  119. bool ProcessMemCheckPurifyOutput(const std::string& str, std::string& log,
  120. std::vector<int>& results);
  121. bool ProcessMemCheckCudaOutput(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. void PostProcessDrMemoryTest(cmCTestTestResult& res, int test);
  131. //! append MemoryTesterOutputFile to the test log
  132. void AppendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res,
  133. std::string const& filename);
  134. //! generate the output filename for the given test index
  135. void TestOutputFileNames(int test, std::vector<std::string>& files);
  136. };