]>
Commit | Line | Data |
---|---|---|
ba172962 SL |
1 | From a233828ccb15c264a66b6ad66283357fbf856632 Mon Sep 17 00:00:00 2001 |
2 | From: Stanislav Fomichev <sdf@google.com> | |
3 | Date: Mon, 28 Jan 2019 09:21:16 -0800 | |
4 | Subject: selftests/bpf: skip verifier tests for unsupported program types | |
5 | ||
6 | [ Upstream commit 8184d44c9a577a2f1842ed6cc844bfd4a9981d8e ] | |
7 | ||
8 | Use recently introduced bpf_probe_prog_type() to skip tests in the | |
9 | test_verifier() if bpf_verify_program() fails. The skipped test is | |
10 | indicated in the output. | |
11 | ||
12 | Example: | |
13 | ||
14 | ... | |
15 | 679/p bpf_get_stack return R0 within range SKIP (unsupported program | |
16 | type 5) | |
17 | 680/p ld_abs: invalid op 1 OK | |
18 | ... | |
19 | Summary: 863 PASSED, 165 SKIPPED, 3 FAILED | |
20 | ||
21 | Signed-off-by: Stanislav Fomichev <sdf@google.com> | |
22 | Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> | |
23 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
24 | --- | |
25 | tools/testing/selftests/bpf/test_verifier.c | 9 ++++++++- | |
26 | 1 file changed, 8 insertions(+), 1 deletion(-) | |
27 | ||
28 | diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c | |
29 | index 9db5a7378f40..294fc18aba2a 100644 | |
30 | --- a/tools/testing/selftests/bpf/test_verifier.c | |
31 | +++ b/tools/testing/selftests/bpf/test_verifier.c | |
32 | @@ -32,6 +32,7 @@ | |
33 | #include <linux/if_ether.h> | |
34 | ||
35 | #include <bpf/bpf.h> | |
36 | +#include <bpf/libbpf.h> | |
37 | ||
38 | #ifdef HAVE_GENHDR | |
39 | # include "autoconf.h" | |
40 | @@ -56,6 +57,7 @@ | |
41 | ||
42 | #define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled" | |
43 | static bool unpriv_disabled = false; | |
44 | +static int skips; | |
45 | ||
46 | struct bpf_test { | |
47 | const char *descr; | |
48 | @@ -12770,6 +12772,11 @@ static void do_test_single(struct bpf_test *test, bool unpriv, | |
49 | fd_prog = bpf_verify_program(prog_type ? : BPF_PROG_TYPE_SOCKET_FILTER, | |
50 | prog, prog_len, test->flags & F_LOAD_WITH_STRICT_ALIGNMENT, | |
51 | "GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1); | |
52 | + if (fd_prog < 0 && !bpf_probe_prog_type(prog_type, 0)) { | |
53 | + printf("SKIP (unsupported program type %d)\n", prog_type); | |
54 | + skips++; | |
55 | + goto close_fds; | |
56 | + } | |
57 | ||
58 | expected_ret = unpriv && test->result_unpriv != UNDEF ? | |
59 | test->result_unpriv : test->result; | |
60 | @@ -12905,7 +12912,7 @@ static void get_unpriv_disabled() | |
61 | ||
62 | static int do_test(bool unpriv, unsigned int from, unsigned int to) | |
63 | { | |
64 | - int i, passes = 0, errors = 0, skips = 0; | |
65 | + int i, passes = 0, errors = 0; | |
66 | ||
67 | for (i = from; i < to; i++) { | |
68 | struct bpf_test *test = &tests[i]; | |
69 | -- | |
70 | 2.19.1 | |
71 |