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/gl_surface.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::GLSurface::InitializeOneOffWithMockBindingsForTests();
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
);