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"
16 #include "base/win/windows_version.h"
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
;
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
) {
51 return GPUTestConfig::kOsMacLeopard
;
53 return GPUTestConfig::kOsMacSnowLeopard
;
55 return GPUTestConfig::kOsMacLion
;
57 return GPUTestConfig::kOsMacMountainLion
;
60 #elif defined(OS_ANDROID)
61 return GPUTestConfig::kOsAndroid
;
63 return GPUTestConfig::kOsUnknown
;
66 } // namespace anonymous
68 GPUTestConfig::GPUTestConfig()
69 : validate_gpu_info_(true),
72 build_type_(kBuildTypeUnknown
) {
75 GPUTestConfig::~GPUTestConfig() {
78 void GPUTestConfig::set_os(int32 os
) {
79 DCHECK_EQ(0, os
& ~(kOsAndroid
| kOsWin
| kOsMac
| kOsLinux
| kOsChromeOS
));
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
) {
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_
)
102 if (gpu_device_id_
!= 0 && (gpu_vendor_
.size() != 1 || gpu_vendor_
[0] == 0))
107 bool GPUTestConfig::OverlapsWith(const GPUTestConfig
& config
) const {
109 DCHECK(config
.IsValid());
110 if (config
.os_
!= kOsUnknown
&& os_
!= kOsUnknown
&&
111 (os_
& config
.os_
) == 0)
113 if (config
.gpu_vendor_
.size() > 0 && gpu_vendor_
.size() > 0) {
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
]) {
126 if (config
.gpu_device_id_
!= 0 && gpu_device_id_
!= 0 &&
127 gpu_device_id_
!= config
.gpu_device_id_
)
129 if (config
.build_type_
!= kBuildTypeUnknown
&&
130 build_type_
!= kBuildTypeUnknown
&&
131 (build_type_
& config
.build_type_
) == 0)
136 void GPUTestConfig::DisableGPUInfoValidation() {
137 validate_gpu_info_
= false;
140 void GPUTestConfig::ClearGPUVendor() {
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)
157 AddGPUVendor(gpu_info
.gpu
.vendor_id
);
158 set_gpu_device_id(gpu_info
.gpu
.device_id
);
162 bool GPUTestBotConfig::IsValid() const {
169 case kOsMacSnowLeopard
:
171 case kOsMacMountainLion
:
179 if (validate_gpu_info_
) {
180 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
182 if (gpu_device_id() == 0)
185 switch (build_type()) {
186 case kBuildTypeRelease
:
187 case kBuildTypeDebug
:
195 bool GPUTestBotConfig::Matches(const GPUTestConfig
& config
) const {
197 DCHECK(config
.IsValid());
198 if (config
.os() != kOsUnknown
&& (os() & config
.os()) == 0)
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]) {
211 if (config
.gpu_device_id() != 0 &&
212 gpu_device_id() != config
.gpu_device_id())
214 if (config
.build_type() != kBuildTypeUnknown
&&
215 (build_type() & config
.build_type()) == 0)
220 bool GPUTestBotConfig::Matches(const std::string
& config_data
) const {
221 GPUTestExpectationsParser parser
;
222 GPUTestConfig config
;
224 if (!parser
.ParseConfig(config_data
, &config
))
226 return Matches(config
);
229 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo
* gpu_info
) {
231 if (gpu_info
== NULL
) {
234 result
= CollectGpuID(&my_gpu_info
.gpu
.vendor_id
,
235 &my_gpu_info
.gpu
.device_id
);
236 if (result
== kGpuIDNotSupported
) {
237 DisableGPUInfoValidation();
240 rt
= SetGPUInfo(my_gpu_info
);
243 rt
= SetGPUInfo(*gpu_info
);
245 set_os(GetCurrentOS());
246 if (os() == kOsUnknown
)
249 set_build_type(kBuildTypeRelease
);
251 set_build_type(kBuildTypeDebug
);
257 bool GPUTestBotConfig::CurrentConfigMatches(const std::string
& config_data
) {
258 GPUTestBotConfig my_config
;
259 if (!my_config
.LoadCurrentConfig(NULL
))
261 return my_config
.Matches(config_data
);
265 bool GPUTestBotConfig::CurrentConfigMatches(
266 const std::vector
<std::string
>& configs
) {
267 GPUTestBotConfig my_config
;
268 if (!my_config
.LoadCurrentConfig(NULL
))
270 for (size_t i
= 0 ; i
< configs
.size(); ++i
) {
271 if (my_config
.Matches(configs
[i
]))
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()) {
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
) {