[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / gpu / config / gpu_test_config.cc
blobe3d489c25fa656bfdedfcdd7dc89309924743b0c
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 GpuIDResult result;
237 result = CollectGpuID(&my_gpu_info.gpu.vendor_id,
238 &my_gpu_info.gpu.device_id);
239 if (result == kGpuIDNotSupported) {
240 LOG(ERROR) << "Fail to identify GPU";
241 DisableGPUInfoValidation();
242 rt = true;
243 } else {
244 rt = SetGPUInfo(my_gpu_info);
246 } else {
247 rt = SetGPUInfo(*gpu_info);
249 set_os(GetCurrentOS());
250 if (os() == kOsUnknown) {
251 LOG(ERROR) << "Unknown OS";
252 rt = false;
254 #if defined(NDEBUG)
255 set_build_type(kBuildTypeRelease);
256 #else
257 set_build_type(kBuildTypeDebug);
258 #endif
259 return rt;
262 // static
263 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
264 GPUTestBotConfig my_config;
265 if (!my_config.LoadCurrentConfig(NULL))
266 return false;
267 return my_config.Matches(config_data);
270 // static
271 bool GPUTestBotConfig::CurrentConfigMatches(
272 const std::vector<std::string>& configs) {
273 GPUTestBotConfig my_config;
274 if (!my_config.LoadCurrentConfig(NULL))
275 return false;
276 for (size_t i = 0 ; i < configs.size(); ++i) {
277 if (my_config.Matches(configs[i]))
278 return true;
280 return false;
283 // static
284 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
285 #if defined(OS_MACOSX)
286 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
287 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
288 return true;
290 #elif defined(OS_WIN)
291 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
292 if (base::win::GetVersion() <= base::win::VERSION_VISTA) {
293 return true;
295 #endif
296 return false;
299 } // namespace gpu