Remove support for specifying version on command line.
[chromium-blink-merge.git] / gpu / config / gpu_test_config.cc
blob35a85ce068f2af1e841c1aaf783c688bd5e8645e
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)
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;
60 #elif defined(OS_ANDROID)
61 return GPUTestConfig::kOsAndroid;
62 #endif
63 return GPUTestConfig::kOsUnknown;
66 } // namespace anonymous
68 GPUTestConfig::GPUTestConfig()
69 : validate_gpu_info_(true),
70 os_(kOsUnknown),
71 gpu_device_id_(0),
72 build_type_(kBuildTypeUnknown) {
75 GPUTestConfig::~GPUTestConfig() {
78 void GPUTestConfig::set_os(int32 os) {
79 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
80 os_ = os;
83 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) {
84 DCHECK_NE(0u, gpu_vendor);
85 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
86 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
87 gpu_vendor_.push_back(gpu_vendor);
90 void GPUTestConfig::set_gpu_device_id(uint32 id) {
91 gpu_device_id_ = id;
94 void GPUTestConfig::set_build_type(int32 build_type) {
95 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
96 build_type_ = build_type;
99 bool GPUTestConfig::IsValid() const {
100 if (!validate_gpu_info_)
101 return true;
102 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
103 return false;
104 return true;
107 bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
108 DCHECK(IsValid());
109 DCHECK(config.IsValid());
110 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
111 (os_ & config.os_) == 0)
112 return false;
113 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
114 bool shared = false;
115 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
116 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
117 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
118 shared = true;
119 break;
123 if (!shared)
124 return false;
126 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
127 gpu_device_id_ != config.gpu_device_id_)
128 return false;
129 if (config.build_type_ != kBuildTypeUnknown &&
130 build_type_ != kBuildTypeUnknown &&
131 (build_type_ & config.build_type_) == 0)
132 return false;
133 return true;
136 void GPUTestConfig::DisableGPUInfoValidation() {
137 validate_gpu_info_ = false;
140 void GPUTestConfig::ClearGPUVendor() {
141 gpu_vendor_.clear();
144 GPUTestBotConfig::~GPUTestBotConfig() {
147 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) {
148 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
149 GPUTestConfig::AddGPUVendor(gpu_vendor);
152 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) {
153 DCHECK(validate_gpu_info_);
154 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
155 return false;
156 ClearGPUVendor();
157 AddGPUVendor(gpu_info.gpu.vendor_id);
158 set_gpu_device_id(gpu_info.gpu.device_id);
159 return true;
162 bool GPUTestBotConfig::IsValid() const {
163 switch (os()) {
164 case kOsWinXP:
165 case kOsWinVista:
166 case kOsWin7:
167 case kOsWin8:
168 case kOsMacLeopard:
169 case kOsMacSnowLeopard:
170 case kOsMacLion:
171 case kOsMacMountainLion:
172 case kOsLinux:
173 case kOsChromeOS:
174 case kOsAndroid:
175 break;
176 default:
177 return false;
179 if (validate_gpu_info_) {
180 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
181 return false;
182 if (gpu_device_id() == 0)
183 return false;
185 switch (build_type()) {
186 case kBuildTypeRelease:
187 case kBuildTypeDebug:
188 break;
189 default:
190 return false;
192 return true;
195 bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
196 DCHECK(IsValid());
197 DCHECK(config.IsValid());
198 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
199 return false;
200 if (config.gpu_vendor().size() > 0) {
201 bool contained = false;
202 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
203 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
204 contained = true;
205 break;
208 if (!contained)
209 return false;
211 if (config.gpu_device_id() != 0 &&
212 gpu_device_id() != config.gpu_device_id())
213 return false;
214 if (config.build_type() != kBuildTypeUnknown &&
215 (build_type() & config.build_type()) == 0)
216 return false;
217 return true;
220 bool GPUTestBotConfig::Matches(const std::string& config_data) const {
221 GPUTestExpectationsParser parser;
222 GPUTestConfig config;
224 if (!parser.ParseConfig(config_data, &config))
225 return false;
226 return Matches(config);
229 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) {
230 bool rt;
231 if (gpu_info == NULL) {
232 GPUInfo my_gpu_info;
233 GpuIDResult result;
234 result = CollectGpuID(&my_gpu_info.gpu.vendor_id,
235 &my_gpu_info.gpu.device_id);
236 if (result == kGpuIDNotSupported) {
237 DisableGPUInfoValidation();
238 rt = true;
239 } else {
240 rt = SetGPUInfo(my_gpu_info);
242 } else {
243 rt = SetGPUInfo(*gpu_info);
245 set_os(GetCurrentOS());
246 if (os() == kOsUnknown)
247 rt = false;
248 #if defined(NDEBUG)
249 set_build_type(kBuildTypeRelease);
250 #else
251 set_build_type(kBuildTypeDebug);
252 #endif
253 return rt;
256 // static
257 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
258 GPUTestBotConfig my_config;
259 if (!my_config.LoadCurrentConfig(NULL))
260 return false;
261 return my_config.Matches(config_data);
264 // static
265 bool GPUTestBotConfig::CurrentConfigMatches(
266 const std::vector<std::string>& configs) {
267 GPUTestBotConfig my_config;
268 if (!my_config.LoadCurrentConfig(NULL))
269 return false;
270 for (size_t i = 0 ; i < configs.size(); ++i) {
271 if (my_config.Matches(configs[i]))
272 return true;
274 return false;
277 // static
278 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
279 #if defined(OS_MACOSX)
280 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
281 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
282 return true;
284 #elif defined(OS_WIN)
285 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
286 if (base::win::GetVersion() <= base::win::VERSION_VISTA) {
287 return true;
289 #endif
290 return false;
293 } // namespace gpu