diff options
author | Jesper Dangaard Brouer <brouer@redhat.com> | 2018-02-08 06:48:27 -0500 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-02-08 18:25:12 -0500 |
commit | f09b2e382e9a7053e3ae6f2fb6535efd5760cf5d (patch) | |
tree | 91b16d7227e33007319adfed253b945425a1dbec /tools | |
parent | 864db336c677c288d81524c30a656804785902f9 (diff) |
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/bpf/Makefile | 14 | ||||
-rwxr-xr-x | tools/testing/selftests/bpf/test_libbpf.sh | 49 |
2 files changed, 61 insertions, 2 deletions
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 3f48da0866ba..5c43c187f27c 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile | |||
@@ -13,6 +13,7 @@ endif | |||
13 | CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include | 13 | CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include |
14 | LDLIBS += -lcap -lelf -lrt -lpthread | 14 | LDLIBS += -lcap -lelf -lrt -lpthread |
15 | 15 | ||
16 | # Order correspond to 'make run_tests' order | ||
16 | TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ | 17 | TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ |
17 | test_align test_verifier_log test_dev_cgroup test_tcpbpf_user | 18 | test_align test_verifier_log test_dev_cgroup test_tcpbpf_user |
18 | 19 | ||
@@ -20,17 +21,26 @@ TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test | |||
20 | test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ | 21 | test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ |
21 | sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ | 22 | sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ |
22 | test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \ | 23 | 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 |
24 | 25 | ||
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 \ | ||
26 | test_offload.py | 31 | test_offload.py |
27 | 32 | ||
33 | # Compile but not part of 'make run_tests' | ||
34 | TEST_GEN_PROGS_EXTENDED = test_libbpf_open | ||
35 | |||
28 | include ../lib.mk | 36 | include ../lib.mk |
29 | 37 | ||
30 | BPFOBJ := $(OUTPUT)/libbpf.a cgroup_helpers.c | 38 | BPFOBJ := $(OUTPUT)/libbpf.a cgroup_helpers.c |
31 | 39 | ||
32 | $(TEST_GEN_PROGS): $(BPFOBJ) | 40 | $(TEST_GEN_PROGS): $(BPFOBJ) |
33 | 41 | ||
42 | $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a | ||
43 | |||
34 | .PHONY: force | 44 | .PHONY: force |
35 | 45 | ||
36 | # force a rebuild of BPFOBJ when its dependencies are updated | 46 | # force a rebuild of BPFOBJ when its dependencies are updated |
diff --git a/tools/testing/selftests/bpf/test_libbpf.sh b/tools/testing/selftests/bpf/test_libbpf.sh new file mode 100755 index 000000000000..d97dc914cd49 --- /dev/null +++ b/tools/testing/selftests/bpf/test_libbpf.sh | |||
@@ -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 | ||