Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5aa5bd14 authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller
Browse files

bpf: add initial suite for selftests



Add a start of a test suite for kernel selftests. This moves test_verifier
and test_maps over to tools/testing/selftests/bpf/ along with various
code improvements and also adds a script for invoking test_bpf module.
The test suite can simply be run via selftest framework, f.e.:

  # cd tools/testing/selftests/bpf/
  # make
  # make run_tests

Both test_verifier and test_maps were kind of misplaced in samples/bpf/
directory and we were looking into adding them to selftests for a while
now, so it can be picked up by kbuild bot et al and hopefully also get
more exposure and thus new test case additions.

Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1a776b9c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2521,6 +2521,8 @@ L: netdev@vger.kernel.org
L:	linux-kernel@vger.kernel.org
S:	Supported
F:	kernel/bpf/
F:	tools/testing/selftests/bpf/
F:	lib/test_bpf.c

BROADCOM B44 10/100 ETHERNET DRIVER
M:	Michael Chan <michael.chan@broadcom.com>
@@ -8413,7 +8415,6 @@ F: include/uapi/linux/net_namespace.h
F:	tools/net/
F:	tools/testing/selftests/net/
F:	lib/random32.c
F:	lib/test_bpf.c

NETWORKING [IPv4/IPv6]
M:	"David S. Miller" <davem@davemloft.net>
+0 −3
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
obj- := dummy.o

# List of programs to build
hostprogs-y := test_verifier test_maps
hostprogs-y += sock_example
hostprogs-y += fds_example
hostprogs-y += sockex1
@@ -28,8 +27,6 @@ hostprogs-y += test_current_task_under_cgroup
hostprogs-y += trace_event
hostprogs-y += sampleip

test_verifier-objs := test_verifier.o libbpf.o
test_maps-objs := test_maps.o libbpf.o
sock_example-objs := sock_example.o libbpf.o
fds_example-objs := bpf_load.o libbpf.o fds_example.o
sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
+24 −0
Original line number Diff line number Diff line
@@ -218,6 +218,30 @@
		.off   = OFF,					\
		.imm   = IMM })

/* BPF_LD_IMM64 macro encodes single 'load 64-bit immediate' insn */

#define BPF_LD_IMM64(DST, IMM)					\
	BPF_LD_IMM64_RAW(DST, 0, IMM)

#define BPF_LD_IMM64_RAW(DST, SRC, IMM)				\
	((struct bpf_insn) {					\
		.code  = BPF_LD | BPF_DW | BPF_IMM,		\
		.dst_reg = DST,					\
		.src_reg = SRC,					\
		.off   = 0,					\
		.imm   = (__u32) (IMM) }),			\
	((struct bpf_insn) {					\
		.code  = 0, /* zero is reserved opcode */	\
		.dst_reg = 0,					\
		.src_reg = 0,					\
		.off   = 0,					\
		.imm   = ((__u64) (IMM)) >> 32 })

/* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */

#define BPF_LD_MAP_FD(DST, MAP_FD)				\
	BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD)

/* Program exit */

#define BPF_EXIT_INSN()						\
+2 −1
Original line number Diff line number Diff line
TARGETS = breakpoints
TARGETS =  bpf
TARGETS += breakpoints
TARGETS += capabilities
TARGETS += cpu-hotplug
TARGETS += efivarfs
+2 −0
Original line number Diff line number Diff line
test_verifier
test_maps
Loading