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