From 04fb3862a9054c07418476100fdb427506babf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Sat, 15 Jun 2024 00:14:16 +0000 Subject: [PATCH] Add BPF_MAP_LOCKLESS_FOR_TEST hack for root resolver tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per commit description of https://android-review.git.corp.google.com/c/platform/packages/modules/Connectivity/+/3109108 "Use SingleWriterBpfMap in BpfNetMaps": - firewall.cpp writes to sConfigurationMap, sUidOwnerMap, and sDataSaverEnabledMap, but that code only runs in tests because it requires root privileges. So either those maps need to not use SingleWriterBpfMap in the BpfNetMaps (which would affect performance), or we need to prevent the tests from grabbing the locks, or the tests will (presumably) fail. This avoids grabbing the locks from the test, even though this is absolutely terrible and likely breaks things... But in general the entire firewall.cpp file (and libconnectivity_native_test_utils target) are just one large modularization violation in need of major escalation... Test via: atest resolv_{gold,stress,integration,unit}_test Without this patch: resolv_gold_test: Passed: 16 resolv_integration_test: Passed: 53, Failed: 2, Ignored: 118, Assumption Failed: 0 (Completed With ERRORS) resolv_stress_test: Passed: 2 resolv_unit_test: Passed: 124, Failed: 2 4 tests failed -------------- ResolverMultinetworkTest#DnsWithVpn PrivateDns/TransportParameterizedTest#BlockDnsQuery/DoT CallbackTest#tagSocketCallback ResolvGetAddrInfoTest#InvalidParameters With this patch: resolv_gold_test: Passed: 16 resolv_integration_test: Passed: 178 resolv_stress_test: Passed: 2 resolv_unit_test: Passed: 126 Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: Ie97d015ef66c3864a23484e7ed190fe7d091af5c --- .../native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h | 3 +++ tests/native/utilities/firewall.h | 1 + 2 files changed, 4 insertions(+) diff --git a/staticlibs/native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h b/staticlibs/native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h index eed4fd6c64..5bb3100a78 100644 --- a/staticlibs/native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h +++ b/staticlibs/native/bpf_syscall_wrappers/include/BpfSyscallWrappers.h @@ -135,6 +135,9 @@ int bpfGetFdMapId(const BPF_FD_TYPE map_fd); inline int bpfLock(int fd, short type) { if (fd < 0) return fd; // pass any errors straight through +#ifdef BPF_MAP_LOCKLESS_FOR_TEST + return fd; +#endif #ifdef BPF_FD_JUST_USE_INT int mapId = bpfGetFdMapId(fd); int saved_errno = errno; diff --git a/tests/native/utilities/firewall.h b/tests/native/utilities/firewall.h index b3d69bfa80..a5cb0b9df1 100644 --- a/tests/native/utilities/firewall.h +++ b/tests/native/utilities/firewall.h @@ -18,6 +18,7 @@ #pragma once #include +#define BPF_MAP_LOCKLESS_FOR_TEST #include #include "netd.h"