RK3576 android14 GSI CtsWifiTestCases的android.net.wifi.cts.WifiManagerTest#testAddAndRemoveQosPolicies 测试分析
平台:RK3576,android14, CTS测试工具:android-cts-14_r8-linux_x86-arm
测试fail项:
| Test | Result | Details |
|---|---|---|
| android.net.wifi.cts.WifiManagerTest#testAddAndRemoveQosPolicies |
fail
|
java.lang.AssertionError: empty list should trigger exception: expected java.lang.IllegalArgumentException to be thrown, but nothing was thrown
|
这个测试项,之前在CTS R7 版本测试是PASS的,在CTS R8测试fail。
我们的解决方法是:
generic_arm64:/ $ device_config put wifi application_qos_policy_api_enabled true generic_arm64:/ $ device_config list wifi/application_qos_policy_api_enabled=true
通过ADB输入 device_config put wifi application_qos_policy_api_enabled true 之后,在测试这个测试,就能PASS了。
下面是个人的分析。
这是这项的测试源码:
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
public void testAddAndRemoveQosPolicies() throws Exception {
if (!WifiFeature.isWifiSupported(getContext())) {
// skip the test if WiFi is not supported
return;
}
final Mutable<Boolean> callbackReceived = new Mutable<Boolean>(false);
final Mutable<Boolean> policiesRejected = new Mutable<Boolean>(true);
Consumer<List<Integer>> listener = new Consumer<List<Integer>>() {
@Override
public void accept(List value) {
synchronized (mLock) {
callbackReceived.value = true;
List<Integer> statusList = value;
for (Integer status : statusList) {
if (status != WifiManager.QOS_REQUEST_STATUS_FAILURE_UNKNOWN) {
policiesRejected.value = false;
break;
}
}
Log.i(TAG, "Callback received for QoS add request, size=" + statusList.size()
+ ", rejected=" + policiesRejected.value);
mLock.notify();
}
}
};
// Test that invalid inputs trigger an Exception.
final List<QosPolicyParams> policyParamsList = new ArrayList<>();
assertThrows("null executor should trigger exception", NullPointerException.class,
() -> mWifiManager.addQosPolicies(policyParamsList, null, listener));
assertThrows("null listener should trigger exception", NullPointerException.class,
() -> mWifiManager.addQosPolicies(policyParamsList, mExecutor, null));
assertThrows("null policy list should trigger exception", NullPointerException.class,
() -> mWifiManager.addQosPolicies(null, mExecutor, listener));
UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
try {
uiAutomation.adoptShellPermissionIdentity();
boolean enabled = applicationQosFeatureEnabled();
// If the feature is disabled, verify that all policies are rejected.
if (!enabled) {
Log.i(TAG, "QoS policy APIs are not enabled");
fillQosPolicyParamsList(policyParamsList, 4, true);
mWifiManager.addQosPolicies(policyParamsList, mExecutor, listener);
synchronized (mLock) {
mLock.wait(TEST_WAIT_DURATION_MS);
}
assertTrue(callbackReceived.value);
assertTrue(policiesRejected.value);
return;
}
// Empty params list
assertThrows("empty list should trigger exception", IllegalArgumentException.class,
() -> mWifiManager.addQosPolicies(new ArrayList<>(), mExecutor, listener));
// More than {@link WifiManager#getMaxNumberOfPoliciesPerQosRequest()}
// policies in the list
fillQosPolicyParamsList(policyParamsList,
mWifiManager.getMaxNumberOfPoliciesPerQosRequest() + 1, true);
assertThrows("large list should trigger exception", IllegalArgumentException.class,
() -> mWifiManager.addQosPolicies(policyParamsList, mExecutor, listener));
// Params list contains duplicate policy ids
fillQosPolicyParamsList(policyParamsList, 4, false);
assertThrows("duplicate ids should trigger exception", IllegalArgumentException.class,
() -> mWifiManager.addQosPolicies(policyParamsList, mExecutor, listener));
// Valid list
fillQosPolicyParamsList(policyParamsList, 4, true);
mWifiManager.addQosPolicies(policyParamsList, mExecutor, listener);
// sleep to wait for a response from supplicant
synchronized (mLock) {
mLock.wait(TEST_WAIT_DURATION_MS);
}
int[] policyIds = new int[policyParamsList.size()];
for (int i = 0; i < policyParamsList.size(); i++) {
policyIds[i] = policyParamsList.get(i).getPolicyId();
}
mWifiManager.removeQosPolicies(policyIds);
// sleep to wait for a response from supplicant
synchronized (mLock) {
mLock.wait(TEST_WAIT_DURATION_MS);
}
mWifiManager.removeAllQosPolicies();
} catch (Exception e) {
fail("addAndRemoveQosPolicy unexpected Exception " + e);
} finally {
uiAutomation.dropShellPermissionIdentity();
}
}
// Empty params list
assertThrows("empty list should trigger exception", IllegalArgumentException.class,
() -> mWifiManager.addQosPolicies(new ArrayList<>(), mExecutor, listener));
看测试报告,可以确定是这里报错了。
assertThrows 这是一个断言方法,它的作用是验证执行某个动作(可运行代码)时是否抛出了指定类型的异常。
第一个参数:empty list should trigger exception 这是一个字符串,用于描述测试场景。如果测试失败,这个字符串会显示在日志中。也是根据这个定位到是这个测试方法报错。
第二个参数:IllegalArgumentException.class 这是预期抛出的异常类型。这里期望抛出的异常是 IllegalArgumentException(非法参数异常)。
第三个参数:被测试的代码逻辑(Lambda 表达式)
这项的整体测试意图是:验证当传入空列表时,addQosPolicies() 方法是否抛出 IllegalArgumentException 异常。这是对方法输入验证逻辑的测试。
R7的测试代码和R8的测试代码这块不同处在于 applicationQosFeatureEnabled 方法的不同。
R7 的测试代码如下:
private boolean applicationQosFeatureEnabled() {
boolean overlayEnabled;
try {
WifiResourceUtil resourceUtil = new WifiResourceUtil(mContext);
overlayEnabled = resourceUtil
.getWifiBoolean("config_wifiApplicationCentricQosPolicyFeatureEnabled");
} catch (Exception e) {
Log.i(TAG, "Unable to retrieve the QoS overlay value");
return false;
}
// Supplicant V2 is supported if the vendor partition indicates API > T.
boolean halSupport = PropertyUtil.isVndkApiLevelNewerThan(Build.VERSION_CODES.TIRAMISU);
boolean featureFlagEnabled = DeviceConfig.getBoolean(DEVICE_CONFIG_NAMESPACE,
"application_qos_policy_api_enabled", false);
return overlayEnabled && featureFlagEnabled && halSupport;
}
R8的测试代码如下:
private boolean applicationQosFeatureEnabled() {
boolean overlayEnabled;
try {
WifiResourceUtil resourceUtil = new WifiResourceUtil(mContext);
overlayEnabled = resourceUtil
.getWifiBoolean("config_wifiApplicationCentricQosPolicyFeatureEnabled");
} catch (Exception e) {
Log.i(TAG, "Unable to retrieve the QoS overlay value");
return false;
}
// Supplicant V2 is supported if the vendor partition indicates API > T.
boolean halSupport = PropertyUtil.isVndkApiLevelNewerThan(Build.VERSION_CODES.TIRAMISU);
Log.i(TAG, "QoS support. overlay=" + overlayEnabled + ", hal=" + halSupport);
return overlayEnabled && halSupport;
}
可以看出R7和R8的区别在于 featureFlagEnabled 不同,我通过 adb 来设置 application_qos_policy_api_enabled 值为true或者false,分别测试了下,发现设置为true时候能PASS。 具体原因还在研究中
浙公网安备 33010602011771号