summaryrefslogtreecommitdiff
path: root/tests/common/java/android/net/LinkPropertiesTest.java
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2022-06-10 23:19:48 +0900
committerCherrypicker Worker <android-build-cherrypicker-worker@google.com>2022-06-13 02:05:56 +0000
commitbdd08a2768577a0aefe44be440d8bb7c596448ca (patch)
tree92e8f5f0b0349674d3864b70bdbc6341ea8ddf4a /tests/common/java/android/net/LinkPropertiesTest.java
parentcb2e7764e3acb6855e58860ccff9e642c96ce53d (diff)
Fix LinkProperties exclude routes tests on user builds.
The tests fail on user builds because they target T and attempt to override the compat change, which is not allowed on user builds because the change defaults to on for apps targeting T+. Fix this by marking the tests max target SDK 31. Also improve the tests a bit: - Use a RuleChain to make it explicit that CtsNetTestCasesMaxTargetSdk31 should be evaluated before EnableCompatChanges (otherwise the compat change rule would crash on user builds even if the max target SDK rule was going to skip the test anyway). - Fix the IgnoreUpTo for all exclude route tests to say S+. Currently: - One says R+, which is incorrect because the updated LinkProperties code is in the connectivity module, which only goes back to S, not R. - The others say T+, which is incorrect because the update code is present on S. Fix: 233553525 Test: LinkProperties test in CtsNetTestCasesLatestSdk passes on T user build Test: LinkProperties test in CtsNetTestCasesMaxTargetSdk31 passes on T user build Change-Id: Ie0e2f6761b90a65813ed3610c7b5e930a9fdc982 (cherry picked from commit 1bb94a34909912a449e0b719b6ddd5b8aa4a9f7d) Merged-In: Ie0e2f6761b90a65813ed3610c7b5e930a9fdc982
Diffstat (limited to 'tests/common/java/android/net/LinkPropertiesTest.java')
-rw-r--r--tests/common/java/android/net/LinkPropertiesTest.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/tests/common/java/android/net/LinkPropertiesTest.java b/tests/common/java/android/net/LinkPropertiesTest.java
index 581ee221be..9ed2bb3b86 100644
--- a/tests/common/java/android/net/LinkPropertiesTest.java
+++ b/tests/common/java/android/net/LinkPropertiesTest.java
@@ -20,7 +20,6 @@ import static android.net.RouteInfo.RTN_THROW;
import static android.net.RouteInfo.RTN_UNICAST;
import static android.net.RouteInfo.RTN_UNREACHABLE;
-import static com.android.testutils.DevSdkIgnoreRuleKt.SC_V2;
import static com.android.testutils.ParcelUtils.assertParcelingIsLossless;
import static com.android.testutils.ParcelUtils.parcelingRoundTrip;
@@ -53,6 +52,7 @@ import libcore.junit.util.compat.CoreCompatChangeRule.EnableCompatChanges;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
import java.net.Inet4Address;
@@ -68,11 +68,13 @@ import java.util.Set;
@SmallTest
@ConnectivityModuleTest
public class LinkPropertiesTest {
+ // Use a RuleChain to explicitly specify the order of rules. DevSdkIgnoreRule must run before
+ // PlatformCompatChange rule, because otherwise tests with that should be skipped when targeting
+ // target SDK 33 will still attempt to override compat changes (which on user builds will crash)
+ // before being skipped.
@Rule
- public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
-
- @Rule
- public final PlatformCompatChangeRule compatChangeRule = new PlatformCompatChangeRule();
+ public final RuleChain chain = RuleChain.outerRule(
+ new DevSdkIgnoreRule()).around(new PlatformCompatChangeRule());
private static final InetAddress ADDRV4 = address("75.208.6.1");
private static final InetAddress ADDRV6 = address("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
@@ -1262,7 +1264,8 @@ public class LinkPropertiesTest {
assertFalse(lp.hasIpv4UnreachableDefaultRoute());
}
- @Test @IgnoreUpTo(Build.VERSION_CODES.S_V2)
+ @Test @IgnoreUpTo(Build.VERSION_CODES.R)
+ @CtsNetTestCasesMaxTargetSdk31(reason = "Compat change cannot be overridden when targeting T+")
@EnableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
public void testHasExcludeRoute() {
LinkProperties lp = new LinkProperties();
@@ -1274,7 +1277,8 @@ public class LinkPropertiesTest {
assertTrue(lp.hasExcludeRoute());
}
- @Test @IgnoreUpTo(Build.VERSION_CODES.Q)
+ @Test @IgnoreUpTo(Build.VERSION_CODES.R)
+ @CtsNetTestCasesMaxTargetSdk31(reason = "Compat change cannot be overridden when targeting T+")
@EnableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
public void testRouteAddWithSameKey() throws Exception {
LinkProperties lp = new LinkProperties();
@@ -1291,7 +1295,8 @@ public class LinkPropertiesTest {
assertEquals(2, lp.getRoutes().size());
}
- @Test @IgnoreUpTo(SC_V2)
+ @Test @IgnoreUpTo(Build.VERSION_CODES.R)
+ @CtsNetTestCasesMaxTargetSdk31(reason = "Compat change cannot be overridden when targeting T+")
@EnableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
public void testExcludedRoutesEnabled() {
final LinkProperties lp = new LinkProperties();
@@ -1307,8 +1312,8 @@ public class LinkPropertiesTest {
assertEquals(3, lp.getRoutes().size());
}
- @Test @IgnoreUpTo(SC_V2)
- @CtsNetTestCasesMaxTargetSdk31(reason = "Compat change cannot be overridden on T or above")
+ @Test @IgnoreUpTo(Build.VERSION_CODES.R)
+ @CtsNetTestCasesMaxTargetSdk31(reason = "Compat change cannot be overridden when targeting T+")
@DisableCompatChanges({LinkProperties.EXCLUDED_ROUTES})
public void testExcludedRoutesDisabled() {
final LinkProperties lp = new LinkProperties();