Fix selection of bpf syscall number with COMPAT_UTS_MACHINE.

If the python interpreter is 64-bit but was launched from a 32-bit
environment (this can happen if it is run from a chroot or container),
then 'uname -m' and python's os.uname()[4] will return 'i686' instead of
x86_64 for questionable compatibility reasons. This breaks the
assumption in the bpf.py test that 'uname -m' reliably returns the
personality of the python interpreter, which determines the syscall number
to use for bpf.

Harden the assumptions made by the test by qualifying the architecture
test with the bitness of the python interpreter. We can then correctly
determine when to use the 64-bit syscall number.

This change has only been tested on x86. The ARM part of the change is
very likely to be correct, and cannot make things worse, but I did not
have a device with a 64-bit kernel and 32-bit userspace available to
test.

Bug: 79532682
Test: ./all_tests.sh ran to completion on cuttlefish
Change-Id: I1e9e62ba22344db121e83e97906bc1dcbcb51386
Signed-off-by: Alistair Strachan <astrachan@google.com>
diff --git a/net/test/bpf.py b/net/test/bpf.py
index 24dc7a1..7625265 100755
--- a/net/test/bpf.py
+++ b/net/test/bpf.py
@@ -21,15 +21,23 @@
 import cstruct
 import net_test
 import socket
+import platform
 
 # __NR_bpf syscall numbers for various architectures.
+# NOTE: If python inherited COMPAT_UTS_MACHINE, uname's 'machine' field will
+# return the 32-bit architecture name, even if python itself is 64-bit. To work
+# around this problem and pick the right syscall nr, we can additionally check
+# the bitness of the python interpreter. Assume that the 64-bit architectures
+# are not running with COMPAT_UTS_MACHINE and must be 64-bit at all times.
 # TODO: is there a better way of doing this?
 __NR_bpf = {
-    "aarch64": 280,
-    "armv8l": 386,
-    "i686" : 357,
-    "x86_64": 321,
-}[os.uname()[4]]
+    "aarch64-64bit": 280,
+    "armv8l-32bit": 386,
+    "armv8l-64bit": 280,
+    "i686-32bit": 357,
+    "i686-64bit": 321,
+    "x86_64-64bit": 321,
+}[os.uname()[4] + "-" + platform.architecture()[0]]
 
 LOG_LEVEL = 1
 LOG_SIZE = 65536