Skip to content

Commit f09b2e3

Browse files
netoptimizerborkmann
authored andcommitted
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 864db33 commit f09b2e3

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

tools/testing/selftests/bpf/Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,34 @@ endif
1313
CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
1414
LDLIBS += -lcap -lelf -lrt -lpthread
1515

16+
# Order correspond to 'make run_tests' order
1617
TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
1718
test_align test_verifier_log test_dev_cgroup test_tcpbpf_user
1819

1920
TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
2021
test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
2122
sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \
2223
test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \
23-
sample_map_ret0.o test_tcpbpf_kern.o test_libbpf_open
24+
sample_map_ret0.o test_tcpbpf_kern.o
2425

25-
TEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh \
26+
# Order correspond to 'make run_tests' order
27+
TEST_PROGS := test_kmod.sh \
28+
test_libbpf.sh \
29+
test_xdp_redirect.sh \
30+
test_xdp_meta.sh \
2631
test_offload.py
2732

33+
# Compile but not part of 'make run_tests'
34+
TEST_GEN_PROGS_EXTENDED = test_libbpf_open
35+
2836
include ../lib.mk
2937

3038
BPFOBJ := $(OUTPUT)/libbpf.a cgroup_helpers.c
3139

3240
$(TEST_GEN_PROGS): $(BPFOBJ)
3341

42+
$(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a
43+
3444
.PHONY: force
3545

3646
# force a rebuild of BPFOBJ when its dependencies are updated
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

0 commit comments

Comments
 (0)