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
;
61 return GPUTestConfig::kOsMacYosemite
;
64 #elif defined(OS_ANDROID)
65 return GPUTestConfig::kOsAndroid
;
67 return GPUTestConfig::kOsUnknown
;
70 } // namespace anonymous
72 GPUTestConfig::GPUTestConfig()
73 : validate_gpu_info_(true),
76 build_type_(kBuildTypeUnknown
) {
79 GPUTestConfig::~GPUTestConfig() {
82 void GPUTestConfig::set_os(int32 os
) {
83 DCHECK_EQ(0, os
& ~(kOsAndroid
| kOsWin
| kOsMac
| kOsLinux
| kOsChromeOS
));
87 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor
) {
88 DCHECK_NE(0u, gpu_vendor
);
89 for (size_t i
= 0; i
< gpu_vendor_
.size(); ++i
)
90 DCHECK_NE(gpu_vendor_
[i
], gpu_vendor
);
91 gpu_vendor_
.push_back(gpu_vendor
);
94 void GPUTestConfig::set_gpu_device_id(uint32 id
) {
98 void GPUTestConfig::set_build_type(int32 build_type
) {
99 DCHECK_EQ(0, build_type
& ~(kBuildTypeRelease
| kBuildTypeDebug
));
100 build_type_
= build_type
;
103 bool GPUTestConfig::IsValid() const {
104 if (!validate_gpu_info_
)
106 if (gpu_device_id_
!= 0 && (gpu_vendor_
.size() != 1 || gpu_vendor_
[0] == 0))
111 bool GPUTestConfig::OverlapsWith(const GPUTestConfig
& config
) const {
113 DCHECK(config
.IsValid());
114 if (config
.os_
!= kOsUnknown
&& os_
!= kOsUnknown
&&
115 (os_
& config
.os_
) == 0)
117 if (config
.gpu_vendor_
.size() > 0 && gpu_vendor_
.size() > 0) {
119 for (size_t i
= 0; i
< config
.gpu_vendor_
.size() && !shared
; ++i
) {
120 for (size_t j
= 0; j
< gpu_vendor_
.size(); ++j
) {
121 if (config
.gpu_vendor_
[i
] == gpu_vendor_
[j
]) {
130 if (config
.gpu_device_id_
!= 0 && gpu_device_id_
!= 0 &&
131 gpu_device_id_
!= config
.gpu_device_id_
)
133 if (config
.build_type_
!= kBuildTypeUnknown
&&
134 build_type_
!= kBuildTypeUnknown
&&
135 (build_type_
& config
.build_type_
) == 0)
140 void GPUTestConfig::DisableGPUInfoValidation() {
141 validate_gpu_info_
= false;
144 void GPUTestConfig::ClearGPUVendor() {
148 GPUTestBotConfig::~GPUTestBotConfig() {
151 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor
) {
152 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
153 GPUTestConfig::AddGPUVendor(gpu_vendor
);
156 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo
& gpu_info
) {
157 DCHECK(validate_gpu_info_
);
158 if (gpu_info
.gpu
.device_id
== 0 || gpu_info
.gpu
.vendor_id
== 0)
161 AddGPUVendor(gpu_info
.gpu
.vendor_id
);
162 set_gpu_device_id(gpu_info
.gpu
.device_id
);
166 bool GPUTestBotConfig::IsValid() const {
173 case kOsMacSnowLeopard
:
175 case kOsMacMountainLion
:
176 case kOsMacMavericks
:
185 if (validate_gpu_info_
) {
186 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
188 if (gpu_device_id() == 0)
191 switch (build_type()) {
192 case kBuildTypeRelease
:
193 case kBuildTypeDebug
:
201 bool GPUTestBotConfig::Matches(const GPUTestConfig
& config
) const {
203 DCHECK(config
.IsValid());
204 if (config
.os() != kOsUnknown
&& (os() & config
.os()) == 0)
206 if (config
.gpu_vendor().size() > 0) {
207 bool contained
= false;
208 for (size_t i
= 0; i
< config
.gpu_vendor().size(); ++i
) {
209 if (config
.gpu_vendor()[i
] == gpu_vendor()[0]) {
217 if (config
.gpu_device_id() != 0 &&
218 gpu_device_id() != config
.gpu_device_id())
220 if (config
.build_type() != kBuildTypeUnknown
&&
221 (build_type() & config
.build_type()) == 0)
226 bool GPUTestBotConfig::Matches(const std::string
& config_data
) const {
227 GPUTestExpectationsParser parser
;
228 GPUTestConfig config
;
230 if (!parser
.ParseConfig(config_data
, &config
))
232 return Matches(config
);
235 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo
* gpu_info
) {
237 if (gpu_info
== NULL
) {
239 CollectInfoResult result
= CollectGpuID(
240 &my_gpu_info
.gpu
.vendor_id
, &my_gpu_info
.gpu
.device_id
);
241 if (result
!= kCollectInfoSuccess
) {
242 LOG(ERROR
) << "Fail to identify GPU";
243 DisableGPUInfoValidation();
246 rt
= SetGPUInfo(my_gpu_info
);
249 rt
= SetGPUInfo(*gpu_info
);
251 set_os(GetCurrentOS());
252 if (os() == kOsUnknown
) {
253 LOG(ERROR
) << "Unknown OS";
257 set_build_type(kBuildTypeRelease
);
259 set_build_type(kBuildTypeDebug
);
265 bool GPUTestBotConfig::CurrentConfigMatches(const std::string
& config_data
) {
266 GPUTestBotConfig my_config
;
267 if (!my_config
.LoadCurrentConfig(NULL
))
269 return my_config
.Matches(config_data
);
273 bool GPUTestBotConfig::CurrentConfigMatches(
274 const std::vector
<std::string
>& configs
) {
275 GPUTestBotConfig my_config
;
276 if (!my_config
.LoadCurrentConfig(NULL
))
278 for (size_t i
= 0 ; i
< configs
.size(); ++i
) {
279 if (my_config
.Matches(configs
[i
]))
286 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
287 #if defined(OS_MACOSX)
288 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
289 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
292 #elif defined(OS_WIN)
293 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
294 if (base::win::GetVersion() <= base::win::VERSION_VISTA
) {