Skip to content

Commit 77bc361

Browse files
committed
selftests/bpf: Skip building arena tests if unsupported
BPF selftests always try building with arena tests, but since kernel arena support is not built-in on unsupported archs, this leads to failures trying to build or run (e.g. seen with test_progs on 32-bit), and can complicate 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 <[email protected]>
1 parent 9725492 commit 77bc361

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
@@ -74,6 +74,10 @@ ifneq ($(shell $(CLANG) --target=bpf -mcpu=help 2>&1 | grep 'v4'),)
7474
CLANG_CPUV4 := 1
7575
endif
7676

77+
# Enable arena verifier tests only if supported
78+
ENABLE_ARENA_TESTS := $(filter $(SRCARCH),x86 riscv s390 arm64)
79+
CFLAGS += $(if $(ENABLE_ARENA_TESTS),-DENABLE_ARENA_TESTS)
80+
7781
# Order correspond to 'make run_tests' order
7882
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_progs \
7983
test_sockmap \
@@ -545,15 +549,18 @@ define DEFINE_TEST_RUNNER
545549
LSKEL_SIGN := -S -k $(PRIVATE_KEY) -i $(VERIFICATION_CERT)
546550
TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
547551
TRUNNER_BINARY := $1$(if $2,-)$2
552+
TRUNNER_TEST_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
553+
$$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
548554
TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
549-
$$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
555+
$$(TRUNNER_TEST_SRCS))
550556
TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
551557
$$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
552558
TRUNNER_LIB_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
553559
$$(filter %.c,$(TRUNNER_LIB_SOURCES)))
554560
TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
555561
TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
556-
TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
562+
TRUNNER_BPF_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
563+
$$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)))
557564
TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.bpf.o, $$(TRUNNER_BPF_SRCS))
558565
TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
559566
$$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\
@@ -656,7 +663,9 @@ $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
656663
$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
657664
$$(shell (echo '/* Generated header, do not edit */'; \
658665
sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
659-
$(TRUNNER_TESTS_DIR)/*.c | sort ; \
666+
$(TRUNNER_TESTS_DIR)/*.c \
667+
$$(if $(ENABLE_ARENA_TESTS),,| grep -v 'arena') \
668+
| sort ; \
660669
) > $$@)
661670
endif
662671

@@ -769,6 +778,10 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
769778
$(VERIFY_SIG_SETUP) \
770779
$(wildcard progs/btf_dump_test_case_*.c) \
771780
$(wildcard progs/*.bpf.o)
781+
ifeq ($(ENABLE_ARENA_TESTS),)
782+
TRUNNER_ARENA_FILTER := $(notdir $(wildcard prog_tests/*arena*.c) \
783+
$(wildcard progs/*arena*.c))
784+
endif
772785
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
773786
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
774787
$(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_async_cb_context.skel.h"
1216
#include "verifier_basic_stack.skel.h"
@@ -146,9 +150,11 @@ static void run_tests_aux(const char *skel_name,
146150
#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL)
147151

148152
void test_verifier_and(void) { RUN(verifier_and); }
153+
#ifdef ENABLE_ARENA_TESTS
149154
void test_verifier_arena(void) { RUN(verifier_arena); }
150155
void test_verifier_arena_large(void) { RUN(verifier_arena_large); }
151156
void test_verifier_arena_ldsx(void) { RUN(verifier_arena_ldsx); }
157+
#endif
152158
void test_verifier_basic_stack(void) { RUN(verifier_basic_stack); }
153159
void test_verifier_bitfield_write(void) { RUN(verifier_bitfield_write); }
154160
void test_verifier_bounds(void) { RUN(verifier_bounds); }

0 commit comments

Comments
 (0)