chrome: Cleanup some entries from presubmit's exclude list.
[chromium-blink-merge.git] / gpu / config / gpu_test_config.cc
blob2328bd663ec19839c5138d03e715dca55d46b9fc
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.
5 #include "gpu/config/gpu_test_config.h"
7 #include "base/logging.h"
8 #include "base/sys_info.h"
9 #include "gpu/config/gpu_info.h"
10 #include "gpu/config/gpu_info_collector.h"
11 #include "gpu/config/gpu_test_expectations_parser.h"
13 #if defined(OS_MACOSX)
14 #include "base/mac/mac_util.h"
15 #elif defined(OS_WIN)
16 #include "base/win/windows_version.h"
17 #endif
19 namespace gpu {
21 namespace {
23 GPUTestConfig::OS GetCurrentOS() {
24 #if defined(OS_CHROMEOS)
25 return GPUTestConfig::kOsChromeOS;
26 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
27 return GPUTestConfig::kOsLinux;
28 #elif defined(OS_WIN)
29 int32 major_version = 0;
30 int32 minor_version = 0;
31 int32 bugfix_version = 0;
32 base::SysInfo::OperatingSystemVersionNumbers(
33 &major_version, &minor_version, &bugfix_version);
34 if (major_version == 5)
35 return GPUTestConfig::kOsWinXP;
36 if (major_version == 6 && minor_version == 0)
37 return GPUTestConfig::kOsWinVista;
38 if (major_version == 6 && minor_version == 1)
39 return GPUTestConfig::kOsWin7;
40 if (major_version == 6 && (minor_version == 2 || minor_version == 3))
41 return GPUTestConfig::kOsWin8;
42 #elif defined(OS_MACOSX)
43 int32 major_version = 0;
44 int32 minor_version = 0;
45 int32 bugfix_version = 0;
46 base::SysInfo::OperatingSystemVersionNumbers(
47 &major_version, &minor_version, &bugfix_version);
48 if (major_version == 10) {
49 switch (minor_version) {
50 case 5:
51 return GPUTestConfig::kOsMacLeopard;
52 case 6:
53 return GPUTestConfig::kOsMacSnowLeopard;
54 case 7:
55 return GPUTestConfig::kOsMacLion;
56 case 8:
57 return GPUTestConfig::kOsMacMountainLion;
58 case 9:
59 return GPUTestConfig::kOsMacMavericks;
62 #elif defined(OS_ANDROID)
63 return GPUTestConfig::kOsAndroid;
64 #endif
65 return GPUTestConfig::kOsUnknown;
68 } // namespace anonymous
70 GPUTestConfig::GPUTestConfig()
71 : validate_gpu_info_(true),
72 os_(kOsUnknown),
73 gpu_device_id_(0),
74 build_type_(kBuildTypeUnknown) {
77 GPUTestConfig::~GPUTestConfig() {
80 void GPUTestConfig::set_os(int32 os) {
81 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
82 os_ = os;
85 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) {
86 DCHECK_NE(0u, gpu_vendor);
87 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
88 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
89 gpu_vendor_.push_back(gpu_vendor);
92 void GPUTestConfig::set_gpu_device_id(uint32 id) {
93 gpu_device_id_ = id;
96 void GPUTestConfig::set_build_type(int32 build_type) {
97 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
98 build_type_ = build_type;
101 bool GPUTestConfig::IsValid() const {
102 if (!validate_gpu_info_)
103 return true;
104 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
105 return false;
106 return true;
109 bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
110 DCHECK(IsValid());
111 DCHECK(config.IsValid());
112 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
113 (os_ & config.os_) == 0)
114 return false;
115 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
116 bool shared = false;
117 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
118 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
119 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
120 shared = true;
121 break;
125 if (!shared)
126 return false;
128 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
129 gpu_device_id_ != config.gpu_device_id_)
130 return false;
131 if (config.build_type_ != kBuildTypeUnknown &&
132 build_type_ != kBuildTypeUnknown &&
133 (build_type_ & config.build_type_) == 0)
134 return false;
135 return true;
138 void GPUTestConfig::DisableGPUInfoValidation() {
139 validate_gpu_info_ = false;
142 void GPUTestConfig::ClearGPUVendor() {
143 gpu_vendor_.clear();
146 GPUTestBotConfig::~GPUTestBotConfig() {
149 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) {
150 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
151 GPUTestConfig::AddGPUVendor(gpu_vendor);
154 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) {
155 DCHECK(validate_gpu_info_);
156 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
157 return false;
158 ClearGPUVendor();
159 AddGPUVendor(gpu_info.gpu.vendor_id);
160 set_gpu_device_id(gpu_info.gpu.device_id);
161 return true;
164 bool GPUTestBotConfig::IsValid() const {
165 switch (os()) {
166 case kOsWinXP:
167 case kOsWinVista:
168 case kOsWin7:
169 case kOsWin8:
170 case kOsMacLeopard:
171 case kOsMacSnowLeopard:
172 case kOsMacLion:
173 case kOsMacMountainLion:
174 case kOsMacMavericks:
175 case kOsLinux:
176 case kOsChromeOS:
177 case kOsAndroid:
178 break;
179 default:
180 return false;
182 if (validate_gpu_info_) {
183 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
184 return false;
185 if (gpu_device_id() == 0)
186 return false;
188 switch (build_type()) {
189 case kBuildTypeRelease:
190 case kBuildTypeDebug:
191 break;
192 default:
193 return false;
195 return true;
198 bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
199 DCHECK(IsValid());
200 DCHECK(config.IsValid());
201 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
202 return false;
203 if (config.gpu_vendor().size() > 0) {
204 bool contained = false;
205 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
206 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
207 contained = true;
208 break;
211 if (!contained)
212 return false;
214 if (config.gpu_device_id() != 0 &&
215 gpu_device_id() != config.gpu_device_id())
216 return false;
217 if (config.build_type() != kBuildTypeUnknown &&
218 (build_type() & config.build_type()) == 0)
219 return false;
220 return true;
223 bool GPUTestBotConfig::Matches(const std::string& config_data) const {
224 GPUTestExpectationsParser parser;
225 GPUTestConfig config;
227 if (!parser.ParseConfig(config_data, &config))
228 return false;
229 return Matches(config);
232 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) {
233 bool rt;
234 if (gpu_info == NULL) {
235 GPUInfo my_gpu_info;
236 CollectInfoResult result = CollectGpuID(
237 &my_gpu_info.gpu.vendor_id, &my_gpu_info.gpu.device_id);
238 if (result != kCollectInfoSuccess) {
239 LOG(ERROR) << "Fail to identify GPU";
240 DisableGPUInfoValidation();
241 rt = true;
242 } else {
243 rt = SetGPUInfo(my_gpu_info);
245 } else {
246 rt = SetGPUInfo(*gpu_info);
248 set_os(GetCurrentOS());
249 if (os() == kOsUnknown) {
250 LOG(ERROR) << "Unknown OS";
251 rt = false;
253 #if defined(NDEBUG)
254 set_build_type(kBuildTypeRelease);
255 #else
256 set_build_type(kBuildTypeDebug);
257 #endif
258 return rt;
261 // static
262 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
263 GPUTestBotConfig my_config;
264 if (!my_config.LoadCurrentConfig(NULL))
265 return false;
266 return my_config.Matches(config_data);
269 // static
270 bool GPUTestBotConfig::CurrentConfigMatches(
271 const std::vector<std::string>& configs) {
272 GPUTestBotConfig my_config;
273 if (!my_config.LoadCurrentConfig(NULL))
274 return false;
275 for (size_t i = 0 ; i < configs.size(); ++i) {
276 if (my_config.Matches(configs[i]))
277 return true;
279 return false;
282 // static
283 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
284 #if defined(OS_MACOSX)
285 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
286 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
287 return true;
289 #elif defined(OS_WIN)
290 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
291 if (base::win::GetVersion() <= base::win::VERSION_VISTA) {
292 return true;
294 #endif
295 return false;
298 } // namespace gpu