Revert of Revert of Remove accelerated hardware decode blacklist entry for Mac OS...
[chromium-blink-merge.git] / gpu / config / gpu_control_list_unittest.cc
blobf96818387c52653f745f207f517d9d5954f1bd38
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 <vector>
7 #include "base/memory/scoped_ptr.h"
8 #include "gpu/config/gpu_control_list.h"
9 #include "gpu/config/gpu_info.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 const char kOsVersion[] = "10.6.4";
13 const uint32 kIntelVendorId = 0x8086;
14 const uint32 kNvidiaVendorId = 0x10de;
15 const uint32 kAmdVendorId = 0x10de;
17 #define LONG_STRING_CONST(...) #__VA_ARGS__
19 #define EXPECT_EMPTY_SET(feature_set) EXPECT_EQ(0u, feature_set.size())
20 #define EXPECT_SINGLE_FEATURE(feature_set, feature) \
21 EXPECT_TRUE(feature_set.size() == 1 && feature_set.count(feature) == 1)
23 namespace gpu {
25 enum TestFeatureType {
26 TEST_FEATURE_0 = 1,
27 TEST_FEATURE_1 = 1 << 2,
28 TEST_FEATURE_2 = 1 << 3,
31 class GpuControlListTest : public testing::Test {
32 public:
33 GpuControlListTest() { }
35 ~GpuControlListTest() override {}
37 const GPUInfo& gpu_info() const {
38 return gpu_info_;
41 GpuControlList* Create() {
42 GpuControlList* rt = new GpuControlList();
43 rt->AddSupportedFeature("test_feature_0", TEST_FEATURE_0);
44 rt->AddSupportedFeature("test_feature_1", TEST_FEATURE_1);
45 rt->AddSupportedFeature("test_feature_2", TEST_FEATURE_2);
46 return rt;
49 protected:
50 void SetUp() override {
51 gpu_info_.gpu.vendor_id = kNvidiaVendorId;
52 gpu_info_.gpu.device_id = 0x0640;
53 gpu_info_.driver_vendor = "NVIDIA";
54 gpu_info_.driver_version = "1.6.18";
55 gpu_info_.driver_date = "7-14-2009";
56 gpu_info_.machine_model_name = "MacBookPro";
57 gpu_info_.machine_model_version = "7.1";
58 gpu_info_.gl_vendor = "NVIDIA Corporation";
59 gpu_info_.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
60 gpu_info_.performance_stats.graphics = 5.0;
61 gpu_info_.performance_stats.gaming = 5.0;
62 gpu_info_.performance_stats.overall = 5.0;
65 void TearDown() override {}
67 private:
68 GPUInfo gpu_info_;
71 TEST_F(GpuControlListTest, DefaultControlListSettings) {
72 scoped_ptr<GpuControlList> control_list(Create());
73 // Default control list settings: all feature are allowed.
74 std::set<int> features = control_list->MakeDecision(
75 GpuControlList::kOsMacosx, kOsVersion, gpu_info());
76 EXPECT_EMPTY_SET(features);
79 TEST_F(GpuControlListTest, EmptyControlList) {
80 // Empty list: all features are allowed.
81 const std::string empty_list_json = LONG_STRING_CONST(
83 "name": "gpu control list",
84 "version": "2.5",
85 "entries": [
89 scoped_ptr<GpuControlList> control_list(Create());
91 EXPECT_TRUE(control_list->LoadList(empty_list_json,
92 GpuControlList::kAllOs));
93 EXPECT_EQ("2.5", control_list->version());
94 std::set<int> features = control_list->MakeDecision(
95 GpuControlList::kOsMacosx, kOsVersion, gpu_info());
96 EXPECT_EMPTY_SET(features);
99 TEST_F(GpuControlListTest, DetailedEntryAndInvalidJson) {
100 // exact setting.
101 const std::string exact_list_json = LONG_STRING_CONST(
103 "name": "gpu control list",
104 "version": "0.1",
105 "entries": [
107 "id": 5,
108 "os": {
109 "type": "macosx",
110 "version": {
111 "op": "=",
112 "value": "10.6.4"
115 "vendor_id": "0x10de",
116 "device_id": ["0x0640"],
117 "driver_version": {
118 "op": "=",
119 "value": "1.6.18"
121 "features": [
122 "test_feature_0"
128 scoped_ptr<GpuControlList> control_list(Create());
130 EXPECT_TRUE(control_list->LoadList(exact_list_json, GpuControlList::kAllOs));
131 std::set<int> features = control_list->MakeDecision(
132 GpuControlList::kOsMacosx, kOsVersion, gpu_info());
133 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
135 // Invalid json input should not change the current control_list settings.
136 const std::string invalid_json = "invalid";
138 EXPECT_FALSE(control_list->LoadList(invalid_json, GpuControlList::kAllOs));
139 features = control_list->MakeDecision(
140 GpuControlList::kOsMacosx, kOsVersion, gpu_info());
141 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
142 std::vector<uint32> entries;
143 control_list->GetDecisionEntries(&entries, false);
144 ASSERT_EQ(1u, entries.size());
145 EXPECT_EQ(5u, entries[0]);
146 EXPECT_EQ(5u, control_list->max_entry_id());
149 TEST_F(GpuControlListTest, VendorOnAllOsEntry) {
150 // ControlList a vendor on all OS.
151 const std::string vendor_json = LONG_STRING_CONST(
153 "name": "gpu control list",
154 "version": "0.1",
155 "entries": [
157 "id": 1,
158 "vendor_id": "0x10de",
159 "features": [
160 "test_feature_0"
166 scoped_ptr<GpuControlList> control_list(Create());
168 // ControlList entries won't be filtered to the current OS only upon loading.
169 EXPECT_TRUE(control_list->LoadList(vendor_json, GpuControlList::kAllOs));
170 std::set<int> features = control_list->MakeDecision(
171 GpuControlList::kOsMacosx, kOsVersion, gpu_info());
172 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
173 features = control_list->MakeDecision(
174 GpuControlList::kOsWin, kOsVersion, gpu_info());
175 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
176 features = control_list->MakeDecision(
177 GpuControlList::kOsLinux, kOsVersion, gpu_info());
178 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
179 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) || \
180 defined(OS_OPENBSD)
181 // ControlList entries will be filtered to the current OS only upon loading.
182 EXPECT_TRUE(control_list->LoadList(
183 vendor_json, GpuControlList::kCurrentOsOnly));
184 features = control_list->MakeDecision(
185 GpuControlList::kOsMacosx, kOsVersion, gpu_info());
186 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
187 features = control_list->MakeDecision(
188 GpuControlList::kOsWin, kOsVersion, gpu_info());
189 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
190 features = control_list->MakeDecision(
191 GpuControlList::kOsLinux, kOsVersion, gpu_info());
192 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
193 #endif
196 TEST_F(GpuControlListTest, UnknownField) {
197 const std::string unknown_field_json = LONG_STRING_CONST(
199 "name": "gpu control list",
200 "version": "0.1",
201 "entries": [
203 "id": 1,
204 "unknown_field": 0,
205 "features": [
206 "test_feature_1"
210 "id": 2,
211 "features": [
212 "test_feature_0"
218 scoped_ptr<GpuControlList> control_list(Create());
220 EXPECT_FALSE(control_list->LoadList(
221 unknown_field_json, GpuControlList::kAllOs));
224 TEST_F(GpuControlListTest, UnknownExceptionField) {
225 const std::string unknown_exception_field_json = LONG_STRING_CONST(
227 "name": "gpu control list",
228 "version": "0.1",
229 "entries": [
231 "id": 1,
232 "unknown_field": 0,
233 "features": [
234 "test_feature_2"
238 "id": 2,
239 "exceptions": [
241 "unknown_field": 0
244 "features": [
245 "test_feature_1"
249 "id": 3,
250 "features": [
251 "test_feature_0"
257 scoped_ptr<GpuControlList> control_list(Create());
259 EXPECT_FALSE(control_list->LoadList(
260 unknown_exception_field_json, GpuControlList::kAllOs));
263 TEST_F(GpuControlListTest, DisabledEntry) {
264 const std::string disabled_json = LONG_STRING_CONST(
266 "name": "gpu control list",
267 "version": "0.1",
268 "entries": [
270 "id": 1,
271 "disabled": true,
272 "features": [
273 "test_feature_0"
279 scoped_ptr<GpuControlList> control_list(Create());
280 EXPECT_TRUE(control_list->LoadList(disabled_json, GpuControlList::kAllOs));
281 std::set<int> features = control_list->MakeDecision(
282 GpuControlList::kOsWin, kOsVersion, gpu_info());
283 EXPECT_EMPTY_SET(features);
284 std::vector<uint32> flag_entries;
285 control_list->GetDecisionEntries(&flag_entries, false);
286 EXPECT_EQ(0u, flag_entries.size());
287 control_list->GetDecisionEntries(&flag_entries, true);
288 EXPECT_EQ(1u, flag_entries.size());
291 TEST_F(GpuControlListTest, NeedsMoreInfo) {
292 const std::string json = LONG_STRING_CONST(
294 "name": "gpu control list",
295 "version": "0.1",
296 "entries": [
298 "id": 1,
299 "os": {
300 "type": "win"
302 "vendor_id": "0x10de",
303 "driver_version": {
304 "op": "<",
305 "value": "12"
307 "features": [
308 "test_feature_0"
314 GPUInfo gpu_info;
315 gpu_info.gpu.vendor_id = kNvidiaVendorId;
317 scoped_ptr<GpuControlList> control_list(Create());
318 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
320 std::set<int> features = control_list->MakeDecision(
321 GpuControlList::kOsWin, kOsVersion, gpu_info);
322 EXPECT_EMPTY_SET(features);
323 EXPECT_TRUE(control_list->needs_more_info());
324 std::vector<uint32> decision_entries;
325 control_list->GetDecisionEntries(&decision_entries, false);
326 EXPECT_EQ(0u, decision_entries.size());
328 gpu_info.driver_version = "11";
329 features = control_list->MakeDecision(
330 GpuControlList::kOsWin, kOsVersion, gpu_info);
331 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
332 EXPECT_FALSE(control_list->needs_more_info());
333 control_list->GetDecisionEntries(&decision_entries, false);
334 EXPECT_EQ(1u, decision_entries.size());
337 TEST_F(GpuControlListTest, NeedsMoreInfoForExceptions) {
338 const std::string json = LONG_STRING_CONST(
340 "name": "gpu control list",
341 "version": "0.1",
342 "entries": [
344 "id": 1,
345 "os": {
346 "type": "linux"
348 "vendor_id": "0x8086",
349 "exceptions": [
351 "gl_renderer": ".*mesa.*"
354 "features": [
355 "test_feature_0"
361 GPUInfo gpu_info;
362 gpu_info.gpu.vendor_id = kIntelVendorId;
364 scoped_ptr<GpuControlList> control_list(Create());
365 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
367 // The case this entry does not apply.
368 std::set<int> features = control_list->MakeDecision(
369 GpuControlList::kOsMacosx, kOsVersion, gpu_info);
370 EXPECT_EMPTY_SET(features);
371 EXPECT_FALSE(control_list->needs_more_info());
373 // The case this entry might apply, but need more info.
374 features = control_list->MakeDecision(
375 GpuControlList::kOsLinux, kOsVersion, gpu_info);
376 EXPECT_EMPTY_SET(features);
377 EXPECT_TRUE(control_list->needs_more_info());
379 // The case we have full info, and the exception applies (so the entry
380 // does not apply).
381 gpu_info.gl_renderer = "mesa";
382 features = control_list->MakeDecision(
383 GpuControlList::kOsLinux, kOsVersion, gpu_info);
384 EXPECT_EMPTY_SET(features);
385 EXPECT_FALSE(control_list->needs_more_info());
387 // The case we have full info, and this entry applies.
388 gpu_info.gl_renderer = "my renderer";
389 features = control_list->MakeDecision(GpuControlList::kOsLinux, kOsVersion,
390 gpu_info);
391 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
392 EXPECT_FALSE(control_list->needs_more_info());
395 TEST_F(GpuControlListTest, IgnorableEntries) {
396 // If an entry will not change the control_list decisions, then it should not
397 // trigger the needs_more_info flag.
398 const std::string json = LONG_STRING_CONST(
400 "name": "gpu control list",
401 "version": "0.1",
402 "entries": [
404 "id": 1,
405 "os": {
406 "type": "linux"
408 "vendor_id": "0x8086",
409 "features": [
410 "test_feature_0"
414 "id": 2,
415 "os": {
416 "type": "linux"
418 "vendor_id": "0x8086",
419 "driver_version": {
420 "op": "<",
421 "value": "10.7"
423 "features": [
424 "test_feature_0"
430 GPUInfo gpu_info;
431 gpu_info.gpu.vendor_id = kIntelVendorId;
433 scoped_ptr<GpuControlList> control_list(Create());
434 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
435 std::set<int> features = control_list->MakeDecision(
436 GpuControlList::kOsLinux, kOsVersion, gpu_info);
437 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
438 EXPECT_FALSE(control_list->needs_more_info());
441 TEST_F(GpuControlListTest, ExceptionWithoutVendorId) {
442 const std::string json = LONG_STRING_CONST(
444 "name": "gpu control list",
445 "version": "0.1",
446 "entries": [
448 "id": 1,
449 "os": {
450 "type": "linux"
452 "vendor_id": "0x8086",
453 "exceptions": [
455 "device_id": ["0x2a06"],
456 "driver_version": {
457 "op": ">=",
458 "value": "8.1"
462 "device_id": ["0x2a02"],
463 "driver_version": {
464 "op": ">=",
465 "value": "9.1"
469 "features": [
470 "test_feature_0"
476 GPUInfo gpu_info;
477 gpu_info.gpu.vendor_id = kIntelVendorId;
478 gpu_info.gpu.device_id = 0x2a02;
479 gpu_info.driver_version = "9.1";
481 scoped_ptr<GpuControlList> control_list(Create());
482 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
484 std::set<int> features = control_list->MakeDecision(
485 GpuControlList::kOsLinux, kOsVersion, gpu_info);
486 EXPECT_EMPTY_SET(features);
488 gpu_info.driver_version = "9.0";
489 features = control_list->MakeDecision(
490 GpuControlList::kOsLinux, kOsVersion, gpu_info);
491 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
494 TEST_F(GpuControlListTest, AMDSwitchable) {
495 GPUInfo gpu_info;
496 gpu_info.amd_switchable = true;
497 gpu_info.gpu.vendor_id = kAmdVendorId;
498 gpu_info.gpu.device_id = 0x6760;
499 GPUInfo::GPUDevice integrated_gpu;
500 integrated_gpu.vendor_id = kIntelVendorId;
501 integrated_gpu.device_id = 0x0116;
502 gpu_info.secondary_gpus.push_back(integrated_gpu);
504 { // amd_switchable_discrete entry
505 const std::string json= LONG_STRING_CONST(
507 "name": "gpu control list",
508 "version": "0.1",
509 "entries": [
511 "id": 1,
512 "os": {
513 "type": "win"
515 "multi_gpu_style": "amd_switchable_discrete",
516 "features": [
517 "test_feature_0"
524 scoped_ptr<GpuControlList> control_list(Create());
525 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
527 // Integrated GPU is active
528 gpu_info.gpu.active = false;
529 gpu_info.secondary_gpus[0].active = true;
530 std::set<int> features = control_list->MakeDecision(
531 GpuControlList::kOsWin, kOsVersion, gpu_info);
532 EXPECT_EMPTY_SET(features);
534 // Discrete GPU is active
535 gpu_info.gpu.active = true;
536 gpu_info.secondary_gpus[0].active = false;
537 features = control_list->MakeDecision(
538 GpuControlList::kOsWin, kOsVersion, gpu_info);
539 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
542 { // amd_switchable_integrated entry
543 const std::string json= LONG_STRING_CONST(
545 "name": "gpu control list",
546 "version": "0.1",
547 "entries": [
549 "id": 1,
550 "os": {
551 "type": "win"
553 "multi_gpu_style": "amd_switchable_integrated",
554 "features": [
555 "test_feature_0"
562 scoped_ptr<GpuControlList> control_list(Create());
563 EXPECT_TRUE(control_list->LoadList(json, GpuControlList::kAllOs));
565 // Discrete GPU is active
566 gpu_info.gpu.active = true;
567 gpu_info.secondary_gpus[0].active = false;
568 std::set<int> features = control_list->MakeDecision(
569 GpuControlList::kOsWin, kOsVersion, gpu_info);
570 EXPECT_EMPTY_SET(features);
572 // Integrated GPU is active
573 gpu_info.gpu.active = false;
574 gpu_info.secondary_gpus[0].active = true;
575 features = control_list->MakeDecision(
576 GpuControlList::kOsWin, kOsVersion, gpu_info);
577 EXPECT_SINGLE_FEATURE(features, TEST_FEATURE_0);
579 // For non AMD switchable
580 gpu_info.amd_switchable = false;
581 features = control_list->MakeDecision(
582 GpuControlList::kOsWin, kOsVersion, gpu_info);
583 EXPECT_EMPTY_SET(features);
587 } // namespace gpu