[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 5 | #include "gpu/config/gpu_test_expectations_parser.h" |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 6 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
thestig | c9e38a2 | 2014-09-13 01:02:11 | [diff] [blame] | 10 | #include "base/files/file_util.h" |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
[email protected] | 27c0573 | 2013-02-15 21:55:49 | [diff] [blame] | 13 | #include "base/strings/string_split.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 14 | #include "base/strings/string_util.h" |
| 15 | #include "base/strings/stringprintf.h" |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 16 | |
| 17 | namespace gpu { |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 18 | |
| 19 | namespace { |
| 20 | |
| 21 | enum LineParserStage { |
| 22 | kLineParserBegin = 0, |
| 23 | kLineParserBugID, |
| 24 | kLineParserConfigs, |
| 25 | kLineParserColon, |
| 26 | kLineParserTestName, |
| 27 | kLineParserEqual, |
| 28 | kLineParserExpectations, |
| 29 | }; |
| 30 | |
| 31 | enum Token { |
| 32 | // os |
| 33 | kConfigWinXP = 0, |
| 34 | kConfigWinVista, |
| 35 | kConfigWin7, |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 36 | kConfigWin8, |
wfh | 0355eead | 2015-07-22 04:15:00 | [diff] [blame] | 37 | kConfigWin10, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 38 | kConfigWin, |
| 39 | kConfigMacLeopard, |
| 40 | kConfigMacSnowLeopard, |
| 41 | kConfigMacLion, |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 42 | kConfigMacMountainLion, |
[email protected] | 710089b9 | 2014-02-04 01:16:09 | [diff] [blame] | 43 | kConfigMacMavericks, |
iceman | 3197ce8 | 2015-04-15 11:02:32 | [diff] [blame] | 44 | kConfigMacYosemite, |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 45 | kConfigMacElCapitan, |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 46 | kConfigMacSierra, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 47 | kConfigMac, |
| 48 | kConfigLinux, |
| 49 | kConfigChromeOS, |
[email protected] | 61d7e5e | 2012-07-27 04:08:57 | [diff] [blame] | 50 | kConfigAndroid, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 51 | // gpu vendor |
| 52 | kConfigNVidia, |
| 53 | kConfigAMD, |
| 54 | kConfigIntel, |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 55 | kConfigVMWare, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 56 | // build type |
| 57 | kConfigRelease, |
| 58 | kConfigDebug, |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 59 | // ANGLE renderer |
| 60 | kConfigD3D9, |
| 61 | kConfigD3D11, |
| 62 | kConfigGLDesktop, |
| 63 | kConfigGLES, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 64 | // expectation |
| 65 | kExpectationPass, |
| 66 | kExpectationFail, |
| 67 | kExpectationFlaky, |
| 68 | kExpectationTimeout, |
[email protected] | 55ab019 | 2012-05-11 20:12:37 | [diff] [blame] | 69 | kExpectationSkip, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 70 | // separator |
| 71 | kSeparatorColon, |
| 72 | kSeparatorEqual, |
| 73 | |
| 74 | kNumberOfExactMatchTokens, |
| 75 | |
| 76 | // others |
| 77 | kConfigGPUDeviceID, |
| 78 | kTokenComment, |
| 79 | kTokenWord, |
| 80 | }; |
| 81 | |
| 82 | struct TokenInfo { |
| 83 | const char* name; |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 84 | int32_t flag; |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | const TokenInfo kTokenData[] = { |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 88 | {"xp", GPUTestConfig::kOsWinXP}, |
| 89 | {"vista", GPUTestConfig::kOsWinVista}, |
| 90 | {"win7", GPUTestConfig::kOsWin7}, |
| 91 | {"win8", GPUTestConfig::kOsWin8}, |
| 92 | {"win10", GPUTestConfig::kOsWin10}, |
| 93 | {"win", GPUTestConfig::kOsWin}, |
| 94 | {"leopard", GPUTestConfig::kOsMacLeopard}, |
| 95 | {"snowleopard", GPUTestConfig::kOsMacSnowLeopard}, |
| 96 | {"lion", GPUTestConfig::kOsMacLion}, |
| 97 | {"mountainlion", GPUTestConfig::kOsMacMountainLion}, |
| 98 | {"mavericks", GPUTestConfig::kOsMacMavericks}, |
| 99 | {"yosemite", GPUTestConfig::kOsMacYosemite}, |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 100 | {"elcapitan", GPUTestConfig::kOsMacElCapitan}, |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 101 | {"sierra", GPUTestConfig::kOsMacSierra}, |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 102 | {"mac", GPUTestConfig::kOsMac}, |
| 103 | {"linux", GPUTestConfig::kOsLinux}, |
| 104 | {"chromeos", GPUTestConfig::kOsChromeOS}, |
| 105 | {"android", GPUTestConfig::kOsAndroid}, |
| 106 | {"nvidia", 0x10DE}, |
| 107 | {"amd", 0x1002}, |
| 108 | {"intel", 0x8086}, |
| 109 | {"vmware", 0x15ad}, |
| 110 | {"release", GPUTestConfig::kBuildTypeRelease}, |
| 111 | {"debug", GPUTestConfig::kBuildTypeDebug}, |
| 112 | {"d3d9", GPUTestConfig::kAPID3D9}, |
| 113 | {"d3d11", GPUTestConfig::kAPID3D11}, |
| 114 | {"opengl", GPUTestConfig::kAPIGLDesktop}, |
| 115 | {"gles", GPUTestConfig::kAPIGLES}, |
| 116 | {"pass", GPUTestExpectationsParser::kGpuTestPass}, |
| 117 | {"fail", GPUTestExpectationsParser::kGpuTestFail}, |
| 118 | {"flaky", GPUTestExpectationsParser::kGpuTestFlaky}, |
| 119 | {"timeout", GPUTestExpectationsParser::kGpuTestTimeout}, |
| 120 | {"skip", GPUTestExpectationsParser::kGpuTestSkip}, |
| 121 | {":", 0}, |
| 122 | {"=", 0}, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | enum ErrorType { |
| 126 | kErrorFileIO = 0, |
| 127 | kErrorIllegalEntry, |
| 128 | kErrorInvalidEntry, |
| 129 | kErrorEntryWithOsConflicts, |
| 130 | kErrorEntryWithGpuVendorConflicts, |
| 131 | kErrorEntryWithBuildTypeConflicts, |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 132 | kErrorEntryWithAPIConflicts, |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 133 | kErrorEntryWithGpuDeviceIdConflicts, |
| 134 | kErrorEntryWithExpectationConflicts, |
| 135 | kErrorEntriesOverlap, |
| 136 | |
| 137 | kNumberOfErrors, |
| 138 | }; |
| 139 | |
| 140 | const char* kErrorMessage[] = { |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 141 | "file IO failed", |
| 142 | "entry with wrong format", |
| 143 | "entry invalid, likely wrong modifiers combination", |
| 144 | "entry with OS modifier conflicts", |
| 145 | "entry with GPU vendor modifier conflicts", |
| 146 | "entry with GPU build type conflicts", |
| 147 | "entry with GPU API conflicts", |
| 148 | "entry with GPU device id conflicts or malformat", |
| 149 | "entry with expectation modifier conflicts", |
| 150 | "two entries' configs overlap", |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | Token ParseToken(const std::string& word) { |
brettw | 9550931 | 2015-07-16 23:57:33 | [diff] [blame] | 154 | if (base::StartsWith(word, "//", base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 155 | return kTokenComment; |
brettw | 9550931 | 2015-07-16 23:57:33 | [diff] [blame] | 156 | if (base::StartsWith(word, "0x", base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 157 | return kConfigGPUDeviceID; |
| 158 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 159 | for (int32_t i = 0; i < kNumberOfExactMatchTokens; ++i) { |
brettw | bc17d2c8 | 2015-06-09 22:39:08 | [diff] [blame] | 160 | if (base::LowerCaseEqualsASCII(word, kTokenData[i].name)) |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 161 | return static_cast<Token>(i); |
| 162 | } |
| 163 | return kTokenWord; |
| 164 | } |
| 165 | |
[email protected] | 55ab019 | 2012-05-11 20:12:37 | [diff] [blame] | 166 | // reference name can have the last character as *. |
| 167 | bool NamesMatching(const std::string& ref, const std::string& test_name) { |
| 168 | size_t len = ref.length(); |
| 169 | if (len == 0) |
| 170 | return false; |
| 171 | if (ref[len - 1] == '*') { |
| 172 | if (test_name.length() > len -1 && |
| 173 | ref.compare(0, len - 1, test_name, 0, len - 1) == 0) |
| 174 | return true; |
| 175 | return false; |
| 176 | } |
| 177 | return (ref == test_name); |
| 178 | } |
| 179 | |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 180 | } // namespace anonymous |
| 181 | |
| 182 | GPUTestExpectationsParser::GPUTestExpectationsParser() { |
| 183 | // Some sanity check. |
| 184 | DCHECK_EQ(static_cast<unsigned int>(kNumberOfExactMatchTokens), |
| 185 | sizeof(kTokenData) / sizeof(kTokenData[0])); |
| 186 | DCHECK_EQ(static_cast<unsigned int>(kNumberOfErrors), |
| 187 | sizeof(kErrorMessage) / sizeof(kErrorMessage[0])); |
| 188 | } |
| 189 | |
| 190 | GPUTestExpectationsParser::~GPUTestExpectationsParser() { |
| 191 | } |
| 192 | |
| 193 | bool GPUTestExpectationsParser::LoadTestExpectations(const std::string& data) { |
| 194 | entries_.clear(); |
| 195 | error_messages_.clear(); |
| 196 | |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 197 | std::vector<std::string> lines = base::SplitString( |
| 198 | data, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 199 | bool rt = true; |
| 200 | for (size_t i = 0; i < lines.size(); ++i) { |
| 201 | if (!ParseLine(lines[i], i + 1)) |
| 202 | rt = false; |
| 203 | } |
| 204 | if (DetectConflictsBetweenEntries()) { |
| 205 | entries_.clear(); |
| 206 | rt = false; |
| 207 | } |
| 208 | |
| 209 | return rt; |
| 210 | } |
| 211 | |
[email protected] | d30a36f | 2013-02-07 04:16:26 | [diff] [blame] | 212 | bool GPUTestExpectationsParser::LoadTestExpectations( |
| 213 | const base::FilePath& path) { |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 214 | entries_.clear(); |
| 215 | error_messages_.clear(); |
| 216 | |
| 217 | std::string data; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 218 | if (!base::ReadFileToString(path, &data)) { |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 219 | error_messages_.push_back(kErrorMessage[kErrorFileIO]); |
| 220 | return false; |
| 221 | } |
| 222 | return LoadTestExpectations(data); |
| 223 | } |
| 224 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 225 | int32_t GPUTestExpectationsParser::GetTestExpectation( |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 226 | const std::string& test_name, |
| 227 | const GPUTestBotConfig& bot_config) const { |
| 228 | for (size_t i = 0; i < entries_.size(); ++i) { |
[email protected] | 55ab019 | 2012-05-11 20:12:37 | [diff] [blame] | 229 | if (NamesMatching(entries_[i].test_name, test_name) && |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 230 | bot_config.Matches(entries_[i].test_config)) |
| 231 | return entries_[i].test_expectation; |
| 232 | } |
| 233 | return kGpuTestPass; |
| 234 | } |
| 235 | |
| 236 | const std::vector<std::string>& |
| 237 | GPUTestExpectationsParser::GetErrorMessages() const { |
| 238 | return error_messages_; |
| 239 | } |
| 240 | |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 241 | bool GPUTestExpectationsParser::ParseConfig( |
| 242 | const std::string& config_data, GPUTestConfig* config) { |
| 243 | DCHECK(config); |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 244 | std::vector<std::string> tokens = base::SplitString( |
| 245 | config_data, base::kWhitespaceASCII, base::KEEP_WHITESPACE, |
| 246 | base::SPLIT_WANT_NONEMPTY); |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 247 | |
| 248 | for (size_t i = 0; i < tokens.size(); ++i) { |
| 249 | Token token = ParseToken(tokens[i]); |
| 250 | switch (token) { |
| 251 | case kConfigWinXP: |
| 252 | case kConfigWinVista: |
| 253 | case kConfigWin7: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 254 | case kConfigWin8: |
wfh | 0355eead | 2015-07-22 04:15:00 | [diff] [blame] | 255 | case kConfigWin10: |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 256 | case kConfigWin: |
| 257 | case kConfigMacLeopard: |
| 258 | case kConfigMacSnowLeopard: |
| 259 | case kConfigMacLion: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 260 | case kConfigMacMountainLion: |
[email protected] | 710089b9 | 2014-02-04 01:16:09 | [diff] [blame] | 261 | case kConfigMacMavericks: |
iceman | 3197ce8 | 2015-04-15 11:02:32 | [diff] [blame] | 262 | case kConfigMacYosemite: |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 263 | case kConfigMacElCapitan: |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 264 | case kConfigMacSierra: |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 265 | case kConfigMac: |
| 266 | case kConfigLinux: |
| 267 | case kConfigChromeOS: |
[email protected] | 61d7e5e | 2012-07-27 04:08:57 | [diff] [blame] | 268 | case kConfigAndroid: |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 269 | case kConfigNVidia: |
| 270 | case kConfigAMD: |
| 271 | case kConfigIntel: |
| 272 | case kConfigVMWare: |
| 273 | case kConfigRelease: |
| 274 | case kConfigDebug: |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 275 | case kConfigD3D9: |
| 276 | case kConfigD3D11: |
| 277 | case kConfigGLDesktop: |
| 278 | case kConfigGLES: |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 279 | case kConfigGPUDeviceID: |
| 280 | if (token == kConfigGPUDeviceID) { |
| 281 | if (!UpdateTestConfig(config, tokens[i], 0)) |
| 282 | return false; |
| 283 | } else { |
| 284 | if (!UpdateTestConfig(config, token, 0)) |
| 285 | return false; |
| 286 | } |
| 287 | break; |
| 288 | default: |
| 289 | return false; |
| 290 | } |
| 291 | } |
| 292 | return true; |
| 293 | } |
| 294 | |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 295 | bool GPUTestExpectationsParser::ParseLine( |
| 296 | const std::string& line_data, size_t line_number) { |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 297 | std::vector<std::string> tokens = base::SplitString( |
| 298 | line_data, base::kWhitespaceASCII, base::KEEP_WHITESPACE, |
| 299 | base::SPLIT_WANT_NONEMPTY); |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 300 | int32_t stage = kLineParserBegin; |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 301 | GPUTestExpectationEntry entry; |
| 302 | entry.line_number = line_number; |
| 303 | GPUTestConfig& config = entry.test_config; |
| 304 | bool comments_encountered = false; |
| 305 | for (size_t i = 0; i < tokens.size() && !comments_encountered; ++i) { |
| 306 | Token token = ParseToken(tokens[i]); |
| 307 | switch (token) { |
| 308 | case kTokenComment: |
| 309 | comments_encountered = true; |
| 310 | break; |
| 311 | case kConfigWinXP: |
| 312 | case kConfigWinVista: |
| 313 | case kConfigWin7: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 314 | case kConfigWin8: |
wfh | 0355eead | 2015-07-22 04:15:00 | [diff] [blame] | 315 | case kConfigWin10: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 316 | case kConfigWin: |
| 317 | case kConfigMacLeopard: |
| 318 | case kConfigMacSnowLeopard: |
| 319 | case kConfigMacLion: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 320 | case kConfigMacMountainLion: |
[email protected] | 710089b9 | 2014-02-04 01:16:09 | [diff] [blame] | 321 | case kConfigMacMavericks: |
iceman | 3197ce8 | 2015-04-15 11:02:32 | [diff] [blame] | 322 | case kConfigMacYosemite: |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 323 | case kConfigMacElCapitan: |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 324 | case kConfigMacSierra: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 325 | case kConfigMac: |
| 326 | case kConfigLinux: |
| 327 | case kConfigChromeOS: |
[email protected] | 61d7e5e | 2012-07-27 04:08:57 | [diff] [blame] | 328 | case kConfigAndroid: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 329 | case kConfigNVidia: |
| 330 | case kConfigAMD: |
| 331 | case kConfigIntel: |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 332 | case kConfigVMWare: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 333 | case kConfigRelease: |
| 334 | case kConfigDebug: |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 335 | case kConfigD3D9: |
| 336 | case kConfigD3D11: |
| 337 | case kConfigGLDesktop: |
| 338 | case kConfigGLES: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 339 | case kConfigGPUDeviceID: |
| 340 | // MODIFIERS, could be in any order, need at least one. |
| 341 | if (stage != kLineParserConfigs && stage != kLineParserBugID) { |
| 342 | PushErrorMessage(kErrorMessage[kErrorIllegalEntry], |
| 343 | line_number); |
| 344 | return false; |
| 345 | } |
| 346 | if (token == kConfigGPUDeviceID) { |
| 347 | if (!UpdateTestConfig(&config, tokens[i], line_number)) |
| 348 | return false; |
| 349 | } else { |
| 350 | if (!UpdateTestConfig(&config, token, line_number)) |
| 351 | return false; |
| 352 | } |
| 353 | if (stage == kLineParserBugID) |
| 354 | stage++; |
| 355 | break; |
| 356 | case kSeparatorColon: |
| 357 | // : |
| 358 | if (stage != kLineParserConfigs) { |
| 359 | PushErrorMessage(kErrorMessage[kErrorIllegalEntry], |
| 360 | line_number); |
| 361 | return false; |
| 362 | } |
| 363 | stage++; |
| 364 | break; |
| 365 | case kSeparatorEqual: |
| 366 | // = |
| 367 | if (stage != kLineParserTestName) { |
| 368 | PushErrorMessage(kErrorMessage[kErrorIllegalEntry], |
| 369 | line_number); |
| 370 | return false; |
| 371 | } |
| 372 | stage++; |
| 373 | break; |
| 374 | case kTokenWord: |
| 375 | // BUG_ID or TEST_NAME |
| 376 | if (stage == kLineParserBegin) { |
| 377 | // Bug ID is not used for anything; ignore it. |
| 378 | } else if (stage == kLineParserColon) { |
| 379 | entry.test_name = tokens[i]; |
| 380 | } else { |
| 381 | PushErrorMessage(kErrorMessage[kErrorIllegalEntry], |
| 382 | line_number); |
| 383 | return false; |
| 384 | } |
| 385 | stage++; |
| 386 | break; |
| 387 | case kExpectationPass: |
| 388 | case kExpectationFail: |
| 389 | case kExpectationFlaky: |
| 390 | case kExpectationTimeout: |
[email protected] | 55ab019 | 2012-05-11 20:12:37 | [diff] [blame] | 391 | case kExpectationSkip: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 392 | // TEST_EXPECTATIONS |
| 393 | if (stage != kLineParserEqual && stage != kLineParserExpectations) { |
| 394 | PushErrorMessage(kErrorMessage[kErrorIllegalEntry], |
| 395 | line_number); |
| 396 | return false; |
| 397 | } |
| 398 | if ((kTokenData[token].flag & entry.test_expectation) != 0) { |
| 399 | PushErrorMessage(kErrorMessage[kErrorEntryWithExpectationConflicts], |
| 400 | line_number); |
| 401 | return false; |
| 402 | } |
| 403 | entry.test_expectation = |
| 404 | (kTokenData[token].flag | entry.test_expectation); |
| 405 | if (stage == kLineParserEqual) |
| 406 | stage++; |
| 407 | break; |
| 408 | default: |
| 409 | DCHECK(false); |
| 410 | break; |
| 411 | } |
| 412 | } |
| 413 | if (stage == kLineParserBegin) { |
| 414 | // The whole line is empty or all comments |
| 415 | return true; |
| 416 | } |
| 417 | if (stage == kLineParserExpectations) { |
| 418 | if (!config.IsValid()) { |
| 419 | PushErrorMessage(kErrorMessage[kErrorInvalidEntry], line_number); |
| 420 | return false; |
| 421 | } |
| 422 | entries_.push_back(entry); |
| 423 | return true; |
| 424 | } |
| 425 | PushErrorMessage(kErrorMessage[kErrorIllegalEntry], line_number); |
| 426 | return false; |
| 427 | } |
| 428 | |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 429 | bool GPUTestExpectationsParser::UpdateTestConfig(GPUTestConfig* config, |
| 430 | int32_t token, |
| 431 | size_t line_number) { |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 432 | DCHECK(config); |
| 433 | switch (token) { |
| 434 | case kConfigWinXP: |
| 435 | case kConfigWinVista: |
| 436 | case kConfigWin7: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 437 | case kConfigWin8: |
wfh | 0355eead | 2015-07-22 04:15:00 | [diff] [blame] | 438 | case kConfigWin10: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 439 | case kConfigWin: |
| 440 | case kConfigMacLeopard: |
| 441 | case kConfigMacSnowLeopard: |
| 442 | case kConfigMacLion: |
[email protected] | c9fc22f | 2012-11-16 23:39:56 | [diff] [blame] | 443 | case kConfigMacMountainLion: |
[email protected] | 710089b9 | 2014-02-04 01:16:09 | [diff] [blame] | 444 | case kConfigMacMavericks: |
iceman | 3197ce8 | 2015-04-15 11:02:32 | [diff] [blame] | 445 | case kConfigMacYosemite: |
bajones | 019b3c80 | 2015-11-18 19:36:58 | [diff] [blame] | 446 | case kConfigMacElCapitan: |
erikchen | af3ffdd2 | 2016-07-21 22:34:56 | [diff] [blame] | 447 | case kConfigMacSierra: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 448 | case kConfigMac: |
| 449 | case kConfigLinux: |
| 450 | case kConfigChromeOS: |
[email protected] | 61d7e5e | 2012-07-27 04:08:57 | [diff] [blame] | 451 | case kConfigAndroid: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 452 | if ((config->os() & kTokenData[token].flag) != 0) { |
| 453 | PushErrorMessage(kErrorMessage[kErrorEntryWithOsConflicts], |
| 454 | line_number); |
| 455 | return false; |
| 456 | } |
| 457 | config->set_os(config->os() | kTokenData[token].flag); |
| 458 | break; |
| 459 | case kConfigNVidia: |
| 460 | case kConfigAMD: |
| 461 | case kConfigIntel: |
[email protected] | 830631c | 2012-06-13 05:06:08 | [diff] [blame] | 462 | case kConfigVMWare: |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 463 | { |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 464 | uint32_t gpu_vendor = static_cast<uint32_t>(kTokenData[token].flag); |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 465 | for (size_t i = 0; i < config->gpu_vendor().size(); ++i) { |
| 466 | if (config->gpu_vendor()[i] == gpu_vendor) { |
| 467 | PushErrorMessage( |
| 468 | kErrorMessage[kErrorEntryWithGpuVendorConflicts], |
| 469 | line_number); |
| 470 | return false; |
| 471 | } |
| 472 | } |
| 473 | config->AddGPUVendor(gpu_vendor); |
| 474 | } |
| 475 | break; |
| 476 | case kConfigRelease: |
| 477 | case kConfigDebug: |
| 478 | if ((config->build_type() & kTokenData[token].flag) != 0) { |
| 479 | PushErrorMessage( |
| 480 | kErrorMessage[kErrorEntryWithBuildTypeConflicts], |
| 481 | line_number); |
| 482 | return false; |
| 483 | } |
| 484 | config->set_build_type( |
| 485 | config->build_type() | kTokenData[token].flag); |
| 486 | break; |
jmadill | 073a323 | 2015-07-22 21:10:52 | [diff] [blame] | 487 | case kConfigD3D9: |
| 488 | case kConfigD3D11: |
| 489 | case kConfigGLDesktop: |
| 490 | case kConfigGLES: |
| 491 | if ((config->api() & kTokenData[token].flag) != 0) { |
| 492 | PushErrorMessage(kErrorMessage[kErrorEntryWithAPIConflicts], |
| 493 | line_number); |
| 494 | return false; |
| 495 | } |
| 496 | config->set_api(config->api() | kTokenData[token].flag); |
| 497 | break; |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 498 | default: |
| 499 | DCHECK(false); |
| 500 | break; |
| 501 | } |
| 502 | return true; |
| 503 | } |
| 504 | |
| 505 | bool GPUTestExpectationsParser::UpdateTestConfig( |
| 506 | GPUTestConfig* config, |
| 507 | const std::string& gpu_device_id, |
| 508 | size_t line_number) { |
| 509 | DCHECK(config); |
avi | f15d60a | 2015-12-21 17:06:33 | [diff] [blame] | 510 | uint32_t device_id = 0; |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 511 | if (config->gpu_device_id() != 0 || |
[email protected] | 3fb0169 | 2013-10-23 13:37:04 | [diff] [blame] | 512 | !base::HexStringToUInt(gpu_device_id, &device_id) || |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 513 | device_id == 0) { |
| 514 | PushErrorMessage(kErrorMessage[kErrorEntryWithGpuDeviceIdConflicts], |
| 515 | line_number); |
| 516 | return false; |
| 517 | } |
| 518 | config->set_gpu_device_id(device_id); |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | bool GPUTestExpectationsParser::DetectConflictsBetweenEntries() { |
| 523 | bool rt = false; |
| 524 | for (size_t i = 0; i < entries_.size(); ++i) { |
| 525 | for (size_t j = i + 1; j < entries_.size(); ++j) { |
| 526 | if (entries_[i].test_name == entries_[j].test_name && |
| 527 | entries_[i].test_config.OverlapsWith(entries_[j].test_config)) { |
| 528 | PushErrorMessage(kErrorMessage[kErrorEntriesOverlap], |
| 529 | entries_[i].line_number, |
| 530 | entries_[j].line_number); |
| 531 | rt = true; |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | return rt; |
| 536 | } |
| 537 | |
| 538 | void GPUTestExpectationsParser::PushErrorMessage( |
| 539 | const std::string& message, size_t line_number) { |
| 540 | error_messages_.push_back( |
| 541 | base::StringPrintf("Line %d : %s", |
| 542 | static_cast<int>(line_number), message.c_str())); |
| 543 | } |
| 544 | |
| 545 | void GPUTestExpectationsParser::PushErrorMessage( |
| 546 | const std::string& message, |
| 547 | size_t entry1_line_number, |
| 548 | size_t entry2_line_number) { |
| 549 | error_messages_.push_back( |
| 550 | base::StringPrintf("Line %d and %d : %s", |
| 551 | static_cast<int>(entry1_line_number), |
| 552 | static_cast<int>(entry2_line_number), |
| 553 | message.c_str())); |
| 554 | } |
| 555 | |
[email protected] | db78bca5 | 2012-01-27 01:53:58 | [diff] [blame] | 556 | GPUTestExpectationsParser:: GPUTestExpectationEntry::GPUTestExpectationEntry() |
| 557 | : test_expectation(0), |
| 558 | line_number(0) { |
| 559 | } |
| 560 | |
[email protected] | 129f019e | 2013-05-28 23:38:02 | [diff] [blame] | 561 | } // namespace gpu |
| 562 | |