Skip to content

Commit 33484b9

Browse files
ianelliottusCommit Bot
authored andcommitted
A4A opt-in/out: add TestRuleProcess test and use a test fixture
The new TestRuleProcess test tests the full rule-processing paths. The test fixture reduces code duplication. Bug: angleproject:2993 Change-Id: Ia07ea408fb771dfd1a21cc2fd4610e0e88f529ea Reviewed-on: https://chromium-review.googlesource.com/c/1366314 Commit-Queue: Ian Elliott <ianelliott@google.com> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>
1 parent 0c2dc8c commit 33484b9

File tree

1 file changed

+106
-31
lines changed

1 file changed

+106
-31
lines changed

src/feature_support_util/feature_support_util_unittest.cpp

Lines changed: 106 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,28 @@
1313

1414
using namespace angle;
1515

16+
constexpr char kMfr[] = "MfrFoo";
17+
constexpr char kModel[] = "ModelX";
18+
19+
class FeatureSupportUtilTest : public testing::Test
20+
{
21+
protected:
22+
FeatureSupportUtilTest()
23+
{
24+
mSystemInfo.machineManufacturer = kMfr;
25+
mSystemInfo.machineModelName = kModel;
26+
mSystemInfo.gpus.resize(1);
27+
mSystemInfo.gpus[0].vendorId = 123;
28+
mSystemInfo.gpus[0].deviceId = 234;
29+
mSystemInfo.gpus[0].driverVendor = "GPUVendorA";
30+
mSystemInfo.gpus[0].detailedDriverVersion = {1, 2, 3, 4};
31+
}
32+
33+
SystemInfo mSystemInfo;
34+
};
35+
1636
// Test the ANGLEGetFeatureSupportUtilAPIVersion function
17-
TEST(FeatureSupportUtilTest, APIVersion)
37+
TEST_F(FeatureSupportUtilTest, APIVersion)
1838
{
1939
unsigned int versionToUse;
2040
unsigned int zero = 0;
@@ -37,45 +57,100 @@ TEST(FeatureSupportUtilTest, APIVersion)
3757
}
3858

3959
// Test the ANGLEAddDeviceInfoToSystemInfo function
40-
TEST(FeatureSupportUtilTest, SystemInfo)
60+
TEST_F(FeatureSupportUtilTest, SystemInfo)
4161
{
42-
// TODO(ianelliott): Replace this with a gtest "fixture", per review feedback.
43-
SystemInfo systemInfo;
62+
SystemInfo systemInfo = mSystemInfo;
4463
systemInfo.machineManufacturer = "BAD";
4564
systemInfo.machineModelName = "BAD";
46-
systemInfo.gpus.resize(1);
47-
systemInfo.gpus[0].vendorId = 123;
48-
systemInfo.gpus[0].deviceId = 234;
49-
systemInfo.gpus[0].driverVendor = "DriverVendorA";
50-
systemInfo.gpus[0].detailedDriverVersion = {1, 2, 3, 4};
51-
52-
char mfr[] = "Google";
53-
char model[] = "Pixel1";
54-
55-
ANGLEAddDeviceInfoToSystemInfo(mfr, model, &systemInfo);
56-
EXPECT_EQ("Google", systemInfo.machineManufacturer);
57-
EXPECT_EQ("Pixel1", systemInfo.machineModelName);
65+
66+
ANGLEAddDeviceInfoToSystemInfo(kMfr, kModel, &systemInfo);
67+
EXPECT_EQ(kMfr, systemInfo.machineManufacturer);
68+
EXPECT_EQ(kModel, systemInfo.machineModelName);
5869
}
5970

6071
// Test the ANGLEAndroidParseRulesString function
61-
TEST(FeatureSupportUtilTest, ParseRules)
72+
TEST_F(FeatureSupportUtilTest, ParseRules)
73+
{
74+
constexpr char kRulesFileContents[] = R"rulefile(
6275
{
63-
// TODO(ianelliott): Replace this with a gtest "fixture", per review feedback.
64-
SystemInfo systemInfo;
65-
systemInfo.machineManufacturer = "Google";
66-
systemInfo.machineModelName = "Pixel1";
67-
systemInfo.gpus.resize(1);
68-
systemInfo.gpus[0].vendorId = 123;
69-
systemInfo.gpus[0].deviceId = 234;
70-
systemInfo.gpus[0].driverVendor = "DriverVendorA";
71-
systemInfo.gpus[0].detailedDriverVersion = {1, 2, 3, 4};
72-
73-
constexpr char rulesFileContents[] =
74-
"{\"Rules\":[{\"Rule\":\"Default Rule (i.e. use native driver)\", \"AppChoice\":true, "
75-
"\"NonChoice\":false}]}\n";
76+
"Rules" : [
77+
{
78+
"Rule" : "Default Rule (i.e. do not use ANGLE)",
79+
"UseANGLE" : false
80+
}
81+
]
82+
}
83+
)rulefile";
7684
RulesHandle rulesHandle = nullptr;
7785
int rulesVersion = 0;
78-
EXPECT_TRUE(ANGLEAndroidParseRulesString(rulesFileContents, &rulesHandle, &rulesVersion));
86+
EXPECT_TRUE(ANGLEAndroidParseRulesString(kRulesFileContents, &rulesHandle, &rulesVersion));
7987
EXPECT_NE(nullptr, rulesHandle);
8088
ANGLEFreeRulesHandle(rulesHandle);
8189
}
90+
91+
// Test the ANGLEAndroidParseRulesString and ANGLEShouldBeUsedForApplication functions
92+
TEST_F(FeatureSupportUtilTest, TestRuleProcessing)
93+
{
94+
SystemInfo systemInfo = mSystemInfo;
95+
96+
constexpr char kRulesFileContents[] = R"rulefile(
97+
{
98+
"Rules" : [
99+
{
100+
"Rule" : "Default Rule (i.e. do not use ANGLE)",
101+
"UseANGLE" : false
102+
},
103+
{
104+
"Rule" : "Supported application(s)",
105+
"UseANGLE" : true,
106+
"Applications" : [
107+
{
108+
"AppName" : "com.isvA.app1"
109+
}
110+
]
111+
},
112+
{
113+
"Rule" : "Exceptions for bad drivers(s)",
114+
"UseANGLE" : false,
115+
"Applications" : [
116+
{
117+
"AppName" : "com.isvA.app1"
118+
}
119+
],
120+
"Devices" : [
121+
{
122+
"Manufacturer" : "MfrFoo",
123+
"Model" : "ModelX",
124+
"GPUs" : [
125+
{
126+
"Vendor" : "GPUVendorA",
127+
"DeviceId" : 234,
128+
"VerMajor" : 1, "VerMinor" : 2, "VerSubMinor" : 3, "VerPatch" : 4}
129+
}
130+
]
131+
}
132+
]
133+
}
134+
]
135+
}
136+
)rulefile";
137+
RulesHandle rulesHandle = nullptr;
138+
int rulesVersion = 0;
139+
EXPECT_TRUE(ANGLEAndroidParseRulesString(kRulesFileContents, &rulesHandle, &rulesVersion));
140+
EXPECT_NE(nullptr, rulesHandle);
141+
142+
// Test app1 with a SystemInfo that has an unsupported driver--should fail:
143+
constexpr char kApp1[] = "com.isvA.app1";
144+
EXPECT_FALSE(ANGLEShouldBeUsedForApplication(rulesHandle, rulesVersion, &systemInfo, kApp1));
145+
146+
// Test app1 with a SystemInfo that has a supported driver--should pass:
147+
systemInfo.gpus[0].detailedDriverVersion = {1, 2, 3, 5};
148+
EXPECT_TRUE(ANGLEShouldBeUsedForApplication(rulesHandle, rulesVersion, &systemInfo, kApp1));
149+
150+
// Test unsupported app2--should fail:
151+
constexpr char kApp2[] = "com.isvB.app2";
152+
EXPECT_FALSE(ANGLEShouldBeUsedForApplication(rulesHandle, rulesVersion, &systemInfo, kApp2));
153+
154+
// Free the rules data structures:
155+
ANGLEFreeRulesHandle(rulesHandle);
156+
}

0 commit comments

Comments
 (0)