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 || 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
) {
51 return GPUTestConfig::kOsMacLeopard
;
53 return GPUTestConfig::kOsMacSnowLeopard
;
55 return GPUTestConfig::kOsMacLion
;
57 return GPUTestConfig::kOsMacMountainLion
;
59 return GPUTestConfig::kOsMacMavericks
;
62 #elif defined(OS_ANDROID)
63 return GPUTestConfig::kOsAndroid
;
65 return GPUTestConfig::kOsUnknown
;
68 } // namespace anonymous
70 GPUTestConfig::GPUTestConfig()
71 : validate_gpu_info_(true),
74 build_type_(kBuildTypeUnknown
) {
77 GPUTestConfig::~GPUTestConfig() {
80 void GPUTestConfig::set_os(int32 os
) {
81 DCHECK_EQ(0, os
& ~(kOsAndroid
| kOsWin
| kOsMac
| kOsLinux
| kOsChromeOS
));
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
) {
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_
)
104 if (gpu_device_id_
!= 0 && (gpu_vendor_
.size() != 1 || gpu_vendor_
[0] == 0))
109 bool GPUTestConfig::OverlapsWith(const GPUTestConfig
& config
) const {
111 DCHECK(config
.IsValid());
112 if (config
.os_
!= kOsUnknown
&& os_
!= kOsUnknown
&&
113 (os_
& config
.os_
) == 0)
115 if (config
.gpu_vendor_
.size() > 0 && gpu_vendor_
.size() > 0) {
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
]) {
128 if (config
.gpu_device_id_
!= 0 && gpu_device_id_
!= 0 &&
129 gpu_device_id_
!= config
.gpu_device_id_
)
131 if (config
.build_type_
!= kBuildTypeUnknown
&&
132 build_type_
!= kBuildTypeUnknown
&&
133 (build_type_
& config
.build_type_
) == 0)
138 void GPUTestConfig::DisableGPUInfoValidation() {
139 validate_gpu_info_
= false;
142 void GPUTestConfig::ClearGPUVendor() {
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)
159 AddGPUVendor(gpu_info
.gpu
.vendor_id
);
160 set_gpu_device_id(gpu_info
.gpu
.device_id
);
164 bool GPUTestBotConfig::IsValid() const {
171 case kOsMacSnowLeopard
:
173 case kOsMacMountainLion
:
174 case kOsMacMavericks
:
182 if (validate_gpu_info_
) {
183 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
185 if (gpu_device_id() == 0)
188 switch (build_type()) {
189 case kBuildTypeRelease
:
190 case kBuildTypeDebug
:
198 bool GPUTestBotConfig::Matches(const GPUTestConfig
& config
) const {
200 DCHECK(config
.IsValid());
201 if (config
.os() != kOsUnknown
&& (os() & config
.os()) == 0)
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]) {
214 if (config
.gpu_device_id() != 0 &&
215 gpu_device_id() != config
.gpu_device_id())
217 if (config
.build_type() != kBuildTypeUnknown
&&
218 (build_type() & config
.build_type()) == 0)
223 bool GPUTestBotConfig::Matches(const std::string
& config_data
) const {
224 GPUTestExpectationsParser parser
;
225 GPUTestConfig config
;
227 if (!parser
.ParseConfig(config_data
, &config
))
229 return Matches(config
);
232 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo
* gpu_info
) {
234 if (gpu_info
== NULL
) {
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();
244 rt
= SetGPUInfo(my_gpu_info
);
247 rt
= SetGPUInfo(*gpu_info
);
249 set_os(GetCurrentOS());
250 if (os() == kOsUnknown
) {
251 LOG(ERROR
) << "Unknown OS";
255 set_build_type(kBuildTypeRelease
);
257 set_build_type(kBuildTypeDebug
);
263 bool GPUTestBotConfig::CurrentConfigMatches(const std::string
& config_data
) {
264 GPUTestBotConfig my_config
;
265 if (!my_config
.LoadCurrentConfig(NULL
))
267 return my_config
.Matches(config_data
);
271 bool GPUTestBotConfig::CurrentConfigMatches(
272 const std::vector
<std::string
>& configs
) {
273 GPUTestBotConfig my_config
;
274 if (!my_config
.LoadCurrentConfig(NULL
))
276 for (size_t i
= 0 ; i
< configs
.size(); ++i
) {
277 if (my_config
.Matches(configs
[i
]))
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()) {
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
) {