Skip to content

Commit fac46d0

Browse files
committed
selftests/bpf: Skip building arena tests if unsupported
BPF selftests always try building arena tests, but since kernel arena support is not built-in on unsupported archs, this leads to failures trying to build e.g. test_progs on 32-bit, and complicates overall testing. Past arena test code has been mainly added as separate source files, making it simpler to selectively build the tests. Update Makefile to filter out arena test sources from build rules and the tests.h header, and pass macro ENABLE_ARENA_TESTS via CFLAGS (e.g. for prog_tests/verifier.c). Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
1 parent bae6afc commit fac46d0

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),)
7070
CLANG_CPUV4 := 1
7171
endif
7272

73+
# Enable arena verifier tests only if supported
74+
ENABLE_ARENA_TESTS := $(filter $(SRCARCH),x86 riscv s390 arm64)
75+
CFLAGS += $(if $(ENABLE_ARENA_TESTS),-DENABLE_ARENA_TESTS)
76+
7377
# Order correspond to 'make run_tests' order
7478
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_progs \
7579
test_sockmap \
@@ -540,13 +544,16 @@ define DEFINE_TEST_RUNNER
540544
LSKEL_SIGN := -S -k $(PRIVATE_KEY) -i $(VERIFICATION_CERT)
541545
TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
542546
TRUNNER_BINARY := $1$(if $2,-)$2
547+
TRUNNER_TEST_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
548+
$$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
543549
TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
544-
$$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
550+
$$(TRUNNER_TEST_SRCS))
545551
TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
546552
$$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
547553
TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
548554
TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
549-
TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
555+
TRUNNER_BPF_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
556+
$$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)))
550557
TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.bpf.o, $$(TRUNNER_BPF_SRCS))
551558
TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
552559
$$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\
@@ -649,7 +656,9 @@ $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
649656
$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
650657
$$(shell (echo '/* Generated header, do not edit */'; \
651658
sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
652-
$(TRUNNER_TESTS_DIR)/*.c | sort ; \
659+
$(TRUNNER_TESTS_DIR)/*.c \
660+
$$(if $(ENABLE_ARENA_TESTS),,| grep -v 'arena') \
661+
| sort ; \
653662
) > $$@)
654663
endif
655664

@@ -756,6 +765,10 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
756765
$(VERIFY_SIG_SETUP) \
757766
$(wildcard progs/btf_dump_test_case_*.c) \
758767
$(wildcard progs/*.bpf.o)
768+
ifeq ($(ENABLE_ARENA_TESTS),)
769+
TRUNNER_ARENA_FILTER := $(notdir $(wildcard prog_tests/*arena*.c) \
770+
$(wildcard progs/*arena*.c))
771+
endif
759772
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
760773
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
761774
$(eval $(call DEFINE_TEST_RUNNER,test_progs))

tools/testing/selftests/bpf/prog_tests/verifier.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
#include "cap_helpers.h"
66
#include "verifier_and.skel.h"
7+
8+
#ifdef ENABLE_ARENA_TESTS
79
#include "verifier_arena.skel.h"
810
#include "verifier_arena_large.skel.h"
911
#include "verifier_arena_ldsx.skel.h"
12+
#endif
13+
1014
#include "verifier_array_access.skel.h"
1115
#include "verifier_basic_stack.skel.h"
1216
#include "verifier_bitfield_write.skel.h"
@@ -144,9 +148,11 @@ static void run_tests_aux(const char *skel_name,
144148
#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL)
145149

146150
void test_verifier_and(void) { RUN(verifier_and); }
151+
#ifdef ENABLE_ARENA_TESTS
147152
void test_verifier_arena(void) { RUN(verifier_arena); }
148153
void test_verifier_arena_large(void) { RUN(verifier_arena_large); }
149154
void test_verifier_arena_ldsx(void) { RUN(verifier_arena_ldsx); }
155+
#endif
150156
void test_verifier_basic_stack(void) { RUN(verifier_basic_stack); }
151157
void test_verifier_bitfield_write(void) { RUN(verifier_bitfield_write); }
152158
void test_verifier_bounds(void) { RUN(verifier_bounds); }

0 commit comments

Comments
 (0)