Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 965be4e3 authored by Automerger Merge Worker's avatar Automerger Merge Worker Committed by Chiachang Wang
Browse files

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 09e5726e)
parent ed3c321c
Loading
Loading
Loading
Loading
+73 −10
Original line number Original line Diff line number Diff line
@@ -19,19 +19,40 @@ package android.net;
import static android.net.RouteInfo.RTN_UNREACHABLE;
import static android.net.RouteInfo.RTN_UNREACHABLE;


import static com.android.testutils.MiscAssertsKt.assertEqualBothWays;
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.MiscAssertsKt.assertNotEqualEitherWay;
import static com.android.testutils.ParcelUtilsKt.assertParcelSane;
import static com.android.testutils.ParcelUtilsKt.assertParcelingIsLossless;
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.Inet4Address;
import java.net.Inet6Address;
import java.net.Inet6Address;
import java.net.InetAddress;
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) {
    private InetAddress Address(String addr) {
        return InetAddress.parseNumericAddress(addr);
        return InetAddress.parseNumericAddress(addr);
@@ -41,16 +62,33 @@ public class RouteInfoTest extends TestCase {
        return new IpPrefix(prefix);
        return new IpPrefix(prefix);
    }
    }


    @SmallTest
    @Test
    public void testConstructor() {
    public void testConstructor() {
        RouteInfo r;
        RouteInfo r;

        // Invalid input.
        // Invalid input.
        try {
        try {
            r = new RouteInfo((IpPrefix) null, null, "rmnet0");
            r = new RouteInfo((IpPrefix) null, null, "rmnet0");
            fail("Expected RuntimeException:  destination and gateway null");
            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.
        // Null destination is default route.
        r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
        r = new RouteInfo((IpPrefix) null, Address("2001:db8::1"), null);
        assertEquals(Prefix("::/0"), r.getDestination());
        assertEquals(Prefix("::/0"), r.getDestination());
@@ -74,6 +112,7 @@ public class RouteInfoTest extends TestCase {
        assertNull(r.getInterface());
        assertNull(r.getInterface());
    }
    }


    @Test
    public void testMatches() {
    public void testMatches() {
        class PatchedRouteInfo {
        class PatchedRouteInfo {
            private final RouteInfo mRouteInfo;
            private final RouteInfo mRouteInfo;
@@ -113,6 +152,7 @@ public class RouteInfoTest extends TestCase {
        assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
        assertFalse(ipv4Default.matches(Address("2001:db8::f00")));
    }
    }


    @Test
    public void testEquals() {
    public void testEquals() {
        // IPv4
        // IPv4
        RouteInfo r1 = new RouteInfo(Prefix("2001:db8:ace::/48"), Address("2001:db8::1"), "wlan0");
        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);
        assertNotEqualEitherWay(r1, r3);
    }
    }


    @Test
    public void testHostAndDefaultRoutes() {
    public void testHostAndDefaultRoutes() {
        RouteInfo r;
        RouteInfo r;


@@ -228,6 +269,7 @@ public class RouteInfoTest extends TestCase {
        assertFalse(r.isIPv6Default());
        assertFalse(r.isIPv6Default());
    }
    }


    @Test
    public void testTruncation() {
    public void testTruncation() {
      LinkAddress l;
      LinkAddress l;
      RouteInfo r;
      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
    // 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
    // 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);
    // requestRouteToHostAddress("230.0.0.0", MOBILE_HIPRI);
    @Test
    public void testMulticastRoute() {
    public void testMulticastRoute() {
      RouteInfo r;
      RouteInfo r;
      r = new RouteInfo(Prefix("230.0.0.0/32"), Address("192.0.2.1"), "wlan0");
      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.
      // No exceptions? Good.
    }
    }


    @Test
    public void testParceling() {
    public void testParceling() {
        RouteInfo r;
        RouteInfo r;
        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");
        assertParcelingIsLossless(r);
        r = new RouteInfo(Prefix("192.0.2.0/24"), Address("192.0.2.1"), "wlan0", RTN_UNREACHABLE);
        assertParcelingIsLossless(r);
    }


        r = new RouteInfo(Prefix("::/0"), Address("2001:db8::"), null);
    @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);
        assertParcelingIsLossless(r);
    }


        r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
    @Test @IgnoreAfter(Build.VERSION_CODES.Q)
        assertParcelSane(r, 7);
    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() {
    public void testMtu() {
        RouteInfo r;
        RouteInfo r;
        r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",
        r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",