Rationalize and fix chromium android linker histogram recording.
[chromium-blink-merge.git] / gpu / config / gpu_driver_bug_list_unittest.cc
blobe927e6c2c785b11fef1efb58bd8c2cd0c5e196f5
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__
16 namespace gpu {
18 class GpuDriverBugListTest : public testing::Test {
19 public:
20 GpuDriverBugListTest() { }
22 virtual ~GpuDriverBugListTest() { }
24 const GPUInfo& gpu_info() const {
25 return gpu_info_;
28 protected:
29 virtual void SetUp() {
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 virtual void TearDown() {
47 private:
48 GPUInfo gpu_info_;
51 TEST_F(GpuDriverBugListTest, CurrentDriverBugListValidation) {
52 scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
53 std::string json;
54 EXPECT_TRUE(list->LoadList(kGpuDriverBugListJson, GpuControlList::kAllOs));
57 TEST_F(GpuDriverBugListTest, CurrentListForARM) {
58 scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
59 EXPECT_TRUE(list->LoadList(kGpuDriverBugListJson, GpuControlList::kAllOs));
61 GPUInfo gpu_info;
62 gpu_info.gl_vendor = "ARM";
63 gpu_info.gl_renderer = "MALi_T604";
64 std::set<int> bugs = list->MakeDecision(
65 GpuControlList::kOsAndroid, "4.1", gpu_info);
66 EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS));
69 TEST_F(GpuDriverBugListTest, CurrentListForImagination) {
70 scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
71 EXPECT_TRUE(list->LoadList(kGpuDriverBugListJson, GpuControlList::kAllOs));
73 GPUInfo gpu_info;
74 gpu_info.gl_vendor = "Imagination Technologies";
75 gpu_info.gl_renderer = "PowerVR SGX 540";
76 std::set<int> bugs = list->MakeDecision(
77 GpuControlList::kOsAndroid, "4.1", gpu_info);
78 EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS));
81 TEST_F(GpuDriverBugListTest, GpuSwitching) {
82 const std::string json = LONG_STRING_CONST(
84 "name": "gpu driver bug list",
85 "version": "0.1",
86 "entries": [
88 "id": 1,
89 "os": {
90 "type": "macosx"
92 "features": [
93 "force_discrete_gpu"
97 "id": 2,
98 "os": {
99 "type": "win"
101 "features": [
102 "force_integrated_gpu"
108 scoped_ptr<GpuDriverBugList> driver_bug_list(GpuDriverBugList::Create());
109 EXPECT_TRUE(driver_bug_list->LoadList(json, GpuControlList::kAllOs));
110 std::set<int> switching = driver_bug_list->MakeDecision(
111 GpuControlList::kOsMacosx, "10.8", gpu_info());
112 EXPECT_EQ(1u, switching.size());
113 EXPECT_EQ(1u, switching.count(FORCE_DISCRETE_GPU));
114 std::vector<uint32> entries;
115 driver_bug_list->GetDecisionEntries(&entries, false);
116 ASSERT_EQ(1u, entries.size());
117 EXPECT_EQ(1u, entries[0]);
119 driver_bug_list.reset(GpuDriverBugList::Create());
120 EXPECT_TRUE(driver_bug_list->LoadList(json, GpuControlList::kAllOs));
121 switching = driver_bug_list->MakeDecision(
122 GpuControlList::kOsWin, "6.1", gpu_info());
123 EXPECT_EQ(1u, switching.size());
124 EXPECT_EQ(1u, switching.count(FORCE_INTEGRATED_GPU));
125 driver_bug_list->GetDecisionEntries(&entries, false);
126 ASSERT_EQ(1u, entries.size());
127 EXPECT_EQ(2u, entries[0]);
130 TEST_F(GpuDriverBugListTest, AppendSingleWorkaround) {
131 base::CommandLine command_line(0, NULL);
132 command_line.AppendSwitch(
133 GpuDriverBugWorkaroundTypeToString(DISABLE_MULTISAMPLING));
134 std::set<int> workarounds;
135 workarounds.insert(EXIT_ON_CONTEXT_LOST);
136 workarounds.insert(INIT_VERTEX_ATTRIBUTES);
137 EXPECT_EQ(2u, workarounds.size());
138 GpuDriverBugList::AppendWorkaroundsFromCommandLine(
139 &workarounds, command_line);
140 EXPECT_EQ(3u, workarounds.size());
141 EXPECT_EQ(1u, workarounds.count(DISABLE_MULTISAMPLING));
144 TEST_F(GpuDriverBugListTest, AppendForceGPUWorkaround) {
145 base::CommandLine command_line(0, NULL);
146 command_line.AppendSwitch(
147 GpuDriverBugWorkaroundTypeToString(FORCE_DISCRETE_GPU));
148 std::set<int> workarounds;
149 workarounds.insert(EXIT_ON_CONTEXT_LOST);
150 workarounds.insert(FORCE_INTEGRATED_GPU);
151 EXPECT_EQ(2u, workarounds.size());
152 EXPECT_EQ(1u, workarounds.count(FORCE_INTEGRATED_GPU));
153 GpuDriverBugList::AppendWorkaroundsFromCommandLine(
154 &workarounds, command_line);
155 EXPECT_EQ(2u, workarounds.size());
156 EXPECT_EQ(0u, workarounds.count(FORCE_INTEGRATED_GPU));
157 EXPECT_EQ(1u, workarounds.count(FORCE_DISCRETE_GPU));
160 TEST_F(GpuDriverBugListTest, NVIDIANumberingScheme) {
161 const std::string json = LONG_STRING_CONST(
163 "name": "gpu driver bug list",
164 "version": "0.1",
165 "entries": [
167 "id": 1,
168 "os": {
169 "type": "win"
171 "vendor_id": "0x10de",
172 "driver_version": {
173 "op": "<=",
174 "value": "8.17.12.6973"
176 "features": [
177 "disable_d3d11"
184 scoped_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
185 EXPECT_TRUE(list->LoadList(json, GpuControlList::kAllOs));
187 GPUInfo gpu_info;
188 gpu_info.gl_vendor = "NVIDIA";
189 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
190 gpu_info.gpu.vendor_id = 0x10de;
191 gpu_info.gpu.device_id = 0x0640;
193 // test the same driver version number
194 gpu_info.driver_version = "8.17.12.6973";
195 std::set<int> bugs = list->MakeDecision(
196 GpuControlList::kOsWin, "7.0", gpu_info);
197 EXPECT_EQ(1u, bugs.count(DISABLE_D3D11));
199 // test a lower driver version number
200 gpu_info.driver_version = "8.15.11.8647";
202 bugs = list->MakeDecision(GpuControlList::kOsWin, "7.0", gpu_info);
203 EXPECT_EQ(1u, bugs.count(DISABLE_D3D11));
205 // test a higher driver version number
206 gpu_info.driver_version = "9.18.13.2723";
207 bugs = list->MakeDecision(GpuControlList::kOsWin, "7.0", gpu_info);
208 EXPECT_EQ(0u, bugs.count(DISABLE_D3D11));
211 } // namespace gpu