blob: 543938a4ca7f36e5ac2e5a7d380a35c5136c5c10 [file] [log] [blame]
[email protected]1a6ad5f2012-01-25 04:29:581// 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.
4
[email protected]de53ac332012-01-25 20:02:515#include "content/test/gpu/gpu_test_config.h"
[email protected]1a6ad5f2012-01-25 04:29:586
7#include "base/logging.h"
8#include "base/sys_info.h"
[email protected]830631c2012-06-13 05:06:089#include "content/test/gpu/gpu_test_expectations_parser.h"
[email protected]d7b5cc72013-05-23 20:05:0010#include "gpu/config/gpu_info.h"
11#include "gpu/config/gpu_info_collector.h"
[email protected]1a6ad5f2012-01-25 04:29:5812
13namespace {
14
15GPUTestConfig::OS GetCurrentOS() {
16#if defined(OS_CHROMEOS)
17 return GPUTestConfig::kOsChromeOS;
18#elif defined(OS_LINUX) || defined(OS_OPENBSD)
19 return GPUTestConfig::kOsLinux;
20#elif defined(OS_WIN)
21 int32 major_version = 0;
22 int32 minor_version = 0;
23 int32 bugfix_version = 0;
24 base::SysInfo::OperatingSystemVersionNumbers(
25 &major_version, &minor_version, &bugfix_version);
26 if (major_version == 5)
27 return GPUTestConfig::kOsWinXP;
28 if (major_version == 6 && minor_version == 0)
29 return GPUTestConfig::kOsWinVista;
30 if (major_version == 6 && minor_version == 1)
31 return GPUTestConfig::kOsWin7;
[email protected]c9fc22f2012-11-16 23:39:5632 if (major_version == 6 && minor_version == 2)
33 return GPUTestConfig::kOsWin8;
[email protected]1a6ad5f2012-01-25 04:29:5834#elif defined(OS_MACOSX)
35 int32 major_version = 0;
36 int32 minor_version = 0;
37 int32 bugfix_version = 0;
38 base::SysInfo::OperatingSystemVersionNumbers(
39 &major_version, &minor_version, &bugfix_version);
40 if (major_version == 10) {
41 switch (minor_version) {
42 case 5:
43 return GPUTestConfig::kOsMacLeopard;
44 case 6:
45 return GPUTestConfig::kOsMacSnowLeopard;
46 case 7:
47 return GPUTestConfig::kOsMacLion;
[email protected]c9fc22f2012-11-16 23:39:5648 case 8:
49 return GPUTestConfig::kOsMacMountainLion;
[email protected]1a6ad5f2012-01-25 04:29:5850 }
51 }
[email protected]67d96b62012-07-24 03:38:2552#elif defined(OS_ANDROID)
53 return GPUTestConfig::kOsAndroid;
[email protected]1a6ad5f2012-01-25 04:29:5854#endif
55 return GPUTestConfig::kOsUnknown;
56}
57
58} // namespace anonymous
59
60GPUTestConfig::GPUTestConfig()
[email protected]b4ede6602013-05-15 16:46:5561 : validate_gpu_info_(true),
62 os_(kOsUnknown),
[email protected]1a6ad5f2012-01-25 04:29:5863 gpu_device_id_(0),
64 build_type_(kBuildTypeUnknown) {
65}
66
67GPUTestConfig::~GPUTestConfig() {
68}
69
70void GPUTestConfig::set_os(int32 os) {
[email protected]67d96b62012-07-24 03:38:2571 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
[email protected]1a6ad5f2012-01-25 04:29:5872 os_ = os;
73}
74
75void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) {
76 DCHECK_NE(0u, gpu_vendor);
77 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
78 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
79 gpu_vendor_.push_back(gpu_vendor);
80}
81
82void GPUTestConfig::set_gpu_device_id(uint32 id) {
83 gpu_device_id_ = id;
84}
85
86void GPUTestConfig::set_build_type(int32 build_type) {
87 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
88 build_type_ = build_type;
89}
90
91bool GPUTestConfig::IsValid() const {
[email protected]b4ede6602013-05-15 16:46:5592 if (!validate_gpu_info_)
93 return true;
[email protected]1a6ad5f2012-01-25 04:29:5894 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
95 return false;
96 return true;
97}
98
99bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
100 DCHECK(IsValid());
101 DCHECK(config.IsValid());
102 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
103 (os_ & config.os_) == 0)
104 return false;
105 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
106 bool shared = false;
107 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
108 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
109 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
110 shared = true;
111 break;
112 }
113 }
114 }
115 if (!shared)
116 return false;
117 }
118 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
119 gpu_device_id_ != config.gpu_device_id_)
120 return false;
121 if (config.build_type_ != kBuildTypeUnknown &&
122 build_type_ != kBuildTypeUnknown &&
123 (build_type_ & config.build_type_) == 0)
124 return false;
125 return true;
126}
127
[email protected]b4ede6602013-05-15 16:46:55128void GPUTestConfig::DisableGPUInfoValidation() {
129 validate_gpu_info_ = false;
130}
131
[email protected]1a6ad5f2012-01-25 04:29:58132void GPUTestConfig::ClearGPUVendor() {
133 gpu_vendor_.clear();
134}
135
136GPUTestBotConfig::~GPUTestBotConfig() {
137}
138
139void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) {
140 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
141 GPUTestConfig::AddGPUVendor(gpu_vendor);
142}
143
[email protected]d7b5cc72013-05-23 20:05:00144bool GPUTestBotConfig::SetGPUInfo(const gpu::GPUInfo& gpu_info) {
[email protected]b4ede6602013-05-15 16:46:55145 DCHECK(validate_gpu_info_);
[email protected]a094e2c2012-05-10 23:02:42146 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
[email protected]1a6ad5f2012-01-25 04:29:58147 return false;
148 ClearGPUVendor();
[email protected]a094e2c2012-05-10 23:02:42149 AddGPUVendor(gpu_info.gpu.vendor_id);
150 set_gpu_device_id(gpu_info.gpu.device_id);
[email protected]1a6ad5f2012-01-25 04:29:58151 return true;
152}
153
154bool GPUTestBotConfig::IsValid() const {
155 switch (os()) {
156 case kOsWinXP:
157 case kOsWinVista:
158 case kOsWin7:
[email protected]c9fc22f2012-11-16 23:39:56159 case kOsWin8:
[email protected]1a6ad5f2012-01-25 04:29:58160 case kOsMacLeopard:
161 case kOsMacSnowLeopard:
162 case kOsMacLion:
[email protected]c9fc22f2012-11-16 23:39:56163 case kOsMacMountainLion:
[email protected]1a6ad5f2012-01-25 04:29:58164 case kOsLinux:
165 case kOsChromeOS:
[email protected]67d96b62012-07-24 03:38:25166 case kOsAndroid:
[email protected]1a6ad5f2012-01-25 04:29:58167 break;
168 default:
169 return false;
170 }
[email protected]b4ede6602013-05-15 16:46:55171 if (validate_gpu_info_) {
172 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
173 return false;
174 if (gpu_device_id() == 0)
175 return false;
176 }
[email protected]1a6ad5f2012-01-25 04:29:58177 switch (build_type()) {
178 case kBuildTypeRelease:
179 case kBuildTypeDebug:
180 break;
181 default:
182 return false;
183 }
184 return true;
185}
186
187bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
188 DCHECK(IsValid());
189 DCHECK(config.IsValid());
190 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
191 return false;
192 if (config.gpu_vendor().size() > 0) {
193 bool contained = false;
194 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
195 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
196 contained = true;
197 break;
198 }
199 }
200 if (!contained)
201 return false;
202 }
203 if (config.gpu_device_id() != 0 &&
204 gpu_device_id() != config.gpu_device_id())
205 return false;
206 if (config.build_type() != kBuildTypeUnknown &&
207 (build_type() & config.build_type()) == 0)
208 return false;
209 return true;
210}
211
[email protected]830631c2012-06-13 05:06:08212bool GPUTestBotConfig::Matches(const std::string& config_data) const {
213 GPUTestExpectationsParser parser;
214 GPUTestConfig config;
215
216 if (!parser.ParseConfig(config_data, &config))
217 return false;
218 return Matches(config);
219}
220
[email protected]d7b5cc72013-05-23 20:05:00221bool GPUTestBotConfig::LoadCurrentConfig(const gpu::GPUInfo* gpu_info) {
[email protected]b0186392012-01-28 02:12:14222 bool rt;
223 if (gpu_info == NULL) {
[email protected]d7b5cc72013-05-23 20:05:00224 gpu::GPUInfo my_gpu_info;
225 gpu::GpuIDResult result;
226 result = gpu::CollectGpuID(&my_gpu_info.gpu.vendor_id,
227 &my_gpu_info.gpu.device_id);
228 if (result == gpu::kGpuIDNotSupported) {
[email protected]b4ede6602013-05-15 16:46:55229 DisableGPUInfoValidation();
230 rt = true;
231 } else {
232 rt = SetGPUInfo(my_gpu_info);
233 }
[email protected]b0186392012-01-28 02:12:14234 } else {
235 rt = SetGPUInfo(*gpu_info);
236 }
[email protected]1a6ad5f2012-01-25 04:29:58237 set_os(GetCurrentOS());
238 if (os() == kOsUnknown)
239 rt = false;
240#if defined(NDEBUG)
241 set_build_type(kBuildTypeRelease);
242#else
243 set_build_type(kBuildTypeDebug);
244#endif
245 return rt;
246}
247
[email protected]830631c2012-06-13 05:06:08248// static
249bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
250 GPUTestBotConfig my_config;
251 if (!my_config.LoadCurrentConfig(NULL))
252 return false;
253 return my_config.Matches(config_data);
254}
255
256// static
257bool GPUTestBotConfig::CurrentConfigMatches(
258 const std::vector<std::string>& configs) {
259 GPUTestBotConfig my_config;
260 if (!my_config.LoadCurrentConfig(NULL))
261 return false;
262 for (size_t i = 0 ; i < configs.size(); ++i) {
263 if (my_config.Matches(configs[i]))
264 return true;
265 }
266 return false;
267}
268