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/json/json_reader.h"
6 #include "gpu/config/gpu_control_list.h"
7 #include "gpu/config/gpu_info.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 #define LONG_STRING_CONST(...) #__VA_ARGS__
14 enum TestFeatureType
{
20 class GpuControlListEntryTest
: public testing::Test
{
22 GpuControlListEntryTest() { }
23 ~GpuControlListEntryTest() override
{}
25 const GPUInfo
& gpu_info() const {
29 typedef GpuControlList::ScopedGpuControlListEntry ScopedEntry
;
31 static ScopedEntry
GetEntryFromString(
32 const std::string
& json
, bool supports_feature_type_all
) {
33 scoped_ptr
<base::Value
> root
;
34 root
.reset(base::JSONReader::Read(json
));
35 base::DictionaryValue
* value
= NULL
;
36 if (root
.get() == NULL
|| !root
->GetAsDictionary(&value
))
39 GpuControlList::FeatureMap feature_map
;
40 feature_map
["test_feature_0"] = TEST_FEATURE_0
;
41 feature_map
["test_feature_1"] = TEST_FEATURE_1
;
42 feature_map
["test_feature_2"] = TEST_FEATURE_2
;
44 return GpuControlList::GpuControlListEntry::GetEntryFromValue(
45 value
, true, feature_map
, supports_feature_type_all
);
48 static ScopedEntry
GetEntryFromString(const std::string
& json
) {
49 return GetEntryFromString(json
, false);
52 void SetUp() override
{
53 gpu_info_
.gpu
.vendor_id
= 0x10de;
54 gpu_info_
.gpu
.device_id
= 0x0640;
55 gpu_info_
.gpu
.active
= true;
56 gpu_info_
.driver_vendor
= "NVIDIA";
57 gpu_info_
.driver_version
= "1.6.18";
58 gpu_info_
.driver_date
= "7-14-2009";
59 gpu_info_
.gl_version
= "2.1 NVIDIA-8.24.11 310.90.9b01";
60 gpu_info_
.gl_vendor
= "NVIDIA Corporation";
61 gpu_info_
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
68 TEST_F(GpuControlListEntryTest
, DetailedEntry
) {
69 const std::string json
= LONG_STRING_CONST(
72 "description": "test entry",
73 "cr_bugs": [1024, 678],
74 "webkit_bugs": [1950],
82 "vendor_id": "0x10de",
83 "device_id": ["0x0640"],
94 ScopedEntry
entry(GetEntryFromString(json
));
95 EXPECT_TRUE(entry
.get() != NULL
);
96 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
97 EXPECT_FALSE(entry
->disabled());
98 EXPECT_EQ(5u, entry
->id());
99 EXPECT_STREQ("test entry", entry
->description().c_str());
100 EXPECT_EQ(2u, entry
->cr_bugs().size());
101 EXPECT_EQ(1024, entry
->cr_bugs()[0]);
102 EXPECT_EQ(678, entry
->cr_bugs()[1]);
103 EXPECT_EQ(1u, entry
->webkit_bugs().size());
104 EXPECT_EQ(1950, entry
->webkit_bugs()[0]);
105 EXPECT_EQ(1u, entry
->features().size());
106 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_0
));
107 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info()));
108 EXPECT_TRUE(entry
->Contains(
109 GpuControlList::kOsMacosx
, "10.6.4", gpu_info()));
112 TEST_F(GpuControlListEntryTest
, VendorOnAllOsEntry
) {
113 const std::string json
= LONG_STRING_CONST(
116 "vendor_id": "0x10de",
122 ScopedEntry
entry(GetEntryFromString(json
));
123 EXPECT_TRUE(entry
.get() != NULL
);
124 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
126 const GpuControlList::OsType os_type
[] = {
127 GpuControlList::kOsMacosx
,
128 GpuControlList::kOsWin
,
129 GpuControlList::kOsLinux
,
130 GpuControlList::kOsChromeOS
,
131 GpuControlList::kOsAndroid
133 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
134 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
137 TEST_F(GpuControlListEntryTest
, VendorOnLinuxEntry
) {
138 const std::string json
= LONG_STRING_CONST(
144 "vendor_id": "0x10de",
150 ScopedEntry
entry(GetEntryFromString(json
));
151 EXPECT_TRUE(entry
.get() != NULL
);
152 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
154 const GpuControlList::OsType os_type
[] = {
155 GpuControlList::kOsMacosx
,
156 GpuControlList::kOsWin
,
157 GpuControlList::kOsChromeOS
,
158 GpuControlList::kOsAndroid
160 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
161 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
162 EXPECT_TRUE(entry
->Contains(
163 GpuControlList::kOsLinux
, "10.6", gpu_info()));
166 TEST_F(GpuControlListEntryTest
, AllExceptNVidiaOnLinuxEntry
) {
167 const std::string json
= LONG_STRING_CONST(
175 "vendor_id": "0x10de"
183 ScopedEntry
entry(GetEntryFromString(json
));
184 EXPECT_TRUE(entry
.get() != NULL
);
185 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
187 const GpuControlList::OsType os_type
[] = {
188 GpuControlList::kOsMacosx
,
189 GpuControlList::kOsWin
,
190 GpuControlList::kOsLinux
,
191 GpuControlList::kOsChromeOS
,
192 GpuControlList::kOsAndroid
194 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
195 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
198 TEST_F(GpuControlListEntryTest
, AllExceptIntelOnLinuxEntry
) {
199 const std::string json
= LONG_STRING_CONST(
207 "vendor_id": "0x8086"
215 ScopedEntry
entry(GetEntryFromString(json
));
216 EXPECT_TRUE(entry
.get() != NULL
);
217 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
219 const GpuControlList::OsType os_type
[] = {
220 GpuControlList::kOsMacosx
,
221 GpuControlList::kOsWin
,
222 GpuControlList::kOsChromeOS
,
223 GpuControlList::kOsAndroid
225 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
226 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
227 EXPECT_TRUE(entry
->Contains(
228 GpuControlList::kOsLinux
, "10.6", gpu_info()));
231 TEST_F(GpuControlListEntryTest
, DateOnWindowsEntry
) {
232 const std::string json
= LONG_STRING_CONST(
247 ScopedEntry
entry(GetEntryFromString(json
));
248 EXPECT_TRUE(entry
.get() != NULL
);
249 EXPECT_EQ(GpuControlList::kOsWin
, entry
->GetOsType());
252 gpu_info
.driver_date
= "4-12-2010";
253 EXPECT_TRUE(entry
->Contains(
254 GpuControlList::kOsWin
, "10.6", gpu_info
));
255 gpu_info
.driver_date
= "5-8-2010";
256 EXPECT_FALSE(entry
->Contains(
257 GpuControlList::kOsWin
, "10.6", gpu_info
));
258 gpu_info
.driver_date
= "5-9-2010";
259 EXPECT_FALSE(entry
->Contains(
260 GpuControlList::kOsWin
, "10.6", gpu_info
));
263 TEST_F(GpuControlListEntryTest
, MultipleDevicesEntry
) {
264 const std::string json
= LONG_STRING_CONST(
267 "vendor_id": "0x10de",
268 "device_id": ["0x1023", "0x0640"],
274 ScopedEntry
entry(GetEntryFromString(json
));
275 EXPECT_TRUE(entry
.get() != NULL
);
276 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
278 const GpuControlList::OsType os_type
[] = {
279 GpuControlList::kOsMacosx
,
280 GpuControlList::kOsWin
,
281 GpuControlList::kOsLinux
,
282 GpuControlList::kOsChromeOS
,
283 GpuControlList::kOsAndroid
285 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
286 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
289 TEST_F(GpuControlListEntryTest
, ChromeOSEntry
) {
290 const std::string json
= LONG_STRING_CONST(
301 ScopedEntry
entry(GetEntryFromString(json
));
302 EXPECT_TRUE(entry
.get() != NULL
);
303 EXPECT_EQ(GpuControlList::kOsChromeOS
, entry
->GetOsType());
305 const GpuControlList::OsType os_type
[] = {
306 GpuControlList::kOsMacosx
,
307 GpuControlList::kOsWin
,
308 GpuControlList::kOsLinux
,
309 GpuControlList::kOsAndroid
311 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
312 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
313 EXPECT_TRUE(entry
->Contains(
314 GpuControlList::kOsChromeOS
, "10.6", gpu_info()));
317 TEST_F(GpuControlListEntryTest
, MalformedVendor
) {
318 const std::string json
= LONG_STRING_CONST(
321 "vendor_id": "[0x10de]",
327 ScopedEntry
entry(GetEntryFromString(json
));
328 EXPECT_TRUE(entry
.get() == NULL
);
331 TEST_F(GpuControlListEntryTest
, UnknownFieldEntry
) {
332 const std::string json
= LONG_STRING_CONST(
341 ScopedEntry
entry(GetEntryFromString(json
));
342 EXPECT_TRUE(entry
.get() == NULL
);
345 TEST_F(GpuControlListEntryTest
, UnknownExceptionFieldEntry
) {
346 const std::string json
= LONG_STRING_CONST(
359 ScopedEntry
entry(GetEntryFromString(json
));
360 EXPECT_TRUE(entry
.get() == NULL
);
363 TEST_F(GpuControlListEntryTest
, UnknownFeatureEntry
) {
364 const std::string json
= LONG_STRING_CONST(
368 "some_unknown_feature",
373 ScopedEntry
entry(GetEntryFromString(json
));
374 EXPECT_TRUE(entry
.get() == NULL
);
377 TEST_F(GpuControlListEntryTest
, GlVersionGLESEntry
) {
378 const std::string json
= LONG_STRING_CONST(
391 ScopedEntry
entry(GetEntryFromString(json
));
392 EXPECT_TRUE(entry
.get() != NULL
);
395 gpu_info
.gl_version
= "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
396 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
398 gpu_info
.gl_version
= "OpenGL ES 3.0V@66.0 AU@ (CL@)";
399 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
401 gpu_info
.gl_version
= "OpenGL ES 3.1 V@66.0 AU@ (CL@)";
402 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
404 gpu_info
.gl_version
= "3.0 NVIDIA-8.24.11 310.90.9b01";
405 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
407 gpu_info
.gl_version
= "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
408 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
411 TEST_F(GpuControlListEntryTest
, GlVersionANGLEEntry
) {
412 const std::string json
= LONG_STRING_CONST(
425 ScopedEntry
entry(GetEntryFromString(json
));
426 EXPECT_TRUE(entry
.get() != NULL
);
429 gpu_info
.gl_version
= "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
430 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
432 gpu_info
.gl_version
= "3.0 NVIDIA-8.24.11 310.90.9b01";
433 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
435 gpu_info
.gl_version
= "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
436 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
438 gpu_info
.gl_version
= "OpenGL ES 2.0 (ANGLE 1.2.0.2450)";
439 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
442 TEST_F(GpuControlListEntryTest
, GlVersionGLEntry
) {
443 const std::string json
= LONG_STRING_CONST(
456 ScopedEntry
entry(GetEntryFromString(json
));
457 EXPECT_TRUE(entry
.get() != NULL
);
460 gpu_info
.gl_version
= "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
461 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
463 gpu_info
.gl_version
= "3.0 NVIDIA-8.24.11 310.90.9b01";
464 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
466 gpu_info
.gl_version
= "4.0 NVIDIA-8.24.11 310.90.9b01";
467 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
469 gpu_info
.gl_version
= "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
470 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
473 TEST_F(GpuControlListEntryTest
, GlVendorEqual
) {
474 const std::string json
= LONG_STRING_CONST(
477 "gl_vendor": "NVIDIA",
483 ScopedEntry
entry(GetEntryFromString(json
));
484 EXPECT_TRUE(entry
.get() != NULL
);
487 gpu_info
.gl_vendor
= "NVIDIA";
488 EXPECT_TRUE(entry
->Contains(
489 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
492 gpu_info
.gl_vendor
= "NVidia";
493 EXPECT_FALSE(entry
->Contains(
494 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
496 gpu_info
.gl_vendor
= "NVIDIA-x";
497 EXPECT_FALSE(entry
->Contains(
498 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
501 TEST_F(GpuControlListEntryTest
, GlVendorWithDot
) {
502 const std::string json
= LONG_STRING_CONST(
505 "gl_vendor": "X\\.Org.*",
511 ScopedEntry
entry(GetEntryFromString(json
));
512 EXPECT_TRUE(entry
.get() != NULL
);
515 gpu_info
.gl_vendor
= "X.Org R300 Project";
516 EXPECT_TRUE(entry
->Contains(
517 GpuControlList::kOsLinux
, "", gpu_info
));
519 gpu_info
.gl_vendor
= "X.Org";
520 EXPECT_TRUE(entry
->Contains(
521 GpuControlList::kOsLinux
, "", gpu_info
));
524 TEST_F(GpuControlListEntryTest
, GlRendererContains
) {
525 const std::string json
= LONG_STRING_CONST(
528 "gl_renderer": ".*GeForce.*",
534 ScopedEntry
entry(GetEntryFromString(json
));
535 EXPECT_TRUE(entry
.get() != NULL
);
538 gpu_info
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
539 EXPECT_TRUE(entry
->Contains(
540 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
543 gpu_info
.gl_renderer
= "NVIDIA GEFORCE GT 120 OpenGL Engine";
544 EXPECT_FALSE(entry
->Contains(
545 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
547 gpu_info
.gl_renderer
= "GeForce GT 120 OpenGL Engine";
548 EXPECT_TRUE(entry
->Contains(
549 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
551 gpu_info
.gl_renderer
= "NVIDIA GeForce";
552 EXPECT_TRUE(entry
->Contains(
553 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
555 gpu_info
.gl_renderer
= "NVIDIA Ge Force";
556 EXPECT_FALSE(entry
->Contains(
557 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
560 TEST_F(GpuControlListEntryTest
, GlRendererCaseInsensitive
) {
561 const std::string json
= LONG_STRING_CONST(
564 "gl_renderer": "(?i).*software.*",
570 ScopedEntry
entry(GetEntryFromString(json
));
571 EXPECT_TRUE(entry
.get() != NULL
);
574 gpu_info
.gl_renderer
= "software rasterizer";
575 EXPECT_TRUE(entry
->Contains(
576 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
578 gpu_info
.gl_renderer
= "Software Rasterizer";
579 EXPECT_TRUE(entry
->Contains(
580 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
583 TEST_F(GpuControlListEntryTest
, GlExtensionsEndWith
) {
584 const std::string json
= LONG_STRING_CONST(
587 "gl_extensions": ".*GL_SUN_slice_accum",
593 ScopedEntry
entry(GetEntryFromString(json
));
594 EXPECT_TRUE(entry
.get() != NULL
);
597 gpu_info
.gl_extensions
= "GL_SGIS_generate_mipmap "
599 "GL_SUN_slice_accum";
600 EXPECT_TRUE(entry
->Contains(
601 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
603 gpu_info
.gl_extensions
= "GL_SGIS_generate_mipmap "
604 "GL_SUN_slice_accum "
606 EXPECT_FALSE(entry
->Contains(
607 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
610 TEST_F(GpuControlListEntryTest
, DisabledEntry
) {
611 const std::string json
= LONG_STRING_CONST(
620 ScopedEntry
entry(GetEntryFromString(json
));
621 EXPECT_TRUE(entry
.get() != NULL
);
622 EXPECT_TRUE(entry
->disabled());
625 TEST_F(GpuControlListEntryTest
, OptimusEntry
) {
626 const std::string json
= LONG_STRING_CONST(
632 "multi_gpu_style": "optimus",
639 gpu_info
.optimus
= true;
641 ScopedEntry
entry(GetEntryFromString(json
));
642 EXPECT_TRUE(entry
.get() != NULL
);
643 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
644 EXPECT_TRUE(entry
->Contains(
645 GpuControlList::kOsLinux
, "10.6", gpu_info
));
648 TEST_F(GpuControlListEntryTest
, AMDSwitchableEntry
) {
649 const std::string json
= LONG_STRING_CONST(
655 "multi_gpu_style": "amd_switchable",
662 gpu_info
.amd_switchable
= true;
664 ScopedEntry
entry(GetEntryFromString(json
));
665 EXPECT_TRUE(entry
.get() != NULL
);
666 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
667 EXPECT_TRUE(entry
->Contains(
668 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
671 TEST_F(GpuControlListEntryTest
, DriverVendorBeginWith
) {
672 const std::string json
= LONG_STRING_CONST(
675 "driver_vendor": "NVIDIA.*",
681 ScopedEntry
entry(GetEntryFromString(json
));
682 EXPECT_TRUE(entry
.get() != NULL
);
685 gpu_info
.driver_vendor
= "NVIDIA Corporation";
686 EXPECT_TRUE(entry
->Contains(
687 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
690 gpu_info
.driver_vendor
= "NVidia Corporation";
691 EXPECT_FALSE(entry
->Contains(
692 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
694 gpu_info
.driver_vendor
= "NVIDIA";
695 EXPECT_TRUE(entry
->Contains(
696 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
698 gpu_info
.driver_vendor
= "USA NVIDIA";
699 EXPECT_FALSE(entry
->Contains(
700 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
703 TEST_F(GpuControlListEntryTest
, LexicalDriverVersionEntry
) {
704 const std::string json
= LONG_STRING_CONST(
710 "vendor_id": "0x1002",
722 gpu_info
.gpu
.vendor_id
= 0x1002;
724 ScopedEntry
entry(GetEntryFromString(json
));
725 EXPECT_TRUE(entry
.get() != NULL
);
726 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
728 gpu_info
.driver_version
= "8.76";
729 EXPECT_TRUE(entry
->Contains(
730 GpuControlList::kOsLinux
, "10.6", gpu_info
));
732 gpu_info
.driver_version
= "8.768";
733 EXPECT_TRUE(entry
->Contains(
734 GpuControlList::kOsLinux
, "10.6", gpu_info
));
736 gpu_info
.driver_version
= "8.76.8";
737 EXPECT_TRUE(entry
->Contains(
738 GpuControlList::kOsLinux
, "10.6", gpu_info
));
741 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoEntry
) {
742 const std::string json
= LONG_STRING_CONST(
745 "vendor_id": "0x8086",
755 ScopedEntry
entry(GetEntryFromString(json
));
756 EXPECT_TRUE(entry
.get() != NULL
);
759 gpu_info
.gpu
.vendor_id
= 0x8086;
760 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
));
762 gpu_info
.driver_version
= "10.6";
763 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
));
766 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoForExceptionsEntry
) {
767 const std::string json
= LONG_STRING_CONST(
770 "vendor_id": "0x8086",
773 "gl_renderer": ".*mesa.*"
781 ScopedEntry
entry(GetEntryFromString(json
));
782 EXPECT_TRUE(entry
.get() != NULL
);
785 gpu_info
.gpu
.vendor_id
= 0x8086;
786 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
));
788 gpu_info
.gl_renderer
= "mesa";
789 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
));
792 TEST_F(GpuControlListEntryTest
, FeatureTypeAllEntry
) {
793 const std::string json
= LONG_STRING_CONST(
801 ScopedEntry
entry(GetEntryFromString(json
, true));
802 EXPECT_TRUE(entry
.get() != NULL
);
803 EXPECT_EQ(3u, entry
->features().size());
804 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_0
));
805 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_1
));
806 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_2
));
809 TEST_F(GpuControlListEntryTest
, InvalidVendorIdEntry
) {
810 const std::string json
= LONG_STRING_CONST(
813 "vendor_id": "0x0000",
819 ScopedEntry
entry(GetEntryFromString(json
));
820 EXPECT_TRUE(entry
.get() == NULL
);
823 TEST_F(GpuControlListEntryTest
, InvalidDeviceIdEntry
) {
824 const std::string json
= LONG_STRING_CONST(
827 "vendor_id": "0x10de",
828 "device_id": ["0x1023", "0x0000"],
834 ScopedEntry
entry(GetEntryFromString(json
));
835 EXPECT_TRUE(entry
.get() == NULL
);
838 TEST_F(GpuControlListEntryTest
, SingleActiveGPU
) {
839 const std::string json
= LONG_STRING_CONST(
845 "vendor_id": "0x10de",
846 "device_id": ["0x0640"],
847 "multi_gpu_category": "active",
853 ScopedEntry
entry(GetEntryFromString(json
));
854 EXPECT_TRUE(entry
.get() != NULL
);
855 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
856 EXPECT_TRUE(entry
->Contains(
857 GpuControlList::kOsMacosx
, "10.6", gpu_info()));
860 TEST_F(GpuControlListEntryTest
, MachineModelName
) {
861 const std::string json
= LONG_STRING_CONST(
867 "machine_model_name": [
868 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
875 ScopedEntry
entry(GetEntryFromString(json
));
876 EXPECT_TRUE(entry
.get() != NULL
);
877 EXPECT_EQ(GpuControlList::kOsAndroid
, entry
->GetOsType());
880 gpu_info
.machine_model_name
= "Nexus 4";
881 EXPECT_TRUE(entry
->Contains(
882 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
884 gpu_info
.machine_model_name
= "XT1032";
885 EXPECT_TRUE(entry
->Contains(
886 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
888 gpu_info
.machine_model_name
= "XT1032i";
889 EXPECT_FALSE(entry
->Contains(
890 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
892 gpu_info
.machine_model_name
= "Nexus 5";
893 EXPECT_FALSE(entry
->Contains(
894 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
896 gpu_info
.machine_model_name
= "Nexus";
897 EXPECT_FALSE(entry
->Contains(
898 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
900 gpu_info
.machine_model_name
= "";
901 EXPECT_FALSE(entry
->Contains(
902 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
904 gpu_info
.machine_model_name
= "GT-N7100";
905 EXPECT_TRUE(entry
->Contains(
906 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
908 gpu_info
.machine_model_name
= "GT-I9300";
909 EXPECT_TRUE(entry
->Contains(
910 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
912 gpu_info
.machine_model_name
= "SCH-I545";
913 EXPECT_TRUE(entry
->Contains(
914 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
917 TEST_F(GpuControlListEntryTest
, MachineModelNameException
) {
918 const std::string json
= LONG_STRING_CONST(
926 "machine_model_name": ["Nexus.*"]
934 ScopedEntry
entry(GetEntryFromString(json
));
935 EXPECT_TRUE(entry
.get() != NULL
);
936 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
939 gpu_info
.machine_model_name
= "Nexus 4";
940 EXPECT_FALSE(entry
->Contains(
941 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
942 EXPECT_TRUE(entry
->Contains(
943 GpuControlList::kOsLinux
, "4.1", gpu_info
));
945 gpu_info
.machine_model_name
= "Nexus 7";
946 EXPECT_FALSE(entry
->Contains(
947 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
948 EXPECT_TRUE(entry
->Contains(
949 GpuControlList::kOsLinux
, "4.1", gpu_info
));
951 gpu_info
.machine_model_name
= "";
952 EXPECT_TRUE(entry
->Contains(
953 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
954 EXPECT_TRUE(entry
->Contains(
955 GpuControlList::kOsLinux
, "4.1", gpu_info
));
958 TEST_F(GpuControlListEntryTest
, MachineModelVersion
) {
959 const std::string json
= LONG_STRING_CONST(
965 "machine_model_name": ["MacBookPro"],
966 "machine_model_version": {
975 ScopedEntry
entry(GetEntryFromString(json
));
976 EXPECT_TRUE(entry
.get() != NULL
);
978 gpu_info
.machine_model_name
= "MacBookPro";
979 gpu_info
.machine_model_version
= "7.1";
980 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
981 EXPECT_TRUE(entry
->Contains(
982 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
985 TEST_F(GpuControlListEntryTest
, MachineModelVersionException
) {
986 const std::string json
= LONG_STRING_CONST(
992 "machine_model_name": ["MacBookPro"],
995 "machine_model_version": {
1006 ScopedEntry
entry(GetEntryFromString(json
));
1007 EXPECT_TRUE(entry
.get() != NULL
);
1008 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1011 gpu_info
.machine_model_name
= "MacBookPro";
1012 gpu_info
.machine_model_version
= "7.0";
1013 EXPECT_TRUE(entry
->Contains(
1014 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1016 gpu_info
.machine_model_version
= "7.2";
1017 EXPECT_FALSE(entry
->Contains(
1018 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1020 gpu_info
.machine_model_version
= "";
1021 EXPECT_TRUE(entry
->Contains(
1022 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1025 class GpuControlListEntryDualGPUTest
: public GpuControlListEntryTest
{
1027 GpuControlListEntryDualGPUTest() { }
1028 ~GpuControlListEntryDualGPUTest() override
{}
1030 void SetUp() override
{
1031 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
1032 // secondary, and initially Intel is active.
1033 gpu_info_
.gpu
.vendor_id
= 0x10de;
1034 gpu_info_
.gpu
.device_id
= 0x0640;
1035 gpu_info_
.gpu
.active
= false;
1036 GPUInfo::GPUDevice second_gpu
;
1037 second_gpu
.vendor_id
= 0x8086;
1038 second_gpu
.device_id
= 0x0166;
1039 second_gpu
.active
= true;
1040 gpu_info_
.secondary_gpus
.push_back(second_gpu
);
1043 void ActivatePrimaryGPU() {
1044 gpu_info_
.gpu
.active
= true;
1045 gpu_info_
.secondary_gpus
[0].active
= false;
1048 void EntryShouldApply(const std::string
& entry_json
) const {
1049 EXPECT_TRUE(EntryApplies(entry_json
));
1052 void EntryShouldNotApply(const std::string
& entry_json
) const {
1053 EXPECT_FALSE(EntryApplies(entry_json
));
1057 bool EntryApplies(const std::string
& entry_json
) const {
1058 ScopedEntry
entry(GetEntryFromString(entry_json
));
1059 EXPECT_TRUE(entry
.get());
1060 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1061 return entry
->Contains(GpuControlList::kOsMacosx
, "10.6", gpu_info());
1065 TEST_F(GpuControlListEntryDualGPUTest
, CategoryAny
) {
1066 const std::string json_intel
= LONG_STRING_CONST(
1072 "vendor_id": "0x8086",
1073 "device_id": ["0x0166"],
1074 "multi_gpu_category": "any",
1080 EntryShouldApply(json_intel
);
1082 const std::string json_nvidia
= LONG_STRING_CONST(
1088 "vendor_id": "0x10de",
1089 "device_id": ["0x0640"],
1090 "multi_gpu_category": "any",
1096 EntryShouldApply(json_nvidia
);
1099 TEST_F(GpuControlListEntryDualGPUTest
, CategoryPrimarySecondary
) {
1100 const std::string json_secondary
= LONG_STRING_CONST(
1106 "vendor_id": "0x8086",
1107 "device_id": ["0x0166"],
1108 "multi_gpu_category": "secondary",
1114 EntryShouldApply(json_secondary
);
1116 const std::string json_primary
= LONG_STRING_CONST(
1122 "vendor_id": "0x8086",
1123 "device_id": ["0x0166"],
1124 "multi_gpu_category": "primary",
1130 EntryShouldNotApply(json_primary
);
1132 const std::string json_default
= LONG_STRING_CONST(
1138 "vendor_id": "0x8086",
1139 "device_id": ["0x0166"],
1145 // Default is primary.
1146 EntryShouldNotApply(json_default
);
1149 TEST_F(GpuControlListEntryDualGPUTest
, ActiveSecondaryGPU
) {
1150 const std::string json
= LONG_STRING_CONST(
1156 "vendor_id": "0x8086",
1157 "device_id": ["0x0166", "0x0168"],
1158 "multi_gpu_category": "active",
1164 // By default, secondary GPU is active.
1165 EntryShouldApply(json
);
1167 ActivatePrimaryGPU();
1168 EntryShouldNotApply(json
);
1171 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActiveSecondaryGPU
) {
1172 const std::string json
= LONG_STRING_CONST(
1178 "vendor_id": "0x8086",
1179 "multi_gpu_category": "active",
1185 // By default, secondary GPU is active.
1186 EntryShouldApply(json
);
1188 ActivatePrimaryGPU();
1189 EntryShouldNotApply(json
);
1192 TEST_F(GpuControlListEntryDualGPUTest
, ActivePrimaryGPU
) {
1193 const std::string json
= LONG_STRING_CONST(
1199 "vendor_id": "0x10de",
1200 "device_id": ["0x0640"],
1201 "multi_gpu_category": "active",
1207 // By default, secondary GPU is active.
1208 EntryShouldNotApply(json
);
1210 ActivatePrimaryGPU();
1211 EntryShouldApply(json
);
1214 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActivePrimaryGPU
) {
1215 const std::string json
= LONG_STRING_CONST(
1221 "vendor_id": "0x10de",
1222 "multi_gpu_category": "active",
1228 // By default, secondary GPU is active.
1229 EntryShouldNotApply(json
);
1231 ActivatePrimaryGPU();
1232 EntryShouldApply(json
);