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";
39 gpu_info_
.performance_stats
.graphics
= 5.0;
40 gpu_info_
.performance_stats
.gaming
= 5.0;
41 gpu_info_
.performance_stats
.overall
= 5.0;
44 void TearDown() override
{}
50 TEST_F(GpuDriverBugListTest
, CurrentDriverBugListValidation
) {
51 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
53 EXPECT_TRUE(list
->LoadList(kGpuDriverBugListJson
, GpuControlList::kAllOs
));
56 TEST_F(GpuDriverBugListTest
, CurrentListForARM
) {
57 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
58 EXPECT_TRUE(list
->LoadList(kGpuDriverBugListJson
, GpuControlList::kAllOs
));
61 gpu_info
.gl_vendor
= "ARM";
62 gpu_info
.gl_renderer
= "MALi_T604";
63 std::set
<int> bugs
= list
->MakeDecision(
64 GpuControlList::kOsAndroid
, "4.1", gpu_info
);
65 EXPECT_EQ(1u, bugs
.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS
));
68 TEST_F(GpuDriverBugListTest
, CurrentListForImagination
) {
69 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
70 EXPECT_TRUE(list
->LoadList(kGpuDriverBugListJson
, GpuControlList::kAllOs
));
73 gpu_info
.gl_vendor
= "Imagination Technologies";
74 gpu_info
.gl_renderer
= "PowerVR SGX 540";
75 std::set
<int> bugs
= list
->MakeDecision(
76 GpuControlList::kOsAndroid
, "4.1", gpu_info
);
77 EXPECT_EQ(1u, bugs
.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS
));
80 TEST_F(GpuDriverBugListTest
, GpuSwitching
) {
81 const std::string json
= LONG_STRING_CONST(
83 "name": "gpu driver bug list",
101 "force_integrated_gpu"
107 scoped_ptr
<GpuDriverBugList
> driver_bug_list(GpuDriverBugList::Create());
108 EXPECT_TRUE(driver_bug_list
->LoadList(json
, GpuControlList::kAllOs
));
109 std::set
<int> switching
= driver_bug_list
->MakeDecision(
110 GpuControlList::kOsMacosx
, "10.8", gpu_info());
111 EXPECT_EQ(1u, switching
.size());
112 EXPECT_EQ(1u, switching
.count(FORCE_DISCRETE_GPU
));
113 std::vector
<uint32
> entries
;
114 driver_bug_list
->GetDecisionEntries(&entries
, false);
115 ASSERT_EQ(1u, entries
.size());
116 EXPECT_EQ(1u, entries
[0]);
118 driver_bug_list
.reset(GpuDriverBugList::Create());
119 EXPECT_TRUE(driver_bug_list
->LoadList(json
, GpuControlList::kAllOs
));
120 switching
= driver_bug_list
->MakeDecision(
121 GpuControlList::kOsWin
, "6.1", gpu_info());
122 EXPECT_EQ(1u, switching
.size());
123 EXPECT_EQ(1u, switching
.count(FORCE_INTEGRATED_GPU
));
124 driver_bug_list
->GetDecisionEntries(&entries
, false);
125 ASSERT_EQ(1u, entries
.size());
126 EXPECT_EQ(2u, entries
[0]);
129 TEST_F(GpuDriverBugListTest
, AppendSingleWorkaround
) {
130 base::CommandLine
command_line(0, NULL
);
131 command_line
.AppendSwitch(
132 GpuDriverBugWorkaroundTypeToString(DISABLE_MULTISAMPLING
));
133 std::set
<int> workarounds
;
134 workarounds
.insert(EXIT_ON_CONTEXT_LOST
);
135 workarounds
.insert(INIT_VERTEX_ATTRIBUTES
);
136 EXPECT_EQ(2u, workarounds
.size());
137 GpuDriverBugList::AppendWorkaroundsFromCommandLine(
138 &workarounds
, command_line
);
139 EXPECT_EQ(3u, workarounds
.size());
140 EXPECT_EQ(1u, workarounds
.count(DISABLE_MULTISAMPLING
));
143 TEST_F(GpuDriverBugListTest
, AppendForceGPUWorkaround
) {
144 base::CommandLine
command_line(0, NULL
);
145 command_line
.AppendSwitch(
146 GpuDriverBugWorkaroundTypeToString(FORCE_DISCRETE_GPU
));
147 std::set
<int> workarounds
;
148 workarounds
.insert(EXIT_ON_CONTEXT_LOST
);
149 workarounds
.insert(FORCE_INTEGRATED_GPU
);
150 EXPECT_EQ(2u, workarounds
.size());
151 EXPECT_EQ(1u, workarounds
.count(FORCE_INTEGRATED_GPU
));
152 GpuDriverBugList::AppendWorkaroundsFromCommandLine(
153 &workarounds
, command_line
);
154 EXPECT_EQ(2u, workarounds
.size());
155 EXPECT_EQ(0u, workarounds
.count(FORCE_INTEGRATED_GPU
));
156 EXPECT_EQ(1u, workarounds
.count(FORCE_DISCRETE_GPU
));
159 TEST_F(GpuDriverBugListTest
, NVIDIANumberingScheme
) {
160 const std::string json
= LONG_STRING_CONST(
162 "name": "gpu driver bug list",
170 "vendor_id": "0x10de",
173 "value": "8.17.12.6973"
183 scoped_ptr
<GpuDriverBugList
> list(GpuDriverBugList::Create());
184 EXPECT_TRUE(list
->LoadList(json
, GpuControlList::kAllOs
));
187 gpu_info
.gl_vendor
= "NVIDIA";
188 gpu_info
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
189 gpu_info
.gpu
.vendor_id
= 0x10de;
190 gpu_info
.gpu
.device_id
= 0x0640;
192 // test the same driver version number
193 gpu_info
.driver_version
= "8.17.12.6973";
194 std::set
<int> bugs
= list
->MakeDecision(
195 GpuControlList::kOsWin
, "7.0", gpu_info
);
196 EXPECT_EQ(1u, bugs
.count(DISABLE_D3D11
));
198 // test a lower driver version number
199 gpu_info
.driver_version
= "8.15.11.8647";
201 bugs
= list
->MakeDecision(GpuControlList::kOsWin
, "7.0", gpu_info
);
202 EXPECT_EQ(1u, bugs
.count(DISABLE_D3D11
));
204 // test a higher driver version number
205 gpu_info
.driver_version
= "9.18.13.2723";
206 bugs
= list
->MakeDecision(GpuControlList::kOsWin
, "7.0", gpu_info
);
207 EXPECT_EQ(0u, bugs
.count(DISABLE_D3D11
));