Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / config / gpu_control_list_entry_unittest.cc
blobd52ad6cb400dee744bbe506e9cd034862a946831
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 = base::JSONReader::Read(json);
34 base::DictionaryValue* value = NULL;
35 if (!root || !root->GetAsDictionary(&value))
36 return NULL;
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";
63 protected:
64 GPUInfo gpu_info_;
67 TEST_F(GpuControlListEntryTest, DetailedEntry) {
68 const std::string json = LONG_STRING_CONST(
70 "id": 5,
71 "description": "test entry",
72 "cr_bugs": [1024, 678],
73 "webkit_bugs": [1950],
74 "os": {
75 "type": "macosx",
76 "version": {
77 "op": "=",
78 "value": "10.6.4"
81 "vendor_id": "0x10de",
82 "device_id": ["0x0640"],
83 "driver_version": {
84 "op": "=",
85 "value": "1.6.18"
87 "features": [
88 "test_feature_0"
90 "disabled_extensions": [
91 "test_extension1",
92 "test_extension2"
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()));
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(
120 "id": 1,
121 "vendor_id": "0x10de",
122 "features": [
123 "test_feature_0"
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(
145 "id": 1,
146 "os": {
147 "type": "linux"
149 "vendor_id": "0x10de",
150 "features": [
151 "test_feature_0"
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(
174 "id": 1,
175 "os": {
176 "type": "linux"
178 "exceptions": [
180 "vendor_id": "0x10de"
183 "features": [
184 "test_feature_0"
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(
206 "id": 1,
207 "os": {
208 "type": "linux"
210 "exceptions": [
212 "vendor_id": "0x8086"
215 "features": [
216 "test_feature_0"
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(
239 "id": 1,
240 "os": {
241 "type": "win"
243 "driver_date": {
244 "op": "<",
245 "value": "2010.5.8"
247 "features": [
248 "test_feature_0"
252 ScopedEntry entry(GetEntryFromString(json));
253 EXPECT_TRUE(entry.get() != NULL);
254 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType());
256 GPUInfo gpu_info;
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(
271 "id": 1,
272 "vendor_id": "0x10de",
273 "device_id": ["0x1023", "0x0640"],
274 "features": [
275 "test_feature_0"
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(
297 "id": 1,
298 "os": {
299 "type": "chromeos"
301 "features": [
302 "test_feature_0"
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(
325 "id": 1,
326 "vendor_id": "[0x10de]",
327 "features": [
328 "test_feature_0"
332 ScopedEntry entry(GetEntryFromString(json));
333 EXPECT_TRUE(entry.get() == NULL);
336 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) {
337 const std::string json = LONG_STRING_CONST(
339 "id": 1,
340 "unknown_field": 0,
341 "features": [
342 "test_feature_0"
346 ScopedEntry entry(GetEntryFromString(json));
347 EXPECT_TRUE(entry.get() == NULL);
350 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) {
351 const std::string json = LONG_STRING_CONST(
353 "id": 2,
354 "exceptions": [
356 "unknown_field": 0
359 "features": [
360 "test_feature_0"
364 ScopedEntry entry(GetEntryFromString(json));
365 EXPECT_TRUE(entry.get() == NULL);
368 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) {
369 const std::string json = LONG_STRING_CONST(
371 "id": 1,
372 "features": [
373 "some_unknown_feature",
374 "test_feature_0"
378 ScopedEntry entry(GetEntryFromString(json));
379 EXPECT_TRUE(entry.get() == NULL);
382 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) {
383 const std::string json = LONG_STRING_CONST(
385 "id": 1,
386 "gl_type": "gles",
387 "gl_version": {
388 "op": "=",
389 "value": "3.0"
391 "features": [
392 "test_feature_0"
396 ScopedEntry entry(GetEntryFromString(json));
397 EXPECT_TRUE(entry.get() != NULL);
399 GPUInfo gpu_info;
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(
419 "id": 1,
420 "gl_type": "angle",
421 "gl_version": {
422 "op": ">",
423 "value": "2.0"
425 "features": [
426 "test_feature_0"
430 ScopedEntry entry(GetEntryFromString(json));
431 EXPECT_TRUE(entry.get() != NULL);
433 GPUInfo gpu_info;
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(
450 "id": 1,
451 "gl_type": "gl",
452 "gl_version": {
453 "op": "<",
454 "value": "4.0"
456 "features": [
457 "test_feature_0"
461 ScopedEntry entry(GetEntryFromString(json));
462 EXPECT_TRUE(entry.get() != NULL);
464 GPUInfo gpu_info;
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(
481 "id": 1,
482 "gl_vendor": "NVIDIA",
483 "features": [
484 "test_feature_0"
488 ScopedEntry entry(GetEntryFromString(json));
489 EXPECT_TRUE(entry.get() != NULL);
491 GPUInfo gpu_info;
492 gpu_info.gl_vendor = "NVIDIA";
493 EXPECT_TRUE(entry->Contains(
494 GpuControlList::kOsMacosx, "10.9", gpu_info));
496 // Case sensitive.
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(
509 "id": 1,
510 "gl_vendor": "X\\.Org.*",
511 "features": [
512 "test_feature_0"
516 ScopedEntry entry(GetEntryFromString(json));
517 EXPECT_TRUE(entry.get() != NULL);
519 GPUInfo gpu_info;
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(
532 "id": 1,
533 "gl_renderer": ".*GeForce.*",
534 "features": [
535 "test_feature_0"
539 ScopedEntry entry(GetEntryFromString(json));
540 EXPECT_TRUE(entry.get() != NULL);
542 GPUInfo gpu_info;
543 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
544 EXPECT_TRUE(entry->Contains(
545 GpuControlList::kOsMacosx, "10.9", gpu_info));
547 // Case sensitive.
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(
568 "id": 1,
569 "gl_renderer": "(?i).*software.*",
570 "features": [
571 "test_feature_0"
575 ScopedEntry entry(GetEntryFromString(json));
576 EXPECT_TRUE(entry.get() != NULL);
578 GPUInfo gpu_info;
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(
591 "id": 1,
592 "gl_extensions": ".*GL_SUN_slice_accum",
593 "features": [
594 "test_feature_0"
598 ScopedEntry entry(GetEntryFromString(json));
599 EXPECT_TRUE(entry.get() != NULL);
601 GPUInfo gpu_info;
602 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap "
603 "GL_SGIX_shadow "
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 "
610 "GL_SGIX_shadow";
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(
618 "id": 1,
619 "disabled": true,
620 "features": [
621 "test_feature_0"
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(
633 "id": 1,
634 "os": {
635 "type": "linux"
637 "multi_gpu_style": "optimus",
638 "features": [
639 "test_feature_0"
643 GPUInfo gpu_info;
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(
656 "id": 1,
657 "os": {
658 "type": "macosx"
660 "multi_gpu_style": "amd_switchable",
661 "features": [
662 "test_feature_0"
666 GPUInfo gpu_info;
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(
679 "id": 1,
680 "driver_vendor": "NVIDIA.*",
681 "features": [
682 "test_feature_0"
686 ScopedEntry entry(GetEntryFromString(json));
687 EXPECT_TRUE(entry.get() != NULL);
689 GPUInfo gpu_info;
690 gpu_info.driver_vendor = "NVIDIA Corporation";
691 EXPECT_TRUE(entry->Contains(
692 GpuControlList::kOsMacosx, "10.9", gpu_info));
694 // Case sensitive.
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(
711 "id": 1,
712 "os": {
713 "type": "linux"
715 "vendor_id": "0x1002",
716 "driver_version": {
717 "op": "=",
718 "style": "lexical",
719 "value": "8.76"
721 "features": [
722 "test_feature_0"
726 GPUInfo gpu_info;
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(
749 "id": 1,
750 "vendor_id": "0x8086",
751 "driver_version": {
752 "op": "<",
753 "value": "10.7"
755 "features": [
756 "test_feature_1"
760 ScopedEntry entry(GetEntryFromString(json));
761 EXPECT_TRUE(entry.get() != NULL);
763 GPUInfo gpu_info;
764 gpu_info.gpu.vendor_id = 0x8086;
765 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
767 gpu_info.driver_version = "10.6";
768 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
771 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
772 const std::string json = LONG_STRING_CONST(
774 "id": 1,
775 "vendor_id": "0x8086",
776 "exceptions": [
778 "gl_renderer": ".*mesa.*"
781 "features": [
782 "test_feature_1"
786 ScopedEntry entry(GetEntryFromString(json));
787 EXPECT_TRUE(entry.get() != NULL);
789 GPUInfo gpu_info;
790 gpu_info.gpu.vendor_id = 0x8086;
791 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
793 gpu_info.gl_renderer = "mesa";
794 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
797 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) {
798 const std::string json = LONG_STRING_CONST(
800 "id": 1,
801 "features": [
802 "all"
806 ScopedEntry entry(GetEntryFromString(json, true));
807 EXPECT_TRUE(entry.get() != NULL);
808 EXPECT_EQ(3u, entry->features().size());
809 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
810 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1));
811 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2));
814 TEST_F(GpuControlListEntryTest, InvalidVendorIdEntry) {
815 const std::string json = LONG_STRING_CONST(
817 "id": 1,
818 "vendor_id": "0x0000",
819 "features": [
820 "test_feature_1"
824 ScopedEntry entry(GetEntryFromString(json));
825 EXPECT_TRUE(entry.get() == NULL);
828 TEST_F(GpuControlListEntryTest, InvalidDeviceIdEntry) {
829 const std::string json = LONG_STRING_CONST(
831 "id": 1,
832 "vendor_id": "0x10de",
833 "device_id": ["0x1023", "0x0000"],
834 "features": [
835 "test_feature_1"
839 ScopedEntry entry(GetEntryFromString(json));
840 EXPECT_TRUE(entry.get() == NULL);
843 TEST_F(GpuControlListEntryTest, SingleActiveGPU) {
844 const std::string json = LONG_STRING_CONST(
846 "id": 1,
847 "os": {
848 "type": "macosx"
850 "vendor_id": "0x10de",
851 "device_id": ["0x0640"],
852 "multi_gpu_category": "active",
853 "features": [
854 "test_feature_0"
858 ScopedEntry entry(GetEntryFromString(json));
859 EXPECT_TRUE(entry.get() != NULL);
860 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
861 EXPECT_TRUE(entry->Contains(
862 GpuControlList::kOsMacosx, "10.6", gpu_info()));
865 TEST_F(GpuControlListEntryTest, MachineModelName) {
866 const std::string json = LONG_STRING_CONST(
868 "id": 1,
869 "os": {
870 "type": "android"
872 "machine_model_name": [
873 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
875 "features": [
876 "test_feature_0"
880 ScopedEntry entry(GetEntryFromString(json));
881 EXPECT_TRUE(entry.get() != NULL);
882 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
883 GPUInfo gpu_info;
885 gpu_info.machine_model_name = "Nexus 4";
886 EXPECT_TRUE(entry->Contains(
887 GpuControlList::kOsAndroid, "4.1", gpu_info));
889 gpu_info.machine_model_name = "XT1032";
890 EXPECT_TRUE(entry->Contains(
891 GpuControlList::kOsAndroid, "4.1", gpu_info));
893 gpu_info.machine_model_name = "XT1032i";
894 EXPECT_FALSE(entry->Contains(
895 GpuControlList::kOsAndroid, "4.1", gpu_info));
897 gpu_info.machine_model_name = "Nexus 5";
898 EXPECT_FALSE(entry->Contains(
899 GpuControlList::kOsAndroid, "4.1", gpu_info));
901 gpu_info.machine_model_name = "Nexus";
902 EXPECT_FALSE(entry->Contains(
903 GpuControlList::kOsAndroid, "4.1", gpu_info));
905 gpu_info.machine_model_name = "";
906 EXPECT_FALSE(entry->Contains(
907 GpuControlList::kOsAndroid, "4.1", gpu_info));
909 gpu_info.machine_model_name = "GT-N7100";
910 EXPECT_TRUE(entry->Contains(
911 GpuControlList::kOsAndroid, "4.1", gpu_info));
913 gpu_info.machine_model_name = "GT-I9300";
914 EXPECT_TRUE(entry->Contains(
915 GpuControlList::kOsAndroid, "4.1", gpu_info));
917 gpu_info.machine_model_name = "SCH-I545";
918 EXPECT_TRUE(entry->Contains(
919 GpuControlList::kOsAndroid, "4.1", gpu_info));
922 TEST_F(GpuControlListEntryTest, MachineModelNameException) {
923 const std::string json = LONG_STRING_CONST(
925 "id": 1,
926 "exceptions": [
928 "os": {
929 "type": "android"
931 "machine_model_name": ["Nexus.*"]
934 "features": [
935 "test_feature_0"
939 ScopedEntry entry(GetEntryFromString(json));
940 EXPECT_TRUE(entry.get() != NULL);
941 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
942 GPUInfo gpu_info;
944 gpu_info.machine_model_name = "Nexus 4";
945 EXPECT_FALSE(entry->Contains(
946 GpuControlList::kOsAndroid, "4.1", gpu_info));
947 EXPECT_TRUE(entry->Contains(
948 GpuControlList::kOsLinux, "4.1", gpu_info));
950 gpu_info.machine_model_name = "Nexus 7";
951 EXPECT_FALSE(entry->Contains(
952 GpuControlList::kOsAndroid, "4.1", gpu_info));
953 EXPECT_TRUE(entry->Contains(
954 GpuControlList::kOsLinux, "4.1", gpu_info));
956 gpu_info.machine_model_name = "";
957 EXPECT_TRUE(entry->Contains(
958 GpuControlList::kOsAndroid, "4.1", gpu_info));
959 EXPECT_TRUE(entry->Contains(
960 GpuControlList::kOsLinux, "4.1", gpu_info));
963 TEST_F(GpuControlListEntryTest, MachineModelVersion) {
964 const std::string json = LONG_STRING_CONST(
966 "id": 1,
967 "os": {
968 "type": "macosx"
970 "machine_model_name": ["MacBookPro"],
971 "machine_model_version": {
972 "op": "=",
973 "value": "7.1"
975 "features": [
976 "test_feature_0"
980 ScopedEntry entry(GetEntryFromString(json));
981 EXPECT_TRUE(entry.get() != NULL);
982 GPUInfo gpu_info;
983 gpu_info.machine_model_name = "MacBookPro";
984 gpu_info.machine_model_version = "7.1";
985 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
986 EXPECT_TRUE(entry->Contains(
987 GpuControlList::kOsMacosx, "10.6", gpu_info));
990 TEST_F(GpuControlListEntryTest, MachineModelVersionException) {
991 const std::string json = LONG_STRING_CONST(
993 "id": 1,
994 "os": {
995 "type": "macosx"
997 "machine_model_name": ["MacBookPro"],
998 "exceptions": [
1000 "machine_model_version": {
1001 "op": ">",
1002 "value": "7.1"
1006 "features": [
1007 "test_feature_0"
1011 ScopedEntry entry(GetEntryFromString(json));
1012 EXPECT_TRUE(entry.get() != NULL);
1013 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
1015 GPUInfo gpu_info;
1016 gpu_info.machine_model_name = "MacBookPro";
1017 gpu_info.machine_model_version = "7.0";
1018 EXPECT_TRUE(entry->Contains(
1019 GpuControlList::kOsMacosx, "10.6", gpu_info));
1021 gpu_info.machine_model_version = "7.2";
1022 EXPECT_FALSE(entry->Contains(
1023 GpuControlList::kOsMacosx, "10.6", gpu_info));
1025 gpu_info.machine_model_version = "";
1026 EXPECT_TRUE(entry->Contains(
1027 GpuControlList::kOsMacosx, "10.6", gpu_info));
1030 class GpuControlListEntryDualGPUTest : public GpuControlListEntryTest {
1031 public:
1032 GpuControlListEntryDualGPUTest() { }
1033 ~GpuControlListEntryDualGPUTest() override {}
1035 void SetUp() override {
1036 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
1037 // secondary, and initially Intel is active.
1038 gpu_info_.gpu.vendor_id = 0x10de;
1039 gpu_info_.gpu.device_id = 0x0640;
1040 gpu_info_.gpu.active = false;
1041 GPUInfo::GPUDevice second_gpu;
1042 second_gpu.vendor_id = 0x8086;
1043 second_gpu.device_id = 0x0166;
1044 second_gpu.active = true;
1045 gpu_info_.secondary_gpus.push_back(second_gpu);
1048 void ActivatePrimaryGPU() {
1049 gpu_info_.gpu.active = true;
1050 gpu_info_.secondary_gpus[0].active = false;
1053 void EntryShouldApply(const std::string& entry_json) const {
1054 EXPECT_TRUE(EntryApplies(entry_json));
1057 void EntryShouldNotApply(const std::string& entry_json) const {
1058 EXPECT_FALSE(EntryApplies(entry_json));
1061 private:
1062 bool EntryApplies(const std::string& entry_json) const {
1063 ScopedEntry entry(GetEntryFromString(entry_json));
1064 EXPECT_TRUE(entry.get());
1065 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
1066 return entry->Contains(GpuControlList::kOsMacosx, "10.6", gpu_info());
1070 TEST_F(GpuControlListEntryDualGPUTest, CategoryAny) {
1071 const std::string json_intel = LONG_STRING_CONST(
1073 "id": 1,
1074 "os": {
1075 "type": "macosx"
1077 "vendor_id": "0x8086",
1078 "device_id": ["0x0166"],
1079 "multi_gpu_category": "any",
1080 "features": [
1081 "test_feature_0"
1085 EntryShouldApply(json_intel);
1087 const std::string json_nvidia = LONG_STRING_CONST(
1089 "id": 1,
1090 "os": {
1091 "type": "macosx"
1093 "vendor_id": "0x10de",
1094 "device_id": ["0x0640"],
1095 "multi_gpu_category": "any",
1096 "features": [
1097 "test_feature_0"
1101 EntryShouldApply(json_nvidia);
1104 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) {
1105 const std::string json_secondary = LONG_STRING_CONST(
1107 "id": 1,
1108 "os": {
1109 "type": "macosx"
1111 "vendor_id": "0x8086",
1112 "device_id": ["0x0166"],
1113 "multi_gpu_category": "secondary",
1114 "features": [
1115 "test_feature_0"
1119 EntryShouldApply(json_secondary);
1121 const std::string json_primary = LONG_STRING_CONST(
1123 "id": 1,
1124 "os": {
1125 "type": "macosx"
1127 "vendor_id": "0x8086",
1128 "device_id": ["0x0166"],
1129 "multi_gpu_category": "primary",
1130 "features": [
1131 "test_feature_0"
1135 EntryShouldNotApply(json_primary);
1137 const std::string json_default = LONG_STRING_CONST(
1139 "id": 1,
1140 "os": {
1141 "type": "macosx"
1143 "vendor_id": "0x8086",
1144 "device_id": ["0x0166"],
1145 "features": [
1146 "test_feature_0"
1150 // Default is primary.
1151 EntryShouldNotApply(json_default);
1154 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) {
1155 const std::string json = LONG_STRING_CONST(
1157 "id": 1,
1158 "os": {
1159 "type": "macosx"
1161 "vendor_id": "0x8086",
1162 "device_id": ["0x0166", "0x0168"],
1163 "multi_gpu_category": "active",
1164 "features": [
1165 "test_feature_0"
1169 // By default, secondary GPU is active.
1170 EntryShouldApply(json);
1172 ActivatePrimaryGPU();
1173 EntryShouldNotApply(json);
1176 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActiveSecondaryGPU) {
1177 const std::string json = LONG_STRING_CONST(
1179 "id": 1,
1180 "os": {
1181 "type": "macosx"
1183 "vendor_id": "0x8086",
1184 "multi_gpu_category": "active",
1185 "features": [
1186 "test_feature_0"
1190 // By default, secondary GPU is active.
1191 EntryShouldApply(json);
1193 ActivatePrimaryGPU();
1194 EntryShouldNotApply(json);
1197 TEST_F(GpuControlListEntryDualGPUTest, ActivePrimaryGPU) {
1198 const std::string json = LONG_STRING_CONST(
1200 "id": 1,
1201 "os": {
1202 "type": "macosx"
1204 "vendor_id": "0x10de",
1205 "device_id": ["0x0640"],
1206 "multi_gpu_category": "active",
1207 "features": [
1208 "test_feature_0"
1212 // By default, secondary GPU is active.
1213 EntryShouldNotApply(json);
1215 ActivatePrimaryGPU();
1216 EntryShouldApply(json);
1219 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActivePrimaryGPU) {
1220 const std::string json = LONG_STRING_CONST(
1222 "id": 1,
1223 "os": {
1224 "type": "macosx"
1226 "vendor_id": "0x10de",
1227 "multi_gpu_category": "active",
1228 "features": [
1229 "test_feature_0"
1233 // By default, secondary GPU is active.
1234 EntryShouldNotApply(json);
1236 ActivatePrimaryGPU();
1237 EntryShouldApply(json);
1240 } // namespace gpu