Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/angle
Path: blob/main_old/src/tests/test_utils/runner/TestSuite.h
1694 views
1
//
2
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
3
// Use of this source code is governed by a BSD-style license that can be
4
// found in the LICENSE file.
5
//
6
// TestSuite:
7
// Basic implementation of a test harness in ANGLE.
8
9
#ifndef ANGLE_TESTS_TEST_UTILS_TEST_SUITE_H_
10
#define ANGLE_TESTS_TEST_UTILS_TEST_SUITE_H_
11
12
#include <map>
13
#include <memory>
14
#include <mutex>
15
#include <queue>
16
#include <string>
17
#include <thread>
18
19
#include "HistogramWriter.h"
20
#include "tests/test_expectations/GPUTestExpectationsParser.h"
21
#include "util/test_utils.h"
22
23
namespace angle
24
{
25
struct TestIdentifier
26
{
27
TestIdentifier();
28
TestIdentifier(const std::string &suiteNameIn, const std::string &nameIn);
29
TestIdentifier(const TestIdentifier &other);
30
~TestIdentifier();
31
32
TestIdentifier &operator=(const TestIdentifier &other);
33
34
static bool ParseFromString(const std::string &str, TestIdentifier *idOut);
35
36
bool valid() const { return !testName.empty(); }
37
void sprintfName(char *outBuffer) const;
38
39
std::string testSuiteName;
40
std::string testName;
41
};
42
43
inline bool operator<(const TestIdentifier &a, const TestIdentifier &b)
44
{
45
return std::tie(a.testSuiteName, a.testName) < std::tie(b.testSuiteName, b.testName);
46
}
47
48
inline bool operator==(const TestIdentifier &a, const TestIdentifier &b)
49
{
50
return std::tie(a.testSuiteName, a.testName) == std::tie(b.testSuiteName, b.testName);
51
}
52
53
inline std::ostream &operator<<(std::ostream &os, const TestIdentifier &id)
54
{
55
return os << id.testSuiteName << "." << id.testName;
56
}
57
58
enum class TestResultType
59
{
60
Crash,
61
Fail,
62
NoResult,
63
Pass,
64
Skip,
65
Timeout,
66
Unknown,
67
};
68
69
const char *TestResultTypeToString(TestResultType type);
70
71
struct TestResult
72
{
73
TestResultType type = TestResultType::NoResult;
74
double elapsedTimeSeconds = 0.0;
75
uint32_t flakyFailures = 0;
76
};
77
78
inline bool operator==(const TestResult &a, const TestResult &b)
79
{
80
return a.type == b.type;
81
}
82
83
inline std::ostream &operator<<(std::ostream &os, const TestResult &result)
84
{
85
return os << TestResultTypeToString(result.type);
86
}
87
88
struct TestResults
89
{
90
TestResults();
91
~TestResults();
92
93
std::map<TestIdentifier, TestResult> results;
94
std::mutex currentTestMutex;
95
TestIdentifier currentTest;
96
Timer currentTestTimer;
97
double currentTestTimeout = 0.0;
98
bool allDone = false;
99
std::string testArtifactsFakeTestName;
100
std::vector<std::string> testArtifactPaths;
101
};
102
103
struct FileLine
104
{
105
const char *file;
106
int line;
107
};
108
109
struct ProcessInfo : angle::NonCopyable
110
{
111
ProcessInfo();
112
~ProcessInfo();
113
ProcessInfo(ProcessInfo &&other);
114
ProcessInfo &operator=(ProcessInfo &&rhs);
115
116
ProcessHandle process;
117
std::vector<TestIdentifier> testsInBatch;
118
std::string resultsFileName;
119
std::string filterFileName;
120
std::string commandLine;
121
std::string filterString;
122
};
123
124
using TestQueue = std::queue<std::vector<TestIdentifier>>;
125
126
class TestSuite
127
{
128
public:
129
TestSuite(int *argc, char **argv);
130
~TestSuite();
131
132
int run();
133
void onCrashOrTimeout(TestResultType crashOrTimeout);
134
void addHistogramSample(const std::string &measurement,
135
const std::string &story,
136
double value,
137
const std::string &units);
138
139
static TestSuite *GetInstance() { return mInstance; }
140
141
// Returns the path to the artifact in the output directory.
142
std::string addTestArtifact(const std::string &artifactName);
143
144
int getShardIndex() const { return mShardIndex; }
145
int getBatchId() const { return mBatchId; }
146
147
// Test expectation processing.
148
bool loadTestExpectationsFromFileWithConfig(const GPUTestConfig &config,
149
const std::string &fileName);
150
bool loadAllTestExpectationsFromFile(const std::string &fileName);
151
int32_t getTestExpectation(const std::string &testName);
152
void maybeUpdateTestTimeout(uint32_t testExpectation);
153
int32_t getTestExpectationWithConfigAndUpdateTimeout(const GPUTestConfig &config,
154
const std::string &testName);
155
bool logAnyUnusedTestExpectations();
156
void setTestExpectationsAllowMask(uint32_t mask)
157
{
158
mTestExpectationsParser.setTestExpectationsAllowMask(mask);
159
}
160
161
private:
162
bool parseSingleArg(const char *argument);
163
bool launchChildTestProcess(uint32_t batchId, const std::vector<TestIdentifier> &testsInBatch);
164
bool finishProcess(ProcessInfo *processInfo);
165
int printFailuresAndReturnCount() const;
166
void startWatchdog();
167
void dumpTestExpectationsErrorMessages();
168
int getSlowTestTimeout() const;
169
170
static TestSuite *mInstance;
171
172
std::string mTestExecutableName;
173
std::string mTestSuiteName;
174
TestQueue mTestQueue;
175
std::string mFilterString;
176
std::string mFilterFile;
177
std::string mResultsDirectory;
178
std::string mResultsFile;
179
std::string mHistogramJsonFile;
180
int mShardCount;
181
int mShardIndex;
182
angle::CrashCallback mCrashCallback;
183
TestResults mTestResults;
184
bool mBotMode;
185
bool mDebugTestGroups;
186
bool mGTestListTests;
187
bool mListTests;
188
bool mPrintTestStdout;
189
bool mDisableCrashHandler;
190
int mBatchSize;
191
int mCurrentResultCount;
192
int mTotalResultCount;
193
int mMaxProcesses;
194
int mTestTimeout;
195
int mBatchTimeout;
196
int mBatchId;
197
int mFlakyRetries;
198
int mMaxFailures;
199
int mFailureCount;
200
std::vector<std::string> mChildProcessArgs;
201
std::map<TestIdentifier, FileLine> mTestFileLines;
202
std::vector<ProcessInfo> mCurrentProcesses;
203
std::thread mWatchdogThread;
204
HistogramWriter mHistogramWriter;
205
std::string mTestArtifactDirectory;
206
GPUTestExpectationsParser mTestExpectationsParser;
207
};
208
209
bool GetTestResultsFromFile(const char *fileName, TestResults *resultsOut);
210
} // namespace angle
211
212
#endif // ANGLE_TESTS_TEST_UTILS_TEST_SUITE_H_
213
214