cmCTestMemCheckHandler.h 4.3 KB

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