Fix IPsec CTS tests for interface address checking
Fixes two potentially device/kernel specific, or flaky bugs: 1. Java interface checking by name seems to cache the lookup, resulting in interface address checks occasionally failing (on delete). 2. Link-local addresses appear to be added on all links for some set of kernels and devices. This patch addresses both by only checking that the requested address was added via a address-based NetworkInterface lookup. Bug: 72950854 Test: Ran on sargo-eng on qt-dev/HEAD Test: Manually verified that the addresses are indeed added/removed Change-Id: I3babc72dfe72337c4d68facb1695aec15e504c90
This commit is contained in:
@@ -39,7 +39,6 @@ import static org.junit.Assert.assertArrayEquals;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
@@ -69,9 +68,7 @@ import com.android.compatibility.common.util.SystemUtil;
|
|||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InterfaceAddress;
|
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -512,11 +509,10 @@ public class IpSecManagerTunnelTest extends IpSecBaseTest {
|
|||||||
NetworkInterface netIntf = NetworkInterface.getByName(tunnelIntf.getInterfaceName());
|
NetworkInterface netIntf = NetworkInterface.getByName(tunnelIntf.getInterfaceName());
|
||||||
assertNotNull(netIntf);
|
assertNotNull(netIntf);
|
||||||
|
|
||||||
// Check addresses
|
// Verify address was added
|
||||||
List<InterfaceAddress> intfAddrs = netIntf.getInterfaceAddresses();
|
netIntf = NetworkInterface.getByInetAddress(localInner);
|
||||||
assertEquals(1, intfAddrs.size());
|
assertNotNull(netIntf);
|
||||||
assertEquals(localInner, intfAddrs.get(0).getAddress());
|
assertEquals(tunnelIntf.getInterfaceName(), netIntf.getDisplayName());
|
||||||
assertEquals(innerPrefixLen, intfAddrs.get(0).getNetworkPrefixLength());
|
|
||||||
|
|
||||||
// Configure Transform parameters
|
// Configure Transform parameters
|
||||||
IpSecTransform.Builder transformBuilder = new IpSecTransform.Builder(sContext);
|
IpSecTransform.Builder transformBuilder = new IpSecTransform.Builder(sContext);
|
||||||
@@ -544,15 +540,14 @@ public class IpSecManagerTunnelTest extends IpSecBaseTest {
|
|||||||
// Teardown the test network
|
// Teardown the test network
|
||||||
sTNM.teardownTestNetwork(testNetwork);
|
sTNM.teardownTestNetwork(testNetwork);
|
||||||
|
|
||||||
// Remove addresses and check
|
// Remove addresses and check that interface is still present, but fails lookup-by-addr
|
||||||
tunnelIntf.removeAddress(localInner, innerPrefixLen);
|
tunnelIntf.removeAddress(localInner, innerPrefixLen);
|
||||||
netIntf = NetworkInterface.getByName(tunnelIntf.getInterfaceName());
|
assertNotNull(NetworkInterface.getByName(tunnelIntf.getInterfaceName()));
|
||||||
assertTrue(netIntf.getInterfaceAddresses().isEmpty());
|
assertNull(NetworkInterface.getByInetAddress(localInner));
|
||||||
|
|
||||||
// Check interface was cleaned up
|
// Check interface was cleaned up
|
||||||
tunnelIntf.close();
|
tunnelIntf.close();
|
||||||
netIntf = NetworkInterface.getByName(tunnelIntf.getInterfaceName());
|
assertNull(NetworkInterface.getByName(tunnelIntf.getInterfaceName()));
|
||||||
assertNull(netIntf);
|
|
||||||
} finally {
|
} finally {
|
||||||
if (testNetworkCb != null) {
|
if (testNetworkCb != null) {
|
||||||
sCM.unregisterNetworkCallback(testNetworkCb);
|
sCM.unregisterNetworkCallback(testNetworkCb);
|
||||||
|
|||||||
Reference in New Issue
Block a user