Revert "Use new test utilities from frameworks/libs/net"
Revert submission 1440811-iputils_constants_move
Reason for revert: Likely broke build in b/170438226
Reverted Changes:
Ic382d24e7:Move NetworkStackConstants to frameworks/libs/net
I0d938e296:Use new test utilities from frameworks/libs/net
Change-Id: Iec4709778ba1b30687df265a2a5c694c536b5456
diff --git a/tests/tests/net/src/android/net/cts/CaptivePortalTest.kt b/tests/tests/net/src/android/net/cts/CaptivePortalTest.kt
index f2c5028..12a966f 100644
--- a/tests/tests/net/src/android/net/cts/CaptivePortalTest.kt
+++ b/tests/tests/net/src/android/net/cts/CaptivePortalTest.kt
@@ -30,9 +30,11 @@
import android.net.NetworkRequest
import android.net.Uri
import android.net.cts.NetworkValidationTestUtil.clearValidationTestUrlsDeviceConfig
+import android.net.cts.NetworkValidationTestUtil.runAsShell
import android.net.cts.NetworkValidationTestUtil.setHttpUrlDeviceConfig
import android.net.cts.NetworkValidationTestUtil.setHttpsUrlDeviceConfig
import android.net.cts.NetworkValidationTestUtil.setUrlExpirationDeviceConfig
+import com.android.testutils.TestHttpServer.Request
import android.net.cts.util.CtsNetUtils
import android.net.util.NetworkStackUtils.TEST_CAPTIVE_PORTAL_HTTPS_URL
import android.net.util.NetworkStackUtils.TEST_CAPTIVE_PORTAL_HTTP_URL
@@ -45,9 +47,7 @@
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.runner.AndroidJUnit4
import com.android.testutils.TestHttpServer
-import com.android.testutils.TestHttpServer.Request
import com.android.testutils.isDevSdkInRange
-import com.android.testutils.runAsShell
import fi.iki.elonen.NanoHTTPD.Response.Status
import junit.framework.AssertionFailedError
import org.junit.After
diff --git a/tests/tests/net/src/android/net/cts/NetworkValidationTest.kt b/tests/tests/net/src/android/net/cts/NetworkValidationTest.kt
index 5290f0d..ec656de 100644
--- a/tests/tests/net/src/android/net/cts/NetworkValidationTest.kt
+++ b/tests/tests/net/src/android/net/cts/NetworkValidationTest.kt
@@ -31,6 +31,7 @@
import android.net.TestNetworkInterface
import android.net.TestNetworkManager
import android.net.Uri
+import android.net.cts.NetworkValidationTestUtil.runAsShell
import android.net.dhcp.DhcpDiscoverPacket
import android.net.dhcp.DhcpPacket
import android.net.dhcp.DhcpPacket.DHCP_MESSAGE_TYPE
@@ -44,7 +45,8 @@
import androidx.test.runner.AndroidJUnit4
import com.android.net.module.util.Inet4AddressUtils.getBroadcastAddress
import com.android.net.module.util.Inet4AddressUtils.getPrefixMaskAsInet4Address
-import com.android.net.module.util.NetworkStackConstants.IPV4_ADDR_ANY
+import com.android.server.util.NetworkStackConstants.IPV4_ADDR_ANY
+import com.android.testutils.ArpResponder
import com.android.testutils.DevSdkIgnoreRule
import com.android.testutils.DhcpClientPacketFilter
import com.android.testutils.DhcpOptionFilter
@@ -52,10 +54,10 @@
import com.android.testutils.TapPacketReader
import com.android.testutils.TestHttpServer
import com.android.testutils.TestableNetworkCallback
-import com.android.testutils.runAsShell
import fi.iki.elonen.NanoHTTPD.Response.Status
import org.junit.After
import org.junit.Assume.assumeFalse
+import org.junit.Assume.assumeTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -129,7 +131,7 @@
handlerThread.threadHandler,
iface.fileDescriptor.fileDescriptor,
MAX_PACKET_LENGTH)
- reader.startAsyncForTest()
+ handlerThread.threadHandler.post { reader.start() }
httpServer.start()
// Pad the listening port to make sure it is always of length 5. This ensures the URL has
@@ -231,7 +233,7 @@
timeoutMs: Long,
type: Byte
): T {
- val packetBytes = poll(timeoutMs, DhcpClientPacketFilter()
+ val packetBytes = popPacket(timeoutMs, DhcpClientPacketFilter()
.and(DhcpOptionFilter(DHCP_MESSAGE_TYPE, type)))
?: fail("${packetType.simpleName} not received within timeout")
val packet = DhcpPacket.decodeFullPacket(packetBytes, packetBytes.size, DhcpPacket.ENCAP_L2)
diff --git a/tests/tests/net/src/android/net/cts/NetworkValidationTestUtil.kt b/tests/tests/net/src/android/net/cts/NetworkValidationTestUtil.kt
index f6fc75b..5ef1854 100644
--- a/tests/tests/net/src/android/net/cts/NetworkValidationTestUtil.kt
+++ b/tests/tests/net/src/android/net/cts/NetworkValidationTestUtil.kt
@@ -19,7 +19,9 @@
import android.Manifest
import android.net.util.NetworkStackUtils
import android.provider.DeviceConfig
-import com.android.testutils.runAsShell
+import com.android.compatibility.common.util.SystemUtil.runWithShellPermissionIdentity
+import com.android.compatibility.common.util.ThrowingRunnable
+import kotlin.test.fail
/**
* Collection of utility methods for configuring network validation.
@@ -65,4 +67,13 @@
DeviceConfig.NAMESPACE_CONNECTIVITY, configKey, value, false /* makeDefault */)
}
}
+
+ /**
+ * Wrapper around runWithShellPermissionIdentity with kotlin-like syntax.
+ */
+ fun <T> runAsShell(vararg permissions: String, task: () -> T): T {
+ var ret: T? = null
+ runWithShellPermissionIdentity(ThrowingRunnable { ret = task() }, *permissions)
+ return ret ?: fail("ThrowingRunnable did not return")
+ }
}
\ No newline at end of file