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

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
« no previous file with comments | « gpu/config/gpu_control_list.cc ('k') | gpu/config/gpu_control_list_format.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 sensitive.
495 }; 492 gpu_info.gl_vendor = "NVidia";
496 for (size_t i = 0; i < arraysize(os_type); ++i) 493 EXPECT_FALSE(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 sensitive.
543 gpu_info.gl_renderer = "NVIDIA GEFORCE GT 120 OpenGL Engine";
544 EXPECT_FALSE(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, GlRendererCaseInsensitive) {
561 const std::string json = LONG_STRING_CONST(
562 {
563 "id": 1,
564 "gl_renderer": "(?i).*software.*",
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_renderer = "software rasterizer";
575 EXPECT_TRUE(entry->Contains(
576 GpuControlList::kOsMacosx, "10.9", gpu_info));
577
578 gpu_info.gl_renderer = "Software Rasterizer";
579 EXPECT_TRUE(entry->Contains(
580 GpuControlList::kOsMacosx, "10.9", gpu_info));
581 }
582
583 TEST_F(GpuControlListEntryTest, GlExtensionsEndWith) {
584 const std::string json = LONG_STRING_CONST(
585 {
586 "id": 1,
587 "gl_extensions": ".*GL_SUN_slice_accum",
588 "features": [
589 "test_feature_0"
590 ]
591 }
592 );
593 ScopedEntry entry(GetEntryFromString(json));
594 EXPECT_TRUE(entry.get() != NULL);
595
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));
602
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));
525 } 608 }
526 609
527 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) { 610 TEST_F(GpuControlListEntryTest, PerfGraphicsEntry) {
528 const std::string json = LONG_STRING_CONST( 611 const std::string json = LONG_STRING_CONST(
529 { 612 {
530 "id": 1, 613 "id": 1,
531 "perf_graphics": { 614 "perf_graphics": {
532 "op": "<", 615 "op": "<",
533 "value": "6.0" 616 "value": "6.0"
534 }, 617 },
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 GPUInfo gpu_info; 716 GPUInfo gpu_info;
634 gpu_info.amd_switchable = true; 717 gpu_info.amd_switchable = true;
635 718
636 ScopedEntry entry(GetEntryFromString(json)); 719 ScopedEntry entry(GetEntryFromString(json));
637 EXPECT_TRUE(entry.get() != NULL); 720 EXPECT_TRUE(entry.get() != NULL);
638 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType()); 721 EXPECT_EQ(GpuControlList::kOsMacosx, entry->GetOsType());
639 EXPECT_TRUE(entry->Contains( 722 EXPECT_TRUE(entry->Contains(
640 GpuControlList::kOsMacosx, "10.6", gpu_info)); 723 GpuControlList::kOsMacosx, "10.6", gpu_info));
641 } 724 }
642 725
726 TEST_F(GpuControlListEntryTest, DriverVendorBeginWith) {
727 const std::string json = LONG_STRING_CONST(
728 {
729 "id": 1,
730 "driver_vendor": "NVIDIA.*",
731 "features": [
732 "test_feature_0"
733 ]
734 }
735 );
736 ScopedEntry entry(GetEntryFromString(json));
737 EXPECT_TRUE(entry.get() != NULL);
738
739 GPUInfo gpu_info;
740 gpu_info.driver_vendor = "NVIDIA Corporation";
741 EXPECT_TRUE(entry->Contains(
742 GpuControlList::kOsMacosx, "10.9", gpu_info));
743
744 // Case sensitive.
745 gpu_info.driver_vendor = "NVidia Corporation";
746 EXPECT_FALSE(entry->Contains(
747 GpuControlList::kOsMacosx, "10.9", gpu_info));
748
749 gpu_info.driver_vendor = "NVIDIA";
750 EXPECT_TRUE(entry->Contains(
751 GpuControlList::kOsMacosx, "10.9", gpu_info));
752
753 gpu_info.driver_vendor = "USA NVIDIA";
754 EXPECT_FALSE(entry->Contains(
755 GpuControlList::kOsMacosx, "10.9", gpu_info));
756 }
757
643 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) { 758 TEST_F(GpuControlListEntryTest, LexicalDriverVersionEntry) {
644 const std::string json = LONG_STRING_CONST( 759 const std::string json = LONG_STRING_CONST(
645 { 760 {
646 "id": 1, 761 "id": 1,
647 "os": { 762 "os": {
648 "type": "linux" 763 "type": "linux"
649 }, 764 },
650 "vendor_id": "0x1002", 765 "vendor_id": "0x1002",
651 "driver_version": { 766 "driver_version": {
652 "op": "=", 767 "op": "=",
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info)); 818 EXPECT_FALSE(entry->NeedsMoreInfo(gpu_info));
704 } 819 }
705 820
706 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) { 821 TEST_F(GpuControlListEntryTest, NeedsMoreInfoForExceptionsEntry) {
707 const std::string json = LONG_STRING_CONST( 822 const std::string json = LONG_STRING_CONST(
708 { 823 {
709 "id": 1, 824 "id": 1,
710 "vendor_id": "0x8086", 825 "vendor_id": "0x8086",
711 "exceptions": [ 826 "exceptions": [
712 { 827 {
713 "gl_renderer": { 828 "gl_renderer": ".*mesa.*"
714 "op": "contains",
715 "value": "mesa"
716 }
717 } 829 }
718 ], 830 ],
719 "features": [ 831 "features": [
720 "test_feature_1" 832 "test_feature_1"
721 ] 833 ]
722 } 834 }
723 ); 835 );
724 ScopedEntry entry(GetEntryFromString(json)); 836 ScopedEntry entry(GetEntryFromString(json));
725 EXPECT_TRUE(entry.get() != NULL); 837 EXPECT_TRUE(entry.get() != NULL);
726 838
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 GpuControlList::kOsMacosx, "10.6", gpu_info())); 912 GpuControlList::kOsMacosx, "10.6", gpu_info()));
801 } 913 }
802 914
803 TEST_F(GpuControlListEntryTest, MachineModelName) { 915 TEST_F(GpuControlListEntryTest, MachineModelName) {
804 const std::string json = LONG_STRING_CONST( 916 const std::string json = LONG_STRING_CONST(
805 { 917 {
806 "id": 1, 918 "id": 1,
807 "os": { 919 "os": {
808 "type": "android" 920 "type": "android"
809 }, 921 },
810 "machine_model_name": ["Nexus 4", "XT1032"], 922 "machine_model_name": [
923 "Nexus 4", "XT1032", "GT-.*", "SCH-.*"
924 ],
811 "features": [ 925 "features": [
812 "test_feature_0" 926 "test_feature_0"
813 ] 927 ]
814 } 928 }
815 ); 929 );
816 ScopedEntry entry(GetEntryFromString(json)); 930 ScopedEntry entry(GetEntryFromString(json));
817 EXPECT_TRUE(entry.get() != NULL); 931 EXPECT_TRUE(entry.get() != NULL);
818 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType()); 932 EXPECT_EQ(GpuControlList::kOsAndroid, entry->GetOsType());
819 GPUInfo gpu_info; 933 GPUInfo gpu_info;
820 934
(...skipping 13 matching lines...) Expand all
834 EXPECT_FALSE(entry->Contains( 948 EXPECT_FALSE(entry->Contains(
835 GpuControlList::kOsAndroid, "4.1", gpu_info)); 949 GpuControlList::kOsAndroid, "4.1", gpu_info));
836 950
837 gpu_info.machine_model_name = "Nexus"; 951 gpu_info.machine_model_name = "Nexus";
838 EXPECT_FALSE(entry->Contains( 952 EXPECT_FALSE(entry->Contains(
839 GpuControlList::kOsAndroid, "4.1", gpu_info)); 953 GpuControlList::kOsAndroid, "4.1", gpu_info));
840 954
841 gpu_info.machine_model_name = ""; 955 gpu_info.machine_model_name = "";
842 EXPECT_FALSE(entry->Contains( 956 EXPECT_FALSE(entry->Contains(
843 GpuControlList::kOsAndroid, "4.1", gpu_info)); 957 GpuControlList::kOsAndroid, "4.1", gpu_info));
958
959 gpu_info.machine_model_name = "GT-N7100";
960 EXPECT_TRUE(entry->Contains(
961 GpuControlList::kOsAndroid, "4.1", gpu_info));
962
963 gpu_info.machine_model_name = "GT-I9300";
964 EXPECT_TRUE(entry->Contains(
965 GpuControlList::kOsAndroid, "4.1", gpu_info));
966
967 gpu_info.machine_model_name = "SCH-I545";
968 EXPECT_TRUE(entry->Contains(
969 GpuControlList::kOsAndroid, "4.1", gpu_info));
844 } 970 }
845 971
846 TEST_F(GpuControlListEntryTest, MachineModelNameException) { 972 TEST_F(GpuControlListEntryTest, MachineModelNameException) {
847 const std::string json = LONG_STRING_CONST( 973 const std::string json = LONG_STRING_CONST(
848 { 974 {
849 "id": 1, 975 "id": 1,
850 "exceptions": [ 976 "exceptions": [
851 { 977 {
852 "os": { 978 "os": {
853 "type": "android" 979 "type": "android"
854 }, 980 },
855 "machine_model_name": ["Nexus 4"] 981 "machine_model_name": ["Nexus.*"]
856 } 982 }
857 ], 983 ],
858 "features": [ 984 "features": [
859 "test_feature_0" 985 "test_feature_0"
860 ] 986 ]
861 } 987 }
862 ); 988 );
863 ScopedEntry entry(GetEntryFromString(json)); 989 ScopedEntry entry(GetEntryFromString(json));
864 EXPECT_TRUE(entry.get() != NULL); 990 EXPECT_TRUE(entry.get() != NULL);
865 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType()); 991 EXPECT_EQ(GpuControlList::kOsAny, entry->GetOsType());
866 GPUInfo gpu_info; 992 GPUInfo gpu_info;
867 993
868 gpu_info.machine_model_name = "Nexus 4"; 994 gpu_info.machine_model_name = "Nexus 4";
869 EXPECT_FALSE(entry->Contains( 995 EXPECT_FALSE(entry->Contains(
870 GpuControlList::kOsAndroid, "4.1", gpu_info)); 996 GpuControlList::kOsAndroid, "4.1", gpu_info));
871 EXPECT_TRUE(entry->Contains( 997 EXPECT_TRUE(entry->Contains(
872 GpuControlList::kOsLinux, "4.1", gpu_info)); 998 GpuControlList::kOsLinux, "4.1", gpu_info));
873 999
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));
1005
874 gpu_info.machine_model_name = ""; 1006 gpu_info.machine_model_name = "";
875 EXPECT_TRUE(entry->Contains( 1007 EXPECT_TRUE(entry->Contains(
876 GpuControlList::kOsAndroid, "4.1", gpu_info)); 1008 GpuControlList::kOsAndroid, "4.1", gpu_info));
877 EXPECT_TRUE(entry->Contains( 1009 EXPECT_TRUE(entry->Contains(
878 GpuControlList::kOsLinux, "4.1", gpu_info)); 1010 GpuControlList::kOsLinux, "4.1", gpu_info));
879 } 1011 }
880 1012
881 TEST_F(GpuControlListEntryTest, MachineModelVersion) { 1013 TEST_F(GpuControlListEntryTest, MachineModelVersion) {
882 const std::string json = LONG_STRING_CONST( 1014 const std::string json = LONG_STRING_CONST(
883 { 1015 {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 ); 1282 );
1151 // By default, secondary GPU is active. 1283 // By default, secondary GPU is active.
1152 EntryShouldNotApply(json); 1284 EntryShouldNotApply(json);
1153 1285
1154 ActivatePrimaryGPU(); 1286 ActivatePrimaryGPU();
1155 EntryShouldApply(json); 1287 EntryShouldApply(json);
1156 } 1288 }
1157 1289
1158 } // namespace gpu 1290 } // namespace gpu
1159 1291
OLDNEW
« no previous file with comments | « gpu/config/gpu_control_list.cc ('k') | gpu/config/gpu_control_list_format.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698