Skip Route tests that are R-specific on Q

MTU was added in R so test for it should be run on Q. Also
revise test to adopt rule.

Test: atest CtsNetTestCasesLatestSdk:android.net.LinkAddressTest
      on both devices
Bug: 150918852
Change-Id: Ibab9cfae0d35b26c6e4ca0defbb89769b04201d4
Merged-In: Ibab9cfae0d35b26c6e4ca0defbb89769b04201d4
(cherry picked from commit 09e5726e158d543b7632cd6e22f6e4c29b0bef52)
This commit is contained in:
Automerger Merge Worker
2020-03-10 11:47:02 +00:00
committed by Chiachang Wang
parent ea7800cb54
commit f78e440b27

View File

@@ -19,19 +19,40 @@ package android.net;
import static android.net.RouteInfo.RTN_UNREACHABLE;
import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
import static com.android.testutils.MiscAssertsKt.assertFieldCountEquals;
import static com.android.testutils.MiscAssertsKt.assertNotEqualEitherWay;
import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
import android.test.suitebuilder.annotation.SmallTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.TestCase;
import android.os.Build;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import com.android.testutils.DevSdkIgnoreRule;
import com.android.testutils.DevSdkIgnoreRule.IgnoreAfter;
import com.android.testutils.DevSdkIgnoreRule.IgnoreUpTo;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
public class RouteInfoTest extends TestCase {
@RunWith(AndroidJUnit4.class)
@SmallTest
public class RouteInfoTest {
@Rule
public final DevSdkIgnoreRule ignoreRule = new DevSdkIgnoreRule();
private static final int INVALID_ROUTE_TYPE = -1;
private InetAddress Address(String addr) {
return InetAddress.parseNumericAddress(addr);
@@ -41,15 +62,32 @@ public class RouteInfoTest extends TestCase {
return new IpPrefix(prefix);
}
@SmallTest
@Test
public void testConstructor() {
RouteInfo r;
// Invalid input.
try {
r = new RouteInfo((IpPrefix) null, null, "rmnet0");
fail("Expected RuntimeException: destination and gateway null");
} catch(RuntimeException e) {}
} catch (RuntimeException e) { }
try {
r = new RouteInfo(Prefix("2001:db8:ace::/49"), Address("2001:db8::1"), "rmnet0",
INVALID_ROUTE_TYPE);
fail("Invalid route type should cause exception");
} catch (IllegalArgumentException e) { }
try {
r = new RouteInfo(Prefix("2001:db8:ace::/49"), Address("192.0.2.1"), "rmnet0",
RTN_UNREACHABLE);
fail("Address family mismatch should cause exception");
} catch (IllegalArgumentException e) { }
try {
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("2001:db8::1"), "rmnet0",
RTN_UNREACHABLE);
fail("Address family mismatch should cause exception");
} catch (IllegalArgumentException e) { }
// Null destination is default route.
r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
@@ -74,6 +112,7 @@ public class RouteInfoTest extends TestCase {
assertNull(r.getInterface());
}
@Test
public void testMatches() {
class PatchedRouteInfo {
private final RouteInfo mRouteInfo;
@@ -113,6 +152,7 @@ public class RouteInfoTest extends TestCase {
assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
}
@Test
public void testEquals() {
// IPv4
RouteInfo r1 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
@@ -146,6 +186,7 @@ public class RouteInfoTest extends TestCase {
assertNotEqualEitherWay(r1, r3);
}
@Test
public void testHostAndDefaultRoutes() {
RouteInfo r;
@@ -228,6 +269,7 @@ public class RouteInfoTest extends TestCase {
assertFalse(r.isIPv6Default());
}
@Test
public void testTruncation() {
LinkAddress l;
RouteInfo r;
@@ -244,6 +286,7 @@ public class RouteInfoTest extends TestCase {
// Make sure that creating routes to multicast addresses doesn't throw an exception. Even though
// there's nothing we can do with them, we don't want to crash if, e.g., someone calls
// requestRouteToHostAddress("230.0.0.0", MOBILE_HIPRI);
@Test
public void testMulticastRoute() {
RouteInfo r;
r = new RouteInfo(Prefix("230.0.0.0/32"), Address("192.0.2.1"), "wlan0");
@@ -251,16 +294,36 @@ public class RouteInfoTest extends TestCase {
// No exceptions? Good.
}
@Test
public void testParceling() {
RouteInfo r;
r = new RouteInfo(Prefix("::/0"), Address("2001:db8::"), null);
r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), null);
assertParcelingIsLossless(r);
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
assertParcelSane(r, 7);
assertParcelingIsLossless(r);
r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0", RTN_UNREACHABLE);
assertParcelingIsLossless(r);
}
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testMtuParceling() {
final RouteInfo r = new RouteInfo(Prefix("ff02::1/128"), Address("2001:db8::"), "testiface",
RTN_UNREACHABLE, 1450 /* mtu */);
assertParcelingIsLossless(r);
}
@Test @IgnoreAfter(Build.VERSION_CODES.Q)
public void testFieldCount_Q() {
assertFieldCountEquals(6, RouteInfo.class);
}
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testFieldCount() {
// Make sure any new field is covered by the above parceling tests when changing this number
assertFieldCountEquals(7, RouteInfo.class);
}
@Test @IgnoreUpTo(Build.VERSION_CODES.Q)
public void testMtu() {
RouteInfo r;
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",