1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
gpu / config / gpu_control_list_unittest.cc [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include <memory>
#include <vector>
#include "gpu/config/gpu_control_list.h"
#include "gpu/config/gpu_control_list_testing_data.h"
#include "gpu/config/gpu_info.h"
#include "testing/gtest/include/gtest/gtest.h"
const char kOsVersion[] = "10.6.4";
const uint32_t kIntelVendorId = 0x8086;
const uint32_t kNvidiaVendorId = 0x10de;
#define LONG_STRING_CONST(...) #__VA_ARGS__
#define EXPECT_EMPTY_SET(feature_set) EXPECT_EQ(0u, feature_set.size())
#define EXPECT_SINGLE_FEATURE(feature_set, feature) \
EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1)
namespace gpu {
class GpuControlListTest : public testing::Test,
public testing::WithParamInterface<bool> {
public:
typedef GpuControlList::Entry Entry;
GpuControlListTest() = default;
~GpuControlListTest() override = default;
const GPUInfo& gpu_info() const {
return gpu_info_;
}
std::unique_ptr<GpuControlList> Create(base::span<const Entry> entries) {
std::unique_ptr<GpuControlList> rt(new GpuControlList(entries));
rt->AddSupportedFeature("test_feature_0", TEST_FEATURE_0);
rt->AddSupportedFeature("test_feature_1", TEST_FEATURE_1);
rt->AddSupportedFeature("test_feature_2", TEST_FEATURE_2);
return rt;
}
GpuControlList::GLType GetGLType(const std::string& gl_renderer) {
return GpuControlList::ProcessANGLEGLRenderer(gl_renderer);
}
bool is_angle() const { return GetParam(); }
protected:
void SetUp() override {
gpu_info_.gpu.vendor_id = kNvidiaVendorId;
gpu_info_.gpu.device_id = 0x0640;
gpu_info_.gpu.driver_vendor = "NVIDIA";
gpu_info_.gpu.driver_version = "1.6.18";
gpu_info_.machine_model_name = "MacBookPro";
gpu_info_.machine_model_version = "7.1";
if (is_angle()) {
gpu_info_.gl_vendor = "Google Inc. (NVIDIA Corporation)";
gpu_info_.gl_renderer =
"ANGLE (NVIDIA Corporation, NVIDIA GeForce GT 120 OpenGL Engine,)";
gpu_info_.gl_renderer = "";
} else {
gpu_info_.gl_vendor = "NVIDIA Corporation";
gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
}
}
void TearDown() override {}
private:
GPUInfo gpu_info_;
};
INSTANTIATE_TEST_SUITE_P(,
GpuControlListTest,
testing::Values(false, true),
testing::PrintToStringParamName());
TEST_P(GpuControlListTest, NeedsMoreInfo) {
const Entry kEntries[1] = {
GetGpuControlListTestingEntries()[kGpuControlListTest_NeedsMoreInfo]};
std::unique_ptr<GpuControlList> control_list = Create(kEntries);
GPUInfo gpu_info;
gpu_info.gpu.vendor_id = kNvidiaVendorId;
std::set<int> features = control_list->MakeDecision(
GpuControlList::kOsWin, kOsVersion, gpu_info);
EXPECT_EMPTY_SET(features);
EXPECT_TRUE(control_list->needs_more_info());
std::vector<uint32_t> decision_entries = control_list->GetActiveEntries();
EXPECT_EQ(0u, decision_entries.size());
gpu_info.gpu.driver_version = "11";
features = control_list->MakeDecision(
GpuControlList::kOsWin, kOsVersion, gpu_info);
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
EXPECT_FALSE(control_list->needs_more_info());
decision_entries = control_list->GetActiveEntries();
EXPECT_EQ(1u, decision_entries.size());
EXPECT_EQ(0u, decision_entries[0]);
std::vector<uint32_t> entry_ids =
control_list->GetEntryIDsFromIndices(decision_entries);
EXPECT_EQ(1u, entry_ids.size());
EXPECT_EQ(static_cast<uint32_t>(kGpuControlListTest_NeedsMoreInfo + 1),
entry_ids[0]);
}
TEST_P(GpuControlListTest, NeedsMoreInfoForExceptions) {
const Entry kEntries[1] = {
GetGpuControlListTestingEntries()
[kGpuControlListTest_NeedsMoreInfoForExceptions]};
std::unique_ptr<GpuControlList> control_list = Create(kEntries);
GPUInfo gpu_info;
gpu_info.gpu.vendor_id = kIntelVendorId;
// The case this entry does not apply.
std::set<int> features = control_list->MakeDecision(
GpuControlList::kOsMacosx, kOsVersion, gpu_info);
EXPECT_EMPTY_SET(features);
EXPECT_FALSE(control_list->needs_more_info());
// The case this entry might apply, but need more info.
features = control_list->MakeDecision(
GpuControlList::kOsLinux, kOsVersion, gpu_info);
// Ignore exceptions if main entry info matches
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
EXPECT_TRUE(control_list->needs_more_info());
// The case we have full info, and the exception applies (so the entry
// does not apply).
gpu_info.gl_renderer = is_angle() ? "ANGLE (vendor, mesa, version)" : "mesa";
features = control_list->MakeDecision(
GpuControlList::kOsLinux, kOsVersion, gpu_info);
EXPECT_EMPTY_SET(features);
EXPECT_FALSE(control_list->needs_more_info());
// The case we have full info, and this entry applies.
gpu_info.gl_renderer =
is_angle() ? "ANGLE (vendor, my renderer, version)" : "my renderer";
features = control_list->MakeDecision(GpuControlList::kOsLinux, kOsVersion,
gpu_info);
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
EXPECT_FALSE(control_list->needs_more_info());
}
TEST_P(GpuControlListTest, IgnorableEntries) {
// If an entry will not change the control_list decisions, then it should not
// trigger the needs_more_info flag.
const Entry kEntries[2] = {
GetGpuControlListTestingEntries()[kGpuControlListTest_IgnorableEntries_0],
GetGpuControlListTestingEntries()
[kGpuControlListTest_IgnorableEntries_1]};
std::unique_ptr<GpuControlList> control_list = Create(kEntries);
GPUInfo gpu_info;
gpu_info.gpu.vendor_id = kIntelVendorId;
std::set<int> features = control_list->MakeDecision(
GpuControlList::kOsLinux, kOsVersion, gpu_info);
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
EXPECT_FALSE(control_list->needs_more_info());
}
TEST_P(GpuControlListTest, DisabledExtensionTest) {
// exact setting.
const Entry kEntries[2] = {GetGpuControlListTestingEntries()
[kGpuControlListTest_DisabledExtensionTest_0],
GetGpuControlListTestingEntries()
[kGpuControlListTest_DisabledExtensionTest_1]};
std::unique_ptr<GpuControlList> control_list = Create(kEntries);
GPUInfo gpu_info;
control_list->MakeDecision(GpuControlList::kOsWin, kOsVersion, gpu_info);
std::vector<std::string> disabled_extensions =
control_list->GetDisabledExtensions();
ASSERT_EQ(3u, disabled_extensions.size());
ASSERT_STREQ("test_extension1", disabled_extensions[0].c_str());
ASSERT_STREQ("test_extension2", disabled_extensions[1].c_str());
ASSERT_STREQ("test_extension3", disabled_extensions[2].c_str());
}
TEST_P(GpuControlListTest, LinuxKernelVersion) {
const Entry kEntries[1] = {GetGpuControlListTestingEntries()
[kGpuControlListTest_LinuxKernelVersion]};
std::unique_ptr<GpuControlList> control_list = Create(kEntries);
GPUInfo gpu_info;
gpu_info.gpu.vendor_id = 0x8086;
std::set<int> features = control_list->MakeDecision(
GpuControlList::kOsLinux, "3.13.0-63-generic", gpu_info);
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
features = control_list->MakeDecision(GpuControlList::kOsLinux,
"3.19.2-1-generic", gpu_info);
EXPECT_EMPTY_SET(features);
}
TEST_P(GpuControlListTest, TestGroup) {
const Entry kEntries[3] = {
GetGpuControlListTestingEntries()[kGpuControlListTest_LinuxKernelVersion],
GetGpuControlListTestingEntries()[kGpuControlListTest_TestGroup_0],
GetGpuControlListTestingEntries()[kGpuControlListTest_TestGroup_1]};
std::unique_ptr<GpuControlList> control_list = Create(kEntries);
GPUInfo gpu_info;
// Default test group.
std::set<int> features = control_list->MakeDecision(
GpuControlList::kOsLinux, "3.13.2-1-generic", gpu_info);
EXPECT_EMPTY_SET(features);
// Test group 0, the default test group
features = control_list->MakeDecision(GpuControlList::kOsLinux,
"3.13.2-1-generic", gpu_info, 0);
EXPECT_EMPTY_SET(features);
// Test group 1.
features = control_list->MakeDecision(GpuControlList::kOsLinux,
"3.13.2-1-generic", gpu_info, 1);
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
// Test group 2.
features = control_list->MakeDecision(GpuControlList::kOsLinux,
"3.13.2-1-generic", gpu_info, 2);
EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_1);
}
TEST_P(GpuControlListTest, AngleVulkan) {
EXPECT_EQ(GpuControlList::kGLTypeANGLE_VULKAN,
GetGLType("ANGLE (ARM, Vulkan 1.3.247 (Mali-G52 (0x74021000)), "
"Mali G52-44.1.0)"));
EXPECT_EQ(
GpuControlList::kGLTypeANGLE_VULKAN,
GetGLType("ANGLE (Intel, Vulkan 1.3.289 (Intel(R) Graphics (ADL GT2) "
"(0x00004626)), Intel open-source Mesa driver-24.2.0)"));
EXPECT_EQ(GpuControlList::kGLTypeANGLE_GLES,
GetGLType("ANGLE (ARM, Mali-G52, OpenGL ES 3.1 vxxxxx)"));
EXPECT_EQ(GpuControlList::kGLTypeGLES, GetGLType("Mali-G52"));
}
} // namespace gpu