Add proper kernel support assumption to RateLimitTest
As it turns out, /proc/config.gz can be accessed via shell command from
within a CTS test. This adds a proper kernel support check for the
RateLimitTest.
Bug: 220801455
Test: atest RateLimitTest
Change-Id: I4d3a6848c1c05c313cb74b235294cee982eecf57
diff --git a/tests/cts/net/src/android/net/cts/RateLimitTest.java b/tests/cts/net/src/android/net/cts/RateLimitTest.java
index 5f9e0f3..8a3db26 100644
--- a/tests/cts/net/src/android/net/cts/RateLimitTest.java
+++ b/tests/cts/net/src/android/net/cts/RateLimitTest.java
@@ -28,7 +28,9 @@
import static com.android.testutils.TestPermissionUtil.runAsShell;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import android.content.Context;
import android.icu.text.MessageFormat;
@@ -62,6 +64,7 @@
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -74,6 +77,8 @@
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.stream.Collectors;
@AppModeFull(reason = "Instant apps cannot access /dev/tun, so createTunInterface fails")
@RunWith(DevSdkIgnoreRunner.class)
@@ -102,6 +107,21 @@
private Network mNetwork;
private DatagramSocket mSocket;
+ @BeforeClass
+ public static void assumeKernelSupport() {
+ final String result = SystemUtil.runShellCommandOrThrow("gzip -cd /proc/config.gz");
+ HashSet<String> kernelConfig = Arrays.stream(result.split("\\R")).collect(
+ Collectors.toCollection(HashSet::new));
+
+ // make sure that if for some reason /proc/config.gz returns an empty string, this test
+ // does not silently fail.
+ assertNotEquals(0, result.length());
+
+ assumeTrue(kernelConfig.contains("CONFIG_NET_CLS_MATCHALL=y"));
+ assumeTrue(kernelConfig.contains("CONFIG_NET_ACT_POLICE=y"));
+ assumeTrue(kernelConfig.contains("CONFIG_NET_ACT_BPF=y"));
+ }
+
@Before
public void setUp() throws IOException {
mHandler = new Handler(Looper.getMainLooper());