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 "base/memory/scoped_ptr.h"
6 #include "gpu/config/gpu_info.h"
7 #include "gpu/config/gpu_info_collector.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gl/gl_implementation.h"
11 #include "ui/gl/gl_mock.h"
12 #include "ui/gl/test/gl_surface_test_support.h"
14 using ::gfx::MockGLInterface
;
15 using ::testing::Return
;
16 using ::testing::SetArgPointee
;
21 class GPUInfoCollectorTest
: public testing::Test
{
23 GPUInfoCollectorTest() {}
24 ~GPUInfoCollectorTest() override
{}
26 void SetUp() override
{
27 testing::Test::SetUp();
28 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress
);
29 gfx::GLSurfaceTestSupport::InitializeOneOffWithMockBindings();
30 gl_
.reset(new ::testing::StrictMock
< ::gfx::MockGLInterface
>());
31 ::gfx::MockGLInterface::SetGLInterface(gl_
.get());
33 const uint32 vendor_id
= 0x10de;
34 const uint32 device_id
= 0x0658;
35 const char* driver_vendor
= ""; // not implemented
36 const char* driver_version
= "";
37 const char* shader_version
= "1.40";
38 const char* gl_renderer
= "Quadro FX 380/PCI/SSE2";
39 const char* gl_vendor
= "NVIDIA Corporation";
40 const char* gl_version
= "3.1.0";
41 const char* gl_shading_language_version
= "1.40 NVIDIA via Cg compiler";
42 const char* gl_extensions
=
43 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
44 "GL_EXT_read_format_bgra";
45 #elif defined(OS_MACOSX)
46 const uint32 vendor_id
= 0x10de;
47 const uint32 device_id
= 0x0640;
48 const char* driver_vendor
= ""; // not implemented
49 const char* driver_version
= "1.6.18";
50 const char* shader_version
= "1.20";
51 const char* gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
52 const char* gl_vendor
= "NVIDIA Corporation";
53 const char* gl_version
= "2.1 NVIDIA-1.6.18";
54 const char* gl_shading_language_version
= "1.20 ";
55 const char* gl_extensions
=
56 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
57 "GL_EXT_read_format_bgra";
58 #elif defined(OS_ANDROID)
59 const uint32 vendor_id
= 0; // not implemented
60 const uint32 device_id
= 0; // not implemented
61 const char* driver_vendor
= ""; // not implemented
62 const char* driver_version
= "14.0";
63 const char* shader_version
= "1.00";
64 const char* gl_renderer
= "Adreno (TM) 320";
65 const char* gl_vendor
= "Qualcomm";
66 const char* gl_version
= "OpenGL ES 2.0 V@14.0 AU@04.02 (CL@3206)";
67 const char* gl_shading_language_version
= "1.00";
68 const char* gl_extensions
=
69 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
70 "GL_EXT_read_format_bgra";
71 #else // defined (OS_LINUX)
72 const uint32 vendor_id
= 0x10de;
73 const uint32 device_id
= 0x0658;
74 const char* driver_vendor
= "NVIDIA";
75 const char* driver_version
= "195.36.24";
76 const char* shader_version
= "1.50";
77 const char* gl_renderer
= "Quadro FX 380/PCI/SSE2";
78 const char* gl_vendor
= "NVIDIA Corporation";
79 const char* gl_version
= "3.2.0 NVIDIA 195.36.24";
80 const char* gl_shading_language_version
= "1.50 NVIDIA via Cg compiler";
81 const char* gl_extensions
=
82 "GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 "
83 "GL_EXT_read_format_bgra";
85 test_values_
.gpu
.vendor_id
= vendor_id
;
86 test_values_
.gpu
.device_id
= device_id
;
87 test_values_
.driver_vendor
= driver_vendor
;
88 test_values_
.driver_version
=driver_version
;
89 test_values_
.pixel_shader_version
= shader_version
;
90 test_values_
.vertex_shader_version
= shader_version
;
91 test_values_
.gl_renderer
= gl_renderer
;
92 test_values_
.gl_vendor
= gl_vendor
;
93 test_values_
.gl_version
= gl_version
;
94 test_values_
.gl_extensions
= gl_extensions
;
95 test_values_
.can_lose_context
= false;
97 EXPECT_CALL(*gl_
, GetString(GL_EXTENSIONS
))
98 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
100 EXPECT_CALL(*gl_
, GetString(GL_SHADING_LANGUAGE_VERSION
))
101 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
102 gl_shading_language_version
)));
103 EXPECT_CALL(*gl_
, GetString(GL_VERSION
))
104 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
106 EXPECT_CALL(*gl_
, GetString(GL_VENDOR
))
107 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
109 EXPECT_CALL(*gl_
, GetString(GL_RENDERER
))
110 .WillRepeatedly(Return(reinterpret_cast<const GLubyte
*>(
112 EXPECT_CALL(*gl_
, GetIntegerv(GL_MAX_SAMPLES
, _
))
113 .WillOnce(SetArgPointee
<1>(8))
114 .RetiresOnSaturation();
117 void TearDown() override
{
118 ::gfx::MockGLInterface::SetGLInterface(NULL
);
120 gfx::ClearGLBindings();
122 testing::Test::TearDown();
126 // Use StrictMock to make 100% sure we know how GL will be called.
127 scoped_ptr
< ::testing::StrictMock
< ::gfx::MockGLInterface
> > gl_
;
128 GPUInfo test_values_
;
131 // TODO(rlp): Test the vendor and device id collection if deemed necessary as
132 // it involves several complicated mocks for each platform.
134 TEST_F(GPUInfoCollectorTest
, CollectGraphicsInfoGL
) {
136 CollectGraphicsInfoGL(&gpu_info
);
137 EXPECT_EQ(test_values_
.driver_vendor
,
138 gpu_info
.driver_vendor
);
140 // Skip Windows because the driver version is obtained from bot registry.
141 EXPECT_EQ(test_values_
.driver_version
,
142 gpu_info
.driver_version
);
144 EXPECT_EQ(test_values_
.pixel_shader_version
,
145 gpu_info
.pixel_shader_version
);
146 EXPECT_EQ(test_values_
.vertex_shader_version
,
147 gpu_info
.vertex_shader_version
);
148 EXPECT_EQ(test_values_
.gl_version
, gpu_info
.gl_version
);
149 EXPECT_EQ(test_values_
.gl_renderer
, gpu_info
.gl_renderer
);
150 EXPECT_EQ(test_values_
.gl_vendor
, gpu_info
.gl_vendor
);
151 EXPECT_EQ(test_values_
.gl_extensions
, gpu_info
.gl_extensions
);
154 class CollectDriverInfoGLTest
: public testing::Test
{
156 CollectDriverInfoGLTest() {}
157 ~CollectDriverInfoGLTest() override
{}
159 void SetUp() override
{}
160 void TearDown() override
{}
163 TEST_F(CollectDriverInfoGLTest
, CollectDriverInfoGL
) {
165 const char* gl_renderer
;
166 const char* gl_vendor
;
167 const char* gl_version
;
168 const char* expected_driver_version
;
170 #if defined(OS_ANDROID)
173 "OpenGL ES 2.0 V@14.0 AU@04.02 (CL@3206)",
175 {"Adreno (TM) 420", "Qualcomm", "OpenGL ES 3.0 V@84.0 AU@ (CL@)", "84.0"},
176 {"PowerVR Rogue G6430",
177 "Imagination Technologies",
178 "OpenGL ES 3.1 build 1.4@3283119",
180 {"Mali-T604", "ARM", "OpenGL ES 3.1", "0"},
182 "NVIDIA Corporation",
183 "OpenGL ES 3.1 NVIDIA 343.00",
186 "NVIDIA Corporation",
187 "OpenGL ES 2.0 14.01003",
191 "OpenGL ES 2.0 with_long_version_string=1.2.3.4",
195 "OpenGL ES 2.0 with_short_version_string=1",
199 "OpenGL ES 2.0 with_no_version_string",
201 #elif defined(OS_MACOSX)
202 {"Intel Iris Pro OpenGL Engine",
206 #elif defined(OS_LINUX)
207 {"Quadro K2000/PCIe/SSE2",
208 "NVIDIA Corporation",
209 "4.4.0 NVIDIA 331.79",
212 {NULL
, NULL
, NULL
, NULL
}
216 for (int i
= 0; kTestStrings
[i
].gl_renderer
!= NULL
; ++i
) {
217 gpu_info
.gl_renderer
= kTestStrings
[i
].gl_renderer
;
218 gpu_info
.gl_vendor
= kTestStrings
[i
].gl_vendor
;
219 gpu_info
.gl_version
= kTestStrings
[i
].gl_version
;
220 EXPECT_EQ(CollectDriverInfoGL(&gpu_info
), kCollectInfoSuccess
);
221 EXPECT_EQ(gpu_info
.driver_version
, kTestStrings
[i
].expected_driver_version
);