Re-enable blink_perf.canvas on Windows
[chromium-blink-merge.git] / gpu / config / gpu_control_list_entry_unittest.cc
blobf955bdb6590b58174d93a200ce32f844139eb2d9
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__
12 namespace gpu {
14 enum TestFeatureType {
15 TEST_FEATURE_0 = 0,
16 TEST_FEATURE_1,
17 TEST_FEATURE_2
20 class GpuControlListEntryTest : public testing::Test {
21 public:
22 GpuControlListEntryTest() { }
23 ~GpuControlListEntryTest() override {}
25 const GPUInfo& gpu_info() const {
26 return gpu_info_;
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))
37 return NULL;
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";
64 protected:
65 GPUInfo gpu_info_;
68 TEST_F(GpuControlListEntryTest, DetailedEntry) {
69 const std::string json = LONG_STRING_CONST(
71 "id": 5,
72 "description": "test entry",
73 "cr_bugs": [1024, 678],
74 "webkit_bugs": [1950],
75 "os": {
76 "type": "macosx",
77 "version": {
78 "op": "=",
79 "value": "10.6.4"
82 "vendor_id": "0x10de",
83 "device_id": ["0x0640"],
84 "driver_version": {
85 "op": "=",
86 "value": "1.6.18"
88 "features": [
89 "test_feature_0"
91 "disabled_extensions": [
92 "test_extension1",
93 "test_extension2"
98 ScopedEntry entry(GetEntryFromString(json));
99 EXPECT_TRUE(entry.get() != NULL);
100 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
101 EXPECT_FALSE(entry->disabled());
102 EXPECT_EQ(5u, entry->id());
103 EXPECT_STREQ("test entry", entry->description().c_str());
104 EXPECT_EQ(2u, entry->cr_bugs().size());
105 EXPECT_EQ(1024, entry->cr_bugs()[0]);
106 EXPECT_EQ(678, entry->cr_bugs()[1]);
107 EXPECT_EQ(1u, entry->webkit_bugs().size());
108 EXPECT_EQ(1950, entry->webkit_bugs()[0]);
109 EXPECT_EQ(1u, entry->features().size());
110 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
111 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info()));
112 EXPECT_TRUE(entry->Contains(
113 GpuControlList::kOsMacosx, "10.6.4", gpu_info()));
114 EXPECT_STREQ("test_extension1", entry->disabled_extensions()[0].c_str());
115 EXPECT_STREQ("test_extension2", entry->disabled_extensions()[1].c_str());
118 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) {
119 const std::string json = LONG_STRING_CONST(
121 "id": 1,
122 "vendor_id": "0x10de",
123 "features": [
124 "test_feature_0"
128 ScopedEntry entry(GetEntryFromString(json));
129 EXPECT_TRUE(entry.get() != NULL);
130 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
132 const GpuControlList::OsType os_type[] = {
133 GpuControlList::kOsMacosx,
134 GpuControlList::kOsWin,
135 GpuControlList::kOsLinux,
136 GpuControlList::kOsChromeOS,
137 GpuControlList::kOsAndroid
139 for (size_t i = 0; i < arraysize(os_type); ++i)
140 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
143 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) {
144 const std::string json = LONG_STRING_CONST(
146 "id": 1,
147 "os": {
148 "type": "linux"
150 "vendor_id": "0x10de",
151 "features": [
152 "test_feature_0"
156 ScopedEntry entry(GetEntryFromString(json));
157 EXPECT_TRUE(entry.get() != NULL);
158 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
160 const GpuControlList::OsType os_type[] = {
161 GpuControlList::kOsMacosx,
162 GpuControlList::kOsWin,
163 GpuControlList::kOsChromeOS,
164 GpuControlList::kOsAndroid
166 for (size_t i = 0; i < arraysize(os_type); ++i)
167 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
168 EXPECT_TRUE(entry->Contains(
169 GpuControlList::kOsLinux, "10.6", gpu_info()));
172 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) {
173 const std::string json = LONG_STRING_CONST(
175 "id": 1,
176 "os": {
177 "type": "linux"
179 "exceptions": [
181 "vendor_id": "0x10de"
184 "features": [
185 "test_feature_0"
189 ScopedEntry entry(GetEntryFromString(json));
190 EXPECT_TRUE(entry.get() != NULL);
191 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
193 const GpuControlList::OsType os_type[] = {
194 GpuControlList::kOsMacosx,
195 GpuControlList::kOsWin,
196 GpuControlList::kOsLinux,
197 GpuControlList::kOsChromeOS,
198 GpuControlList::kOsAndroid
200 for (size_t i = 0; i < arraysize(os_type); ++i)
201 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
204 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) {
205 const std::string json = LONG_STRING_CONST(
207 "id": 1,
208 "os": {
209 "type": "linux"
211 "exceptions": [
213 "vendor_id": "0x8086"
216 "features": [
217 "test_feature_0"
221 ScopedEntry entry(GetEntryFromString(json));
222 EXPECT_TRUE(entry.get() != NULL);
223 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
225 const GpuControlList::OsType os_type[] = {
226 GpuControlList::kOsMacosx,
227 GpuControlList::kOsWin,
228 GpuControlList::kOsChromeOS,
229 GpuControlList::kOsAndroid
231 for (size_t i = 0; i < arraysize(os_type); ++i)
232 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
233 EXPECT_TRUE(entry->Contains(
234 GpuControlList::kOsLinux, "10.6", gpu_info()));
237 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) {
238 const std::string json = LONG_STRING_CONST(
240 "id": 1,
241 "os": {
242 "type": "win"
244 "driver_date": {
245 "op": "<",
246 "value": "2010.5.8"
248 "features": [
249 "test_feature_0"
253 ScopedEntry entry(GetEntryFromString(json));
254 EXPECT_TRUE(entry.get() != NULL);
255 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType());
257 GPUInfo gpu_info;
258 gpu_info.driver_date = "4-12-2010";
259 EXPECT_TRUE(entry->Contains(
260 GpuControlList::kOsWin, "10.6", gpu_info));
261 gpu_info.driver_date = "5-8-2010";
262 EXPECT_FALSE(entry->Contains(
263 GpuControlList::kOsWin, "10.6", gpu_info));
264 gpu_info.driver_date = "5-9-2010";
265 EXPECT_FALSE(entry->Contains(
266 GpuControlList::kOsWin, "10.6", gpu_info));
269 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) {
270 const std::string json = LONG_STRING_CONST(
272 "id": 1,
273 "vendor_id": "0x10de",
274 "device_id": ["0x1023", "0x0640"],
275 "features": [
276 "test_feature_0"
280 ScopedEntry entry(GetEntryFromString(json));
281 EXPECT_TRUE(entry.get() != NULL);
282 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
284 const GpuControlList::OsType os_type[] = {
285 GpuControlList::kOsMacosx,
286 GpuControlList::kOsWin,
287 GpuControlList::kOsLinux,
288 GpuControlList::kOsChromeOS,
289 GpuControlList::kOsAndroid
291 for (size_t i = 0; i < arraysize(os_type); ++i)
292 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
295 TEST_F(GpuControlListEntryTest, ChromeOSEntry) {
296 const std::string json = LONG_STRING_CONST(
298 "id": 1,
299 "os": {
300 "type": "chromeos"
302 "features": [
303 "test_feature_0"
307 ScopedEntry entry(GetEntryFromString(json));
308 EXPECT_TRUE(entry.get() != NULL);
309 EXPECT_EQ(GpuControlList::kOsChromeOS, entry->GetOsType());
311 const GpuControlList::OsType os_type[] = {
312 GpuControlList::kOsMacosx,
313 GpuControlList::kOsWin,
314 GpuControlList::kOsLinux,
315 GpuControlList::kOsAndroid
317 for (size_t i = 0; i < arraysize(os_type); ++i)
318 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
319 EXPECT_TRUE(entry->Contains(
320 GpuControlList::kOsChromeOS, "10.6", gpu_info()));
323 TEST_F(GpuControlListEntryTest, MalformedVendor) {
324 const std::string json = LONG_STRING_CONST(
326 "id": 1,
327 "vendor_id": "[0x10de]",
328 "features": [
329 "test_feature_0"
333 ScopedEntry entry(GetEntryFromString(json));
334 EXPECT_TRUE(entry.get() == NULL);
337 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) {
338 const std::string json = LONG_STRING_CONST(
340 "id": 1,
341 "unknown_field": 0,
342 "features": [
343 "test_feature_0"
347 ScopedEntry entry(GetEntryFromString(json));
348 EXPECT_TRUE(entry.get() == NULL);
351 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) {
352 const std::string json = LONG_STRING_CONST(
354 "id": 2,
355 "exceptions": [
357 "unknown_field": 0
360 "features": [
361 "test_feature_0"
365 ScopedEntry entry(GetEntryFromString(json));
366 EXPECT_TRUE(entry.get() == NULL);
369 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) {
370 const std::string json = LONG_STRING_CONST(
372 "id": 1,
373 "features": [
374 "some_unknown_feature",
375 "test_feature_0"
379 ScopedEntry entry(GetEntryFromString(json));
380 EXPECT_TRUE(entry.get() == NULL);
383 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) {
384 const std::string json = LONG_STRING_CONST(
386 "id": 1,
387 "gl_type": "gles",
388 "gl_version": {
389 "op": "=",
390 "value": "3.0"
392 "features": [
393 "test_feature_0"
397 ScopedEntry entry(GetEntryFromString(json));
398 EXPECT_TRUE(entry.get() != NULL);
400 GPUInfo gpu_info;
401 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
402 EXPECT_TRUE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
404 gpu_info.gl_version = "OpenGL ES 3.0V@66.0 AU@ (CL@)";
405 EXPECT_TRUE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
407 gpu_info.gl_version = "OpenGL ES 3.1 V@66.0 AU@ (CL@)";
408 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
410 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01";
411 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
413 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
414 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
417 TEST_F(GpuControlListEntryTest, GlVersionANGLEEntry) {
418 const std::string json = LONG_STRING_CONST(
420 "id": 1,
421 "gl_type": "angle",
422 "gl_version": {
423 "op": ">",
424 "value": "2.0"
426 "features": [
427 "test_feature_0"
431 ScopedEntry entry(GetEntryFromString(json));
432 EXPECT_TRUE(entry.get() != NULL);
434 GPUInfo gpu_info;
435 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
436 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
438 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01";
439 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
441 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
442 EXPECT_TRUE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
444 gpu_info.gl_version = "OpenGL ES 2.0 (ANGLE 1.2.0.2450)";
445 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
448 TEST_F(GpuControlListEntryTest, GlVersionGLEntry) {
449 const std::string json = LONG_STRING_CONST(
451 "id": 1,
452 "gl_type": "gl",
453 "gl_version": {
454 "op": "<",
455 "value": "4.0"
457 "features": [
458 "test_feature_0"
462 ScopedEntry entry(GetEntryFromString(json));
463 EXPECT_TRUE(entry.get() != NULL);
465 GPUInfo gpu_info;
466 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
467 EXPECT_FALSE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
469 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01";
470 EXPECT_TRUE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
472 gpu_info.gl_version = "4.0 NVIDIA-8.24.11 310.90.9b01";
473 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
475 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)";
476 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
479 TEST_F(GpuControlListEntryTest, GlVendorEqual) {
480 const std::string json = LONG_STRING_CONST(
482 "id": 1,
483 "gl_vendor": "NVIDIA",
484 "features": [
485 "test_feature_0"
489 ScopedEntry entry(GetEntryFromString(json));
490 EXPECT_TRUE(entry.get() != NULL);
492 GPUInfo gpu_info;
493 gpu_info.gl_vendor = "NVIDIA";
494 EXPECT_TRUE(entry->Contains(
495 GpuControlList::kOsMacosx, "10.9", gpu_info));
497 // Case sensitive.
498 gpu_info.gl_vendor = "NVidia";
499 EXPECT_FALSE(entry->Contains(
500 GpuControlList::kOsMacosx, "10.9", gpu_info));
502 gpu_info.gl_vendor = "NVIDIA-x";
503 EXPECT_FALSE(entry->Contains(
504 GpuControlList::kOsMacosx, "10.9", gpu_info));
507 TEST_F(GpuControlListEntryTest, GlVendorWithDot) {
508 const std::string json = LONG_STRING_CONST(
510 "id": 1,
511 "gl_vendor": "X\\.Org.*",
512 "features": [
513 "test_feature_0"
517 ScopedEntry entry(GetEntryFromString(json));
518 EXPECT_TRUE(entry.get() != NULL);
520 GPUInfo gpu_info;
521 gpu_info.gl_vendor = "X.Org R300 Project";
522 EXPECT_TRUE(entry->Contains(
523 GpuControlList::kOsLinux, "", gpu_info));
525 gpu_info.gl_vendor = "X.Org";
526 EXPECT_TRUE(entry->Contains(
527 GpuControlList::kOsLinux, "", gpu_info));
530 TEST_F(GpuControlListEntryTest, GlRendererContains) {
531 const std::string json = LONG_STRING_CONST(
533 "id": 1,
534 "gl_renderer": ".*GeForce.*",
535 "features": [
536 "test_feature_0"
540 ScopedEntry entry(GetEntryFromString(json));
541 EXPECT_TRUE(entry.get() != NULL);
543 GPUInfo gpu_info;
544 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
545 EXPECT_TRUE(entry->Contains(
546 GpuControlList::kOsMacosx, "10.9", gpu_info));
548 // Case sensitive.
549 gpu_info.gl_renderer = "NVIDIA GEFORCE GT 120 OpenGL Engine";
550 EXPECT_FALSE(entry->Contains(
551 GpuControlList::kOsMacosx, "10.9", gpu_info));
553 gpu_info.gl_renderer = "GeForce GT 120 OpenGL Engine";
554 EXPECT_TRUE(entry->Contains(
555 GpuControlList::kOsMacosx, "10.9", gpu_info));
557 gpu_info.gl_renderer = "NVIDIA GeForce";
558 EXPECT_TRUE(entry->Contains(
559 GpuControlList::kOsMacosx, "10.9", gpu_info));
561 gpu_info.gl_renderer = "NVIDIA Ge Force";
562 EXPECT_FALSE(entry->Contains(
563 GpuControlList::kOsMacosx, "10.9", gpu_info));
566 TEST_F(GpuControlListEntryTest, GlRendererCaseInsensitive) {
567 const std::string json = LONG_STRING_CONST(
569 "id": 1,
570 "gl_renderer": "(?i).*software.*",
571 "features": [
572 "test_feature_0"
576 ScopedEntry entry(GetEntryFromString(json));
577 EXPECT_TRUE(entry.get() != NULL);
579 GPUInfo gpu_info;
580 gpu_info.gl_renderer = "software rasterizer";
581 EXPECT_TRUE(entry->Contains(
582 GpuControlList::kOsMacosx, "10.9", gpu_info));
584 gpu_info.gl_renderer = "Software Rasterizer";
585 EXPECT_TRUE(entry->Contains(
586 GpuControlList::kOsMacosx, "10.9", gpu_info));
589 TEST_F(GpuControlListEntryTest, GlExtensionsEndWith) {
590 const std::string json = LONG_STRING_CONST(
592 "id": 1,
593 "gl_extensions": ".*GL_SUN_slice_accum",
594 "features": [
595 "test_feature_0"
599 ScopedEntry entry(GetEntryFromString(json));
600 EXPECT_TRUE(entry.get() != NULL);
602 GPUInfo gpu_info;
603 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap "
604 "GL_SGIX_shadow "
605 "GL_SUN_slice_accum";
606 EXPECT_TRUE(entry->Contains(
607 GpuControlList::kOsMacosx, "10.9", gpu_info));
609 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap "
610 "GL_SUN_slice_accum "
611 "GL_SGIX_shadow";
612 EXPECT_FALSE(entry->Contains(
613 GpuControlList::kOsMacosx, "10.9", gpu_info));
616 TEST_F(GpuControlListEntryTest, DisabledEntry) {
617 const std::string json = LONG_STRING_CONST(
619 "id": 1,
620 "disabled": true,
621 "features": [
622 "test_feature_0"
626 ScopedEntry entry(GetEntryFromString(json));
627 EXPECT_TRUE(entry.get() != NULL);
628 EXPECT_TRUE(entry->disabled());
631 TEST_F(GpuControlListEntryTest, OptimusEntry) {
632 const std::string json = LONG_STRING_CONST(
634 "id": 1,
635 "os": {
636 "type": "linux"
638 "multi_gpu_style": "optimus",
639 "features": [
640 "test_feature_0"
644 GPUInfo gpu_info;
645 gpu_info.optimus = true;
647 ScopedEntry entry(GetEntryFromString(json));
648 EXPECT_TRUE(entry.get() != NULL);
649 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
650 EXPECT_TRUE(entry->Contains(
651 GpuControlList::kOsLinux, "10.6", gpu_info));
654 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) {
655 const std::string json = LONG_STRING_CONST(
657 "id": 1,
658 "os": {
659 "type": "macosx"
661 "multi_gpu_style": "amd_switchable",
662 "features": [
663 "test_feature_0"
667 GPUInfo gpu_info;
668 gpu_info.amd_switchable = true;
670 ScopedEntry entry(GetEntryFromString(json));
671 EXPECT_TRUE(entry.get() != NULL);
672 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
673 EXPECT_TRUE(entry->Contains(
674 GpuControlList::kOsMacosx, "10.6", gpu_info));
677 TEST_F(GpuControlListEntryTest, DriverVendorBeginWith) {
678 const std::string json = LONG_STRING_CONST(
680 "id": 1,
681 "driver_vendor": "NVIDIA.*",
682 "features": [
683 "test_feature_0"
687 ScopedEntry entry(GetEntryFromString(json));
688 EXPECT_TRUE(entry.get() != NULL);
690 GPUInfo gpu_info;
691 gpu_info.driver_vendor = "NVIDIA Corporation";
692 EXPECT_TRUE(entry->Contains(
693 GpuControlList::kOsMacosx, "10.9", gpu_info));
695 // Case sensitive.
696 gpu_info.driver_vendor = "NVidia Corporation";
697 EXPECT_FALSE(entry->Contains(
698 GpuControlList::kOsMacosx, "10.9", gpu_info));
700 gpu_info.driver_vendor = "NVIDIA";
701 EXPECT_TRUE(entry->Contains(
702 GpuControlList::kOsMacosx, "10.9", gpu_info));
704 gpu_info.driver_vendor = "USA NVIDIA";
705 EXPECT_FALSE(entry->Contains(
706 GpuControlList::kOsMacosx, "10.9", gpu_info));
709 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) {
710 const std::string json = LONG_STRING_CONST(
712 "id": 1,
713 "os": {
714 "type": "linux"
716 "vendor_id": "0x1002",
717 "driver_version": {
718 "op": "=",
719 "style": "lexical",
720 "value": "8.76"
722 "features": [
723 "test_feature_0"
727 GPUInfo gpu_info;
728 gpu_info.gpu.vendor_id = 0x1002;
730 ScopedEntry entry(GetEntryFromString(json));
731 EXPECT_TRUE(entry.get() != NULL);
732 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
734 gpu_info.driver_version = "8.76";
735 EXPECT_TRUE(entry->Contains(
736 GpuControlList::kOsLinux, "10.6", gpu_info));
738 gpu_info.driver_version = "8.768";
739 EXPECT_TRUE(entry->Contains(
740 GpuControlList::kOsLinux, "10.6", gpu_info));
742 gpu_info.driver_version = "8.76.8";
743 EXPECT_TRUE(entry->Contains(
744 GpuControlList::kOsLinux, "10.6", gpu_info));
747 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) {
748 const std::string json = LONG_STRING_CONST(
750 "id": 1,
751 "vendor_id": "0x8086",
752 "driver_version": {
753 "op": "<",
754 "value": "10.7"
756 "features": [
757 "test_feature_1"
761 ScopedEntry entry(GetEntryFromString(json));
762 EXPECT_TRUE(entry.get() != NULL);
764 GPUInfo gpu_info;
765 gpu_info.gpu.vendor_id = 0x8086;
766 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
768 gpu_info.driver_version = "10.6";
769 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
772 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
773 const std::string json = LONG_STRING_CONST(
775 "id": 1,
776 "vendor_id": "0x8086",
777 "exceptions": [
779 "gl_renderer": ".*mesa.*"
782 "features": [
783 "test_feature_1"
787 ScopedEntry entry(GetEntryFromString(json));
788 EXPECT_TRUE(entry.get() != NULL);
790 GPUInfo gpu_info;
791 gpu_info.gpu.vendor_id = 0x8086;
792 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
794 gpu_info.gl_renderer = "mesa";
795 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
798 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) {
799 const std::string json = LONG_STRING_CONST(
801 "id": 1,
802 "features": [
803 "all"
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(
818 "id": 1,
819 "vendor_id": "0x0000",
820 "features": [
821 "test_feature_1"
825 ScopedEntry entry(GetEntryFromString(json));
826 EXPECT_TRUE(entry.get() == NULL);
829 TEST_F(GpuControlListEntryTest, InvalidDeviceIdEntry) {
830 const std::string json = LONG_STRING_CONST(
832 "id": 1,
833 "vendor_id": "0x10de",
834 "device_id": ["0x1023", "0x0000"],
835 "features": [
836 "test_feature_1"
840 ScopedEntry entry(GetEntryFromString(json));
841 EXPECT_TRUE(entry.get() == NULL);
844 TEST_F(GpuControlListEntryTest, SingleActiveGPU) {
845 const std::string json = LONG_STRING_CONST(
847 "id": 1,
848 "os": {
849 "type": "macosx"
851 "vendor_id": "0x10de",
852 "device_id": ["0x0640"],
853 "multi_gpu_category": "active",
854 "features": [
855 "test_feature_0"
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(
869 "id": 1,
870 "os": {
871 "type": "android"
873 "machine_model_name": [
874 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
876 "features": [
877 "test_feature_0"
881 ScopedEntry entry(GetEntryFromString(json));
882 EXPECT_TRUE(entry.get() != NULL);
883 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
884 GPUInfo gpu_info;
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(
926 "id": 1,
927 "exceptions": [
929 "os": {
930 "type": "android"
932 "machine_model_name": ["Nexus.*"]
935 "features": [
936 "test_feature_0"
940 ScopedEntry entry(GetEntryFromString(json));
941 EXPECT_TRUE(entry.get() != NULL);
942 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
943 GPUInfo gpu_info;
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(
967 "id": 1,
968 "os": {
969 "type": "macosx"
971 "machine_model_name": ["MacBookPro"],
972 "machine_model_version": {
973 "op": "=",
974 "value": "7.1"
976 "features": [
977 "test_feature_0"
981 ScopedEntry entry(GetEntryFromString(json));
982 EXPECT_TRUE(entry.get() != NULL);
983 GPUInfo gpu_info;
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(
994 "id": 1,
995 "os": {
996 "type": "macosx"
998 "machine_model_name": ["MacBookPro"],
999 "exceptions": [
1001 "machine_model_version": {
1002 "op": ">",
1003 "value": "7.1"
1007 "features": [
1008 "test_feature_0"
1012 ScopedEntry entry(GetEntryFromString(json));
1013 EXPECT_TRUE(entry.get() != NULL);
1014 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
1016 GPUInfo gpu_info;
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 {
1032 public:
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));
1062 private:
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(
1074 "id": 1,
1075 "os": {
1076 "type": "macosx"
1078 "vendor_id": "0x8086",
1079 "device_id": ["0x0166"],
1080 "multi_gpu_category": "any",
1081 "features": [
1082 "test_feature_0"
1086 EntryShouldApply(json_intel);
1088 const std::string json_nvidia = LONG_STRING_CONST(
1090 "id": 1,
1091 "os": {
1092 "type": "macosx"
1094 "vendor_id": "0x10de",
1095 "device_id": ["0x0640"],
1096 "multi_gpu_category": "any",
1097 "features": [
1098 "test_feature_0"
1102 EntryShouldApply(json_nvidia);
1105 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) {
1106 const std::string json_secondary = LONG_STRING_CONST(
1108 "id": 1,
1109 "os": {
1110 "type": "macosx"
1112 "vendor_id": "0x8086",
1113 "device_id": ["0x0166"],
1114 "multi_gpu_category": "secondary",
1115 "features": [
1116 "test_feature_0"
1120 EntryShouldApply(json_secondary);
1122 const std::string json_primary = LONG_STRING_CONST(
1124 "id": 1,
1125 "os": {
1126 "type": "macosx"
1128 "vendor_id": "0x8086",
1129 "device_id": ["0x0166"],
1130 "multi_gpu_category": "primary",
1131 "features": [
1132 "test_feature_0"
1136 EntryShouldNotApply(json_primary);
1138 const std::string json_default = LONG_STRING_CONST(
1140 "id": 1,
1141 "os": {
1142 "type": "macosx"
1144 "vendor_id": "0x8086",
1145 "device_id": ["0x0166"],
1146 "features": [
1147 "test_feature_0"
1151 // Default is primary.
1152 EntryShouldNotApply(json_default);
1155 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) {
1156 const std::string json = LONG_STRING_CONST(
1158 "id": 1,
1159 "os": {
1160 "type": "macosx"
1162 "vendor_id": "0x8086",
1163 "device_id": ["0x0166", "0x0168"],
1164 "multi_gpu_category": "active",
1165 "features": [
1166 "test_feature_0"
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(
1180 "id": 1,
1181 "os": {
1182 "type": "macosx"
1184 "vendor_id": "0x8086",
1185 "multi_gpu_category": "active",
1186 "features": [
1187 "test_feature_0"
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(
1201 "id": 1,
1202 "os": {
1203 "type": "macosx"
1205 "vendor_id": "0x10de",
1206 "device_id": ["0x0640"],
1207 "multi_gpu_category": "active",
1208 "features": [
1209 "test_feature_0"
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(
1223 "id": 1,
1224 "os": {
1225 "type": "macosx"
1227 "vendor_id": "0x10de",
1228 "multi_gpu_category": "active",
1229 "features": [
1230 "test_feature_0"
1234 // By default, secondary GPU is active.
1235 EntryShouldNotApply(json);
1237 ActivatePrimaryGPU();
1238 EntryShouldApply(json);
1241 } // namespace gpu