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
, 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
, PerfGraphicsEntry
) {
611 const std::string json
= LONG_STRING_CONST(
623 ScopedEntry
entry(GetEntryFromString(json
));
624 EXPECT_TRUE(entry
.get() != NULL
);
625 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsWin
, "10.6", gpu_info()));
628 TEST_F(GpuControlListEntryTest
, PerfGamingEntry
) {
629 const std::string json
= LONG_STRING_CONST(
641 ScopedEntry
entry(GetEntryFromString(json
));
642 EXPECT_TRUE(entry
.get() != NULL
);
643 EXPECT_FALSE(entry
->Contains(GpuControlList::kOsWin
, "10.6", gpu_info()));
646 TEST_F(GpuControlListEntryTest
, PerfOverallEntry
) {
647 const std::string json
= LONG_STRING_CONST(
660 ScopedEntry
entry(GetEntryFromString(json
));
661 EXPECT_TRUE(entry
.get() != NULL
);
662 EXPECT_TRUE(entry
->Contains(GpuControlList::kOsWin
, "10.6", gpu_info()));
665 TEST_F(GpuControlListEntryTest
, DisabledEntry
) {
666 const std::string json
= LONG_STRING_CONST(
675 ScopedEntry
entry(GetEntryFromString(json
));
676 EXPECT_TRUE(entry
.get() != NULL
);
677 EXPECT_TRUE(entry
->disabled());
680 TEST_F(GpuControlListEntryTest
, OptimusEntry
) {
681 const std::string json
= LONG_STRING_CONST(
687 "multi_gpu_style": "optimus",
694 gpu_info
.optimus
= true;
696 ScopedEntry
entry(GetEntryFromString(json
));
697 EXPECT_TRUE(entry
.get() != NULL
);
698 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
699 EXPECT_TRUE(entry
->Contains(
700 GpuControlList::kOsLinux
, "10.6", gpu_info
));
703 TEST_F(GpuControlListEntryTest
, AMDSwitchableEntry
) {
704 const std::string json
= LONG_STRING_CONST(
710 "multi_gpu_style": "amd_switchable",
717 gpu_info
.amd_switchable
= true;
719 ScopedEntry
entry(GetEntryFromString(json
));
720 EXPECT_TRUE(entry
.get() != NULL
);
721 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
722 EXPECT_TRUE(entry
->Contains(
723 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
726 TEST_F(GpuControlListEntryTest
, DriverVendorBeginWith
) {
727 const std::string json
= LONG_STRING_CONST(
730 "driver_vendor": "NVIDIA.*",
736 ScopedEntry
entry(GetEntryFromString(json
));
737 EXPECT_TRUE(entry
.get() != NULL
);
740 gpu_info
.driver_vendor
= "NVIDIA Corporation";
741 EXPECT_TRUE(entry
->Contains(
742 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
745 gpu_info
.driver_vendor
= "NVidia Corporation";
746 EXPECT_FALSE(entry
->Contains(
747 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
749 gpu_info
.driver_vendor
= "NVIDIA";
750 EXPECT_TRUE(entry
->Contains(
751 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
753 gpu_info
.driver_vendor
= "USA NVIDIA";
754 EXPECT_FALSE(entry
->Contains(
755 GpuControlList::kOsMacosx
, "10.9", gpu_info
));
758 TEST_F(GpuControlListEntryTest
, LexicalDriverVersionEntry
) {
759 const std::string json
= LONG_STRING_CONST(
765 "vendor_id": "0x1002",
777 gpu_info
.gpu
.vendor_id
= 0x1002;
779 ScopedEntry
entry(GetEntryFromString(json
));
780 EXPECT_TRUE(entry
.get() != NULL
);
781 EXPECT_EQ(GpuControlList::kOsLinux
, entry
->GetOsType());
783 gpu_info
.driver_version
= "8.76";
784 EXPECT_TRUE(entry
->Contains(
785 GpuControlList::kOsLinux
, "10.6", gpu_info
));
787 gpu_info
.driver_version
= "8.768";
788 EXPECT_TRUE(entry
->Contains(
789 GpuControlList::kOsLinux
, "10.6", gpu_info
));
791 gpu_info
.driver_version
= "8.76.8";
792 EXPECT_TRUE(entry
->Contains(
793 GpuControlList::kOsLinux
, "10.6", gpu_info
));
796 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoEntry
) {
797 const std::string json
= LONG_STRING_CONST(
800 "vendor_id": "0x8086",
810 ScopedEntry
entry(GetEntryFromString(json
));
811 EXPECT_TRUE(entry
.get() != NULL
);
814 gpu_info
.gpu
.vendor_id
= 0x8086;
815 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
));
817 gpu_info
.driver_version
= "10.6";
818 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
));
821 TEST_F(GpuControlListEntryTest
, NeedsMoreInfoForExceptionsEntry
) {
822 const std::string json
= LONG_STRING_CONST(
825 "vendor_id": "0x8086",
828 "gl_renderer": ".*mesa.*"
836 ScopedEntry
entry(GetEntryFromString(json
));
837 EXPECT_TRUE(entry
.get() != NULL
);
840 gpu_info
.gpu
.vendor_id
= 0x8086;
841 EXPECT_TRUE(entry
->NeedsMoreInfo(gpu_info
));
843 gpu_info
.gl_renderer
= "mesa";
844 EXPECT_FALSE(entry
->NeedsMoreInfo(gpu_info
));
847 TEST_F(GpuControlListEntryTest
, FeatureTypeAllEntry
) {
848 const std::string json
= LONG_STRING_CONST(
856 ScopedEntry
entry(GetEntryFromString(json
, true));
857 EXPECT_TRUE(entry
.get() != NULL
);
858 EXPECT_EQ(3u, entry
->features().size());
859 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_0
));
860 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_1
));
861 EXPECT_EQ(1u, entry
->features().count(TEST_FEATURE_2
));
864 TEST_F(GpuControlListEntryTest
, InvalidVendorIdEntry
) {
865 const std::string json
= LONG_STRING_CONST(
868 "vendor_id": "0x0000",
874 ScopedEntry
entry(GetEntryFromString(json
));
875 EXPECT_TRUE(entry
.get() == NULL
);
878 TEST_F(GpuControlListEntryTest
, InvalidDeviceIdEntry
) {
879 const std::string json
= LONG_STRING_CONST(
882 "vendor_id": "0x10de",
883 "device_id": ["0x1023", "0x0000"],
889 ScopedEntry
entry(GetEntryFromString(json
));
890 EXPECT_TRUE(entry
.get() == NULL
);
893 TEST_F(GpuControlListEntryTest
, SingleActiveGPU
) {
894 const std::string json
= LONG_STRING_CONST(
900 "vendor_id": "0x10de",
901 "device_id": ["0x0640"],
902 "multi_gpu_category": "active",
908 ScopedEntry
entry(GetEntryFromString(json
));
909 EXPECT_TRUE(entry
.get() != NULL
);
910 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
911 EXPECT_TRUE(entry
->Contains(
912 GpuControlList::kOsMacosx
, "10.6", gpu_info()));
915 TEST_F(GpuControlListEntryTest
, MachineModelName
) {
916 const std::string json
= LONG_STRING_CONST(
922 "machine_model_name": [
923 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
930 ScopedEntry
entry(GetEntryFromString(json
));
931 EXPECT_TRUE(entry
.get() != NULL
);
932 EXPECT_EQ(GpuControlList::kOsAndroid
, entry
->GetOsType());
935 gpu_info
.machine_model_name
= "Nexus 4";
936 EXPECT_TRUE(entry
->Contains(
937 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
939 gpu_info
.machine_model_name
= "XT1032";
940 EXPECT_TRUE(entry
->Contains(
941 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
943 gpu_info
.machine_model_name
= "XT1032i";
944 EXPECT_FALSE(entry
->Contains(
945 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
947 gpu_info
.machine_model_name
= "Nexus 5";
948 EXPECT_FALSE(entry
->Contains(
949 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
951 gpu_info
.machine_model_name
= "Nexus";
952 EXPECT_FALSE(entry
->Contains(
953 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
955 gpu_info
.machine_model_name
= "";
956 EXPECT_FALSE(entry
->Contains(
957 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
959 gpu_info
.machine_model_name
= "GT-N7100";
960 EXPECT_TRUE(entry
->Contains(
961 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
963 gpu_info
.machine_model_name
= "GT-I9300";
964 EXPECT_TRUE(entry
->Contains(
965 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
967 gpu_info
.machine_model_name
= "SCH-I545";
968 EXPECT_TRUE(entry
->Contains(
969 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
972 TEST_F(GpuControlListEntryTest
, MachineModelNameException
) {
973 const std::string json
= LONG_STRING_CONST(
981 "machine_model_name": ["Nexus.*"]
989 ScopedEntry
entry(GetEntryFromString(json
));
990 EXPECT_TRUE(entry
.get() != NULL
);
991 EXPECT_EQ(GpuControlList::kOsAny
, entry
->GetOsType());
994 gpu_info
.machine_model_name
= "Nexus 4";
995 EXPECT_FALSE(entry
->Contains(
996 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
997 EXPECT_TRUE(entry
->Contains(
998 GpuControlList::kOsLinux
, "4.1", gpu_info
));
1000 gpu_info
.machine_model_name
= "Nexus 7";
1001 EXPECT_FALSE(entry
->Contains(
1002 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
1003 EXPECT_TRUE(entry
->Contains(
1004 GpuControlList::kOsLinux
, "4.1", gpu_info
));
1006 gpu_info
.machine_model_name
= "";
1007 EXPECT_TRUE(entry
->Contains(
1008 GpuControlList::kOsAndroid
, "4.1", gpu_info
));
1009 EXPECT_TRUE(entry
->Contains(
1010 GpuControlList::kOsLinux
, "4.1", gpu_info
));
1013 TEST_F(GpuControlListEntryTest
, MachineModelVersion
) {
1014 const std::string json
= LONG_STRING_CONST(
1020 "machine_model_name": ["MacBookPro"],
1021 "machine_model_version": {
1030 ScopedEntry
entry(GetEntryFromString(json
));
1031 EXPECT_TRUE(entry
.get() != NULL
);
1033 gpu_info
.machine_model_name
= "MacBookPro";
1034 gpu_info
.machine_model_version
= "7.1";
1035 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1036 EXPECT_TRUE(entry
->Contains(
1037 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1040 TEST_F(GpuControlListEntryTest
, MachineModelVersionException
) {
1041 const std::string json
= LONG_STRING_CONST(
1047 "machine_model_name": ["MacBookPro"],
1050 "machine_model_version": {
1061 ScopedEntry
entry(GetEntryFromString(json
));
1062 EXPECT_TRUE(entry
.get() != NULL
);
1063 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1066 gpu_info
.machine_model_name
= "MacBookPro";
1067 gpu_info
.machine_model_version
= "7.0";
1068 EXPECT_TRUE(entry
->Contains(
1069 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1071 gpu_info
.machine_model_version
= "7.2";
1072 EXPECT_FALSE(entry
->Contains(
1073 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1075 gpu_info
.machine_model_version
= "";
1076 EXPECT_TRUE(entry
->Contains(
1077 GpuControlList::kOsMacosx
, "10.6", gpu_info
));
1080 class GpuControlListEntryDualGPUTest
: public GpuControlListEntryTest
{
1082 GpuControlListEntryDualGPUTest() { }
1083 virtual ~GpuControlListEntryDualGPUTest() { }
1085 virtual void SetUp() OVERRIDE
{
1086 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
1087 // secondary, and initially Intel is active.
1088 gpu_info_
.gpu
.vendor_id
= 0x10de;
1089 gpu_info_
.gpu
.device_id
= 0x0640;
1090 gpu_info_
.gpu
.active
= false;
1091 GPUInfo::GPUDevice second_gpu
;
1092 second_gpu
.vendor_id
= 0x8086;
1093 second_gpu
.device_id
= 0x0166;
1094 second_gpu
.active
= true;
1095 gpu_info_
.secondary_gpus
.push_back(second_gpu
);
1098 void ActivatePrimaryGPU() {
1099 gpu_info_
.gpu
.active
= true;
1100 gpu_info_
.secondary_gpus
[0].active
= false;
1103 void EntryShouldApply(const std::string
& entry_json
) const {
1104 EXPECT_TRUE(EntryApplies(entry_json
));
1107 void EntryShouldNotApply(const std::string
& entry_json
) const {
1108 EXPECT_FALSE(EntryApplies(entry_json
));
1112 bool EntryApplies(const std::string
& entry_json
) const {
1113 ScopedEntry
entry(GetEntryFromString(entry_json
));
1114 EXPECT_TRUE(entry
.get());
1115 EXPECT_EQ(GpuControlList::kOsMacosx
, entry
->GetOsType());
1116 return entry
->Contains(GpuControlList::kOsMacosx
, "10.6", gpu_info());
1120 TEST_F(GpuControlListEntryDualGPUTest
, CategoryAny
) {
1121 const std::string json_intel
= LONG_STRING_CONST(
1127 "vendor_id": "0x8086",
1128 "device_id": ["0x0166"],
1129 "multi_gpu_category": "any",
1135 EntryShouldApply(json_intel
);
1137 const std::string json_nvidia
= LONG_STRING_CONST(
1143 "vendor_id": "0x10de",
1144 "device_id": ["0x0640"],
1145 "multi_gpu_category": "any",
1151 EntryShouldApply(json_nvidia
);
1154 TEST_F(GpuControlListEntryDualGPUTest
, CategoryPrimarySecondary
) {
1155 const std::string json_secondary
= LONG_STRING_CONST(
1161 "vendor_id": "0x8086",
1162 "device_id": ["0x0166"],
1163 "multi_gpu_category": "secondary",
1169 EntryShouldApply(json_secondary
);
1171 const std::string json_primary
= LONG_STRING_CONST(
1177 "vendor_id": "0x8086",
1178 "device_id": ["0x0166"],
1179 "multi_gpu_category": "primary",
1185 EntryShouldNotApply(json_primary
);
1187 const std::string json_default
= LONG_STRING_CONST(
1193 "vendor_id": "0x8086",
1194 "device_id": ["0x0166"],
1200 // Default is primary.
1201 EntryShouldNotApply(json_default
);
1204 TEST_F(GpuControlListEntryDualGPUTest
, ActiveSecondaryGPU
) {
1205 const std::string json
= LONG_STRING_CONST(
1211 "vendor_id": "0x8086",
1212 "device_id": ["0x0166", "0x0168"],
1213 "multi_gpu_category": "active",
1219 // By default, secondary GPU is active.
1220 EntryShouldApply(json
);
1222 ActivatePrimaryGPU();
1223 EntryShouldNotApply(json
);
1226 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActiveSecondaryGPU
) {
1227 const std::string json
= LONG_STRING_CONST(
1233 "vendor_id": "0x8086",
1234 "multi_gpu_category": "active",
1240 // By default, secondary GPU is active.
1241 EntryShouldApply(json
);
1243 ActivatePrimaryGPU();
1244 EntryShouldNotApply(json
);
1247 TEST_F(GpuControlListEntryDualGPUTest
, ActivePrimaryGPU
) {
1248 const std::string json
= LONG_STRING_CONST(
1254 "vendor_id": "0x10de",
1255 "device_id": ["0x0640"],
1256 "multi_gpu_category": "active",
1262 // By default, secondary GPU is active.
1263 EntryShouldNotApply(json
);
1265 ActivatePrimaryGPU();
1266 EntryShouldApply(json
);
1269 TEST_F(GpuControlListEntryDualGPUTest
, VendorOnlyActivePrimaryGPU
) {
1270 const std::string json
= LONG_STRING_CONST(
1276 "vendor_id": "0x10de",
1277 "multi_gpu_category": "active",
1283 // By default, secondary GPU is active.
1284 EntryShouldNotApply(json
);
1286 ActivatePrimaryGPU();
1287 EntryShouldApply(json
);