Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / gpu / config / gpu_control_list_entry_unittest.cc
blobd693d8511504aa0fc31b89c3c2ca569d7eb814bb
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 virtual ~GpuControlListEntryTest() { }
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 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;
67 protected:
68 GPUInfo gpu_info_;
71 TEST_F(GpuControlListEntryTest, DetailedEntry) {
72 const std::string json = LONG_STRING_CONST(
74 "id": 5,
75 "description": "test entry",
76 "cr_bugs": [1024, 678],
77 "webkit_bugs": [1950],
78 "os": {
79 "type": "macosx",
80 "version": {
81 "op": "=",
82 "value": "10.6.4"
85 "vendor_id": "0x10de",
86 "device_id": ["0x0640"],
87 "driver_version": {
88 "op": "=",
89 "value": "1.6.18"
91 "features": [
92 "test_feature_0"
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(
118 "id": 1,
119 "vendor_id": "0x10de",
120 "features": [
121 "test_feature_0"
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(
143 "id": 1,
144 "os": {
145 "type": "linux"
147 "vendor_id": "0x10de",
148 "features": [
149 "test_feature_0"
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(
172 "id": 1,
173 "os": {
174 "type": "linux"
176 "exceptions": [
178 "vendor_id": "0x10de"
181 "features": [
182 "test_feature_0"
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(
204 "id": 1,
205 "os": {
206 "type": "linux"
208 "exceptions": [
210 "vendor_id": "0x8086"
213 "features": [
214 "test_feature_0"
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(
237 "id": 1,
238 "os": {
239 "type": "win"
241 "driver_date": {
242 "op": "<",
243 "value": "2010.5.8"
245 "features": [
246 "test_feature_0"
250 ScopedEntry entry(GetEntryFromString(json));
251 EXPECT_TRUE(entry.get() != NULL);
252 EXPECT_EQ(GpuControlList::kOsWin, entry->GetOsType());
254 GPUInfo gpu_info;
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(
269 "id": 1,
270 "vendor_id": "0x10de",
271 "device_id": ["0x1023", "0x0640"],
272 "features": [
273 "test_feature_0"
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(
295 "id": 1,
296 "os": {
297 "type": "chromeos"
299 "features": [
300 "test_feature_0"
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(
323 "id": 1,
324 "vendor_id": "[0x10de]",
325 "features": [
326 "test_feature_0"
330 ScopedEntry entry(GetEntryFromString(json));
331 EXPECT_TRUE(entry.get() == NULL);
334 TEST_F(GpuControlListEntryTest, UnknownFieldEntry) {
335 const std::string json = LONG_STRING_CONST(
337 "id": 1,
338 "unknown_field": 0,
339 "features": [
340 "test_feature_0"
344 ScopedEntry entry(GetEntryFromString(json));
345 EXPECT_TRUE(entry.get() == NULL);
348 TEST_F(GpuControlListEntryTest, UnknownExceptionFieldEntry) {
349 const std::string json = LONG_STRING_CONST(
351 "id": 2,
352 "exceptions": [
354 "unknown_field": 0
357 "features": [
358 "test_feature_0"
362 ScopedEntry entry(GetEntryFromString(json));
363 EXPECT_TRUE(entry.get() == NULL);
366 TEST_F(GpuControlListEntryTest, UnknownFeatureEntry) {
367 const std::string json = LONG_STRING_CONST(
369 "id": 1,
370 "features": [
371 "some_unknown_feature",
372 "test_feature_0"
376 ScopedEntry entry(GetEntryFromString(json));
377 EXPECT_TRUE(entry.get() == NULL);
380 TEST_F(GpuControlListEntryTest, GlVersionGLESEntry) {
381 const std::string json = LONG_STRING_CONST(
383 "id": 1,
384 "gl_type": "gles",
385 "gl_version": {
386 "op": "=",
387 "value": "3.0"
389 "features": [
390 "test_feature_0"
394 ScopedEntry entry(GetEntryFromString(json));
395 EXPECT_TRUE(entry.get() != NULL);
397 GPUInfo gpu_info;
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(
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, PerfGraphicsEntry) {
611 const std::string json = LONG_STRING_CONST(
613 "id": 1,
614 "perf_graphics": {
615 "op": "<",
616 "value": "6.0"
618 "features": [
619 "test_feature_0"
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(
631 "id": 1,
632 "perf_graphics": {
633 "op": "<=",
634 "value": "4.0"
636 "features": [
637 "test_feature_0"
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(
649 "id": 1,
650 "perf_overall": {
651 "op": "between",
652 "value": "1.0",
653 "value2": "9.0"
655 "features": [
656 "test_feature_0"
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(
668 "id": 1,
669 "disabled": true,
670 "features": [
671 "test_feature_0"
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(
683 "id": 1,
684 "os": {
685 "type": "linux"
687 "multi_gpu_style": "optimus",
688 "features": [
689 "test_feature_0"
693 GPUInfo gpu_info;
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(
706 "id": 1,
707 "os": {
708 "type": "macosx"
710 "multi_gpu_style": "amd_switchable",
711 "features": [
712 "test_feature_0"
716 GPUInfo gpu_info;
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(
729 "id": 1,
730 "driver_vendor": "NVIDIA.*",
731 "features": [
732 "test_feature_0"
736 ScopedEntry entry(GetEntryFromString(json));
737 EXPECT_TRUE(entry.get() != NULL);
739 GPUInfo gpu_info;
740 gpu_info.driver_vendor = "NVIDIA Corporation";
741 EXPECT_TRUE(entry->Contains(
742 GpuControlList::kOsMacosx, "10.9", gpu_info));
744 // Case sensitive.
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(
761 "id": 1,
762 "os": {
763 "type": "linux"
765 "vendor_id": "0x1002",
766 "driver_version": {
767 "op": "=",
768 "style": "lexical",
769 "value": "8.76"
771 "features": [
772 "test_feature_0"
776 GPUInfo gpu_info;
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(
799 "id": 1,
800 "vendor_id": "0x8086",
801 "driver_version": {
802 "op": "<",
803 "value": "10.7"
805 "features": [
806 "test_feature_1"
810 ScopedEntry entry(GetEntryFromString(json));
811 EXPECT_TRUE(entry.get() != NULL);
813 GPUInfo gpu_info;
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(
824 "id": 1,
825 "vendor_id": "0x8086",
826 "exceptions": [
828 "gl_renderer": ".*mesa.*"
831 "features": [
832 "test_feature_1"
836 ScopedEntry entry(GetEntryFromString(json));
837 EXPECT_TRUE(entry.get() != NULL);
839 GPUInfo gpu_info;
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(
850 "id": 1,
851 "features": [
852 "all"
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(
867 "id": 1,
868 "vendor_id": "0x0000",
869 "features": [
870 "test_feature_1"
874 ScopedEntry entry(GetEntryFromString(json));
875 EXPECT_TRUE(entry.get() == NULL);
878 TEST_F(GpuControlListEntryTest, InvalidDeviceIdEntry) {
879 const std::string json = LONG_STRING_CONST(
881 "id": 1,
882 "vendor_id": "0x10de",
883 "device_id": ["0x1023", "0x0000"],
884 "features": [
885 "test_feature_1"
889 ScopedEntry entry(GetEntryFromString(json));
890 EXPECT_TRUE(entry.get() == NULL);
893 TEST_F(GpuControlListEntryTest, SingleActiveGPU) {
894 const std::string json = LONG_STRING_CONST(
896 "id": 1,
897 "os": {
898 "type": "macosx"
900 "vendor_id": "0x10de",
901 "device_id": ["0x0640"],
902 "multi_gpu_category": "active",
903 "features": [
904 "test_feature_0"
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(
918 "id": 1,
919 "os": {
920 "type": "android"
922 "machine_model_name": [
923 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
925 "features": [
926 "test_feature_0"
930 ScopedEntry entry(GetEntryFromString(json));
931 EXPECT_TRUE(entry.get() != NULL);
932 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
933 GPUInfo gpu_info;
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(
975 "id": 1,
976 "exceptions": [
978 "os": {
979 "type": "android"
981 "machine_model_name": ["Nexus.*"]
984 "features": [
985 "test_feature_0"
989 ScopedEntry entry(GetEntryFromString(json));
990 EXPECT_TRUE(entry.get() != NULL);
991 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
992 GPUInfo gpu_info;
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(
1016 "id": 1,
1017 "os": {
1018 "type": "macosx"
1020 "machine_model_name": ["MacBookPro"],
1021 "machine_model_version": {
1022 "op": "=",
1023 "value": "7.1"
1025 "features": [
1026 "test_feature_0"
1030 ScopedEntry entry(GetEntryFromString(json));
1031 EXPECT_TRUE(entry.get() != NULL);
1032 GPUInfo gpu_info;
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(
1043 "id": 1,
1044 "os": {
1045 "type": "macosx"
1047 "machine_model_name": ["MacBookPro"],
1048 "exceptions": [
1050 "machine_model_version": {
1051 "op": ">",
1052 "value": "7.1"
1056 "features": [
1057 "test_feature_0"
1061 ScopedEntry entry(GetEntryFromString(json));
1062 EXPECT_TRUE(entry.get() != NULL);
1063 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
1065 GPUInfo gpu_info;
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 {
1081 public:
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));
1111 private:
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(
1123 "id": 1,
1124 "os": {
1125 "type": "macosx"
1127 "vendor_id": "0x8086",
1128 "device_id": ["0x0166"],
1129 "multi_gpu_category": "any",
1130 "features": [
1131 "test_feature_0"
1135 EntryShouldApply(json_intel);
1137 const std::string json_nvidia = LONG_STRING_CONST(
1139 "id": 1,
1140 "os": {
1141 "type": "macosx"
1143 "vendor_id": "0x10de",
1144 "device_id": ["0x0640"],
1145 "multi_gpu_category": "any",
1146 "features": [
1147 "test_feature_0"
1151 EntryShouldApply(json_nvidia);
1154 TEST_F(GpuControlListEntryDualGPUTest, CategoryPrimarySecondary) {
1155 const std::string json_secondary = LONG_STRING_CONST(
1157 "id": 1,
1158 "os": {
1159 "type": "macosx"
1161 "vendor_id": "0x8086",
1162 "device_id": ["0x0166"],
1163 "multi_gpu_category": "secondary",
1164 "features": [
1165 "test_feature_0"
1169 EntryShouldApply(json_secondary);
1171 const std::string json_primary = LONG_STRING_CONST(
1173 "id": 1,
1174 "os": {
1175 "type": "macosx"
1177 "vendor_id": "0x8086",
1178 "device_id": ["0x0166"],
1179 "multi_gpu_category": "primary",
1180 "features": [
1181 "test_feature_0"
1185 EntryShouldNotApply(json_primary);
1187 const std::string json_default = LONG_STRING_CONST(
1189 "id": 1,
1190 "os": {
1191 "type": "macosx"
1193 "vendor_id": "0x8086",
1194 "device_id": ["0x0166"],
1195 "features": [
1196 "test_feature_0"
1200 // Default is primary.
1201 EntryShouldNotApply(json_default);
1204 TEST_F(GpuControlListEntryDualGPUTest, ActiveSecondaryGPU) {
1205 const std::string json = LONG_STRING_CONST(
1207 "id": 1,
1208 "os": {
1209 "type": "macosx"
1211 "vendor_id": "0x8086",
1212 "device_id": ["0x0166", "0x0168"],
1213 "multi_gpu_category": "active",
1214 "features": [
1215 "test_feature_0"
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(
1229 "id": 1,
1230 "os": {
1231 "type": "macosx"
1233 "vendor_id": "0x8086",
1234 "multi_gpu_category": "active",
1235 "features": [
1236 "test_feature_0"
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(
1250 "id": 1,
1251 "os": {
1252 "type": "macosx"
1254 "vendor_id": "0x10de",
1255 "device_id": ["0x0640"],
1256 "multi_gpu_category": "active",
1257 "features": [
1258 "test_feature_0"
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(
1272 "id": 1,
1273 "os": {
1274 "type": "macosx"
1276 "vendor_id": "0x10de",
1277 "multi_gpu_category": "active",
1278 "features": [
1279 "test_feature_0"
1283 // By default, secondary GPU is active.
1284 EntryShouldNotApply(json);
1286 ActivatePrimaryGPU();
1287 EntryShouldApply(json);
1290 } // namespace gpu