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 virtual ~GpuControlListEntryTest() { }
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 virtual void SetUp() {
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";
62 gpu_info_
.performance_stats
.graphics
= 5.0;
63 gpu_info_
.performance_stats
.gaming
= 5.0;
64 gpu_info_
.performance_stats
.overall
= 5.0;
71 TEST_F(GpuControlListEntryTest
, DetailedEntry
) {
72 const std::string json
= LONG_STRING_CONST(
75 "description": "test entry",
76 "cr_bugs": [1024, 678],
77 "webkit_bugs": [1950],
85 "vendor_id": "0x10de",
86 "device_id": ["0x0640"],
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()));
111 EXPECT_TRUE(entry
->Contains(
112 GpuControlList::kOsMacosx
, "10.6.4", gpu_info()));
115 TEST_F(GpuControlListEntryTest
, VendorOnAllOsEntry
) {
116 const std::string json
= LONG_STRING_CONST(
119 "vendor_id": "0x10de",
125 ScopedEntry
entry(GetEntryFromString(json
));
126 EXPECT_TRUE(entry
.get() != NULL
);
127 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
129 const GpuControlList::OsType os_type
[] = {
130 GpuControlList::kOsMacosx
,
131 GpuControlList::kOsWin
,
132 GpuControlList::kOsLinux
,
133 GpuControlList::kOsChromeOS
,
134 GpuControlList::kOsAndroid
136 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
137 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
140 TEST_F(GpuControlListEntryTest
, VendorOnLinuxEntry
) {
141 const std::string json
= LONG_STRING_CONST(
147 "vendor_id": "0x10de",
153 ScopedEntry
entry(GetEntryFromString(json
));
154 EXPECT_TRUE(entry
.get() != NULL
);
155 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
157 const GpuControlList::OsType os_type
[] = {
158 GpuControlList::kOsMacosx
,
159 GpuControlList::kOsWin
,
160 GpuControlList::kOsChromeOS
,
161 GpuControlList::kOsAndroid
163 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
164 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
165 EXPECT_TRUE(entry
->Contains(
166 GpuControlList::kOsLinux
, "10.6", gpu_info()));
169 TEST_F(GpuControlListEntryTest
, AllExceptNVidiaOnLinuxEntry
) {
170 const std::string json
= LONG_STRING_CONST(
178 "vendor_id": "0x10de"
186 ScopedEntry
entry(GetEntryFromString(json
));
187 EXPECT_TRUE(entry
.get() != NULL
);
188 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
190 const GpuControlList::OsType os_type
[] = {
191 GpuControlList::kOsMacosx
,
192 GpuControlList::kOsWin
,
193 GpuControlList::kOsLinux
,
194 GpuControlList::kOsChromeOS
,
195 GpuControlList::kOsAndroid
197 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
198 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
201 TEST_F(GpuControlListEntryTest
, AllExceptIntelOnLinuxEntry
) {
202 const std::string json
= LONG_STRING_CONST(
210 "vendor_id": "0x8086"
218 ScopedEntry
entry(GetEntryFromString(json
));
219 EXPECT_TRUE(entry
.get() != NULL
);
220 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
222 const GpuControlList::OsType os_type
[] = {
223 GpuControlList::kOsMacosx
,
224 GpuControlList::kOsWin
,
225 GpuControlList::kOsChromeOS
,
226 GpuControlList::kOsAndroid
228 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
229 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
230 EXPECT_TRUE(entry
->Contains(
231 GpuControlList::kOsLinux
, "10.6", gpu_info()));
234 TEST_F(GpuControlListEntryTest
, DateOnWindowsEntry
) {
235 const std::string json
= LONG_STRING_CONST(
250 ScopedEntry
entry(GetEntryFromString(json
));
251 EXPECT_TRUE(entry
.get() != NULL
);
252 EXPECT_EQ(GpuControlList::kOsWin
, entry
->GetOsType());
255 gpu_info
.driver_date
= "4-12-2010";
256 EXPECT_TRUE(entry
->Contains(
257 GpuControlList::kOsWin
, "10.6", gpu_info
));
258 gpu_info
.driver_date
= "5-8-2010";
259 EXPECT_FALSE(entry
->Contains(
260 GpuControlList::kOsWin
, "10.6", gpu_info
));
261 gpu_info
.driver_date
= "5-9-2010";
262 EXPECT_FALSE(entry
->Contains(
263 GpuControlList::kOsWin
, "10.6", gpu_info
));
266 TEST_F(GpuControlListEntryTest
, MultipleDevicesEntry
) {
267 const std::string json
= LONG_STRING_CONST(
270 "vendor_id": "0x10de",
271 "device_id": ["0x1023", "0x0640"],
277 ScopedEntry
entry(GetEntryFromString(json
));
278 EXPECT_TRUE(entry
.get() != NULL
);
279 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
281 const GpuControlList::OsType os_type
[] = {
282 GpuControlList::kOsMacosx
,
283 GpuControlList::kOsWin
,
284 GpuControlList::kOsLinux
,
285 GpuControlList::kOsChromeOS
,
286 GpuControlList::kOsAndroid
288 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
289 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
292 TEST_F(GpuControlListEntryTest
, ChromeOSEntry
) {
293 const std::string json
= LONG_STRING_CONST(
304 ScopedEntry
entry(GetEntryFromString(json
));
305 EXPECT_TRUE(entry
.get() != NULL
);
306 EXPECT_EQ(GpuControlList::kOsChromeOS
, entry
->GetOsType());
308 const GpuControlList::OsType os_type
[] = {
309 GpuControlList::kOsMacosx
,
310 GpuControlList::kOsWin
,
311 GpuControlList::kOsLinux
,
312 GpuControlList::kOsAndroid
314 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
315 EXPECT_FALSE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
316 EXPECT_TRUE(entry
->Contains(
317 GpuControlList::kOsChromeOS
, "10.6", gpu_info()));
320 TEST_F(GpuControlListEntryTest
, MalformedVendor
) {
321 const std::string json
= LONG_STRING_CONST(
324 "vendor_id": "[0x10de]",
330 ScopedEntry
entry(GetEntryFromString(json
));
331 EXPECT_TRUE(entry
.get() == NULL
);
334 TEST_F(GpuControlListEntryTest
, UnknownFieldEntry
) {
335 const std::string json
= LONG_STRING_CONST(
344 ScopedEntry
entry(GetEntryFromString(json
));
345 EXPECT_TRUE(entry
.get() == NULL
);
348 TEST_F(GpuControlListEntryTest
, UnknownExceptionFieldEntry
) {
349 const std::string json
= LONG_STRING_CONST(
362 ScopedEntry
entry(GetEntryFromString(json
));
363 EXPECT_TRUE(entry
.get() == NULL
);
366 TEST_F(GpuControlListEntryTest
, UnknownFeatureEntry
) {
367 const std::string json
= LONG_STRING_CONST(
371 "some_unknown_feature",
376 ScopedEntry
entry(GetEntryFromString(json
));
377 EXPECT_TRUE(entry
.get() == NULL
);
380 TEST_F(GpuControlListEntryTest
, GlVersionGLESEntry
) {
381 const std::string json
= LONG_STRING_CONST(
394 ScopedEntry
entry(GetEntryFromString(json
));
395 EXPECT_TRUE(entry
.get() != NULL
);
398 gpu_info
.gl_version
= "OpenGL ES 3.0 V@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
, GlVendorEntry
) {
474 const std::string json
= LONG_STRING_CONST(
486 ScopedEntry
entry(GetEntryFromString(json
));
487 EXPECT_TRUE(entry
.get() != NULL
);
489 const GpuControlList::OsType os_type
[] = {
490 GpuControlList::kOsMacosx
,
491 GpuControlList::kOsWin
,
492 GpuControlList::kOsLinux
,
493 GpuControlList::kOsChromeOS
,
494 GpuControlList::kOsAndroid
496 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
497 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
500 TEST_F(GpuControlListEntryTest
, GlRendererEntry
) {
501 const std::string json
= LONG_STRING_CONST(
513 ScopedEntry
entry(GetEntryFromString(json
));
514 EXPECT_TRUE(entry
.get() != NULL
);
516 const GpuControlList::OsType os_type
[] = {
517 GpuControlList::kOsMacosx
,
518 GpuControlList::kOsWin
,
519 GpuControlList::kOsLinux
,
520 GpuControlList::kOsChromeOS
,
521 GpuControlList::kOsAndroid
523 for (size_t i
= 0; i
< arraysize(os_type
); ++i
)
524 EXPECT_TRUE(entry
->Contains(os_type
[i
], "10.6", gpu_info()));
527 TEST_F(GpuControlListEntryTest
, PerfGraphicsEntry
) {
528 const std::string json
= LONG_STRING_CONST(
540 ScopedEntry
entry(GetEntryFromString(json
));
541 EXPECT_TRUE(entry
.get() != NULL
);
542 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsWin
, "10.6", gpu_info()));
545 TEST_F(GpuControlListEntryTest
, PerfGamingEntry
) {
546 const std::string json
= LONG_STRING_CONST(
558 ScopedEntry
entry(GetEntryFromString(json
));
559 EXPECT_TRUE(entry
.get() != NULL
);
560 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "10.6", gpu_info()));
563 TEST_F(GpuControlListEntryTest
, PerfOverallEntry
) {
564 const std::string json
= LONG_STRING_CONST(
577 ScopedEntry
entry(GetEntryFromString(json
));
578 EXPECT_TRUE(entry
.get() != NULL
);
579 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsWin
, "10.6", gpu_info()));
582 TEST_F(GpuControlListEntryTest
, DisabledEntry
) {
583 const std::string json
= LONG_STRING_CONST(
592 ScopedEntry
entry(GetEntryFromString(json
));
593 EXPECT_TRUE(entry
.get() != NULL
);
594 EXPECT_TRUE(entry
->disabled());
597 TEST_F(GpuControlListEntryTest
, OptimusEntry
) {
598 const std::string json
= LONG_STRING_CONST(
604 "multi_gpu_style": "optimus",
611 gpu_info
.optimus
= true;
613 ScopedEntry
entry(GetEntryFromString(json
));
614 EXPECT_TRUE(entry
.get() != NULL
);
615 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
616 EXPECT_TRUE(entry
->Contains(
617 GpuControlList::kOsLinux
, "10.6", gpu_info
));
620 TEST_F(GpuControlListEntryTest
, AMDSwitchableEntry
) {
621 const std::string json
= LONG_STRING_CONST(
627 "multi_gpu_style": "amd_switchable",
634 gpu_info
.amd_switchable
= true;
636 ScopedEntry
entry(GetEntryFromString(json
));
637 EXPECT_TRUE(entry
.get() != NULL
);
638 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
639 EXPECT_TRUE(entry
->Contains(
640 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
643 TEST_F(GpuControlListEntryTest
, LexicalDriverVersionEntry
) {
644 const std::string json
= LONG_STRING_CONST(
650 "vendor_id": "0x1002",
662 gpu_info
.gpu
.vendor_id
= 0x1002;
664 ScopedEntry
entry(GetEntryFromString(json
));
665 EXPECT_TRUE(entry
.get() != NULL
);
666 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
668 gpu_info
.driver_version
= "8.76";
669 EXPECT_TRUE(entry
->Contains(
670 GpuControlList::kOsLinux
, "10.6", gpu_info
));
672 gpu_info
.driver_version
= "8.768";
673 EXPECT_TRUE(entry
->Contains(
674 GpuControlList::kOsLinux
, "10.6", gpu_info
));
676 gpu_info
.driver_version
= "8.76.8";
677 EXPECT_TRUE(entry
->Contains(
678 GpuControlList::kOsLinux
, "10.6", gpu_info
));
681 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoEntry
) {
682 const std::string json
= LONG_STRING_CONST(
685 "vendor_id": "0x8086",
695 ScopedEntry
entry(GetEntryFromString(json
));
696 EXPECT_TRUE(entry
.get() != NULL
);
699 gpu_info
.gpu
.vendor_id
= 0x8086;
700 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
));
702 gpu_info
.driver_version
= "10.6";
703 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
));
706 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoForExceptionsEntry
) {
707 const std::string json
= LONG_STRING_CONST(
710 "vendor_id": "0x8086",
724 ScopedEntry
entry(GetEntryFromString(json
));
725 EXPECT_TRUE(entry
.get() != NULL
);
728 gpu_info
.gpu
.vendor_id
= 0x8086;
729 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
));
731 gpu_info
.gl_renderer
= "mesa";
732 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
));
735 TEST_F(GpuControlListEntryTest
, FeatureTypeAllEntry
) {
736 const std::string json
= LONG_STRING_CONST(
744 ScopedEntry
entry(GetEntryFromString(json
, true));
745 EXPECT_TRUE(entry
.get() != NULL
);
746 EXPECT_EQ(3u, entry
->features().size());
747 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_0
));
748 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_1
));
749 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_2
));
752 TEST_F(GpuControlListEntryTest
, InvalidVendorIdEntry
) {
753 const std::string json
= LONG_STRING_CONST(
756 "vendor_id": "0x0000",
762 ScopedEntry
entry(GetEntryFromString(json
));
763 EXPECT_TRUE(entry
.get() == NULL
);
766 TEST_F(GpuControlListEntryTest
, InvalidDeviceIdEntry
) {
767 const std::string json
= LONG_STRING_CONST(
770 "vendor_id": "0x10de",
771 "device_id": ["0x1023", "0x0000"],
777 ScopedEntry
entry(GetEntryFromString(json
));
778 EXPECT_TRUE(entry
.get() == NULL
);
781 TEST_F(GpuControlListEntryTest
, SingleActiveGPU
) {
782 const std::string json
= LONG_STRING_CONST(
788 "vendor_id": "0x10de",
789 "device_id": ["0x0640"],
790 "multi_gpu_category": "active",
796 ScopedEntry
entry(GetEntryFromString(json
));
797 EXPECT_TRUE(entry
.get() != NULL
);
798 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
799 EXPECT_TRUE(entry
->Contains(
800 GpuControlList::kOsMacosx
, "10.6", gpu_info()));
803 TEST_F(GpuControlListEntryTest
, MachineModelName
) {
804 const std::string json
= LONG_STRING_CONST(
810 "machine_model_name": ["Nexus 4", "XT1032"],
816 ScopedEntry
entry(GetEntryFromString(json
));
817 EXPECT_TRUE(entry
.get() != NULL
);
818 EXPECT_EQ(GpuControlList::kOsAndroid
, entry
->GetOsType());
821 gpu_info
.machine_model_name
= "Nexus 4";
822 EXPECT_TRUE(entry
->Contains(
823 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
825 gpu_info
.machine_model_name
= "XT1032";
826 EXPECT_TRUE(entry
->Contains(
827 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
829 gpu_info
.machine_model_name
= "XT1032i";
830 EXPECT_FALSE(entry
->Contains(
831 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
833 gpu_info
.machine_model_name
= "Nexus 5";
834 EXPECT_FALSE(entry
->Contains(
835 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
837 gpu_info
.machine_model_name
= "Nexus";
838 EXPECT_FALSE(entry
->Contains(
839 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
841 gpu_info
.machine_model_name
= "";
842 EXPECT_FALSE(entry
->Contains(
843 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
846 TEST_F(GpuControlListEntryTest
, MachineModelNameException
) {
847 const std::string json
= LONG_STRING_CONST(
855 "machine_model_name": ["Nexus 4"]
863 ScopedEntry
entry(GetEntryFromString(json
));
864 EXPECT_TRUE(entry
.get() != NULL
);
865 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
868 gpu_info
.machine_model_name
= "Nexus 4";
869 EXPECT_FALSE(entry
->Contains(
870 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
871 EXPECT_TRUE(entry
->Contains(
872 GpuControlList::kOsLinux
, "4.1", gpu_info
));
874 gpu_info
.machine_model_name
= "";
875 EXPECT_TRUE(entry
->Contains(
876 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
877 EXPECT_TRUE(entry
->Contains(
878 GpuControlList::kOsLinux
, "4.1", gpu_info
));
881 TEST_F(GpuControlListEntryTest
, MachineModelVersion
) {
882 const std::string json
= LONG_STRING_CONST(
888 "machine_model_name": ["MacBookPro"],
889 "machine_model_version": {
898 ScopedEntry
entry(GetEntryFromString(json
));
899 EXPECT_TRUE(entry
.get() != NULL
);
901 gpu_info
.machine_model_name
= "MacBookPro";
902 gpu_info
.machine_model_version
= "7.1";
903 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
904 EXPECT_TRUE(entry
->Contains(
905 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
908 TEST_F(GpuControlListEntryTest
, MachineModelVersionException
) {
909 const std::string json
= LONG_STRING_CONST(
915 "machine_model_name": ["MacBookPro"],
918 "machine_model_version": {
929 ScopedEntry
entry(GetEntryFromString(json
));
930 EXPECT_TRUE(entry
.get() != NULL
);
931 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
934 gpu_info
.machine_model_name
= "MacBookPro";
935 gpu_info
.machine_model_version
= "7.0";
936 EXPECT_TRUE(entry
->Contains(
937 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
939 gpu_info
.machine_model_version
= "7.2";
940 EXPECT_FALSE(entry
->Contains(
941 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
943 gpu_info
.machine_model_version
= "";
944 EXPECT_TRUE(entry
->Contains(
945 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
948 class GpuControlListEntryDualGPUTest
: public GpuControlListEntryTest
{
950 GpuControlListEntryDualGPUTest() { }
951 virtual ~GpuControlListEntryDualGPUTest() { }
953 virtual void SetUp() OVERRIDE
{
954 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
955 // secondary, and initially Intel is active.
956 gpu_info_
.gpu
.vendor_id
= 0x10de;
957 gpu_info_
.gpu
.device_id
= 0x0640;
958 gpu_info_
.gpu
.active
= false;
959 GPUInfo::GPUDevice second_gpu
;
960 second_gpu
.vendor_id
= 0x8086;
961 second_gpu
.device_id
= 0x0166;
962 second_gpu
.active
= true;
963 gpu_info_
.secondary_gpus
.push_back(second_gpu
);
966 void ActivatePrimaryGPU() {
967 gpu_info_
.gpu
.active
= true;
968 gpu_info_
.secondary_gpus
[0].active
= false;
971 void EntryShouldApply(const std::string
& entry_json
) const {
972 EXPECT_TRUE(EntryApplies(entry_json
));
975 void EntryShouldNotApply(const std::string
& entry_json
) const {
976 EXPECT_FALSE(EntryApplies(entry_json
));
980 bool EntryApplies(const std::string
& entry_json
) const {
981 ScopedEntry
entry(GetEntryFromString(entry_json
));
982 EXPECT_TRUE(entry
.get());
983 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
984 return entry
->Contains(GpuControlList::kOsMacosx
, "10.6", gpu_info());
988 TEST_F(GpuControlListEntryDualGPUTest
, CategoryAny
) {
989 const std::string json_intel
= LONG_STRING_CONST(
995 "vendor_id": "0x8086",
996 "device_id": ["0x0166"],
997 "multi_gpu_category": "any",
1003 EntryShouldApply(json_intel
);
1005 const std::string json_nvidia
= LONG_STRING_CONST(
1011 "vendor_id": "0x10de",
1012 "device_id": ["0x0640"],
1013 "multi_gpu_category": "any",
1019 EntryShouldApply(json_nvidia
);
1022 TEST_F(GpuControlListEntryDualGPUTest
, CategoryPrimarySecondary
) {
1023 const std::string json_secondary
= LONG_STRING_CONST(
1029 "vendor_id": "0x8086",
1030 "device_id": ["0x0166"],
1031 "multi_gpu_category": "secondary",
1037 EntryShouldApply(json_secondary
);
1039 const std::string json_primary
= LONG_STRING_CONST(
1045 "vendor_id": "0x8086",
1046 "device_id": ["0x0166"],
1047 "multi_gpu_category": "primary",
1053 EntryShouldNotApply(json_primary
);
1055 const std::string json_default
= LONG_STRING_CONST(
1061 "vendor_id": "0x8086",
1062 "device_id": ["0x0166"],
1068 // Default is primary.
1069 EntryShouldNotApply(json_default
);
1072 TEST_F(GpuControlListEntryDualGPUTest
, ActiveSecondaryGPU
) {
1073 const std::string json
= LONG_STRING_CONST(
1079 "vendor_id": "0x8086",
1080 "device_id": ["0x0166", "0x0168"],
1081 "multi_gpu_category": "active",
1087 // By default, secondary GPU is active.
1088 EntryShouldApply(json
);
1090 ActivatePrimaryGPU();
1091 EntryShouldNotApply(json
);
1094 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActiveSecondaryGPU
) {
1095 const std::string json
= LONG_STRING_CONST(
1101 "vendor_id": "0x8086",
1102 "multi_gpu_category": "active",
1108 // By default, secondary GPU is active.
1109 EntryShouldApply(json
);
1111 ActivatePrimaryGPU();
1112 EntryShouldNotApply(json
);
1115 TEST_F(GpuControlListEntryDualGPUTest
, ActivePrimaryGPU
) {
1116 const std::string json
= LONG_STRING_CONST(
1122 "vendor_id": "0x10de",
1123 "device_id": ["0x0640"],
1124 "multi_gpu_category": "active",
1130 // By default, secondary GPU is active.
1131 EntryShouldNotApply(json
);
1133 ActivatePrimaryGPU();
1134 EntryShouldApply(json
);
1137 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActivePrimaryGPU
) {
1138 const std::string json
= LONG_STRING_CONST(
1144 "vendor_id": "0x10de",
1145 "multi_gpu_category": "active",
1151 // By default, secondary GPU is active.
1152 EntryShouldNotApply(json
);
1154 ActivatePrimaryGPU();
1155 EntryShouldApply(json
);