Skip to content

Commit 35ea03e

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 as needed (e.g. prog_tests/verifier.c). Signed-off-by: Tony Ambardar <[email protected]>
1 parent 8d534b3 commit 35ea03e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,16 @@ define DEFINE_TEST_RUNNER
540540
LSKEL_SIGN := -S -k $(PRIVATE_KEY) -i $(VERIFICATION_CERT)
541541
TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
542542
TRUNNER_BINARY := $1$(if $2,-)$2
543+
TRUNNER_TEST_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
544+
$$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
543545
TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
544-
$$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
546+
$$(TRUNNER_TEST_SRCS))
545547
TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
546548
$$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
547549
TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
548550
TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
549-
TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
551+
TRUNNER_BPF_SRCS := $$(filter-out $(TRUNNER_ARENA_FILTER), $$(notdir \
552+
$$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)))
550553
TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.bpf.o, $$(TRUNNER_BPF_SRCS))
551554
TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
552555
$$(filter-out $(SKEL_BLACKLIST) $(LINKED_BPF_SRCS),\
@@ -649,7 +652,9 @@ $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
649652
$$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
650653
$$(shell (echo '/* Generated header, do not edit */'; \
651654
sed -n -E 's/^void (serial_)?test_([a-zA-Z0-9_]+)\((void)?\).*/DEFINE_TEST(\2)/p' \
652-
$(TRUNNER_TESTS_DIR)/*.c | sort ; \
655+
$(TRUNNER_TESTS_DIR)/*.c \
656+
$$(if $(ENABLE_ARENA_TESTS),,| grep -v 'arena') \
657+
| sort ; \
653658
) > $$@)
654659
endif
655660

@@ -724,6 +729,8 @@ $(VERIFICATION_CERT) $(PRIVATE_KEY): $(VERIFY_SIG_SETUP)
724729
$(VERIFY_SIG_HDR): $(VERIFICATION_CERT)
725730
$(Q)xxd -i -n test_progs_verification_cert $< > $@
726731

732+
ENABLE_ARENA_TESTS := $(filter $(SRCARCH),x86 riscv s390 arm64)
733+
727734
# Define test_progs test runner.
728735
TRUNNER_TESTS_DIR := prog_tests
729736
TRUNNER_BPF_PROGS_DIR := progs
@@ -756,6 +763,10 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
756763
$(VERIFY_SIG_SETUP) \
757764
$(wildcard progs/btf_dump_test_case_*.c) \
758765
$(wildcard progs/*.bpf.o)
766+
ifeq ($(ENABLE_ARENA_TESTS),)
767+
TRUNNER_ARENA_FILTER := $(notdir $(wildcard prog_tests/*arena*.c) \
768+
$(wildcard progs/*arena*.c))
769+
endif
759770
TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
760771
TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS
761772
$(eval $(call DEFINE_TEST_RUNNER,test_progs))
@@ -897,6 +908,9 @@ $(OUTPUT)/uprobe_autoattach.test.o \
897908
$(OUTPUT)/usdt.test.o \
898909
$(OUTPUT)/uprobe_multi: CFLAGS += $(if $(filter arm, $(ARCH)),-marm)
899910

911+
# Disable arena verifier tests when unsupported
912+
$(OUTPUT)/verifier.test.o: CFLAGS += $(if $(ENABLE_ARENA_TESTS),-DENABLE_ARENA_TESTS)
913+
900914
EXTRA_CLEAN := $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \
901915
prog_tests/tests.h map_tests/tests.h verifier/tests.h \
902916
feature bpftool $(TEST_KMOD_TARGETS) \

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
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"
11+
#endif
12+
913
#include "verifier_array_access.skel.h"
1014
#include "verifier_basic_stack.skel.h"
1115
#include "verifier_bitfield_write.skel.h"
@@ -143,8 +147,10 @@ static void run_tests_aux(const char *skel_name,
143147
#define RUN(skel) run_tests_aux(#skel, skel##__elf_bytes, NULL)
144148

145149
void test_verifier_and(void) { RUN(verifier_and); }
150+
#ifdef ENABLE_ARENA_TESTS
146151
void test_verifier_arena(void) { RUN(verifier_arena); }
147152
void test_verifier_arena_large(void) { RUN(verifier_arena_large); }
153+
#endif
148154
void test_verifier_basic_stack(void) { RUN(verifier_basic_stack); }
149155
void test_verifier_bitfield_write(void) { RUN(verifier_bitfield_write); }
150156
void test_verifier_bounds(void) { RUN(verifier_bounds); }

0 commit comments

Comments
 (0)