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.
4 
5 #include <vector>
6 
7 #include "base/command_line.h"
8 #include "gpu/config/gpu_driver_bug_list.h"
9 #include "gpu/config/gpu_driver_bug_workaround_type.h"
10 #include "gpu/config/gpu_info.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace gpu {
14 
15 class GpuDriverBugListTest : public testing::Test {
16  public:
17   GpuDriverBugListTest() = default;
18   ~GpuDriverBugListTest() override = default;
19 };
20 
21 #if defined(OS_ANDROID)
TEST_F(GpuDriverBugListTest,CurrentListForARM)22 TEST_F(GpuDriverBugListTest, CurrentListForARM) {
23   std::unique_ptr<GpuDriverBugList> list = GpuDriverBugList::Create();
24   GPUInfo gpu_info;
25   gpu_info.gl_vendor = "ARM";
26   gpu_info.gl_renderer = "MALi_T604";
27   gpu_info.gl_version = "OpenGL ES 2.0";
28   std::set<int> bugs = list->MakeDecision(
29       GpuControlList::kOsAndroid, "4.1", gpu_info);
30   EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS));
31 }
32 
TEST_F(GpuDriverBugListTest,CurrentListForImagination)33 TEST_F(GpuDriverBugListTest, CurrentListForImagination) {
34   std::unique_ptr<GpuDriverBugList> list = GpuDriverBugList::Create();
35   GPUInfo gpu_info;
36   gpu_info.gl_vendor = "Imagination Technologies";
37   gpu_info.gl_renderer = "PowerVR SGX 540";
38   gpu_info.gl_version = "OpenGL ES 2.0";
39   std::set<int> bugs = list->MakeDecision(
40       GpuControlList::kOsAndroid, "4.1", gpu_info);
41   EXPECT_EQ(1u, bugs.count(USE_CLIENT_SIDE_ARRAYS_FOR_STREAM_BUFFERS));
42 }
43 #endif  // OS_ANDROID
44 
TEST_F(GpuDriverBugListTest,AppendSingleWorkaround)45 TEST_F(GpuDriverBugListTest, AppendSingleWorkaround) {
46   base::CommandLine command_line(0, nullptr);
47   command_line.AppendSwitch(GpuDriverBugWorkaroundTypeToString(
48       DISABLE_CHROMIUM_FRAMEBUFFER_MULTISAMPLE));
49   std::set<int> workarounds;
50   workarounds.insert(EXIT_ON_CONTEXT_LOST);
51   workarounds.insert(INIT_VERTEX_ATTRIBUTES);
52   EXPECT_EQ(2u, workarounds.size());
53   GpuDriverBugList::AppendWorkaroundsFromCommandLine(
54       &workarounds, command_line);
55   EXPECT_EQ(3u, workarounds.size());
56   EXPECT_EQ(1u, workarounds.count(DISABLE_CHROMIUM_FRAMEBUFFER_MULTISAMPLE));
57 }
58 
TEST_F(GpuDriverBugListTest,AppendForceGPUWorkaround)59 TEST_F(GpuDriverBugListTest, AppendForceGPUWorkaround) {
60   base::CommandLine command_line(0, nullptr);
61   command_line.AppendSwitch(
62       GpuDriverBugWorkaroundTypeToString(FORCE_HIGH_PERFORMANCE_GPU));
63   std::set<int> workarounds;
64   workarounds.insert(EXIT_ON_CONTEXT_LOST);
65   workarounds.insert(FORCE_LOW_POWER_GPU);
66   EXPECT_EQ(2u, workarounds.size());
67   EXPECT_EQ(1u, workarounds.count(FORCE_LOW_POWER_GPU));
68   GpuDriverBugList::AppendWorkaroundsFromCommandLine(
69       &workarounds, command_line);
70   EXPECT_EQ(2u, workarounds.size());
71   EXPECT_EQ(0u, workarounds.count(FORCE_LOW_POWER_GPU));
72   EXPECT_EQ(1u, workarounds.count(FORCE_HIGH_PERFORMANCE_GPU));
73 }
74 
75 // Test for invariant "Assume the newly last added entry has the largest ID".
76 // See GpuControlList::GpuControlList.
77 // It checks gpu_driver_bug_list.json
TEST_F(GpuDriverBugListTest,TestBlacklistIsValid)78 TEST_F(GpuDriverBugListTest, TestBlacklistIsValid) {
79   std::unique_ptr<GpuDriverBugList> list(GpuDriverBugList::Create());
80   auto max_entry_id = list->max_entry_id();
81 
82   std::vector<uint32_t> indices(list->num_entries());
83   int current = 0;
84   std::generate(indices.begin(), indices.end(),
85                 [&current] () { return current++; });
86 
87   auto entries = list->GetEntryIDsFromIndices(indices);
88   auto real_max_entry_id = *std::max_element(entries.begin(), entries.end());
89   EXPECT_EQ(real_max_entry_id, max_entry_id);
90 }
91 
92 }  // namespace gpu
93