Hash :
056f8044
Author :
Date :
2022-10-11T11:58:20
Perf tests: write metrics to file and read from merge script. The idea behind is to save metrics in a structured output with full context so that we don't have to parse stdout and reconstruct that context (e.g. which test was running when the output was printed etc). Note: we already have a "histogram" file (addHistogramSample) written but it is structured using some UUID-based ids making its digestion more complicated (https://anglebug.com/7299#c3). This CL just writes events as one-json-per-line simplifying downstream handling and debugging. Just a sanity check / logging in the merge script for now. Bug: angleproject:7299 Change-Id: I56dada643eceef180ce9bb1aa9ae6a641ea41e4c Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3945112 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Roman Lavrov <romanl@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// TestSuite:
// Basic implementation of a test harness in ANGLE.
#ifndef ANGLE_TESTS_TEST_UTILS_TEST_SUITE_H_
#define ANGLE_TESTS_TEST_UTILS_TEST_SUITE_H_
#include <map>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <thread>
#include "HistogramWriter.h"
#include "tests/test_expectations/GPUTestExpectationsParser.h"
#include "util/test_utils.h"
namespace angle
{
struct TestIdentifier
{
TestIdentifier();
TestIdentifier(const std::string &suiteNameIn, const std::string &nameIn);
TestIdentifier(const TestIdentifier &other);
~TestIdentifier();
TestIdentifier &operator=(const TestIdentifier &other);
static bool ParseFromString(const std::string &str, TestIdentifier *idOut);
bool valid() const { return !testName.empty(); }
void snprintfName(char *outBuffer, size_t maxLen) const;
std::string testSuiteName;
std::string testName;
};
inline bool operator<(const TestIdentifier &a, const TestIdentifier &b)
{
return std::tie(a.testSuiteName, a.testName) < std::tie(b.testSuiteName, b.testName);
}
inline bool operator==(const TestIdentifier &a, const TestIdentifier &b)
{
return std::tie(a.testSuiteName, a.testName) == std::tie(b.testSuiteName, b.testName);
}
inline std::ostream &operator<<(std::ostream &os, const TestIdentifier &id)
{
return os << id.testSuiteName << "." << id.testName;
}
enum class TestResultType
{
Crash,
Fail,
NoResult,
Pass,
Skip,
Timeout,
Unknown,
};
const char *TestResultTypeToString(TestResultType type);
struct TestResult
{
TestResultType type = TestResultType::NoResult;
std::vector<double> elapsedTimeSeconds = std::vector<double>({0.0});
uint32_t flakyFailures = 0;
};
inline bool operator==(const TestResult &a, const TestResult &b)
{
return a.type == b.type;
}
inline std::ostream &operator<<(std::ostream &os, const TestResult &result)
{
return os << TestResultTypeToString(result.type);
}
struct TestResults
{
TestResults();
~TestResults();
std::map<TestIdentifier, TestResult> results;
std::mutex currentTestMutex;
TestIdentifier currentTest;
Timer currentTestTimer;
double currentTestTimeout = 0.0;
bool allDone = false;
std::string testArtifactsFakeTestName;
std::vector<std::string> testArtifactPaths;
};
struct FileLine
{
const char *file;
int line;
};
struct ProcessInfo : angle::NonCopyable
{
ProcessInfo();
~ProcessInfo();
ProcessInfo(ProcessInfo &&other);
ProcessInfo &operator=(ProcessInfo &&rhs);
ProcessHandle process;
std::vector<TestIdentifier> testsInBatch;
std::string resultsFileName;
std::string filterFileName;
std::string commandLine;
std::string filterString;
};
using TestQueue = std::queue<std::vector<TestIdentifier>>;
class MetricWriter
{
public:
MetricWriter() {}
void enable(const std::string &testArtifactDirectory);
void writeInfo(const std::string &name,
const std::string &backend,
const std::string &story,
const std::string &metric,
const std::string &units);
void writeDoubleValue(double value);
void writeIntegerValue(size_t value);
void close();
private:
std::string mPath;
FILE *mFile = nullptr;
};
class TestSuite
{
public:
TestSuite(int *argc, char **argv);
TestSuite(int *argc, char **argv, std::function<void()> registerTestsCallback);
~TestSuite();
int run();
void onCrashOrTimeout(TestResultType crashOrTimeout);
void addHistogramSample(const std::string &measurement,
const std::string &story,
double value,
const std::string &units);
static TestSuite *GetInstance() { return mInstance; }
static MetricWriter &GetMetricWriter() { return GetInstance()->mMetricWriter; }
// Returns the path to the artifact in the output directory.
bool hasTestArtifactsDirectory() const;
std::string reserveTestArtifactPath(const std::string &artifactName);
int getShardIndex() const { return mShardIndex; }
int getBatchId() const { return mBatchId; }
// Test expectation processing.
bool loadTestExpectationsFromFileWithConfig(const GPUTestConfig &config,
const std::string &fileName);
bool loadAllTestExpectationsFromFile(const std::string &fileName);
int32_t getTestExpectation(const std::string &testName);
void maybeUpdateTestTimeout(uint32_t testExpectation);
int32_t getTestExpectationWithConfigAndUpdateTimeout(const GPUTestConfig &config,
const std::string &testName);
bool logAnyUnusedTestExpectations();
void setTestExpectationsAllowMask(uint32_t mask)
{
mTestExpectationsParser.setTestExpectationsAllowMask(mask);
}
const std::string &getTestExecutableName() const { return mTestExecutableName; }
private:
bool parseSingleArg(int *argc, char **argv, int argIndex);
bool launchChildTestProcess(uint32_t batchId, const std::vector<TestIdentifier> &testsInBatch);
bool finishProcess(ProcessInfo *processInfo);
int printFailuresAndReturnCount() const;
void startWatchdog();
void dumpTestExpectationsErrorMessages();
int getSlowTestTimeout() const;
void writeOutputFiles(bool interrupted);
static TestSuite *mInstance;
std::string mTestExecutableName;
TestQueue mTestQueue;
std::string mFilterString;
std::string mFilterFile;
std::string mResultsDirectory;
std::string mResultsFile;
std::string mHistogramJsonFile;
int mShardCount;
int mShardIndex;
angle::CrashCallback mCrashCallback;
TestResults mTestResults;
bool mBotMode;
bool mDebugTestGroups;
bool mGTestListTests;
bool mListTests;
bool mPrintTestStdout;
bool mDisableCrashHandler;
int mBatchSize;
int mCurrentResultCount;
int mTotalResultCount;
int mMaxProcesses;
int mTestTimeout;
int mBatchTimeout;
int mBatchId;
int mFlakyRetries;
int mMaxFailures;
int mFailureCount;
bool mModifiedPreferredDevice;
std::vector<std::string> mChildProcessArgs;
std::map<TestIdentifier, FileLine> mTestFileLines;
std::vector<ProcessInfo> mCurrentProcesses;
std::thread mWatchdogThread;
HistogramWriter mHistogramWriter;
MetricWriter mMetricWriter;
std::string mTestArtifactDirectory;
GPUTestExpectationsParser mTestExpectationsParser;
class TestEventListener;
};
std::string ReplaceDashesWithQuestionMark(std::string dashesString);
bool GetTestResultsFromFile(const char *fileName, TestResults *resultsOut);
} // namespace angle
#endif // ANGLE_TESTS_TEST_UTILS_TEST_SUITE_H_