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
= base::JSONReader::Read(json
);
34 base::DictionaryValue
* value
= NULL
;
35 if (!root
|| !root
->GetAsDictionary(&value
))
38 GpuControlList::FeatureMap feature_map
;
39 feature_map
["test_feature_0"] = TEST_FEATURE_0
;
40 feature_map
["test_feature_1"] = TEST_FEATURE_1
;
41 feature_map
["test_feature_2"] = TEST_FEATURE_2
;
43 return GpuControlList::GpuControlListEntry::GetEntryFromValue(
44 value
, true, feature_map
, supports_feature_type_all
);
47 static ScopedEntry
GetEntryFromString(const std::string
& json
) {
48 return GetEntryFromString(json
, false);
51 void SetUp() override
{
52 gpu_info_
.gpu
.vendor_id
= 0x10de;
53 gpu_info_
.gpu
.device_id
= 0x0640;
54 gpu_info_
.gpu
.active
= true;
55 gpu_info_
.driver_vendor
= "NVIDIA";
56 gpu_info_
.driver_version
= "1.6.18";
57 gpu_info_
.driver_date
= "7-14-2009";
58 gpu_info_
.gl_version
= "2.1 NVIDIA-8.24.11 310.90.9b01";
59 gpu_info_
.gl_vendor
= "NVIDIA Corporation";
60 gpu_info_
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
67 TEST_F(GpuControlListEntryTest
, DetailedEntry
) {
68 const std::string json
= LONG_STRING_CONST(
71 "description": "test entry",
72 "cr_bugs": [1024, 678],
73 "webkit_bugs": [1950],
81 "vendor_id": "0x10de",
82 "device_id": ["0x0640"],
90 "disabled_extensions": [
97 ScopedEntry
entry(GetEntryFromString(json
));
98 EXPECT_TRUE(entry
.get() != NULL
);
99 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
100 EXPECT_FALSE(entry
->disabled());
101 EXPECT_EQ(5u, entry
->id());
102 EXPECT_STREQ("test entry", entry
->description().c_str());
103 EXPECT_EQ(2u, entry
->cr_bugs().size());
104 EXPECT_EQ(1024, entry
->cr_bugs()[0]);
105 EXPECT_EQ(678, entry
->cr_bugs()[1]);
106 EXPECT_EQ(1u, entry
->webkit_bugs().size());
107 EXPECT_EQ(1950, entry
->webkit_bugs()[0]);
108 EXPECT_EQ(1u, entry
->features().size());
109 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_0
));
110 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info(), true));
111 EXPECT_TRUE(entry
->Contains(
112 GpuControlList::kOsMacosx
, "10.6.4", gpu_info()));
113 EXPECT_STREQ("test_extension1", entry
->disabled_extensions()[0].c_str());
114 EXPECT_STREQ("test_extension2", entry
->disabled_extensions()[1].c_str());
117 TEST_F(GpuControlListEntryTest
, VendorOnAllOsEntry
) {
118 const std::string json
= LONG_STRING_CONST(
121 "vendor_id": "0x10de",
127 ScopedEntry
entry(GetEntryFromString(json
));
128 EXPECT_TRUE(entry
.get() != NULL
);
129 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
131 const GpuControlList::OsType os_type
[] = {
132 GpuControlList::kOsMacosx
,
133 GpuControlList::kOsWin
,
134 GpuControlList::kOsLinux
,
135 GpuControlList::kOsChromeOS
,
136 GpuControlList::kOsAndroid
138 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
139 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
142 TEST_F(GpuControlListEntryTest
, VendorOnLinuxEntry
) {
143 const std::string json
= LONG_STRING_CONST(
149 "vendor_id": "0x10de",
155 ScopedEntry
entry(GetEntryFromString(json
));
156 EXPECT_TRUE(entry
.get() != NULL
);
157 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
159 const GpuControlList::OsType os_type
[] = {
160 GpuControlList::kOsMacosx
,
161 GpuControlList::kOsWin
,
162 GpuControlList::kOsChromeOS
,
163 GpuControlList::kOsAndroid
165 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
166 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
167 EXPECT_TRUE(entry
->Contains(
168 GpuControlList::kOsLinux
, "10.6", gpu_info()));
171 TEST_F(GpuControlListEntryTest
, AllExceptNVidiaOnLinuxEntry
) {
172 const std::string json
= LONG_STRING_CONST(
180 "vendor_id": "0x10de"
188 ScopedEntry
entry(GetEntryFromString(json
));
189 EXPECT_TRUE(entry
.get() != NULL
);
190 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
192 const GpuControlList::OsType os_type
[] = {
193 GpuControlList::kOsMacosx
,
194 GpuControlList::kOsWin
,
195 GpuControlList::kOsLinux
,
196 GpuControlList::kOsChromeOS
,
197 GpuControlList::kOsAndroid
199 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
200 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
203 TEST_F(GpuControlListEntryTest
, AllExceptIntelOnLinuxEntry
) {
204 const std::string json
= LONG_STRING_CONST(
212 "vendor_id": "0x8086"
220 ScopedEntry
entry(GetEntryFromString(json
));
221 EXPECT_TRUE(entry
.get() != NULL
);
222 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
224 const GpuControlList::OsType os_type
[] = {
225 GpuControlList::kOsMacosx
,
226 GpuControlList::kOsWin
,
227 GpuControlList::kOsChromeOS
,
228 GpuControlList::kOsAndroid
230 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
231 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
232 EXPECT_TRUE(entry
->Contains(
233 GpuControlList::kOsLinux
, "10.6", gpu_info()));
236 TEST_F(GpuControlListEntryTest
, DateOnWindowsEntry
) {
237 const std::string json
= LONG_STRING_CONST(
252 ScopedEntry
entry(GetEntryFromString(json
));
253 EXPECT_TRUE(entry
.get() != NULL
);
254 EXPECT_EQ(GpuControlList::kOsWin
, entry
->GetOsType());
257 gpu_info
.driver_date
= "4-12-2010";
258 EXPECT_TRUE(entry
->Contains(
259 GpuControlList::kOsWin
, "10.6", gpu_info
));
260 gpu_info
.driver_date
= "5-8-2010";
261 EXPECT_FALSE(entry
->Contains(
262 GpuControlList::kOsWin
, "10.6", gpu_info
));
263 gpu_info
.driver_date
= "5-9-2010";
264 EXPECT_FALSE(entry
->Contains(
265 GpuControlList::kOsWin
, "10.6", gpu_info
));
268 TEST_F(GpuControlListEntryTest
, MultipleDevicesEntry
) {
269 const std::string json
= LONG_STRING_CONST(
272 "vendor_id": "0x10de",
273 "device_id": ["0x1023", "0x0640"],
279 ScopedEntry
entry(GetEntryFromString(json
));
280 EXPECT_TRUE(entry
.get() != NULL
);
281 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
283 const GpuControlList::OsType os_type
[] = {
284 GpuControlList::kOsMacosx
,
285 GpuControlList::kOsWin
,
286 GpuControlList::kOsLinux
,
287 GpuControlList::kOsChromeOS
,
288 GpuControlList::kOsAndroid
290 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
291 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
294 TEST_F(GpuControlListEntryTest
, ChromeOSEntry
) {
295 const std::string json
= LONG_STRING_CONST(
306 ScopedEntry
entry(GetEntryFromString(json
));
307 EXPECT_TRUE(entry
.get() != NULL
);
308 EXPECT_EQ(GpuControlList::kOsChromeOS
, entry
->GetOsType());
310 const GpuControlList::OsType os_type
[] = {
311 GpuControlList::kOsMacosx
,
312 GpuControlList::kOsWin
,
313 GpuControlList::kOsLinux
,
314 GpuControlList::kOsAndroid
316 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
317 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
318 EXPECT_TRUE(entry
->Contains(
319 GpuControlList::kOsChromeOS
, "10.6", gpu_info()));
322 TEST_F(GpuControlListEntryTest
, MalformedVendor
) {
323 const std::string json
= LONG_STRING_CONST(
326 "vendor_id": "[0x10de]",
332 ScopedEntry
entry(GetEntryFromString(json
));
333 EXPECT_TRUE(entry
.get() == NULL
);
336 TEST_F(GpuControlListEntryTest
, UnknownFieldEntry
) {
337 const std::string json
= LONG_STRING_CONST(
346 ScopedEntry
entry(GetEntryFromString(json
));
347 EXPECT_TRUE(entry
.get() == NULL
);
350 TEST_F(GpuControlListEntryTest
, UnknownExceptionFieldEntry
) {
351 const std::string json
= LONG_STRING_CONST(
364 ScopedEntry
entry(GetEntryFromString(json
));
365 EXPECT_TRUE(entry
.get() == NULL
);
368 TEST_F(GpuControlListEntryTest
, UnknownFeatureEntry
) {
369 const std::string json
= LONG_STRING_CONST(
373 "some_unknown_feature",
378 ScopedEntry
entry(GetEntryFromString(json
));
379 EXPECT_TRUE(entry
.get() == NULL
);
382 TEST_F(GpuControlListEntryTest
, GlVersionGLESEntry
) {
383 const std::string json
= LONG_STRING_CONST(
396 ScopedEntry
entry(GetEntryFromString(json
));
397 EXPECT_TRUE(entry
.get() != NULL
);
400 gpu_info
.gl_version
= "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
401 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
403 gpu_info
.gl_version
= "OpenGL ES 3.0V@66.0 AU@ (CL@)";
404 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
406 gpu_info
.gl_version
= "OpenGL ES 3.1 V@66.0 AU@ (CL@)";
407 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
409 gpu_info
.gl_version
= "3.0 NVIDIA-8.24.11 310.90.9b01";
410 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
412 gpu_info
.gl_version
= "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
413 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
416 TEST_F(GpuControlListEntryTest
, GlVersionANGLEEntry
) {
417 const std::string json
= LONG_STRING_CONST(
430 ScopedEntry
entry(GetEntryFromString(json
));
431 EXPECT_TRUE(entry
.get() != NULL
);
434 gpu_info
.gl_version
= "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
435 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
437 gpu_info
.gl_version
= "3.0 NVIDIA-8.24.11 310.90.9b01";
438 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
440 gpu_info
.gl_version
= "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
441 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
443 gpu_info
.gl_version
= "OpenGL ES 2.0 (ANGLE 1.2.0.2450)";
444 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
447 TEST_F(GpuControlListEntryTest
, GlVersionGLEntry
) {
448 const std::string json
= LONG_STRING_CONST(
461 ScopedEntry
entry(GetEntryFromString(json
));
462 EXPECT_TRUE(entry
.get() != NULL
);
465 gpu_info
.gl_version
= "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
466 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsAndroid
, "4.4.2", gpu_info
));
468 gpu_info
.gl_version
= "3.0 NVIDIA-8.24.11 310.90.9b01";
469 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
471 gpu_info
.gl_version
= "4.0 NVIDIA-8.24.11 310.90.9b01";
472 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsMacosx
, "10.9", gpu_info
));
474 gpu_info
.gl_version
= "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
475 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "6.1", gpu_info
));
478 TEST_F(GpuControlListEntryTest
, GlVendorEqual
) {
479 const std::string json
= LONG_STRING_CONST(
482 "gl_vendor": "NVIDIA",
488 ScopedEntry
entry(GetEntryFromString(json
));
489 EXPECT_TRUE(entry
.get() != NULL
);
492 gpu_info
.gl_vendor
= "NVIDIA";
493 EXPECT_TRUE(entry
->Contains(
494 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
497 gpu_info
.gl_vendor
= "NVidia";
498 EXPECT_FALSE(entry
->Contains(
499 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
501 gpu_info
.gl_vendor
= "NVIDIA-x";
502 EXPECT_FALSE(entry
->Contains(
503 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
506 TEST_F(GpuControlListEntryTest
, GlVendorWithDot
) {
507 const std::string json
= LONG_STRING_CONST(
510 "gl_vendor": "X\\.Org.*",
516 ScopedEntry
entry(GetEntryFromString(json
));
517 EXPECT_TRUE(entry
.get() != NULL
);
520 gpu_info
.gl_vendor
= "X.Org R300 Project";
521 EXPECT_TRUE(entry
->Contains(
522 GpuControlList::kOsLinux
, "", gpu_info
));
524 gpu_info
.gl_vendor
= "X.Org";
525 EXPECT_TRUE(entry
->Contains(
526 GpuControlList::kOsLinux
, "", gpu_info
));
529 TEST_F(GpuControlListEntryTest
, GlRendererContains
) {
530 const std::string json
= LONG_STRING_CONST(
533 "gl_renderer": ".*GeForce.*",
539 ScopedEntry
entry(GetEntryFromString(json
));
540 EXPECT_TRUE(entry
.get() != NULL
);
543 gpu_info
.gl_renderer
= "NVIDIA GeForce GT 120 OpenGL Engine";
544 EXPECT_TRUE(entry
->Contains(
545 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
548 gpu_info
.gl_renderer
= "NVIDIA GEFORCE GT 120 OpenGL Engine";
549 EXPECT_FALSE(entry
->Contains(
550 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
552 gpu_info
.gl_renderer
= "GeForce GT 120 OpenGL Engine";
553 EXPECT_TRUE(entry
->Contains(
554 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
556 gpu_info
.gl_renderer
= "NVIDIA GeForce";
557 EXPECT_TRUE(entry
->Contains(
558 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
560 gpu_info
.gl_renderer
= "NVIDIA Ge Force";
561 EXPECT_FALSE(entry
->Contains(
562 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
565 TEST_F(GpuControlListEntryTest
, GlRendererCaseInsensitive
) {
566 const std::string json
= LONG_STRING_CONST(
569 "gl_renderer": "(?i).*software.*",
575 ScopedEntry
entry(GetEntryFromString(json
));
576 EXPECT_TRUE(entry
.get() != NULL
);
579 gpu_info
.gl_renderer
= "software rasterizer";
580 EXPECT_TRUE(entry
->Contains(
581 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
583 gpu_info
.gl_renderer
= "Software Rasterizer";
584 EXPECT_TRUE(entry
->Contains(
585 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
588 TEST_F(GpuControlListEntryTest
, GlExtensionsEndWith
) {
589 const std::string json
= LONG_STRING_CONST(
592 "gl_extensions": ".*GL_SUN_slice_accum",
598 ScopedEntry
entry(GetEntryFromString(json
));
599 EXPECT_TRUE(entry
.get() != NULL
);
602 gpu_info
.gl_extensions
= "GL_SGIS_generate_mipmap "
604 "GL_SUN_slice_accum";
605 EXPECT_TRUE(entry
->Contains(
606 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
608 gpu_info
.gl_extensions
= "GL_SGIS_generate_mipmap "
609 "GL_SUN_slice_accum "
611 EXPECT_FALSE(entry
->Contains(
612 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
615 TEST_F(GpuControlListEntryTest
, DisabledEntry
) {
616 const std::string json
= LONG_STRING_CONST(
625 ScopedEntry
entry(GetEntryFromString(json
));
626 EXPECT_TRUE(entry
.get() != NULL
);
627 EXPECT_TRUE(entry
->disabled());
630 TEST_F(GpuControlListEntryTest
, OptimusEntry
) {
631 const std::string json
= LONG_STRING_CONST(
637 "multi_gpu_style": "optimus",
644 gpu_info
.optimus
= true;
646 ScopedEntry
entry(GetEntryFromString(json
));
647 EXPECT_TRUE(entry
.get() != NULL
);
648 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
649 EXPECT_TRUE(entry
->Contains(
650 GpuControlList::kOsLinux
, "10.6", gpu_info
));
653 TEST_F(GpuControlListEntryTest
, AMDSwitchableEntry
) {
654 const std::string json
= LONG_STRING_CONST(
660 "multi_gpu_style": "amd_switchable",
667 gpu_info
.amd_switchable
= true;
669 ScopedEntry
entry(GetEntryFromString(json
));
670 EXPECT_TRUE(entry
.get() != NULL
);
671 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
672 EXPECT_TRUE(entry
->Contains(
673 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
676 TEST_F(GpuControlListEntryTest
, DriverVendorBeginWith
) {
677 const std::string json
= LONG_STRING_CONST(
680 "driver_vendor": "NVIDIA.*",
686 ScopedEntry
entry(GetEntryFromString(json
));
687 EXPECT_TRUE(entry
.get() != NULL
);
690 gpu_info
.driver_vendor
= "NVIDIA Corporation";
691 EXPECT_TRUE(entry
->Contains(
692 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
695 gpu_info
.driver_vendor
= "NVidia Corporation";
696 EXPECT_FALSE(entry
->Contains(
697 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
699 gpu_info
.driver_vendor
= "NVIDIA";
700 EXPECT_TRUE(entry
->Contains(
701 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
703 gpu_info
.driver_vendor
= "USA NVIDIA";
704 EXPECT_FALSE(entry
->Contains(
705 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
708 TEST_F(GpuControlListEntryTest
, LexicalDriverVersionEntry
) {
709 const std::string json
= LONG_STRING_CONST(
715 "vendor_id": "0x1002",
727 gpu_info
.gpu
.vendor_id
= 0x1002;
729 ScopedEntry
entry(GetEntryFromString(json
));
730 EXPECT_TRUE(entry
.get() != NULL
);
731 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
733 gpu_info
.driver_version
= "8.76";
734 EXPECT_TRUE(entry
->Contains(
735 GpuControlList::kOsLinux
, "10.6", gpu_info
));
737 gpu_info
.driver_version
= "8.768";
738 EXPECT_TRUE(entry
->Contains(
739 GpuControlList::kOsLinux
, "10.6", gpu_info
));
741 gpu_info
.driver_version
= "8.76.8";
742 EXPECT_TRUE(entry
->Contains(
743 GpuControlList::kOsLinux
, "10.6", gpu_info
));
746 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoEntry
) {
747 const std::string json
= LONG_STRING_CONST(
750 "vendor_id": "0x8086",
760 ScopedEntry
entry(GetEntryFromString(json
));
761 EXPECT_TRUE(entry
.get() != NULL
);
764 gpu_info
.gpu
.vendor_id
= 0x8086;
765 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
, true));
767 gpu_info
.driver_version
= "10.6";
768 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
, true));
771 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoForExceptionsEntry
) {
772 const std::string json
= LONG_STRING_CONST(
775 "vendor_id": "0x8086",
778 "gl_renderer": ".*mesa.*"
786 ScopedEntry
entry(GetEntryFromString(json
));
787 EXPECT_TRUE(entry
.get() != NULL
);
790 gpu_info
.gpu
.vendor_id
= 0x8086;
791 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
, true));
792 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
, false));
794 gpu_info
.gl_renderer
= "mesa";
795 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
, true));
798 TEST_F(GpuControlListEntryTest
, FeatureTypeAllEntry
) {
799 const std::string json
= LONG_STRING_CONST(
807 ScopedEntry
entry(GetEntryFromString(json
, true));
808 EXPECT_TRUE(entry
.get() != NULL
);
809 EXPECT_EQ(3u, entry
->features().size());
810 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_0
));
811 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_1
));
812 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_2
));
815 TEST_F(GpuControlListEntryTest
, InvalidVendorIdEntry
) {
816 const std::string json
= LONG_STRING_CONST(
819 "vendor_id": "0x0000",
825 ScopedEntry
entry(GetEntryFromString(json
));
826 EXPECT_TRUE(entry
.get() == NULL
);
829 TEST_F(GpuControlListEntryTest
, InvalidDeviceIdEntry
) {
830 const std::string json
= LONG_STRING_CONST(
833 "vendor_id": "0x10de",
834 "device_id": ["0x1023", "0x0000"],
840 ScopedEntry
entry(GetEntryFromString(json
));
841 EXPECT_TRUE(entry
.get() == NULL
);
844 TEST_F(GpuControlListEntryTest
, SingleActiveGPU
) {
845 const std::string json
= LONG_STRING_CONST(
851 "vendor_id": "0x10de",
852 "device_id": ["0x0640"],
853 "multi_gpu_category": "active",
859 ScopedEntry
entry(GetEntryFromString(json
));
860 EXPECT_TRUE(entry
.get() != NULL
);
861 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
862 EXPECT_TRUE(entry
->Contains(
863 GpuControlList::kOsMacosx
, "10.6", gpu_info()));
866 TEST_F(GpuControlListEntryTest
, MachineModelName
) {
867 const std::string json
= LONG_STRING_CONST(
873 "machine_model_name": [
874 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
881 ScopedEntry
entry(GetEntryFromString(json
));
882 EXPECT_TRUE(entry
.get() != NULL
);
883 EXPECT_EQ(GpuControlList::kOsAndroid
, entry
->GetOsType());
886 gpu_info
.machine_model_name
= "Nexus 4";
887 EXPECT_TRUE(entry
->Contains(
888 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
890 gpu_info
.machine_model_name
= "XT1032";
891 EXPECT_TRUE(entry
->Contains(
892 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
894 gpu_info
.machine_model_name
= "XT1032i";
895 EXPECT_FALSE(entry
->Contains(
896 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
898 gpu_info
.machine_model_name
= "Nexus 5";
899 EXPECT_FALSE(entry
->Contains(
900 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
902 gpu_info
.machine_model_name
= "Nexus";
903 EXPECT_FALSE(entry
->Contains(
904 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
906 gpu_info
.machine_model_name
= "";
907 EXPECT_FALSE(entry
->Contains(
908 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
910 gpu_info
.machine_model_name
= "GT-N7100";
911 EXPECT_TRUE(entry
->Contains(
912 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
914 gpu_info
.machine_model_name
= "GT-I9300";
915 EXPECT_TRUE(entry
->Contains(
916 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
918 gpu_info
.machine_model_name
= "SCH-I545";
919 EXPECT_TRUE(entry
->Contains(
920 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
923 TEST_F(GpuControlListEntryTest
, MachineModelNameException
) {
924 const std::string json
= LONG_STRING_CONST(
932 "machine_model_name": ["Nexus.*"]
940 ScopedEntry
entry(GetEntryFromString(json
));
941 EXPECT_TRUE(entry
.get() != NULL
);
942 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
945 gpu_info
.machine_model_name
= "Nexus 4";
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
= "Nexus 7";
952 EXPECT_FALSE(entry
->Contains(
953 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
954 EXPECT_TRUE(entry
->Contains(
955 GpuControlList::kOsLinux
, "4.1", gpu_info
));
957 gpu_info
.machine_model_name
= "";
958 EXPECT_TRUE(entry
->Contains(
959 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
960 EXPECT_TRUE(entry
->Contains(
961 GpuControlList::kOsLinux
, "4.1", gpu_info
));
964 TEST_F(GpuControlListEntryTest
, MachineModelVersion
) {
965 const std::string json
= LONG_STRING_CONST(
971 "machine_model_name": ["MacBookPro"],
972 "machine_model_version": {
981 ScopedEntry
entry(GetEntryFromString(json
));
982 EXPECT_TRUE(entry
.get() != NULL
);
984 gpu_info
.machine_model_name
= "MacBookPro";
985 gpu_info
.machine_model_version
= "7.1";
986 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
987 EXPECT_TRUE(entry
->Contains(
988 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
991 TEST_F(GpuControlListEntryTest
, MachineModelVersionException
) {
992 const std::string json
= LONG_STRING_CONST(
998 "machine_model_name": ["MacBookPro"],
1001 "machine_model_version": {
1012 ScopedEntry
entry(GetEntryFromString(json
));
1013 EXPECT_TRUE(entry
.get() != NULL
);
1014 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1017 gpu_info
.machine_model_name
= "MacBookPro";
1018 gpu_info
.machine_model_version
= "7.0";
1019 EXPECT_TRUE(entry
->Contains(
1020 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1022 gpu_info
.machine_model_version
= "7.2";
1023 EXPECT_FALSE(entry
->Contains(
1024 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1026 gpu_info
.machine_model_version
= "";
1027 EXPECT_TRUE(entry
->Contains(
1028 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1031 class GpuControlListEntryDualGPUTest
: public GpuControlListEntryTest
{
1033 GpuControlListEntryDualGPUTest() { }
1034 ~GpuControlListEntryDualGPUTest() override
{}
1036 void SetUp() override
{
1037 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
1038 // secondary, and initially Intel is active.
1039 gpu_info_
.gpu
.vendor_id
= 0x10de;
1040 gpu_info_
.gpu
.device_id
= 0x0640;
1041 gpu_info_
.gpu
.active
= false;
1042 GPUInfo::GPUDevice second_gpu
;
1043 second_gpu
.vendor_id
= 0x8086;
1044 second_gpu
.device_id
= 0x0166;
1045 second_gpu
.active
= true;
1046 gpu_info_
.secondary_gpus
.push_back(second_gpu
);
1049 void ActivatePrimaryGPU() {
1050 gpu_info_
.gpu
.active
= true;
1051 gpu_info_
.secondary_gpus
[0].active
= false;
1054 void EntryShouldApply(const std::string
& entry_json
) const {
1055 EXPECT_TRUE(EntryApplies(entry_json
));
1058 void EntryShouldNotApply(const std::string
& entry_json
) const {
1059 EXPECT_FALSE(EntryApplies(entry_json
));
1063 bool EntryApplies(const std::string
& entry_json
) const {
1064 ScopedEntry
entry(GetEntryFromString(entry_json
));
1065 EXPECT_TRUE(entry
.get());
1066 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1067 return entry
->Contains(GpuControlList::kOsMacosx
, "10.6", gpu_info());
1071 TEST_F(GpuControlListEntryDualGPUTest
, CategoryAny
) {
1072 const std::string json_intel
= LONG_STRING_CONST(
1078 "vendor_id": "0x8086",
1079 "device_id": ["0x0166"],
1080 "multi_gpu_category": "any",
1086 EntryShouldApply(json_intel
);
1088 const std::string json_nvidia
= LONG_STRING_CONST(
1094 "vendor_id": "0x10de",
1095 "device_id": ["0x0640"],
1096 "multi_gpu_category": "any",
1102 EntryShouldApply(json_nvidia
);
1105 TEST_F(GpuControlListEntryDualGPUTest
, CategoryPrimarySecondary
) {
1106 const std::string json_secondary
= LONG_STRING_CONST(
1112 "vendor_id": "0x8086",
1113 "device_id": ["0x0166"],
1114 "multi_gpu_category": "secondary",
1120 EntryShouldApply(json_secondary
);
1122 const std::string json_primary
= LONG_STRING_CONST(
1128 "vendor_id": "0x8086",
1129 "device_id": ["0x0166"],
1130 "multi_gpu_category": "primary",
1136 EntryShouldNotApply(json_primary
);
1138 const std::string json_default
= LONG_STRING_CONST(
1144 "vendor_id": "0x8086",
1145 "device_id": ["0x0166"],
1151 // Default is primary.
1152 EntryShouldNotApply(json_default
);
1155 TEST_F(GpuControlListEntryDualGPUTest
, ActiveSecondaryGPU
) {
1156 const std::string json
= LONG_STRING_CONST(
1162 "vendor_id": "0x8086",
1163 "device_id": ["0x0166", "0x0168"],
1164 "multi_gpu_category": "active",
1170 // By default, secondary GPU is active.
1171 EntryShouldApply(json
);
1173 ActivatePrimaryGPU();
1174 EntryShouldNotApply(json
);
1177 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActiveSecondaryGPU
) {
1178 const std::string json
= LONG_STRING_CONST(
1184 "vendor_id": "0x8086",
1185 "multi_gpu_category": "active",
1191 // By default, secondary GPU is active.
1192 EntryShouldApply(json
);
1194 ActivatePrimaryGPU();
1195 EntryShouldNotApply(json
);
1198 TEST_F(GpuControlListEntryDualGPUTest
, ActivePrimaryGPU
) {
1199 const std::string json
= LONG_STRING_CONST(
1205 "vendor_id": "0x10de",
1206 "device_id": ["0x0640"],
1207 "multi_gpu_category": "active",
1213 // By default, secondary GPU is active.
1214 EntryShouldNotApply(json
);
1216 ActivatePrimaryGPU();
1217 EntryShouldApply(json
);
1220 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActivePrimaryGPU
) {
1221 const std::string json
= LONG_STRING_CONST(
1227 "vendor_id": "0x10de",
1228 "multi_gpu_category": "active",
1234 // By default, secondary GPU is active.
1235 EntryShouldNotApply(json
);
1237 ActivatePrimaryGPU();
1238 EntryShouldApply(json
);