Skip to content

Commit 9fa79d7

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 2f02be8 commit 9fa79d7

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 \
@@ -544,13 +548,16 @@ define DEFINE_TEST_RUNNER
544548
LSKEL_SIGN := -S -k $(PRIVATE_KEY) -i $(VERIFICATION_CERT)
545549
TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
546550
TRUNNER_BINARY := $1$(if $2,-)$2
551+
TRUNNER_TEST_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
552+
$$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
547553
TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
548-
$$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
554+
$$(TRUNNER_TEST_SRCS))
549555
TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
550556
$$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
551557
TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
552558
TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
553-
TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
559+
TRUNNER_BPF_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
560+
$$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)))
554561
TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.bpf.o, $$(TRUNNER_BPF_SRCS))
555562
TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
556563
$$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\
@@ -653,7 +660,9 @@ $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
653660
$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
654661
$$(shell (echo '/* Generated header, do not edit */'; \
655662
sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
656-
$(TRUNNER_TESTS_DIR)/*.c | sort ; \
663+
$(TRUNNER_TESTS_DIR)/*.c \
664+
$$(if $(ENABLE_ARENA_TESTS),,| grep -v 'arena') \
665+
| sort ; \
657666
) > $$@)
658667
endif
659668

@@ -760,6 +769,10 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
760769
$(VERIFY_SIG_SETUP) \
761770
$(wildcard progs/btf_dump_test_case_*.c) \
762771
$(wildcard progs/*.bpf.o)
772+
ifeq ($(ENABLE_ARENA_TESTS),)
773+
TRUNNER_ARENA_FILTER := $(notdir $(wildcard prog_tests/*arena*.c) \
774+
$(wildcard progs/*arena*.c))
775+
endif
763776
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
764777
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
765778
$(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"
@@ -145,9 +149,11 @@ static void run_tests_aux(const char *skel_name,
145149
#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL)
146150

147151
void test_verifier_and(void) { RUN(verifier_and); }
152+
#ifdef ENABLE_ARENA_TESTS
148153
void test_verifier_arena(void) { RUN(verifier_arena); }
149154
void test_verifier_arena_large(void) { RUN(verifier_arena_large); }
150155
void test_verifier_arena_ldsx(void) { RUN(verifier_arena_ldsx); }
156+
#endif
151157
void test_verifier_basic_stack(void) { RUN(verifier_basic_stack); }
152158
void test_verifier_bitfield_write(void) { RUN(verifier_bitfield_write); }
153159
void test_verifier_bounds(void) { RUN(verifier_bounds); }

0 commit comments

Comments
 (0)