OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/config/gpu_test_expectations_parser.h" | 5 #include "gpu/config/gpu_test_expectations_parser.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 11 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
12 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
13 | 16 |
14 namespace gpu { | 17 namespace gpu { |
15 | 18 |
16 namespace { | 19 namespace { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 kNumberOfExactMatchTokens, | 73 kNumberOfExactMatchTokens, |
71 | 74 |
72 // others | 75 // others |
73 kConfigGPUDeviceID, | 76 kConfigGPUDeviceID, |
74 kTokenComment, | 77 kTokenComment, |
75 kTokenWord, | 78 kTokenWord, |
76 }; | 79 }; |
77 | 80 |
78 struct TokenInfo { | 81 struct TokenInfo { |
79 const char* name; | 82 const char* name; |
80 int32 flag; | 83 int32_t flag; |
81 }; | 84 }; |
82 | 85 |
83 const TokenInfo kTokenData[] = { | 86 const TokenInfo kTokenData[] = { |
84 {"xp", GPUTestConfig::kOsWinXP}, | 87 {"xp", GPUTestConfig::kOsWinXP}, |
85 {"vista", GPUTestConfig::kOsWinVista}, | 88 {"vista", GPUTestConfig::kOsWinVista}, |
86 {"win7", GPUTestConfig::kOsWin7}, | 89 {"win7", GPUTestConfig::kOsWin7}, |
87 {"win8", GPUTestConfig::kOsWin8}, | 90 {"win8", GPUTestConfig::kOsWin8}, |
88 {"win10", GPUTestConfig::kOsWin10}, | 91 {"win10", GPUTestConfig::kOsWin10}, |
89 {"win", GPUTestConfig::kOsWin}, | 92 {"win", GPUTestConfig::kOsWin}, |
90 {"leopard", GPUTestConfig::kOsMacLeopard}, | 93 {"leopard", GPUTestConfig::kOsMacLeopard}, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 "entry with expectation modifier conflicts", | 147 "entry with expectation modifier conflicts", |
145 "two entries' configs overlap", | 148 "two entries' configs overlap", |
146 }; | 149 }; |
147 | 150 |
148 Token ParseToken(const std::string& word) { | 151 Token ParseToken(const std::string& word) { |
149 if (base::StartsWith(word, "//", base::CompareCase::INSENSITIVE_ASCII)) | 152 if (base::StartsWith(word, "//", base::CompareCase::INSENSITIVE_ASCII)) |
150 return kTokenComment; | 153 return kTokenComment; |
151 if (base::StartsWith(word, "0x", base::CompareCase::INSENSITIVE_ASCII)) | 154 if (base::StartsWith(word, "0x", base::CompareCase::INSENSITIVE_ASCII)) |
152 return kConfigGPUDeviceID; | 155 return kConfigGPUDeviceID; |
153 | 156 |
154 for (int32 i = 0; i < kNumberOfExactMatchTokens; ++i) { | 157 for (int32_t i = 0; i < kNumberOfExactMatchTokens; ++i) { |
155 if (base::LowerCaseEqualsASCII(word, kTokenData[i].name)) | 158 if (base::LowerCaseEqualsASCII(word, kTokenData[i].name)) |
156 return static_cast<Token>(i); | 159 return static_cast<Token>(i); |
157 } | 160 } |
158 return kTokenWord; | 161 return kTokenWord; |
159 } | 162 } |
160 | 163 |
161 // reference name can have the last character as *. | 164 // reference name can have the last character as *. |
162 bool NamesMatching(const std::string& ref, const std::string& test_name) { | 165 bool NamesMatching(const std::string& ref, const std::string& test_name) { |
163 size_t len = ref.length(); | 166 size_t len = ref.length(); |
164 if (len == 0) | 167 if (len == 0) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 error_messages_.clear(); | 213 error_messages_.clear(); |
211 | 214 |
212 std::string data; | 215 std::string data; |
213 if (!base::ReadFileToString(path, &data)) { | 216 if (!base::ReadFileToString(path, &data)) { |
214 error_messages_.push_back(kErrorMessage[kErrorFileIO]); | 217 error_messages_.push_back(kErrorMessage[kErrorFileIO]); |
215 return false; | 218 return false; |
216 } | 219 } |
217 return LoadTestExpectations(data); | 220 return LoadTestExpectations(data); |
218 } | 221 } |
219 | 222 |
220 int32 GPUTestExpectationsParser::GetTestExpectation( | 223 int32_t GPUTestExpectationsParser::GetTestExpectation( |
221 const std::string& test_name, | 224 const std::string& test_name, |
222 const GPUTestBotConfig& bot_config) const { | 225 const GPUTestBotConfig& bot_config) const { |
223 for (size_t i = 0; i < entries_.size(); ++i) { | 226 for (size_t i = 0; i < entries_.size(); ++i) { |
224 if (NamesMatching(entries_[i].test_name, test_name) && | 227 if (NamesMatching(entries_[i].test_name, test_name) && |
225 bot_config.Matches(entries_[i].test_config)) | 228 bot_config.Matches(entries_[i].test_config)) |
226 return entries_[i].test_expectation; | 229 return entries_[i].test_expectation; |
227 } | 230 } |
228 return kGpuTestPass; | 231 return kGpuTestPass; |
229 } | 232 } |
230 | 233 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 } | 287 } |
285 } | 288 } |
286 return true; | 289 return true; |
287 } | 290 } |
288 | 291 |
289 bool GPUTestExpectationsParser::ParseLine( | 292 bool GPUTestExpectationsParser::ParseLine( |
290 const std::string& line_data, size_t line_number) { | 293 const std::string& line_data, size_t line_number) { |
291 std::vector<std::string> tokens = base::SplitString( | 294 std::vector<std::string> tokens = base::SplitString( |
292 line_data, base::kWhitespaceASCII, base::KEEP_WHITESPACE, | 295 line_data, base::kWhitespaceASCII, base::KEEP_WHITESPACE, |
293 base::SPLIT_WANT_NONEMPTY); | 296 base::SPLIT_WANT_NONEMPTY); |
294 int32 stage = kLineParserBegin; | 297 int32_t stage = kLineParserBegin; |
295 GPUTestExpectationEntry entry; | 298 GPUTestExpectationEntry entry; |
296 entry.line_number = line_number; | 299 entry.line_number = line_number; |
297 GPUTestConfig& config = entry.test_config; | 300 GPUTestConfig& config = entry.test_config; |
298 bool comments_encountered = false; | 301 bool comments_encountered = false; |
299 for (size_t i = 0; i < tokens.size() && !comments_encountered; ++i) { | 302 for (size_t i = 0; i < tokens.size() && !comments_encountered; ++i) { |
300 Token token = ParseToken(tokens[i]); | 303 Token token = ParseToken(tokens[i]); |
301 switch (token) { | 304 switch (token) { |
302 case kTokenComment: | 305 case kTokenComment: |
303 comments_encountered = true; | 306 comments_encountered = true; |
304 break; | 307 break; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 PushErrorMessage(kErrorMessage[kErrorInvalidEntry], line_number); | 415 PushErrorMessage(kErrorMessage[kErrorInvalidEntry], line_number); |
413 return false; | 416 return false; |
414 } | 417 } |
415 entries_.push_back(entry); | 418 entries_.push_back(entry); |
416 return true; | 419 return true; |
417 } | 420 } |
418 PushErrorMessage(kErrorMessage[kErrorIllegalEntry], line_number); | 421 PushErrorMessage(kErrorMessage[kErrorIllegalEntry], line_number); |
419 return false; | 422 return false; |
420 } | 423 } |
421 | 424 |
422 bool GPUTestExpectationsParser::UpdateTestConfig( | 425 bool GPUTestExpectationsParser::UpdateTestConfig(GPUTestConfig* config, |
423 GPUTestConfig* config, int32 token, size_t line_number) { | 426 int32_t token, |
| 427 size_t line_number) { |
424 DCHECK(config); | 428 DCHECK(config); |
425 switch (token) { | 429 switch (token) { |
426 case kConfigWinXP: | 430 case kConfigWinXP: |
427 case kConfigWinVista: | 431 case kConfigWinVista: |
428 case kConfigWin7: | 432 case kConfigWin7: |
429 case kConfigWin8: | 433 case kConfigWin8: |
430 case kConfigWin10: | 434 case kConfigWin10: |
431 case kConfigWin: | 435 case kConfigWin: |
432 case kConfigMacLeopard: | 436 case kConfigMacLeopard: |
433 case kConfigMacSnowLeopard: | 437 case kConfigMacSnowLeopard: |
(...skipping 11 matching lines...) Expand all Loading... |
445 line_number); | 449 line_number); |
446 return false; | 450 return false; |
447 } | 451 } |
448 config->set_os(config->os() | kTokenData[token].flag); | 452 config->set_os(config->os() | kTokenData[token].flag); |
449 break; | 453 break; |
450 case kConfigNVidia: | 454 case kConfigNVidia: |
451 case kConfigAMD: | 455 case kConfigAMD: |
452 case kConfigIntel: | 456 case kConfigIntel: |
453 case kConfigVMWare: | 457 case kConfigVMWare: |
454 { | 458 { |
455 uint32 gpu_vendor = | 459 uint32_t gpu_vendor = static_cast<uint32_t>(kTokenData[token].flag); |
456 static_cast<uint32>(kTokenData[token].flag); | |
457 for (size_t i = 0; i < config->gpu_vendor().size(); ++i) { | 460 for (size_t i = 0; i < config->gpu_vendor().size(); ++i) { |
458 if (config->gpu_vendor()[i] == gpu_vendor) { | 461 if (config->gpu_vendor()[i] == gpu_vendor) { |
459 PushErrorMessage( | 462 PushErrorMessage( |
460 kErrorMessage[kErrorEntryWithGpuVendorConflicts], | 463 kErrorMessage[kErrorEntryWithGpuVendorConflicts], |
461 line_number); | 464 line_number); |
462 return false; | 465 return false; |
463 } | 466 } |
464 } | 467 } |
465 config->AddGPUVendor(gpu_vendor); | 468 config->AddGPUVendor(gpu_vendor); |
466 } | 469 } |
(...skipping 25 matching lines...) Expand all Loading... |
492 break; | 495 break; |
493 } | 496 } |
494 return true; | 497 return true; |
495 } | 498 } |
496 | 499 |
497 bool GPUTestExpectationsParser::UpdateTestConfig( | 500 bool GPUTestExpectationsParser::UpdateTestConfig( |
498 GPUTestConfig* config, | 501 GPUTestConfig* config, |
499 const std::string& gpu_device_id, | 502 const std::string& gpu_device_id, |
500 size_t line_number) { | 503 size_t line_number) { |
501 DCHECK(config); | 504 DCHECK(config); |
502 uint32 device_id = 0; | 505 uint32_t device_id = 0; |
503 if (config->gpu_device_id() != 0 || | 506 if (config->gpu_device_id() != 0 || |
504 !base::HexStringToUInt(gpu_device_id, &device_id) || | 507 !base::HexStringToUInt(gpu_device_id, &device_id) || |
505 device_id == 0) { | 508 device_id == 0) { |
506 PushErrorMessage(kErrorMessage[kErrorEntryWithGpuDeviceIdConflicts], | 509 PushErrorMessage(kErrorMessage[kErrorEntryWithGpuDeviceIdConflicts], |
507 line_number); | 510 line_number); |
508 return false; | 511 return false; |
509 } | 512 } |
510 config->set_gpu_device_id(device_id); | 513 config->set_gpu_device_id(device_id); |
511 return true; | 514 return true; |
512 } | 515 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 message.c_str())); | 548 message.c_str())); |
546 } | 549 } |
547 | 550 |
548 GPUTestExpectationsParser:: GPUTestExpectationEntry::GPUTestExpectationEntry() | 551 GPUTestExpectationsParser:: GPUTestExpectationEntry::GPUTestExpectationEntry() |
549 : test_expectation(0), | 552 : test_expectation(0), |
550 line_number(0) { | 553 line_number(0) { |
551 } | 554 } |
552 | 555 |
553 } // namespace gpu | 556 } // namespace gpu |
554 | 557 |
OLD | NEW |