Skip to content

Commit 8184d44

Browse files
fomichevborkmann
authored andcommitted
selftests/bpf: skip verifier tests for unsupported program types
Use recently introduced bpf_probe_prog_type() to skip tests in the test_verifier() if bpf_verify_program() fails. The skipped test is indicated in the output. Example: ... 679/p bpf_get_stack return R0 within range SKIP (unsupported program type 5) 680/p ld_abs: invalid op 1 OK ... Summary: 863 PASSED, 165 SKIPPED, 3 FAILED Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent e8ddbfb commit 8184d44

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/testing/selftests/bpf/test_verifier.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/if_ether.h>
3535

3636
#include <bpf/bpf.h>
37+
#include <bpf/libbpf.h>
3738

3839
#ifdef HAVE_GENHDR
3940
# include "autoconf.h"
@@ -59,6 +60,7 @@
5960

6061
#define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled"
6162
static bool unpriv_disabled = false;
63+
static int skips;
6264

6365
struct bpf_test {
6466
const char *descr;
@@ -598,6 +600,11 @@ static void do_test_single(struct bpf_test *test, bool unpriv,
598600
pflags |= BPF_F_ANY_ALIGNMENT;
599601
fd_prog = bpf_verify_program(prog_type, prog, prog_len, pflags,
600602
"GPL", 0, bpf_vlog, sizeof(bpf_vlog), 1);
603+
if (fd_prog < 0 && !bpf_probe_prog_type(prog_type, 0)) {
604+
printf("SKIP (unsupported program type %d)\n", prog_type);
605+
skips++;
606+
goto close_fds;
607+
}
601608

602609
expected_ret = unpriv && test->result_unpriv != UNDEF ?
603610
test->result_unpriv : test->result;
@@ -751,7 +758,7 @@ static bool test_as_unpriv(struct bpf_test *test)
751758

752759
static int do_test(bool unpriv, unsigned int from, unsigned int to)
753760
{
754-
int i, passes = 0, errors = 0, skips = 0;
761+
int i, passes = 0, errors = 0;
755762

756763
for (i = from; i < to; i++) {
757764
struct bpf_test *test = &tests[i];

0 commit comments

Comments
 (0)