Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: gpu/config/gpu_control_list_entry_unittest.cc

Issue 452293002: Use RE string pattern matching for blacklist strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "gpu/config/gpu_control_list.h" 6 #include "gpu/config/gpu_control_list.h"
7 #include "gpu/config/gpu_info.h" 7 #include "gpu/config/gpu_info.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define LONG_STRING_CONST(...) #__VA_ARGS__ 10 #define LONG_STRING_CONST(...) #__VA_ARGS__
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 gpu_info.gl_version = "3.0 NVIDIA-8.24.11 310.90.9b01"; 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)); 464 EXPECT_TRUE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
465 465
466 gpu_info.gl_version = "4.0 NVIDIA-8.24.11 310.90.9b01"; 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)); 467 EXPECT_FALSE(entry->Contains(GpuControlList::kOsMacosx, "10.9", gpu_info));
468 468
469 gpu_info.gl_version = "OpenGL ES 3.0 (ANGLE 1.2.0.2450)"; 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)); 470 EXPECT_FALSE(entry->Contains(GpuControlList::kOsWin, "6.1", gpu_info));
471 } 471 }
472 472
473 TEST_F(GpuControlListEntryTest, GlVendorEntry) { 473 TEST_F(GpuControlListEntryTest, GlVendorEqual) {
474 const std::string json = LONG_STRING_CONST( 474 const std::string json = LONG_STRING_CONST(
475 { 475 {
476 "id": 1, 476 "id": 1,
477 "gl_vendor": { 477 "gl_vendor": "NVIDIA",
478 "op": "beginwith",
479 "value": "NVIDIA"
480 },
481 "features": [ 478 "features": [
482 "test_feature_0" 479 "test_feature_0"
483 ] 480 ]
484 } 481 }
485 ); 482 );
486 ScopedEntry entry(GetEntryFromString(json)); 483 ScopedEntry entry(GetEntryFromString(json));
487 EXPECT_TRUE(entry.get() != NULL); 484 EXPECT_TRUE(entry.get() != NULL);
488 485
489 const GpuControlList::OsType os_type[] = { 486 GPUInfo gpu_info;
490 GpuControlList::kOsMacosx, 487 gpu_info.gl_vendor = "NVIDIA";
491 GpuControlList::kOsWin, 488 EXPECT_TRUE(entry->Contains(
492 GpuControlList::kOsLinux, 489 GpuControlList::kOsMacosx, "10.9", gpu_info));
493 GpuControlList::kOsChromeOS, 490
494 GpuControlList::kOsAndroid 491 // Case insensitive.
495 }; 492 gpu_info.gl_vendor = "NVidia";
496 for (size_t i = 0; i < arraysize(os_type); ++i) 493 EXPECT_TRUE(entry->Contains(
497 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); 494 GpuControlList::kOsMacosx, "10.9", gpu_info));
495
496 gpu_info.gl_vendor = "NVIDIA-x";
497 EXPECT_FALSE(entry->Contains(
498 GpuControlList::kOsMacosx, "10.9", gpu_info));
498 } 499 }
499 500
500 TEST_F(GpuControlListEntryTest, GlRendererEntry) { 501 TEST_F(GpuControlListEntryTest, GlVendorWithDot) {
501 const std::string json = LONG_STRING_CONST( 502 const std::string json = LONG_STRING_CONST(
502 { 503 {
503 "id": 1, 504 "id": 1,
504 "gl_renderer": { 505 "gl_vendor": "X\\.Org.*",
505 "op": "contains",
506 "value": "GeForce"
507 },
508 "features": [ 506 "features": [
509 "test_feature_0" 507 "test_feature_0"
510 ] 508 ]
511 } 509 }
512 ); 510 );
513 ScopedEntry entry(GetEntryFromString(json)); 511 ScopedEntry entry(GetEntryFromString(json));
514 EXPECT_TRUE(entry.get() != NULL); 512 EXPECT_TRUE(entry.get() != NULL);
515 513
516 const GpuControlList::OsType os_type[] = { 514 GPUInfo gpu_info;
517 GpuControlList::kOsMacosx, 515 gpu_info.gl_vendor = "X.Org R300 Project";
518 GpuControlList::kOsWin, 516 EXPECT_TRUE(entry->Contains(
519 GpuControlList::kOsLinux, 517 GpuControlList::kOsLinux, "", gpu_info));
520 GpuControlList::kOsChromeOS, 518
521 GpuControlList::kOsAndroid 519 gpu_info.gl_vendor = "X.Org";
522 }; 520 EXPECT_TRUE(entry->Contains(
523 for (size_t i = 0; i < arraysize(os_type); ++i) 521 GpuControlList::kOsLinux, "", gpu_info));
524 EXPECT_TRUE(entry->Contains(os_type[i], "10.6", gpu_info())); 522 }
523
524 TEST_F(GpuControlListEntryTest, GlRendererContains) {
525 const std::string json = LONG_STRING_CONST(
526 {
527 "id": 1,
528 "gl_renderer": ".*GeForce.*",
529 "features": [
530 "test_feature_0"
531 ]
532 }
533 );
534 ScopedEntry entry(GetEntryFromString(json));
535 EXPECT_TRUE(entry.get() != NULL);
536
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));
541
542 // Case insensitive.
543 gpu_info.gl_renderer = "NVIDIA GEFORCE GT 120 OpenGL Engine";
544 EXPECT_TRUE(entry->Contains(
545 GpuControlList::kOsMacosx, "10.9", gpu_info));
546
547 gpu_info.gl_renderer = "GeForce GT 120 OpenGL Engine";
548 EXPECT_TRUE(entry->Contains(
549 GpuControlList::kOsMacosx, "10.9", gpu_info));
550
551 gpu_info.gl_renderer = "NVIDIA GeForce";
552 EXPECT_TRUE(entry->Contains(
553 GpuControlList::kOsMacosx, "10.9", gpu_info));
554
555 gpu_info.gl_renderer = "NVIDIA Ge Force";
556 EXPECT_FALSE(entry->Contains(
557 GpuControlList::kOsMacosx, "10.9", gpu_info));
558 }
559
560 TEST_F(GpuControlListEntryTest, GlExtensionsEndWith) {
561 const std::string json = LONG_STRING_CONST(
562 {
563 "id": 1,
564 "gl_extensions": ".*GL_SUN_slice_accum",
565 "features": [
566 "test_feature_0"
567 ]
568 }
569 );
570 ScopedEntry entry(GetEntryFromString(json));
571 EXPECT_TRUE(entry.get() != NULL);
572
573 GPUInfo gpu_info;
574 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap "
575 "GL_SGIX_shadow "
576 "GL_SUN_slice_accum";
577 EXPECT_TRUE(entry->Contains(
578 GpuControlList::kOsMacosx, "10.9", gpu_info));
579
580 gpu_info.gl_extensions = "GL_SGIS_generate_mipmap "
581 "GL_SUN_slice_accum "
582 "GL_SGIX_shadow";
583 EXPECT_FALSE(entry->Contains(
584 GpuControlList::kOsMacosx, "10.9", gpu_info));
525 } 585 }
526 586
527 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) { 587 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) {
528 const std::string json = LONG_STRING_CONST( 588 const std::string json = LONG_STRING_CONST(
529 { 589 {
530 "id": 1, 590 "id": 1,
531 "perf_graphics": { 591 "perf_graphics": {
532 "op": "<", 592 "op": "<",
533 "value": "6.0" 593 "value": "6.0"
534 }, 594 },
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 GPUInfo gpu_info; 693 GPUInfo gpu_info;
634 gpu_info.amd_switchable = true; 694 gpu_info.amd_switchable = true;
635 695
636 ScopedEntry entry(GetEntryFromString(json)); 696 ScopedEntry entry(GetEntryFromString(json));
637 EXPECT_TRUE(entry.get() != NULL); 697 EXPECT_TRUE(entry.get() != NULL);
638 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); 698 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
639 EXPECT_TRUE(entry->Contains( 699 EXPECT_TRUE(entry->Contains(
640 GpuControlList::kOsMacosx, "10.6", gpu_info)); 700 GpuControlList::kOsMacosx, "10.6", gpu_info));
641 } 701 }
642 702
703 TEST_F(GpuControlListEntryTest, DriverVendorBeginWith) {
704 const std::string json = LONG_STRING_CONST(
705 {
706 "id": 1,
707 "driver_vendor": "NVIDIA.*",
708 "features": [
709 "test_feature_0"
710 ]
711 }
712 );
713 ScopedEntry entry(GetEntryFromString(json));
714 EXPECT_TRUE(entry.get() != NULL);
715
716 GPUInfo gpu_info;
717 gpu_info.driver_vendor = "NVIDIA Corporation";
718 EXPECT_TRUE(entry->Contains(
719 GpuControlList::kOsMacosx, "10.9", gpu_info));
720
721 // Case insensitive.
722 gpu_info.driver_vendor = "NVidia Corporation";
723 EXPECT_TRUE(entry->Contains(
724 GpuControlList::kOsMacosx, "10.9", gpu_info));
725
726 gpu_info.driver_vendor = "NVIDIA";
727 EXPECT_TRUE(entry->Contains(
728 GpuControlList::kOsMacosx, "10.9", gpu_info));
729
730 gpu_info.driver_vendor = "USA NVIDIA";
731 EXPECT_FALSE(entry->Contains(
732 GpuControlList::kOsMacosx, "10.9", gpu_info));
733 }
734
643 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) { 735 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) {
644 const std::string json = LONG_STRING_CONST( 736 const std::string json = LONG_STRING_CONST(
645 { 737 {
646 "id": 1, 738 "id": 1,
647 "os": { 739 "os": {
648 "type": "linux" 740 "type": "linux"
649 }, 741 },
650 "vendor_id": "0x1002", 742 "vendor_id": "0x1002",
651 "driver_version": { 743 "driver_version": {
652 "op": "=", 744 "op": "=",
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info)); 795 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
704 } 796 }
705 797
706 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) { 798 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
707 const std::string json = LONG_STRING_CONST( 799 const std::string json = LONG_STRING_CONST(
708 { 800 {
709 "id": 1, 801 "id": 1,
710 "vendor_id": "0x8086", 802 "vendor_id": "0x8086",
711 "exceptions": [ 803 "exceptions": [
712 { 804 {
713 "gl_renderer": { 805 "gl_renderer": ".*mesa.*"
714 "op": "contains",
715 "value": "mesa"
716 }
717 } 806 }
718 ], 807 ],
719 "features": [ 808 "features": [
720 "test_feature_1" 809 "test_feature_1"
721 ] 810 ]
722 } 811 }
723 ); 812 );
724 ScopedEntry entry(GetEntryFromString(json)); 813 ScopedEntry entry(GetEntryFromString(json));
725 EXPECT_TRUE(entry.get() != NULL); 814 EXPECT_TRUE(entry.get() != NULL);
726 815
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 GpuControlList::kOsMacosx, "10.6", gpu_info())); 889 GpuControlList::kOsMacosx, "10.6", gpu_info()));
801 } 890 }
802 891
803 TEST_F(GpuControlListEntryTest, MachineModelName) { 892 TEST_F(GpuControlListEntryTest, MachineModelName) {
804 const std::string json = LONG_STRING_CONST( 893 const std::string json = LONG_STRING_CONST(
805 { 894 {
806 "id": 1, 895 "id": 1,
807 "os": { 896 "os": {
808 "type": "android" 897 "type": "android"
809 }, 898 },
810 "machine_model_name": ["Nexus 4", "XT1032"], 899 "machine_model_name": [
900 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
901 ],
811 "features": [ 902 "features": [
812 "test_feature_0" 903 "test_feature_0"
813 ] 904 ]
814 } 905 }
815 ); 906 );
816 ScopedEntry entry(GetEntryFromString(json)); 907 ScopedEntry entry(GetEntryFromString(json));
817 EXPECT_TRUE(entry.get() != NULL); 908 EXPECT_TRUE(entry.get() != NULL);
818 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType()); 909 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
819 GPUInfo gpu_info; 910 GPUInfo gpu_info;
820 911
(...skipping 13 matching lines...) Expand all
834 EXPECT_FALSE(entry->Contains( 925 EXPECT_FALSE(entry->Contains(
835 GpuControlList::kOsAndroid, "4.1", gpu_info)); 926 GpuControlList::kOsAndroid, "4.1", gpu_info));
836 927
837 gpu_info.machine_model_name = "Nexus"; 928 gpu_info.machine_model_name = "Nexus";
838 EXPECT_FALSE(entry->Contains( 929 EXPECT_FALSE(entry->Contains(
839 GpuControlList::kOsAndroid, "4.1", gpu_info)); 930 GpuControlList::kOsAndroid, "4.1", gpu_info));
840 931
841 gpu_info.machine_model_name = ""; 932 gpu_info.machine_model_name = "";
842 EXPECT_FALSE(entry->Contains( 933 EXPECT_FALSE(entry->Contains(
843 GpuControlList::kOsAndroid, "4.1", gpu_info)); 934 GpuControlList::kOsAndroid, "4.1", gpu_info));
935
936 gpu_info.machine_model_name = "GT-N7100";
937 EXPECT_TRUE(entry->Contains(
938 GpuControlList::kOsAndroid, "4.1", gpu_info));
939
940 gpu_info.machine_model_name = "GT-I9300";
941 EXPECT_TRUE(entry->Contains(
942 GpuControlList::kOsAndroid, "4.1", gpu_info));
943
944 gpu_info.machine_model_name = "SCH-I545";
945 EXPECT_TRUE(entry->Contains(
946 GpuControlList::kOsAndroid, "4.1", gpu_info));
844 } 947 }
845 948
846 TEST_F(GpuControlListEntryTest, MachineModelNameException) { 949 TEST_F(GpuControlListEntryTest, MachineModelNameException) {
847 const std::string json = LONG_STRING_CONST( 950 const std::string json = LONG_STRING_CONST(
848 { 951 {
849 "id": 1, 952 "id": 1,
850 "exceptions": [ 953 "exceptions": [
851 { 954 {
852 "os": { 955 "os": {
853 "type": "android" 956 "type": "android"
854 }, 957 },
855 "machine_model_name": ["Nexus 4"] 958 "machine_model_name": ["Nexus.*"]
856 } 959 }
857 ], 960 ],
858 "features": [ 961 "features": [
859 "test_feature_0" 962 "test_feature_0"
860 ] 963 ]
861 } 964 }
862 ); 965 );
863 ScopedEntry entry(GetEntryFromString(json)); 966 ScopedEntry entry(GetEntryFromString(json));
864 EXPECT_TRUE(entry.get() != NULL); 967 EXPECT_TRUE(entry.get() != NULL);
865 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); 968 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
866 GPUInfo gpu_info; 969 GPUInfo gpu_info;
867 970
868 gpu_info.machine_model_name = "Nexus 4"; 971 gpu_info.machine_model_name = "Nexus 4";
869 EXPECT_FALSE(entry->Contains( 972 EXPECT_FALSE(entry->Contains(
870 GpuControlList::kOsAndroid, "4.1", gpu_info)); 973 GpuControlList::kOsAndroid, "4.1", gpu_info));
871 EXPECT_TRUE(entry->Contains( 974 EXPECT_TRUE(entry->Contains(
872 GpuControlList::kOsLinux, "4.1", gpu_info)); 975 GpuControlList::kOsLinux, "4.1", gpu_info));
873 976
977 gpu_info.machine_model_name = "Nexus 7";
978 EXPECT_FALSE(entry->Contains(
979 GpuControlList::kOsAndroid, "4.1", gpu_info));
980 EXPECT_TRUE(entry->Contains(
981 GpuControlList::kOsLinux, "4.1", gpu_info));
982
874 gpu_info.machine_model_name = ""; 983 gpu_info.machine_model_name = "";
875 EXPECT_TRUE(entry->Contains( 984 EXPECT_TRUE(entry->Contains(
876 GpuControlList::kOsAndroid, "4.1", gpu_info)); 985 GpuControlList::kOsAndroid, "4.1", gpu_info));
877 EXPECT_TRUE(entry->Contains( 986 EXPECT_TRUE(entry->Contains(
878 GpuControlList::kOsLinux, "4.1", gpu_info)); 987 GpuControlList::kOsLinux, "4.1", gpu_info));
879 } 988 }
880 989
881 TEST_F(GpuControlListEntryTest, MachineModelVersion) { 990 TEST_F(GpuControlListEntryTest, MachineModelVersion) {
882 const std::string json = LONG_STRING_CONST( 991 const std::string json = LONG_STRING_CONST(
883 { 992 {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 ); 1259 );
1151 // By default, secondary GPU is active. 1260 // By default, secondary GPU is active.
1152 EntryShouldNotApply(json); 1261 EntryShouldNotApply(json);
1153 1262
1154 ActivatePrimaryGPU(); 1263 ActivatePrimaryGPU();
1155 EntryShouldApply(json); 1264 EntryShouldApply(json);
1156 } 1265 }
1157 1266
1158 } // namespace gpu 1267 } // namespace gpu
1159 1268
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698