Update UI for WebStore bundle installs.
[chromium-blink-merge.git] / gpu / config / gpu_control_list_entry_unittest.cc
blob0c31e208a11d0334317f5c68cd56ebad63a2620d
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"
94 ScopedEntry entry(GetEntryFromString(json));
95 EXPECT_TRUE(entry.get() != NULL);
96 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
97 EXPECT_FALSE(entry->disabled());
98 EXPECT_EQ(5u, entry->id());
99 EXPECT_STREQ("test entry", entry->description().c_str());
100 EXPECT_EQ(2u, entry->cr_bugs().size());
101 EXPECT_EQ(1024, entry->cr_bugs()[0]);
102 EXPECT_EQ(678, entry->cr_bugs()[1]);
103 EXPECT_EQ(1u, entry->webkit_bugs().size());
104 EXPECT_EQ(1950, entry->webkit_bugs()[0]);
105 EXPECT_EQ(1u, entry->features().size());
106 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
107 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info()));
108 EXPECT_TRUE(entry->Contains(
109 GpuControlList::kOsMacosx, "10.6.4", gpu_info()));
112 TEST_F(GpuControlListEntryTest, VendorOnAllOsEntry) {
113 const std::string json = LONG_STRING_CONST(
115 "id": 1,
116 "vendor_id": "0x10de",
117 "features": [
118 "test_feature_0"
122 ScopedEntry entry(GetEntryFromString(json));
123 EXPECT_TRUE(entry.get() != NULL);
124 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
126 const GpuControlList::OsType os_type[] = {
127 GpuControlList::kOsMacosx,
128 GpuControlList::kOsWin,
129 GpuControlList::kOsLinux,
130 GpuControlList::kOsChromeOS,
131 GpuControlList::kOsAndroid
133 for (size_t i = 0; i < arraysize(os_type); ++i)
134 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
137 TEST_F(GpuControlListEntryTest, VendorOnLinuxEntry) {
138 const std::string json = LONG_STRING_CONST(
140 "id": 1,
141 "os": {
142 "type": "linux"
144 "vendor_id": "0x10de",
145 "features": [
146 "test_feature_0"
150 ScopedEntry entry(GetEntryFromString(json));
151 EXPECT_TRUE(entry.get() != NULL);
152 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
154 const GpuControlList::OsType os_type[] = {
155 GpuControlList::kOsMacosx,
156 GpuControlList::kOsWin,
157 GpuControlList::kOsChromeOS,
158 GpuControlList::kOsAndroid
160 for (size_t i = 0; i < arraysize(os_type); ++i)
161 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
162 EXPECT_TRUE(entry->Contains(
163 GpuControlList::kOsLinux, "10.6", gpu_info()));
166 TEST_F(GpuControlListEntryTest, AllExceptNVidiaOnLinuxEntry) {
167 const std::string json = LONG_STRING_CONST(
169 "id": 1,
170 "os": {
171 "type": "linux"
173 "exceptions": [
175 "vendor_id": "0x10de"
178 "features": [
179 "test_feature_0"
183 ScopedEntry entry(GetEntryFromString(json));
184 EXPECT_TRUE(entry.get() != NULL);
185 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
187 const GpuControlList::OsType os_type[] = {
188 GpuControlList::kOsMacosx,
189 GpuControlList::kOsWin,
190 GpuControlList::kOsLinux,
191 GpuControlList::kOsChromeOS,
192 GpuControlList::kOsAndroid
194 for (size_t i = 0; i < arraysize(os_type); ++i)
195 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
198 TEST_F(GpuControlListEntryTest, AllExceptIntelOnLinuxEntry) {
199 const std::string json = LONG_STRING_CONST(
201 "id": 1,
202 "os": {
203 "type": "linux"
205 "exceptions": [
207 "vendor_id": "0x8086"
210 "features": [
211 "test_feature_0"
215 ScopedEntry entry(GetEntryFromString(json));
216 EXPECT_TRUE(entry.get() != NULL);
217 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
219 const GpuControlList::OsType os_type[] = {
220 GpuControlList::kOsMacosx,
221 GpuControlList::kOsWin,
222 GpuControlList::kOsChromeOS,
223 GpuControlList::kOsAndroid
225 for (size_t i = 0; i < arraysize(os_type); ++i)
226 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
227 EXPECT_TRUE(entry->Contains(
228 GpuControlList::kOsLinux, "10.6", gpu_info()));
231 TEST_F(GpuControlListEntryTest, DateOnWindowsEntry) {
232 const std::string json = LONG_STRING_CONST(
234 "id": 1,
235 "os": {
236 "type": "win"
238 "driver_date": {
239 "op": "<",
240 "value": "2010.5.8"
242 "features": [
243 "test_feature_0"
247 ScopedEntry entry(GetEntryFromString(json));
248 EXPECT_TRUE(entry.get() != NULL);
249 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType());
251 GPUInfo gpu_info;
252 gpu_info.driver_date = "4-12-2010";
253 EXPECT_TRUE(entry->Contains(
254 GpuControlList::kOsWin, "10.6", gpu_info));
255 gpu_info.driver_date = "5-8-2010";
256 EXPECT_FALSE(entry->Contains(
257 GpuControlList::kOsWin, "10.6", gpu_info));
258 gpu_info.driver_date = "5-9-2010";
259 EXPECT_FALSE(entry->Contains(
260 GpuControlList::kOsWin, "10.6", gpu_info));
263 TEST_F(GpuControlListEntryTest, MultipleDevicesEntry) {
264 const std::string json = LONG_STRING_CONST(
266 "id": 1,
267 "vendor_id": "0x10de",
268 "device_id": ["0x1023", "0x0640"],
269 "features": [
270 "test_feature_0"
274 ScopedEntry entry(GetEntryFromString(json));
275 EXPECT_TRUE(entry.get() != NULL);
276 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
278 const GpuControlList::OsType os_type[] = {
279 GpuControlList::kOsMacosx,
280 GpuControlList::kOsWin,
281 GpuControlList::kOsLinux,
282 GpuControlList::kOsChromeOS,
283 GpuControlList::kOsAndroid
285 for (size_t i = 0; i < arraysize(os_type); ++i)
286 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info()));
289 TEST_F(GpuControlListEntryTest, ChromeOSEntry) {
290 const std::string json = LONG_STRING_CONST(
292 "id": 1,
293 "os": {
294 "type": "chromeos"
296 "features": [
297 "test_feature_0"
301 ScopedEntry entry(GetEntryFromString(json));
302 EXPECT_TRUE(entry.get() != NULL);
303 EXPECT_EQ(GpuControlList::kOsChromeOS, entry->GetOsType());
305 const GpuControlList::OsType os_type[] = {
306 GpuControlList::kOsMacosx,
307 GpuControlList::kOsWin,
308 GpuControlList::kOsLinux,
309 GpuControlList::kOsAndroid
311 for (size_t i = 0; i < arraysize(os_type); ++i)
312 EXPECT_FALSE(entry->Contains(os_type[i], "10.6", gpu_info()));
313 EXPECT_TRUE(entry->Contains(
314 GpuControlList::kOsChromeOS, "10.6", gpu_info()));
317 TEST_F(GpuControlListEntryTest, MalformedVendor) {
318 const std::string json = LONG_STRING_CONST(
320 "id": 1,
321 "vendor_id": "[0x10de]",
322 "features": [
323 "test_feature_0"
327 ScopedEntry entry(GetEntryFromString(json));
328 EXPECT_TRUE(entry.get() == NULL);
331 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) {
332 const std::string json = LONG_STRING_CONST(
334 "id": 1,
335 "unknown_field": 0,
336 "features": [
337 "test_feature_0"
341 ScopedEntry entry(GetEntryFromString(json));
342 EXPECT_TRUE(entry.get() == NULL);
345 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) {
346 const std::string json = LONG_STRING_CONST(
348 "id": 2,
349 "exceptions": [
351 "unknown_field": 0
354 "features": [
355 "test_feature_0"
359 ScopedEntry entry(GetEntryFromString(json));
360 EXPECT_TRUE(entry.get() == NULL);
363 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) {
364 const std::string json = LONG_STRING_CONST(
366 "id": 1,
367 "features": [
368 "some_unknown_feature",
369 "test_feature_0"
373 ScopedEntry entry(GetEntryFromString(json));
374 EXPECT_TRUE(entry.get() == NULL);
377 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) {
378 const std::string json = LONG_STRING_CONST(
380 "id": 1,
381 "gl_type": "gles",
382 "gl_version": {
383 "op": "=",
384 "value": "3.0"
386 "features": [
387 "test_feature_0"
391 ScopedEntry entry(GetEntryFromString(json));
392 EXPECT_TRUE(entry.get() != NULL);
394 GPUInfo gpu_info;
395 gpu_info.gl_version = "OpenGL ES 3.0 V@66.0 AU@ (CL@)";
396 EXPECT_TRUE(entry->Contains(GpuControlList::kOsAndroid, "4.4.2", gpu_info));
398 gpu_info.gl_version = "OpenGL ES 3.0V@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(
414 "id": 1,
415 "gl_type": "angle",
416 "gl_version": {
417 "op": ">",
418 "value": "2.0"
420 "features": [
421 "test_feature_0"
425 ScopedEntry entry(GetEntryFromString(json));
426 EXPECT_TRUE(entry.get() != NULL);
428 GPUInfo gpu_info;
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(
445 "id": 1,
446 "gl_type": "gl",
447 "gl_version": {
448 "op": "<",
449 "value": "4.0"
451 "features": [
452 "test_feature_0"
456 ScopedEntry entry(GetEntryFromString(json));
457 EXPECT_TRUE(entry.get() != NULL);
459 GPUInfo gpu_info;
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(
476 "id": 1,
477 "gl_vendor": "NVIDIA",
478 "features": [
479 "test_feature_0"
483 ScopedEntry entry(GetEntryFromString(json));
484 EXPECT_TRUE(entry.get() != NULL);
486 GPUInfo gpu_info;
487 gpu_info.gl_vendor = "NVIDIA";
488 EXPECT_TRUE(entry->Contains(
489 GpuControlList::kOsMacosx, "10.9", gpu_info));
491 // Case sensitive.
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(
504 "id": 1,
505 "gl_vendor": "X\\.Org.*",
506 "features": [
507 "test_feature_0"
511 ScopedEntry entry(GetEntryFromString(json));
512 EXPECT_TRUE(entry.get() != NULL);
514 GPUInfo gpu_info;
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(
527 "id": 1,
528 "gl_renderer": ".*GeForce.*",
529 "features": [
530 "test_feature_0"
534 ScopedEntry entry(GetEntryFromString(json));
535 EXPECT_TRUE(entry.get() != NULL);
537 GPUInfo gpu_info;
538 gpu_info.gl_renderer = "NVIDIA GeForce GT 120 OpenGL Engine";
539 EXPECT_TRUE(entry->Contains(
540 GpuControlList::kOsMacosx, "10.9", gpu_info));
542 // Case sensitive.
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(
563 "id": 1,
564 "gl_renderer": "(?i).*software.*",
565 "features": [
566 "test_feature_0"
570 ScopedEntry entry(GetEntryFromString(json));
571 EXPECT_TRUE(entry.get() != NULL);
573 GPUInfo gpu_info;
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(
586 "id": 1,
587 "gl_extensions": ".*GL_SUN_slice_accum",
588 "features": [
589 "test_feature_0"
593 ScopedEntry entry(GetEntryFromString(json));
594 EXPECT_TRUE(entry.get() != NULL);
596 GPUInfo gpu_info;
597 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap "
598 "GL_SGIX_shadow "
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 "
605 "GL_SGIX_shadow";
606 EXPECT_FALSE(entry->Contains(
607 GpuControlList::kOsMacosx, "10.9", gpu_info));
610 TEST_F(GpuControlListEntryTest, DisabledEntry) {
611 const std::string json = LONG_STRING_CONST(
613 "id": 1,
614 "disabled": true,
615 "features": [
616 "test_feature_0"
620 ScopedEntry entry(GetEntryFromString(json));
621 EXPECT_TRUE(entry.get() != NULL);
622 EXPECT_TRUE(entry->disabled());
625 TEST_F(GpuControlListEntryTest, OptimusEntry) {
626 const std::string json = LONG_STRING_CONST(
628 "id": 1,
629 "os": {
630 "type": "linux"
632 "multi_gpu_style": "optimus",
633 "features": [
634 "test_feature_0"
638 GPUInfo gpu_info;
639 gpu_info.optimus = true;
641 ScopedEntry entry(GetEntryFromString(json));
642 EXPECT_TRUE(entry.get() != NULL);
643 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
644 EXPECT_TRUE(entry->Contains(
645 GpuControlList::kOsLinux, "10.6", gpu_info));
648 TEST_F(GpuControlListEntryTest, AMDSwitchableEntry) {
649 const std::string json = LONG_STRING_CONST(
651 "id": 1,
652 "os": {
653 "type": "macosx"
655 "multi_gpu_style": "amd_switchable",
656 "features": [
657 "test_feature_0"
661 GPUInfo gpu_info;
662 gpu_info.amd_switchable = true;
664 ScopedEntry entry(GetEntryFromString(json));
665 EXPECT_TRUE(entry.get() != NULL);
666 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
667 EXPECT_TRUE(entry->Contains(
668 GpuControlList::kOsMacosx, "10.6", gpu_info));
671 TEST_F(GpuControlListEntryTest, DriverVendorBeginWith) {
672 const std::string json = LONG_STRING_CONST(
674 "id": 1,
675 "driver_vendor": "NVIDIA.*",
676 "features": [
677 "test_feature_0"
681 ScopedEntry entry(GetEntryFromString(json));
682 EXPECT_TRUE(entry.get() != NULL);
684 GPUInfo gpu_info;
685 gpu_info.driver_vendor = "NVIDIA Corporation";
686 EXPECT_TRUE(entry->Contains(
687 GpuControlList::kOsMacosx, "10.9", gpu_info));
689 // Case sensitive.
690 gpu_info.driver_vendor = "NVidia Corporation";
691 EXPECT_FALSE(entry->Contains(
692 GpuControlList::kOsMacosx, "10.9", gpu_info));
694 gpu_info.driver_vendor = "NVIDIA";
695 EXPECT_TRUE(entry->Contains(
696 GpuControlList::kOsMacosx, "10.9", gpu_info));
698 gpu_info.driver_vendor = "USA NVIDIA";
699 EXPECT_FALSE(entry->Contains(
700 GpuControlList::kOsMacosx, "10.9", gpu_info));
703 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) {
704 const std::string json = LONG_STRING_CONST(
706 "id": 1,
707 "os": {
708 "type": "linux"
710 "vendor_id": "0x1002",
711 "driver_version": {
712 "op": "=",
713 "style": "lexical",
714 "value": "8.76"
716 "features": [
717 "test_feature_0"
721 GPUInfo gpu_info;
722 gpu_info.gpu.vendor_id = 0x1002;
724 ScopedEntry entry(GetEntryFromString(json));
725 EXPECT_TRUE(entry.get() != NULL);
726 EXPECT_EQ(GpuControlList::kOsLinux, entry->GetOsType());
728 gpu_info.driver_version = "8.76";
729 EXPECT_TRUE(entry->Contains(
730 GpuControlList::kOsLinux, "10.6", gpu_info));
732 gpu_info.driver_version = "8.768";
733 EXPECT_TRUE(entry->Contains(
734 GpuControlList::kOsLinux, "10.6", gpu_info));
736 gpu_info.driver_version = "8.76.8";
737 EXPECT_TRUE(entry->Contains(
738 GpuControlList::kOsLinux, "10.6", gpu_info));
741 TEST_F(GpuControlListEntryTest, NeedsMoreInfoEntry) {
742 const std::string json = LONG_STRING_CONST(
744 "id": 1,
745 "vendor_id": "0x8086",
746 "driver_version": {
747 "op": "<",
748 "value": "10.7"
750 "features": [
751 "test_feature_1"
755 ScopedEntry entry(GetEntryFromString(json));
756 EXPECT_TRUE(entry.get() != NULL);
758 GPUInfo gpu_info;
759 gpu_info.gpu.vendor_id = 0x8086;
760 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
762 gpu_info.driver_version = "10.6";
763 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
766 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
767 const std::string json = LONG_STRING_CONST(
769 "id": 1,
770 "vendor_id": "0x8086",
771 "exceptions": [
773 "gl_renderer": ".*mesa.*"
776 "features": [
777 "test_feature_1"
781 ScopedEntry entry(GetEntryFromString(json));
782 EXPECT_TRUE(entry.get() != NULL);
784 GPUInfo gpu_info;
785 gpu_info.gpu.vendor_id = 0x8086;
786 EXPECT_TRUE(entry->NeedsMoreInfo(gpu_info));
788 gpu_info.gl_renderer = "mesa";
789 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
792 TEST_F(GpuControlListEntryTest, FeatureTypeAllEntry) {
793 const std::string json = LONG_STRING_CONST(
795 "id": 1,
796 "features": [
797 "all"
801 ScopedEntry entry(GetEntryFromString(json, true));
802 EXPECT_TRUE(entry.get() != NULL);
803 EXPECT_EQ(3u, entry->features().size());
804 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_0));
805 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_1));
806 EXPECT_EQ(1u, entry->features().count(TEST_FEATURE_2));
809 TEST_F(GpuControlListEntryTest, InvalidVendorIdEntry) {
810 const std::string json = LONG_STRING_CONST(
812 "id": 1,
813 "vendor_id": "0x0000",
814 "features": [
815 "test_feature_1"
819 ScopedEntry entry(GetEntryFromString(json));
820 EXPECT_TRUE(entry.get() == NULL);
823 TEST_F(GpuControlListEntryTest, InvalidDeviceIdEntry) {
824 const std::string json = LONG_STRING_CONST(
826 "id": 1,
827 "vendor_id": "0x10de",
828 "device_id": ["0x1023", "0x0000"],
829 "features": [
830 "test_feature_1"
834 ScopedEntry entry(GetEntryFromString(json));
835 EXPECT_TRUE(entry.get() == NULL);
838 TEST_F(GpuControlListEntryTest, SingleActiveGPU) {
839 const std::string json = LONG_STRING_CONST(
841 "id": 1,
842 "os": {
843 "type": "macosx"
845 "vendor_id": "0x10de",
846 "device_id": ["0x0640"],
847 "multi_gpu_category": "active",
848 "features": [
849 "test_feature_0"
853 ScopedEntry entry(GetEntryFromString(json));
854 EXPECT_TRUE(entry.get() != NULL);
855 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
856 EXPECT_TRUE(entry->Contains(
857 GpuControlList::kOsMacosx, "10.6", gpu_info()));
860 TEST_F(GpuControlListEntryTest, MachineModelName) {
861 const std::string json = LONG_STRING_CONST(
863 "id": 1,
864 "os": {
865 "type": "android"
867 "machine_model_name": [
868 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
870 "features": [
871 "test_feature_0"
875 ScopedEntry entry(GetEntryFromString(json));
876 EXPECT_TRUE(entry.get() != NULL);
877 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
878 GPUInfo gpu_info;
880 gpu_info.machine_model_name = "Nexus 4";
881 EXPECT_TRUE(entry->Contains(
882 GpuControlList::kOsAndroid, "4.1", gpu_info));
884 gpu_info.machine_model_name = "XT1032";
885 EXPECT_TRUE(entry->Contains(
886 GpuControlList::kOsAndroid, "4.1", gpu_info));
888 gpu_info.machine_model_name = "XT1032i";
889 EXPECT_FALSE(entry->Contains(
890 GpuControlList::kOsAndroid, "4.1", gpu_info));
892 gpu_info.machine_model_name = "Nexus 5";
893 EXPECT_FALSE(entry->Contains(
894 GpuControlList::kOsAndroid, "4.1", gpu_info));
896 gpu_info.machine_model_name = "Nexus";
897 EXPECT_FALSE(entry->Contains(
898 GpuControlList::kOsAndroid, "4.1", gpu_info));
900 gpu_info.machine_model_name = "";
901 EXPECT_FALSE(entry->Contains(
902 GpuControlList::kOsAndroid, "4.1", gpu_info));
904 gpu_info.machine_model_name = "GT-N7100";
905 EXPECT_TRUE(entry->Contains(
906 GpuControlList::kOsAndroid, "4.1", gpu_info));
908 gpu_info.machine_model_name = "GT-I9300";
909 EXPECT_TRUE(entry->Contains(
910 GpuControlList::kOsAndroid, "4.1", gpu_info));
912 gpu_info.machine_model_name = "SCH-I545";
913 EXPECT_TRUE(entry->Contains(
914 GpuControlList::kOsAndroid, "4.1", gpu_info));
917 TEST_F(GpuControlListEntryTest, MachineModelNameException) {
918 const std::string json = LONG_STRING_CONST(
920 "id": 1,
921 "exceptions": [
923 "os": {
924 "type": "android"
926 "machine_model_name": ["Nexus.*"]
929 "features": [
930 "test_feature_0"
934 ScopedEntry entry(GetEntryFromString(json));
935 EXPECT_TRUE(entry.get() != NULL);
936 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
937 GPUInfo gpu_info;
939 gpu_info.machine_model_name = "Nexus 4";
940 EXPECT_FALSE(entry->Contains(
941 GpuControlList::kOsAndroid, "4.1", gpu_info));
942 EXPECT_TRUE(entry->Contains(
943 GpuControlList::kOsLinux, "4.1", gpu_info));
945 gpu_info.machine_model_name = "Nexus 7";
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 = "";
952 EXPECT_TRUE(entry->Contains(
953 GpuControlList::kOsAndroid, "4.1", gpu_info));
954 EXPECT_TRUE(entry->Contains(
955 GpuControlList::kOsLinux, "4.1", gpu_info));
958 TEST_F(GpuControlListEntryTest, MachineModelVersion) {
959 const std::string json = LONG_STRING_CONST(
961 "id": 1,
962 "os": {
963 "type": "macosx"
965 "machine_model_name": ["MacBookPro"],
966 "machine_model_version": {
967 "op": "=",
968 "value": "7.1"
970 "features": [
971 "test_feature_0"
975 ScopedEntry entry(GetEntryFromString(json));
976 EXPECT_TRUE(entry.get() != NULL);
977 GPUInfo gpu_info;
978 gpu_info.machine_model_name = "MacBookPro";
979 gpu_info.machine_model_version = "7.1";
980 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
981 EXPECT_TRUE(entry->Contains(
982 GpuControlList::kOsMacosx, "10.6", gpu_info));
985 TEST_F(GpuControlListEntryTest, MachineModelVersionException) {
986 const std::string json = LONG_STRING_CONST(
988 "id": 1,
989 "os": {
990 "type": "macosx"
992 "machine_model_name": ["MacBookPro"],
993 "exceptions": [
995 "machine_model_version": {
996 "op": ">",
997 "value": "7.1"
1001 "features": [
1002 "test_feature_0"
1006 ScopedEntry entry(GetEntryFromString(json));
1007 EXPECT_TRUE(entry.get() != NULL);
1008 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
1010 GPUInfo gpu_info;
1011 gpu_info.machine_model_name = "MacBookPro";
1012 gpu_info.machine_model_version = "7.0";
1013 EXPECT_TRUE(entry->Contains(
1014 GpuControlList::kOsMacosx, "10.6", gpu_info));
1016 gpu_info.machine_model_version = "7.2";
1017 EXPECT_FALSE(entry->Contains(
1018 GpuControlList::kOsMacosx, "10.6", gpu_info));
1020 gpu_info.machine_model_version = "";
1021 EXPECT_TRUE(entry->Contains(
1022 GpuControlList::kOsMacosx, "10.6", gpu_info));
1025 class GpuControlListEntryDualGPUTest : public GpuControlListEntryTest {
1026 public:
1027 GpuControlListEntryDualGPUTest() { }
1028 ~GpuControlListEntryDualGPUTest() override {}
1030 void SetUp() override {
1031 // Set up a NVIDIA/Intel dual, with NVIDIA as primary and Intel as
1032 // secondary, and initially Intel is active.
1033 gpu_info_.gpu.vendor_id = 0x10de;
1034 gpu_info_.gpu.device_id = 0x0640;
1035 gpu_info_.gpu.active = false;
1036 GPUInfo::GPUDevice second_gpu;
1037 second_gpu.vendor_id = 0x8086;
1038 second_gpu.device_id = 0x0166;
1039 second_gpu.active = true;
1040 gpu_info_.secondary_gpus.push_back(second_gpu);
1043 void ActivatePrimaryGPU() {
1044 gpu_info_.gpu.active = true;
1045 gpu_info_.secondary_gpus[0].active = false;
1048 void EntryShouldApply(const std::string& entry_json) const {
1049 EXPECT_TRUE(EntryApplies(entry_json));
1052 void EntryShouldNotApply(const std::string& entry_json) const {
1053 EXPECT_FALSE(EntryApplies(entry_json));
1056 private:
1057 bool EntryApplies(const std::string& entry_json) const {
1058 ScopedEntry entry(GetEntryFromString(entry_json));
1059 EXPECT_TRUE(entry.get());
1060 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
1061 return entry->Contains(GpuControlList::kOsMacosx, "10.6", gpu_info());
1065 TEST_F(GpuControlListEntryDualGPUTest, CategoryAny) {
1066 const std::string json_intel = LONG_STRING_CONST(
1068 "id": 1,
1069 "os": {
1070 "type": "macosx"
1072 "vendor_id": "0x8086",
1073 "device_id": ["0x0166"],
1074 "multi_gpu_category": "any",
1075 "features": [
1076 "test_feature_0"
1080 EntryShouldApply(json_intel);
1082 const std::string json_nvidia = LONG_STRING_CONST(
1084 "id": 1,
1085 "os": {
1086 "type": "macosx"
1088 "vendor_id": "0x10de",
1089 "device_id": ["0x0640"],
1090 "multi_gpu_category": "any",
1091 "features": [
1092 "test_feature_0"
1096 EntryShouldApply(json_nvidia);
1099 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) {
1100 const std::string json_secondary = LONG_STRING_CONST(
1102 "id": 1,
1103 "os": {
1104 "type": "macosx"
1106 "vendor_id": "0x8086",
1107 "device_id": ["0x0166"],
1108 "multi_gpu_category": "secondary",
1109 "features": [
1110 "test_feature_0"
1114 EntryShouldApply(json_secondary);
1116 const std::string json_primary = LONG_STRING_CONST(
1118 "id": 1,
1119 "os": {
1120 "type": "macosx"
1122 "vendor_id": "0x8086",
1123 "device_id": ["0x0166"],
1124 "multi_gpu_category": "primary",
1125 "features": [
1126 "test_feature_0"
1130 EntryShouldNotApply(json_primary);
1132 const std::string json_default = LONG_STRING_CONST(
1134 "id": 1,
1135 "os": {
1136 "type": "macosx"
1138 "vendor_id": "0x8086",
1139 "device_id": ["0x0166"],
1140 "features": [
1141 "test_feature_0"
1145 // Default is primary.
1146 EntryShouldNotApply(json_default);
1149 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) {
1150 const std::string json = LONG_STRING_CONST(
1152 "id": 1,
1153 "os": {
1154 "type": "macosx"
1156 "vendor_id": "0x8086",
1157 "device_id": ["0x0166", "0x0168"],
1158 "multi_gpu_category": "active",
1159 "features": [
1160 "test_feature_0"
1164 // By default, secondary GPU is active.
1165 EntryShouldApply(json);
1167 ActivatePrimaryGPU();
1168 EntryShouldNotApply(json);
1171 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActiveSecondaryGPU) {
1172 const std::string json = LONG_STRING_CONST(
1174 "id": 1,
1175 "os": {
1176 "type": "macosx"
1178 "vendor_id": "0x8086",
1179 "multi_gpu_category": "active",
1180 "features": [
1181 "test_feature_0"
1185 // By default, secondary GPU is active.
1186 EntryShouldApply(json);
1188 ActivatePrimaryGPU();
1189 EntryShouldNotApply(json);
1192 TEST_F(GpuControlListEntryDualGPUTest, ActivePrimaryGPU) {
1193 const std::string json = LONG_STRING_CONST(
1195 "id": 1,
1196 "os": {
1197 "type": "macosx"
1199 "vendor_id": "0x10de",
1200 "device_id": ["0x0640"],
1201 "multi_gpu_category": "active",
1202 "features": [
1203 "test_feature_0"
1207 // By default, secondary GPU is active.
1208 EntryShouldNotApply(json);
1210 ActivatePrimaryGPU();
1211 EntryShouldApply(json);
1214 TEST_F(GpuControlListEntryDualGPUTest, VendorOnlyActivePrimaryGPU) {
1215 const std::string json = LONG_STRING_CONST(
1217 "id": 1,
1218 "os": {
1219 "type": "macosx"
1221 "vendor_id": "0x10de",
1222 "multi_gpu_category": "active",
1223 "features": [
1224 "test_feature_0"
1228 // By default, secondary GPU is active.
1229 EntryShouldNotApply(json);
1231 ActivatePrimaryGPU();
1232 EntryShouldApply(json);
1235 } // namespace gpu