net-test: turn off xfrm_*_test.py on 32-on-64 6.18+ am: b49ee894d9 Original change: https://googleplex-android-review.googlesource.com/c/kernel/tests/+/40948288 Change-Id: I09dcf42c537adb145a882559dc91c192ae9e681d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/net/test/all_tests.py b/net/test/all_tests.py index baa917f..c6bb6d5 100755 --- a/net/test/all_tests.py +++ b/net/test/all_tests.py
@@ -15,7 +15,6 @@ # limitations under the License. import argparse -import ctypes import importlib import os import sys @@ -25,16 +24,6 @@ import namespace import net_test -# man 2 personality -personality = ctypes.CDLL(None).personality -personality.restype = ctypes.c_int -personality.argtypes = [ctypes.c_ulong] - -# From Linux kernel's include/uapi/linux/personality.h -PER_QUERY = 0xFFFFFFFF -PER_LINUX = 0 -PER_LINUX32 = 8 - all_test_modules = [ 'anycast_test', 'bpf_test', @@ -87,16 +76,9 @@ def RunTests(modules_to_test, excludes=None): - uname = os.uname() - linux = uname.sysname - kver = uname.release - arch = uname.machine - p = personality(PER_LINUX) - true_arch = os.uname().machine - personality(p) print('Running on %s %s %s %s/%s-%sbit%s%s' - % (linux, kver, net_test.LINUX_VERSION, true_arch, arch, - '64' if sys.maxsize > 0x7FFFFFFF else '32', + % (net_test.SYSNAME, net_test.RELEASE, net_test.LINUX_VERSION, + net_test.TRUE_ARCH, net_test.ARCH, net_test.BITNESS, ' GKI' if gki.IS_GKI else '', ' GSI' if net_test.IS_GSI else ''), file=sys.stderr) namespace.EnterNewNetworkNamespace()
diff --git a/net/test/bpf.py b/net/test/bpf.py index 8226f62..b3d7e29 100755 --- a/net/test/bpf.py +++ b/net/test/bpf.py
@@ -44,7 +44,7 @@ "x86_64-32bit": 357, "x86_64-64bit": 321, "riscv64-64bit": 280, -}[os.uname()[4] + "-" + ("64" if sys.maxsize > 0x7FFFFFFF else "32") + "bit"] +}[f"{net_test.ARCH}-{net_test.BITNESS}bit"] # Note: This is *not* correct for parisc & sparc architectures SO_NETNS_COOKIE = 71
diff --git a/net/test/kernel_feature_test.py b/net/test/kernel_feature_test.py index 1f76dd5..3881ac9 100755 --- a/net/test/kernel_feature_test.py +++ b/net/test/kernel_feature_test.py
@@ -33,7 +33,7 @@ try: return gzip.open("/proc/config.gz", mode="rt") except FileNotFoundError: - return open("/boot/config-" + os.uname()[2], mode="rt") + return open("/boot/config-" + net_test.RELEASE, mode="rt") @classmethod def loadKernelConfig(cls):
diff --git a/net/test/net_test.py b/net/test/net_test.py index e29884e..31e3bcc 100644 --- a/net/test/net_test.py +++ b/net/test/net_test.py
@@ -15,6 +15,7 @@ # limitations under the License. import contextlib +import ctypes import fcntl import os import random @@ -106,6 +107,34 @@ # From //system/gsid/libgsi.cpp IsGsiRunning() IS_GSI = os.access("/metadata/gsi/dsu/booted", os.F_OK) +# man 2 personality +personality = ctypes.CDLL(None).personality +personality.restype = ctypes.c_int +personality.argtypes = [ctypes.c_ulong] + +# From Linux kernel's include/uapi/linux/personality.h +PER_QUERY = 0xFFFFFFFF +PER_LINUX = 0 +PER_LINUX32 = 8 + +# Check system info and if running 32-bit userspace on a 64-bit kernel. +_uname = os.uname() +SYSNAME = _uname.sysname +RELEASE = _uname.release +ARCH = _uname.machine +# Since ARCH can be a bit of a lie, also fetch the 'true' kernel arch +_p = personality(PER_LINUX) +TRUE_ARCH = os.uname().machine +personality(_p) + +# This is the bitness of the python interpreter (ie. current userspace) +BITNESS = 64 if sys.maxsize > 0x7FFFFFFF else 32 +IS_USERSPACE32 = BITNESS == 32 + +# This is the bitness of the kernel itself +IS_KERNEL64 = TRUE_ARCH.endswith("64") + + # NonGXI() is useful to run tests starting from a specific kernel version, # thus allowing one to test for correctly backported fixes, # without running the tests on non-updatable kernels (as part of GSI tests).
diff --git a/net/test/xfrm_base.py b/net/test/xfrm_base.py index e5aadf3..2af23e1 100644 --- a/net/test/xfrm_base.py +++ b/net/test/xfrm_base.py
@@ -18,6 +18,7 @@ from scapy import all as scapy import binascii import struct +import unittest import csocket import cstruct @@ -271,6 +272,31 @@ return packet, esp_hdr +# XFRM/ipsec tests are for CAP_NET_ADMIN requiring interfaces, as such we only need to test these +# kernel apis at the bitness of netd & system_server - ie. there is no need to test 32-bit api +# (potentially used by unpriv app) if those system processes are 64-bit. +# +# ACK 6.18+ no longer includes the Android hack to make 32-on-64 xfrm api use 64-bit struct layout, +# which was needed (basically for historical reasons) to match the behaviour of ancient kernels +# which failed (forgot) to do compat translations on this specific code path. +# This results in all xfrm_* tests failing on 6.18+ 32-on-64 (this is because the python xfrm struct +# definitions hard code 64-bit layout, while the new kernels perform up/down translation to 32-bit, +# this 64-bit layout is *also* hardcoded elsewhere in the non-python Android code base). +# +# NetBpfLoad.cpp already enforces "64-bit userspace required on 6.13+ kernels." +# As such, in theory, there is no need to test 32-bit on 6.13+ at all... +# +# But for safety let's make sure we disable the test only on 6.18+ 64-bit kernels that are *not* +# using personality uname() arch spoofing (commonly used by CF for 32-bit system server env). +# Hence the check for ARCH and not TRUE_ARCH below. +# +# This skip clause is needed to fix (for example) an Android T/13 device that upgrades to Android 17 +# while uprevving the kernel to 6.18. Unlike modern new launch devices which are 64-bit only, it +# (most likely) supported 32-bit apps and will thus run VTS in both 32 and 64-bit mode. +# +# See b/532739201 +@unittest.skipIf(net_test.IS_USERSPACE32 and net_test.ARCH.endswith("64") and net_test.LINUX_VERSION >= (6, 18, 0), + "xfrm_ tests need to be skipped on 32-bit userspace 64-bit kernel 6.18+") class XfrmBaseTest(multinetwork_base.MultiNetworkBaseTest): """Base test class for all XFRM-related testing."""