From b37f76f28ea31dddfe6d5fe7601df6ea1fb2374f Mon Sep 17 00:00:00 2001 From: Hungming Chen Date: Mon, 27 Jun 2022 15:00:55 +0800 Subject: [PATCH] Ignore BPF tethering offload test if tether config is disabled Needed because OEM can disable BPF offload by PRO. Bug: 237144191 Bug: 236925089 Test: atest EthernetTetheringTest Change-Id: Idf965caa44aeaae1f084d2c4fcd516a352c1b138 --- .../tethering/BpfCoordinator.java | 2 ++ .../android/net/EthernetTetheringTest.java | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java index c403548e3d..1368eeec72 100644 --- a/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java +++ b/Tethering/src/com/android/networkstack/tethering/BpfCoordinator.java @@ -944,6 +944,8 @@ public class BpfCoordinator { * be allowed to be accessed on the handler thread. */ public void dump(@NonNull IndentingPrintWriter pw) { + // Note that EthernetTetheringTest#isTetherConfigBpfOffloadEnabled relies on + // "mIsBpfEnabled" to check tethering config via dumpsys. Beware of the change if any. pw.println("mIsBpfEnabled: " + mIsBpfEnabled); pw.println("Polling " + (mPollingStarted ? "started" : "not started")); pw.println("Stats provider " + (mStatsProvider != null diff --git a/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java b/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java index 819936dddb..7ccb7f565b 100644 --- a/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java +++ b/Tethering/tests/integration/src/android/net/EthernetTetheringTest.java @@ -1125,12 +1125,18 @@ public class EthernetTetheringTest { @IgnoreUpTo(Build.VERSION_CODES.R) public void testTetherUdpV4AfterR() throws Exception { final String kernelVersion = VintfRuntimeInfo.getKernelVersion(); - boolean usingBpf = isUdpOffloadSupportedByKernel(kernelVersion); - if (!usingBpf) { + final boolean isUdpOffloadSupported = isUdpOffloadSupportedByKernel(kernelVersion); + if (!isUdpOffloadSupported) { Log.i(TAG, "testTetherUdpV4AfterR will skip BPF offload test for kernel " + kernelVersion); } - runUdp4Test(initTetheringTester(toList(TEST_IP4_ADDR), toList(TEST_IP4_DNS)), usingBpf); + final boolean isTetherConfigBpfOffloadEnabled = isTetherConfigBpfOffloadEnabled(); + if (!isTetherConfigBpfOffloadEnabled) { + Log.i(TAG, "testTetherUdpV4AfterR will skip BPF offload test " + + "because tethering config doesn't enable BPF offload."); + } + runUdp4Test(initTetheringTester(toList(TEST_IP4_ADDR), toList(TEST_IP4_DNS)), + isUdpOffloadSupported && isTetherConfigBpfOffloadEnabled); } @Nullable @@ -1189,6 +1195,21 @@ public class EthernetTetheringTest { return null; } + private boolean isTetherConfigBpfOffloadEnabled() throws Exception { + final String dumpStr = DumpTestUtils.dumpService(Context.TETHERING_SERVICE, "--short"); + + // BPF offload tether config can be overridden by "config_tether_enable_bpf_offload" in + // packages/modules/Connectivity/Tethering/res/values/config.xml. OEM may disable config by + // RRO to override the enabled default value. Get the tethering config via dumpsys. + // $ dumpsys tethering + // mIsBpfEnabled: true + boolean enabled = dumpStr.contains("mIsBpfEnabled: true"); + if (!enabled) { + Log.d(TAG, "BPF offload tether config not enabled: " + dumpStr); + } + return enabled; + } + @NonNull private Inet6Address getClatIpv6Address(TetheringTester tester, TetheredDevice tethered) throws Exception {