cmCTestMemCheckHandler.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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);
  28. cmCTestMemCheckHandler();
  29. void Initialize();
  30. protected:
  31. virtual int PreProcessHandler();
  32. virtual int PostProcessHandler();
  33. virtual void GenerateTestCommand(std::vector<std::string>& args, int test);
  34. private:
  35. enum { // Memory checkers
  36. UNKNOWN = 0,
  37. VALGRIND,
  38. PURIFY,
  39. BOUNDS_CHECKER,
  40. // checkers after here do not use the standard error list
  41. ADDRESS_SANITIZER,
  42. THREAD_SANITIZER,
  43. MEMORY_SANITIZER,
  44. UB_SANITIZER
  45. };
  46. public:
  47. enum { // Memory faults
  48. ABR = 0,
  49. ABW,
  50. ABWL,
  51. COR,
  52. EXU,
  53. FFM,
  54. FIM,
  55. FMM,
  56. FMR,
  57. FMW,
  58. FUM,
  59. IPR,
  60. IPW,
  61. MAF,
  62. MLK,
  63. MPK,
  64. NPR,
  65. ODS,
  66. PAR,
  67. PLK,
  68. UMC,
  69. UMR,
  70. NO_MEMORY_FAULT
  71. };
  72. private:
  73. enum { // 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. 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);
  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 memmory errors.
  113. bool ProcessMemCheckOutput(const std::string& str,
  114. std::string& log, std::vector<int>& results);
  115. bool ProcessMemCheckValgrindOutput(const std::string& str,
  116. std::string& log,
  117. std::vector<int>& results);
  118. bool ProcessMemCheckPurifyOutput(const std::string& str,
  119. std::string& log,
  120. std::vector<int>& results);
  121. bool ProcessMemCheckSanitizerOutput(const std::string& str,
  122. std::string& log,
  123. std::vector<int>& results);
  124. bool ProcessMemCheckBoundsCheckerOutput(const std::string& str,
  125. std::string& log,
  126. std::vector<int>& results);
  127. void PostProcessTest(cmCTestTestResult& res, int test);
  128. void PostProcessBoundsCheckerTest(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. };
  135. #endif