1 // Copyright (c) 2013 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/command_line.h"
6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "gpu/config/gpu_control_list_jsons.h"
9 #include "gpu/config/gpu_driver_bug_list.h"
10 #include "gpu/config/gpu_driver_bug_workaround_type.h"
11 #include "gpu/config/gpu_info.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 #define LONG_STRING_CONST(...) #__VA_ARGS__
18 class GpuDriverBugListTest
: public testing::Test
{
20 GpuDriverBugListTest() { }
22 ~GpuDriverBugListTest() override
{}
24 const GPUInfo
& gpu_info() const {
29 void SetUp() override
{
30 gpu_info_
.gpu
.vendor_id
= 0x10de;
31 gpu_info_
.gpu
.device_id
= 0x0640;
32 gpu_info_
.driver_vendor
= "NVIDIA";
33 gpu_info_
.driver_version
= "1.6.18";
34 gpu_info_
.driver_date
= "7-14-2009";
35 gpu_info_
.machine_model_name
= "MacBookPro";
36 gpu_info_
.machine_model_version
= "7.1";
37 gpu_info_
.gl_vendor
= "NVIDIA Corporation";
38 gpu_info_
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
41 void TearDown() override
{}
47 TEST_F(GpuDriverBugListTest
, CurrentDriverBugListValidation
) {
48 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
50 EXPECT_TRUE(list
->LoadList(kGpuDriverBugListJson
, GpuControlList::kAllOs
));
53 TEST_F(GpuDriverBugListTest
, CurrentListForARM
) {
54 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
55 EXPECT_TRUE(list
->LoadList(kGpuDriverBugListJson
, GpuControlList::kAllOs
));
58 gpu_info
.gl_vendor
= "ARM";
59 gpu_info
.gl_renderer
= "MALi_T604";
60 std::set
<int> bugs
= list
->MakeDecision(
61 GpuControlList::kOsAndroid
, "4.1", gpu_info
);
62 EXPECT_EQ(1u, bugs
.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS
));
65 TEST_F(GpuDriverBugListTest
, CurrentListForImagination
) {
66 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
67 EXPECT_TRUE(list
->LoadList(kGpuDriverBugListJson
, GpuControlList::kAllOs
));
70 gpu_info
.gl_vendor
= "Imagination Technologies";
71 gpu_info
.gl_renderer
= "PowerVR SGX 540";
72 std::set
<int> bugs
= list
->MakeDecision(
73 GpuControlList::kOsAndroid
, "4.1", gpu_info
);
74 EXPECT_EQ(1u, bugs
.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS
));
77 TEST_F(GpuDriverBugListTest
, GpuSwitching
) {
78 const std::string json
= LONG_STRING_CONST(
80 "name": "gpu driver bug list",
98 "force_integrated_gpu"
104 scoped_ptr
<GpuDriverBugList
> driver_bug_list(GpuDriverBugList::Create());
105 EXPECT_TRUE(driver_bug_list
->LoadList(json
, GpuControlList::kAllOs
));
106 std::set
<int> switching
= driver_bug_list
->MakeDecision(
107 GpuControlList::kOsMacosx
, "10.8", gpu_info());
108 EXPECT_EQ(1u, switching
.size());
109 EXPECT_EQ(1u, switching
.count(FORCE_DISCRETE_GPU
));
110 std::vector
<uint32
> entries
;
111 driver_bug_list
->GetDecisionEntries(&entries
, false);
112 ASSERT_EQ(1u, entries
.size());
113 EXPECT_EQ(1u, entries
[0]);
115 driver_bug_list
.reset(GpuDriverBugList::Create());
116 EXPECT_TRUE(driver_bug_list
->LoadList(json
, GpuControlList::kAllOs
));
117 switching
= driver_bug_list
->MakeDecision(
118 GpuControlList::kOsWin
, "6.1", gpu_info());
119 EXPECT_EQ(1u, switching
.size());
120 EXPECT_EQ(1u, switching
.count(FORCE_INTEGRATED_GPU
));
121 driver_bug_list
->GetDecisionEntries(&entries
, false);
122 ASSERT_EQ(1u, entries
.size());
123 EXPECT_EQ(2u, entries
[0]);
126 TEST_F(GpuDriverBugListTest
, AppendSingleWorkaround
) {
127 base::CommandLine
command_line(0, NULL
);
128 command_line
.AppendSwitch(GpuDriverBugWorkaroundTypeToString(
129 DISABLE_CHROMIUM_FRAMEBUFFER_MULTISAMPLE
));
130 std::set
<int> workarounds
;
131 workarounds
.insert(EXIT_ON_CONTEXT_LOST
);
132 workarounds
.insert(INIT_VERTEX_ATTRIBUTES
);
133 EXPECT_EQ(2u, workarounds
.size());
134 GpuDriverBugList::AppendWorkaroundsFromCommandLine(
135 &workarounds
, command_line
);
136 EXPECT_EQ(3u, workarounds
.size());
137 EXPECT_EQ(1u, workarounds
.count(DISABLE_CHROMIUM_FRAMEBUFFER_MULTISAMPLE
));
140 TEST_F(GpuDriverBugListTest
, AppendForceGPUWorkaround
) {
141 base::CommandLine
command_line(0, NULL
);
142 command_line
.AppendSwitch(
143 GpuDriverBugWorkaroundTypeToString(FORCE_DISCRETE_GPU
));
144 std::set
<int> workarounds
;
145 workarounds
.insert(EXIT_ON_CONTEXT_LOST
);
146 workarounds
.insert(FORCE_INTEGRATED_GPU
);
147 EXPECT_EQ(2u, workarounds
.size());
148 EXPECT_EQ(1u, workarounds
.count(FORCE_INTEGRATED_GPU
));
149 GpuDriverBugList::AppendWorkaroundsFromCommandLine(
150 &workarounds
, command_line
);
151 EXPECT_EQ(2u, workarounds
.size());
152 EXPECT_EQ(0u, workarounds
.count(FORCE_INTEGRATED_GPU
));
153 EXPECT_EQ(1u, workarounds
.count(FORCE_DISCRETE_GPU
));
156 TEST_F(GpuDriverBugListTest
, NVIDIANumberingScheme
) {
157 const std::string json
= LONG_STRING_CONST(
159 "name": "gpu driver bug list",
167 "vendor_id": "0x10de",
170 "value": "8.17.12.6973"
180 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
181 EXPECT_TRUE(list
->LoadList(json
, GpuControlList::kAllOs
));
184 gpu_info
.gl_vendor
= "NVIDIA";
185 gpu_info
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
186 gpu_info
.gpu
.vendor_id
= 0x10de;
187 gpu_info
.gpu
.device_id
= 0x0640;
189 // test the same driver version number
190 gpu_info
.driver_version
= "8.17.12.6973";
191 std::set
<int> bugs
= list
->MakeDecision(
192 GpuControlList::kOsWin
, "7.0", gpu_info
);
193 EXPECT_EQ(1u, bugs
.count(DISABLE_D3D11
));
195 // test a lower driver version number
196 gpu_info
.driver_version
= "8.15.11.8647";
198 bugs
= list
->MakeDecision(GpuControlList::kOsWin
, "7.0", gpu_info
);
199 EXPECT_EQ(1u, bugs
.count(DISABLE_D3D11
));
201 // test a higher driver version number
202 gpu_info
.driver_version
= "9.18.13.2723";
203 bugs
= list
->MakeDecision(GpuControlList::kOsWin
, "7.0", gpu_info
);
204 EXPECT_EQ(0u, bugs
.count(DISABLE_D3D11
));