Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: add selftest that use test_libbpf_open

This script test_libbpf.sh will be part of the 'make run_tests'
invocation, but can also be invoked manually in this directory,
and a verbose mode can be enabled via setting the environment
variable $VERBOSE like:

$ VERBOSE=yes ./test_libbpf.sh

The script contains some tests that are commented out, as they
currently fail. They are reminders about what we need to improve
for the libbpf loader library.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Jesper Dangaard Brouer and committed by
Daniel Borkmann
f09b2e38 864db336

+61 -2
+12 -2
tools/testing/selftests/bpf/Makefile
··· 13 13 CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include 14 14 LDLIBS += -lcap -lelf -lrt -lpthread 15 15 16 + # Order correspond to 'make run_tests' order 16 17 TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ 17 18 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user 18 19 ··· 21 20 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ 22 21 sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ 23 22 test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \ 24 - sample_map_ret0.o test_tcpbpf_kern.o test_libbpf_open 23 + sample_map_ret0.o test_tcpbpf_kern.o 25 24 26 - TEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh \ 25 + # Order correspond to 'make run_tests' order 26 + TEST_PROGS := test_kmod.sh \ 27 + test_libbpf.sh \ 28 + test_xdp_redirect.sh \ 29 + test_xdp_meta.sh \ 27 30 test_offload.py 31 + 32 + # Compile but not part of 'make run_tests' 33 + TEST_GEN_PROGS_EXTENDED = test_libbpf_open 28 34 29 35 include ../lib.mk 30 36 31 37 BPFOBJ := $(OUTPUT)/libbpf.a cgroup_helpers.c 32 38 33 39 $(TEST_GEN_PROGS): $(BPFOBJ) 40 + 41 + $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a 34 42 35 43 .PHONY: force 36 44
+49
tools/testing/selftests/bpf/test_libbpf.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + export TESTNAME=test_libbpf 5 + 6 + # Determine selftest success via shell exit code 7 + exit_handler() 8 + { 9 + if (( $? == 0 )); then 10 + echo "selftests: $TESTNAME [PASS]"; 11 + else 12 + echo "$TESTNAME: failed at file $LAST_LOADED" 1>&2 13 + echo "selftests: $TESTNAME [FAILED]"; 14 + fi 15 + } 16 + 17 + libbpf_open_file() 18 + { 19 + LAST_LOADED=$1 20 + if [ -n "$VERBOSE" ]; then 21 + ./test_libbpf_open $1 22 + else 23 + ./test_libbpf_open --quiet $1 24 + fi 25 + } 26 + 27 + # Exit script immediately (well catched by trap handler) if any 28 + # program/thing exits with a non-zero status. 29 + set -e 30 + 31 + # (Use 'trap -l' to list meaning of numbers) 32 + trap exit_handler 0 2 3 6 9 33 + 34 + libbpf_open_file test_l4lb.o 35 + 36 + # TODO: fix libbpf to load noinline functions 37 + # [warning] libbpf: incorrect bpf_call opcode 38 + #libbpf_open_file test_l4lb_noinline.o 39 + 40 + # TODO: fix test_xdp_meta.c to load with libbpf 41 + # [warning] libbpf: test_xdp_meta.o doesn't provide kernel version 42 + #libbpf_open_file test_xdp_meta.o 43 + 44 + # TODO: fix libbpf to handle .eh_frame 45 + # [warning] libbpf: relocation failed: no section(10) 46 + #libbpf_open_file ../../../../samples/bpf/tracex3_kern.o 47 + 48 + # Success 49 + exit 0