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 if (major_version
== 10)
43 return GPUTestConfig::kOsWin10
;
44 #elif defined(OS_MACOSX)
45 int32 major_version
= 0;
46 int32 minor_version
= 0;
47 int32 bugfix_version
= 0;
48 base::SysInfo::OperatingSystemVersionNumbers(
49 &major_version
, &minor_version
, &bugfix_version
);
50 if (major_version
== 10) {
51 switch (minor_version
) {
53 return GPUTestConfig::kOsMacLeopard
;
55 return GPUTestConfig::kOsMacSnowLeopard
;
57 return GPUTestConfig::kOsMacLion
;
59 return GPUTestConfig::kOsMacMountainLion
;
61 return GPUTestConfig::kOsMacMavericks
;
63 return GPUTestConfig::kOsMacYosemite
;
66 #elif defined(OS_ANDROID)
67 return GPUTestConfig::kOsAndroid
;
69 return GPUTestConfig::kOsUnknown
;
72 } // namespace anonymous
74 GPUTestConfig::GPUTestConfig()
75 : validate_gpu_info_(true),
78 build_type_(kBuildTypeUnknown
),
81 GPUTestConfig::~GPUTestConfig() {
84 void GPUTestConfig::set_os(int32 os
) {
85 DCHECK_EQ(0, os
& ~(kOsAndroid
| kOsWin
| kOsMac
| kOsLinux
| kOsChromeOS
));
89 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor
) {
90 DCHECK_NE(0u, gpu_vendor
);
91 for (size_t i
= 0; i
< gpu_vendor_
.size(); ++i
)
92 DCHECK_NE(gpu_vendor_
[i
], gpu_vendor
);
93 gpu_vendor_
.push_back(gpu_vendor
);
96 void GPUTestConfig::set_gpu_device_id(uint32 id
) {
100 void GPUTestConfig::set_build_type(int32 build_type
) {
101 DCHECK_EQ(0, build_type
& ~(kBuildTypeRelease
| kBuildTypeDebug
));
102 build_type_
= build_type
;
105 void GPUTestConfig::set_api(int32 api
) {
106 DCHECK_EQ(0, api
& ~(kAPID3D9
| kAPID3D11
| kAPIGLDesktop
| kAPIGLES
));
110 bool GPUTestConfig::IsValid() const {
111 if (!validate_gpu_info_
)
113 if (gpu_device_id_
!= 0 && (gpu_vendor_
.size() != 1 || gpu_vendor_
[0] == 0))
118 bool GPUTestConfig::OverlapsWith(const GPUTestConfig
& config
) const {
120 DCHECK(config
.IsValid());
121 if (config
.os_
!= kOsUnknown
&& os_
!= kOsUnknown
&&
122 (os_
& config
.os_
) == 0)
124 if (config
.gpu_vendor_
.size() > 0 && gpu_vendor_
.size() > 0) {
126 for (size_t i
= 0; i
< config
.gpu_vendor_
.size() && !shared
; ++i
) {
127 for (size_t j
= 0; j
< gpu_vendor_
.size(); ++j
) {
128 if (config
.gpu_vendor_
[i
] == gpu_vendor_
[j
]) {
137 if (config
.gpu_device_id_
!= 0 && gpu_device_id_
!= 0 &&
138 gpu_device_id_
!= config
.gpu_device_id_
)
140 if (config
.build_type_
!= kBuildTypeUnknown
&&
141 build_type_
!= kBuildTypeUnknown
&&
142 (build_type_
& config
.build_type_
) == 0)
147 void GPUTestConfig::DisableGPUInfoValidation() {
148 validate_gpu_info_
= false;
151 void GPUTestConfig::ClearGPUVendor() {
155 GPUTestBotConfig::~GPUTestBotConfig() {
158 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor
) {
159 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
160 GPUTestConfig::AddGPUVendor(gpu_vendor
);
163 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo
& gpu_info
) {
164 DCHECK(validate_gpu_info_
);
165 if (gpu_info
.gpu
.device_id
== 0 || gpu_info
.gpu
.vendor_id
== 0)
168 AddGPUVendor(gpu_info
.gpu
.vendor_id
);
169 set_gpu_device_id(gpu_info
.gpu
.device_id
);
173 bool GPUTestBotConfig::IsValid() const {
181 case kOsMacSnowLeopard
:
183 case kOsMacMountainLion
:
184 case kOsMacMavericks
:
193 if (validate_gpu_info_
) {
194 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
196 if (gpu_device_id() == 0)
199 switch (build_type()) {
200 case kBuildTypeRelease
:
201 case kBuildTypeDebug
:
209 bool GPUTestBotConfig::Matches(const GPUTestConfig
& config
) const {
211 DCHECK(config
.IsValid());
212 if (config
.os() != kOsUnknown
&& (os() & config
.os()) == 0)
214 if (config
.gpu_vendor().size() > 0) {
215 bool contained
= false;
216 for (size_t i
= 0; i
< config
.gpu_vendor().size(); ++i
) {
217 if (config
.gpu_vendor()[i
] == gpu_vendor()[0]) {
225 if (config
.gpu_device_id() != 0 &&
226 gpu_device_id() != config
.gpu_device_id())
228 if (config
.build_type() != kBuildTypeUnknown
&&
229 (build_type() & config
.build_type()) == 0)
231 if (config
.api() != 0 && (api() & config
.api()) == 0)
236 bool GPUTestBotConfig::Matches(const std::string
& config_data
) const {
237 GPUTestExpectationsParser parser
;
238 GPUTestConfig config
;
240 if (!parser
.ParseConfig(config_data
, &config
))
242 return Matches(config
);
245 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo
* gpu_info
) {
247 if (gpu_info
== NULL
) {
249 CollectInfoResult result
= CollectGpuID(
250 &my_gpu_info
.gpu
.vendor_id
, &my_gpu_info
.gpu
.device_id
);
251 if (result
!= kCollectInfoSuccess
) {
252 LOG(ERROR
) << "Fail to identify GPU";
253 DisableGPUInfoValidation();
256 rt
= SetGPUInfo(my_gpu_info
);
259 rt
= SetGPUInfo(*gpu_info
);
261 set_os(GetCurrentOS());
262 if (os() == kOsUnknown
) {
263 LOG(ERROR
) << "Unknown OS";
267 set_build_type(kBuildTypeRelease
);
269 set_build_type(kBuildTypeDebug
);
275 bool GPUTestBotConfig::CurrentConfigMatches(const std::string
& config_data
) {
276 GPUTestBotConfig my_config
;
277 if (!my_config
.LoadCurrentConfig(NULL
))
279 return my_config
.Matches(config_data
);
283 bool GPUTestBotConfig::CurrentConfigMatches(
284 const std::vector
<std::string
>& configs
) {
285 GPUTestBotConfig my_config
;
286 if (!my_config
.LoadCurrentConfig(NULL
))
288 for (size_t i
= 0 ; i
< configs
.size(); ++i
) {
289 if (my_config
.Matches(configs
[i
]))
296 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
297 #if defined(OS_MACOSX)
298 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
299 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
302 #elif defined(OS_WIN)
303 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
304 if (base::win::GetVersion() <= base::win::VERSION_VISTA
) {