Add tests for LinkProperties#EXCLUDED_ROUTES
Add CTS tests for LinkProperties#EXCLUDED_ROUTES gated change. These tests check LinkProperties#getRoutes and LinkProperties#getAllRoutes behavior depending on whether the gated change is enabled. Bug: 186082280 Test: atest HostsideLinkPropertiesGatingTests Change-Id: Id353714331a19d09022d20f186c8f71343686da7
This commit is contained in:
parent
c670977937
commit
f0c8daa0eb
5 changed files with 231 additions and 0 deletions
|
|
@ -26,6 +26,7 @@ java_test_host {
|
|||
"tradefed",
|
||||
],
|
||||
static_libs: [
|
||||
"CompatChangeGatingTestBase",
|
||||
"modules-utils-build-testing",
|
||||
],
|
||||
// Tag this module as a cts test artifact
|
||||
|
|
@ -37,6 +38,8 @@ java_test_host {
|
|||
data: [
|
||||
":CtsHostsideNetworkTestsApp",
|
||||
":CtsHostsideNetworkTestsApp2",
|
||||
":CtsHostsideNetworkTestsApp3",
|
||||
":CtsHostsideNetworkTestsApp3PreT",
|
||||
":CtsHostsideNetworkTestsAppNext",
|
||||
],
|
||||
per_testcase_directory: true,
|
||||
|
|
|
|||
50
tests/cts/hostside/app3/Android.bp
Normal file
50
tests/cts/hostside/app3/Android.bp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//
|
||||
// Copyright (C) 2022 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
java_defaults {
|
||||
name: "CtsHostsideNetworkTestsApp3Defaults",
|
||||
srcs: ["src/**/*.java"],
|
||||
libs: [
|
||||
"junit",
|
||||
],
|
||||
static_libs: [
|
||||
"ctstestrunner-axt",
|
||||
"truth-prebuilt",
|
||||
],
|
||||
|
||||
// Tag this module as a cts test artifact
|
||||
test_suites: [
|
||||
"cts",
|
||||
"general-tests",
|
||||
],
|
||||
}
|
||||
|
||||
android_test_helper_app {
|
||||
name: "CtsHostsideNetworkTestsApp3",
|
||||
defaults: [
|
||||
"cts_support_defaults",
|
||||
"CtsHostsideNetworkTestsApp3Defaults",
|
||||
],
|
||||
}
|
||||
|
||||
android_test_helper_app {
|
||||
name: "CtsHostsideNetworkTestsApp3PreT",
|
||||
target_sdk_version: "31",
|
||||
defaults: [
|
||||
"cts_support_defaults",
|
||||
"CtsHostsideNetworkTestsApp3Defaults",
|
||||
],
|
||||
}
|
||||
27
tests/cts/hostside/app3/AndroidManifest.xml
Normal file
27
tests/cts/hostside/app3/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2022 The Android Open Source Project
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.android.cts.net.hostside.app3">
|
||||
|
||||
<application android:debuggable="true">
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
|
||||
<instrumentation
|
||||
android:name="androidx.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.android.cts.net.hostside.app3" />
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.cts.net.hostside.app3;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.Manifest;
|
||||
import android.net.IpPrefix;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.RouteInfo;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Tests to verify {@link LinkProperties#getRoutes} behavior, depending on
|
||||
* {@LinkProperties#EXCLUDED_ROUTES} change state.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExcludedRoutesGatingTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
InstrumentationRegistry.getInstrumentation().getUiAutomation()
|
||||
.adoptShellPermissionIdentity(Manifest.permission.LOG_COMPAT_CHANGE,
|
||||
Manifest.permission.READ_COMPAT_CHANGE_CONFIG);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
InstrumentationRegistry.getInstrumentation().getUiAutomation()
|
||||
.dropShellPermissionIdentity();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExcludedRoutesChangeEnabled() {
|
||||
final LinkProperties lp = makeLinkPropertiesWithExcludedRoutes();
|
||||
|
||||
// Excluded routes change is enabled: non-RTN_UNICAST routes are visible.
|
||||
assertEquals(2, lp.getRoutes().size());
|
||||
assertEquals(2, lp.getAllRoutes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExcludedRoutesChangeDisabled() {
|
||||
final LinkProperties lp = makeLinkPropertiesWithExcludedRoutes();
|
||||
|
||||
// Excluded routes change is disabled: non-RTN_UNICAST routes are filtered out.
|
||||
assertEquals(0, lp.getRoutes().size());
|
||||
assertEquals(0, lp.getAllRoutes().size());
|
||||
}
|
||||
|
||||
private LinkProperties makeLinkPropertiesWithExcludedRoutes() {
|
||||
final LinkProperties lp = new LinkProperties();
|
||||
|
||||
lp.addRoute(new RouteInfo(new IpPrefix("10.0.0.0/8"), null, null, RouteInfo.RTN_THROW));
|
||||
lp.addRoute(new RouteInfo(new IpPrefix("2001:db8::/64"), null, null,
|
||||
RouteInfo.RTN_UNREACHABLE));
|
||||
|
||||
return lp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.cts.net;
|
||||
|
||||
import android.compat.cts.CompatChangeGatingTestCase;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Tests for the {@link android.net.LinkProperties#EXCLUDED_ROUTES} compatibility change.
|
||||
*/
|
||||
public class HostsideLinkPropertiesGatingTests extends CompatChangeGatingTestCase {
|
||||
private static final String TEST_APK = "CtsHostsideNetworkTestsApp3.apk";
|
||||
private static final String TEST_APK_PRE_T = "CtsHostsideNetworkTestsApp3PreT.apk";
|
||||
private static final String TEST_PKG = "com.android.cts.net.hostside.app3";
|
||||
private static final String TEST_CLASS = ".ExcludedRoutesGatingTest";
|
||||
|
||||
private static final long EXCLUDED_ROUTES_CHANGE_ID = 186082280;
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
uninstallPackage(TEST_PKG, true);
|
||||
}
|
||||
|
||||
public void testExcludedRoutesChangeEnabled() throws Exception {
|
||||
installPackage(TEST_APK, true);
|
||||
runDeviceCompatTest("testExcludedRoutesChangeEnabled");
|
||||
}
|
||||
|
||||
public void testExcludedRoutesChangeDisabledPreT() throws Exception {
|
||||
installPackage(TEST_APK_PRE_T, true);
|
||||
runDeviceCompatTest("testExcludedRoutesChangeDisabled");
|
||||
}
|
||||
|
||||
public void testExcludedRoutesChangeDisabledByOverride() throws Exception {
|
||||
installPackage(TEST_APK, true);
|
||||
runDeviceCompatTestWithChangeDisabled("testExcludedRoutesChangeDisabled");
|
||||
}
|
||||
|
||||
public void testExcludedRoutesChangeEnabledByOverridePreT() throws Exception {
|
||||
installPackage(TEST_APK_PRE_T, true);
|
||||
runDeviceCompatTestWithChangeEnabled("testExcludedRoutesChangeEnabled");
|
||||
}
|
||||
|
||||
private void runDeviceCompatTest(String methodName) throws Exception {
|
||||
runDeviceCompatTest(TEST_PKG, TEST_CLASS, methodName, Set.of(), Set.of());
|
||||
}
|
||||
|
||||
private void runDeviceCompatTestWithChangeEnabled(String methodName) throws Exception {
|
||||
runDeviceCompatTest(TEST_PKG, TEST_CLASS, methodName, Set.of(EXCLUDED_ROUTES_CHANGE_ID),
|
||||
Set.of());
|
||||
}
|
||||
|
||||
private void runDeviceCompatTestWithChangeDisabled(String methodName) throws Exception {
|
||||
runDeviceCompatTest(TEST_PKG, TEST_CLASS, methodName, Set.of(),
|
||||
Set.of(EXCLUDED_ROUTES_CHANGE_ID));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue