forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpu_info_collector_unittest.cc
362 lines (325 loc) · 12.2 KB
/
gpu_info_collector_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include "base/strings/string_split.h"
#include "gpu/config/gpu_info.h"
#include "gpu/config/gpu_info_collector.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/test/gl_surface_test_support.h"
using ::gfx::MockGLInterface;
using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::_;
namespace {
// Allows testing of all configurations on all operating systems.
enum MockedOperatingSystemKind {
kMockedAndroid,
kMockedLinux,
kMockedMacOSX,
kMockedWindows
};
} // anonymous namespace
namespace gpu {
static const MockedOperatingSystemKind kMockedOperatingSystemKinds[] = {
kMockedAndroid,
kMockedLinux,
kMockedMacOSX,
kMockedWindows
};
class GPUInfoCollectorTest
: public testing::Test,
public ::testing::WithParamInterface<MockedOperatingSystemKind> {
public:
GPUInfoCollectorTest() {}
~GPUInfoCollectorTest() override {}
void SetUp() override {
testing::Test::SetUp();
gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress);
gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
gl_.reset(new ::testing::StrictMock< ::gfx::MockGLInterface>());
::gfx::MockGLInterface::SetGLInterface(gl_.get());
switch (GetParam()) {
case kMockedAndroid: {
test_values_.gpu.vendor_id = 0; // not implemented
test_values_.gpu.device_id = 0; // not implemented
test_values_.driver_vendor = ""; // not implemented
test_values_.driver_version = "14.0";
test_values_.pixel_shader_version = "1.00";
test_values_.vertex_shader_version = "1.00";
test_values_.gl_renderer = "Adreno (TM) 320";
test_values_.gl_vendor = "Qualcomm";
test_values_.gl_version = "OpenGL ES 2.0 V@14.0 AU@04.02 (CL@3206)";
test_values_.gl_extensions =
"GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
"GL_EXT_read_format_bgra GL_EXT_multisampled_render_to_texture";
gl_shading_language_version_ = "1.00";
break;
}
case kMockedLinux: {
test_values_.gpu.vendor_id = 0x10de;
test_values_.gpu.device_id = 0x0658;
test_values_.driver_vendor = "NVIDIA";
test_values_.driver_version = "195.36.24";
test_values_.pixel_shader_version = "1.50";
test_values_.vertex_shader_version = "1.50";
test_values_.gl_renderer = "Quadro FX 380/PCI/SSE2";
test_values_.gl_vendor = "NVIDIA Corporation";
test_values_.gl_version = "3.2.0 NVIDIA 195.36.24";
test_values_.gl_extensions =
"GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
"GL_EXT_read_format_bgra";
gl_shading_language_version_ = "1.50 NVIDIA via Cg compiler";
break;
}
case kMockedMacOSX: {
test_values_.gpu.vendor_id = 0x10de;
test_values_.gpu.device_id = 0x0640;
test_values_.driver_vendor = ""; // not implemented
test_values_.driver_version = "1.6.18";
test_values_.pixel_shader_version = "1.20";
test_values_.vertex_shader_version = "1.20";
test_values_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
test_values_.gl_vendor = "NVIDIA Corporation";
test_values_.gl_version = "2.1 NVIDIA-1.6.18";
test_values_.gl_extensions =
"GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
"GL_EXT_read_format_bgra GL_EXT_framebuffer_multisample";
gl_shading_language_version_ = "1.20 ";
break;
}
case kMockedWindows: {
test_values_.gpu.vendor_id = 0x10de;
test_values_.gpu.device_id = 0x0658;
test_values_.driver_vendor = ""; // not implemented
test_values_.driver_version = "";
test_values_.pixel_shader_version = "1.40";
test_values_.vertex_shader_version = "1.40";
test_values_.gl_renderer = "Quadro FX 380/PCI/SSE2";
test_values_.gl_vendor = "NVIDIA Corporation";
test_values_.gl_version = "3.1.0";
test_values_.gl_extensions =
"GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
"GL_EXT_read_format_bgra";
gl_shading_language_version_ = "1.40 NVIDIA via Cg compiler";
break;
}
default: {
NOTREACHED();
break;
}
}
test_values_.can_lose_context = false;
EXPECT_CALL(*gl_, GetString(GL_VERSION))
.WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
test_values_.gl_version.c_str())));
// Now that that expectation is set up, we can call this helper function.
if (gfx::WillUseGLGetStringForExtensions()) {
EXPECT_CALL(*gl_, GetString(GL_EXTENSIONS))
.WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
test_values_.gl_extensions.c_str())));
} else {
split_extensions_.clear();
split_extensions_ = base::SplitString(
test_values_.gl_extensions, " ",
base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
EXPECT_CALL(*gl_, GetIntegerv(GL_NUM_EXTENSIONS, _))
.WillRepeatedly(SetArgPointee<1>(split_extensions_.size()));
for (size_t ii = 0; ii < split_extensions_.size(); ++ii) {
EXPECT_CALL(*gl_, GetStringi(GL_EXTENSIONS, ii))
.WillRepeatedly(Return(reinterpret_cast<const uint8_t*>(
split_extensions_[ii].c_str())));
}
}
EXPECT_CALL(*gl_, GetString(GL_SHADING_LANGUAGE_VERSION))
.WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
gl_shading_language_version_)));
EXPECT_CALL(*gl_, GetString(GL_VENDOR))
.WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
test_values_.gl_vendor.c_str())));
EXPECT_CALL(*gl_, GetString(GL_RENDERER))
.WillRepeatedly(Return(reinterpret_cast<const GLubyte*>(
test_values_.gl_renderer.c_str())));
EXPECT_CALL(*gl_, GetIntegerv(GL_MAX_SAMPLES, _))
.WillOnce(SetArgPointee<1>(8))
.RetiresOnSaturation();
}
void TearDown() override {
::gfx::MockGLInterface::SetGLInterface(NULL);
gl_.reset();
gfx::ClearGLBindings();
testing::Test::TearDown();
}
public:
// Use StrictMock to make 100% sure we know how GL will be called.
std::unique_ptr<::testing::StrictMock<::gfx::MockGLInterface>> gl_;
GPUInfo test_values_;
const char* gl_shading_language_version_ = nullptr;
// Persistent storage is needed for the split extension string.
std::vector<std::string> split_extensions_;
};
INSTANTIATE_TEST_CASE_P(GPUConfig,
GPUInfoCollectorTest,
::testing::ValuesIn(kMockedOperatingSystemKinds));
// TODO(rlp): Test the vendor and device id collection if deemed necessary as
// it involves several complicated mocks for each platform.
// TODO(kbr): This test still has platform-dependent behavior because
// CollectDriverInfoGL behaves differently per platform. This should
// be fixed.
TEST_P(GPUInfoCollectorTest, CollectGraphicsInfoGL) {
GPUInfo gpu_info;
CollectGraphicsInfoGL(&gpu_info);
#if defined(OS_WIN)
if (GetParam() == kMockedWindows) {
EXPECT_EQ(test_values_.driver_vendor,
gpu_info.driver_vendor);
// Skip testing the driver version on Windows because it's
// obtained from the bot's registry.
}
#elif defined(OS_MACOSX)
if (GetParam() == kMockedMacOSX) {
EXPECT_EQ(test_values_.driver_vendor,
gpu_info.driver_vendor);
EXPECT_EQ(test_values_.driver_version,
gpu_info.driver_version);
}
#elif defined(OS_ANDROID)
if (GetParam() == kMockedAndroid) {
EXPECT_EQ(test_values_.driver_vendor,
gpu_info.driver_vendor);
EXPECT_EQ(test_values_.driver_version,
gpu_info.driver_version);
}
#else // defined (OS_LINUX)
if (GetParam() == kMockedLinux) {
EXPECT_EQ(test_values_.driver_vendor,
gpu_info.driver_vendor);
EXPECT_EQ(test_values_.driver_version,
gpu_info.driver_version);
}
#endif
EXPECT_EQ(test_values_.pixel_shader_version,
gpu_info.pixel_shader_version);
EXPECT_EQ(test_values_.vertex_shader_version,
gpu_info.vertex_shader_version);
EXPECT_EQ(test_values_.gl_version, gpu_info.gl_version);
EXPECT_EQ(test_values_.gl_renderer, gpu_info.gl_renderer);
EXPECT_EQ(test_values_.gl_vendor, gpu_info.gl_vendor);
EXPECT_EQ(test_values_.gl_extensions, gpu_info.gl_extensions);
}
class CollectDriverInfoGLTest : public testing::Test {
public:
CollectDriverInfoGLTest() {}
~CollectDriverInfoGLTest() override {}
void SetUp() override {}
void TearDown() override {}
};
TEST_F(CollectDriverInfoGLTest, CollectDriverInfoGL) {
const struct {
const char* gl_renderer;
const char* gl_vendor;
const char* gl_version;
const char* expected_driver_version;
} kTestStrings[] = {
#if defined(OS_ANDROID)
{"Adreno (TM) 320",
"Qualcomm",
"OpenGL ES 2.0 V@14.0 AU@04.02 (CL@3206)",
"14.0"},
{"Adreno (TM) 420", "Qualcomm", "OpenGL ES 3.0 V@84.0 AU@ (CL@)", "84.0"},
{"PowerVR Rogue G6430",
"Imagination Technologies",
"OpenGL ES 3.1 build 1.4@3283119",
"1.4"},
{"Mali-T604", "ARM", "OpenGL ES 3.1", "0"},
{"NVIDIA Tegra",
"NVIDIA Corporation",
"OpenGL ES 3.1 NVIDIA 343.00",
"343.00"},
{"NVIDIA Tegra 3",
"NVIDIA Corporation",
"OpenGL ES 2.0 14.01003",
"14.01003"},
{"random GPU",
"random vendor",
"OpenGL ES 2.0 with_long_version_string=1.2.3.4",
"1.2"},
{"random GPU",
"random vendor",
"OpenGL ES 2.0 with_short_version_string=1",
"0"},
{"random GPU",
"random vendor",
"OpenGL ES 2.0 with_no_version_string",
"0"},
#elif defined(OS_MACOSX)
{"Intel Iris Pro OpenGL Engine",
"Intel Inc.",
"2.1 INTEL-10.6.20",
"10.6.20"},
#elif defined(OS_LINUX)
{"Quadro K2000/PCIe/SSE2",
"NVIDIA Corporation",
"4.4.0 NVIDIA 331.79",
"331.79"},
#endif
{NULL, NULL, NULL, NULL}
};
GPUInfo gpu_info;
for (int i = 0; kTestStrings[i].gl_renderer != NULL; ++i) {
gpu_info.gl_renderer = kTestStrings[i].gl_renderer;
gpu_info.gl_vendor = kTestStrings[i].gl_vendor;
gpu_info.gl_version = kTestStrings[i].gl_version;
EXPECT_EQ(CollectDriverInfoGL(&gpu_info), kCollectInfoSuccess);
EXPECT_EQ(gpu_info.driver_version, kTestStrings[i].expected_driver_version);
}
}
TEST(MultiGPUsTest, IdentifyActiveGPU) {
GPUInfo::GPUDevice nvidia_gpu;
nvidia_gpu.vendor_id = 0x10de;
nvidia_gpu.device_id = 0x0df8;
GPUInfo::GPUDevice intel_gpu;
intel_gpu.vendor_id = 0x8086;
intel_gpu.device_id = 0x0416;
GPUInfo gpu_info;
gpu_info.gpu = nvidia_gpu;
gpu_info.secondary_gpus.push_back(intel_gpu);
EXPECT_FALSE(gpu_info.gpu.active);
EXPECT_FALSE(gpu_info.secondary_gpus[0].active);
IdentifyActiveGPU(&gpu_info);
EXPECT_FALSE(gpu_info.gpu.active);
EXPECT_FALSE(gpu_info.secondary_gpus[0].active);
gpu_info.gl_vendor = "Intel Open Source Technology Center";
gpu_info.gl_renderer = "Mesa DRI Intel(R) Haswell Mobile";
IdentifyActiveGPU(&gpu_info);
EXPECT_FALSE(gpu_info.gpu.active);
EXPECT_TRUE(gpu_info.secondary_gpus[0].active);
gpu_info.gl_vendor = "NVIDIA Corporation";
gpu_info.gl_renderer = "Quadro 600/PCIe/SSE2";
IdentifyActiveGPU(&gpu_info);
EXPECT_TRUE(gpu_info.gpu.active);
EXPECT_FALSE(gpu_info.secondary_gpus[0].active);
}
TEST(MultiGPUsTest, IdentifyActiveGPUAvoidFalseMatch) {
// Verify that "Corporation" won't be matched with "ati".
GPUInfo::GPUDevice amd_gpu;
amd_gpu.vendor_id = 0x1002;
amd_gpu.device_id = 0x0df8;
GPUInfo::GPUDevice intel_gpu;
intel_gpu.vendor_id = 0x8086;
intel_gpu.device_id = 0x0416;
GPUInfo gpu_info;
gpu_info.gpu = amd_gpu;
gpu_info.secondary_gpus.push_back(intel_gpu);
gpu_info.gl_vendor = "Google Corporation";
gpu_info.gl_renderer = "Chrome GPU Team";
IdentifyActiveGPU(&gpu_info);
EXPECT_FALSE(gpu_info.gpu.active);
EXPECT_FALSE(gpu_info.secondary_gpus[0].active);
}
} // namespace gpu