Commit bad2e478 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

selftests/bpf: Turn on libbpf 1.0 mode and fix all IS_ERR checks



Turn ony libbpf 1.0 mode. Fix all the explicit IS_ERR checks that now will be
broken because libbpf returns NULL on error (and sets errno). Fix
ASSERT_OK_PTR and ASSERT_ERR_PTR to work for both old mode and new modes and
use them throughout selftests. This is trivial to do by using
libbpf_get_error() API that all libbpf users are supposed to use, instead of
IS_ERR checks.

A bunch of checks also did explicit -1 comparison for various fd-returning
APIs. Such checks are replaced with >= 0 or < 0 cases.

There were also few misuses of bpf_object__find_map_by_name() in test_maps.
Those are fixed in this patch as well.

Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Acked-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/20210525035935.1461796-3-andrii@kernel.org
parent 5981881d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ void setup_libbpf()
{
	int err;

	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
	libbpf_set_print(libbpf_print_fn);

	err = bump_memlock_rlimit();
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ static void attach_bpf(struct bpf_program *prog)
	struct bpf_link *link;

	link = bpf_program__attach(prog);
	if (IS_ERR(link)) {
	if (!link) {
		fprintf(stderr, "failed to attach program!\n");
		exit(1);
	}
+3 −3
Original line number Diff line number Diff line
@@ -181,7 +181,7 @@ static void ringbuf_libbpf_setup()
	}

	link = bpf_program__attach(ctx->skel->progs.bench_ringbuf);
	if (IS_ERR(link)) {
	if (!link) {
		fprintf(stderr, "failed to attach program!\n");
		exit(1);
	}
@@ -271,7 +271,7 @@ static void ringbuf_custom_setup()
	}

	link = bpf_program__attach(ctx->skel->progs.bench_ringbuf);
	if (IS_ERR(link)) {
	if (!link) {
		fprintf(stderr, "failed to attach program\n");
		exit(1);
	}
@@ -430,7 +430,7 @@ static void perfbuf_libbpf_setup()
	}

	link = bpf_program__attach(ctx->skel->progs.bench_perfbuf);
	if (IS_ERR(link)) {
	if (!link) {
		fprintf(stderr, "failed to attach program\n");
		exit(1);
	}
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ static void attach_bpf(struct bpf_program *prog)
	struct bpf_link *link;

	link = bpf_program__attach(prog);
	if (IS_ERR(link)) {
	if (!link) {
		fprintf(stderr, "failed to attach program!\n");
		exit(1);
	}
+4 −8
Original line number Diff line number Diff line
@@ -85,16 +85,14 @@ void test_attach_probe(void)
	kprobe_link = bpf_program__attach_kprobe(skel->progs.handle_kprobe,
						 false /* retprobe */,
						 SYS_NANOSLEEP_KPROBE_NAME);
	if (CHECK(IS_ERR(kprobe_link), "attach_kprobe",
		  "err %ld\n", PTR_ERR(kprobe_link)))
	if (!ASSERT_OK_PTR(kprobe_link, "attach_kprobe"))
		goto cleanup;
	skel->links.handle_kprobe = kprobe_link;

	kretprobe_link = bpf_program__attach_kprobe(skel->progs.handle_kretprobe,
						    true /* retprobe */,
						    SYS_NANOSLEEP_KPROBE_NAME);
	if (CHECK(IS_ERR(kretprobe_link), "attach_kretprobe",
		  "err %ld\n", PTR_ERR(kretprobe_link)))
	if (!ASSERT_OK_PTR(kretprobe_link, "attach_kretprobe"))
		goto cleanup;
	skel->links.handle_kretprobe = kretprobe_link;

@@ -103,8 +101,7 @@ void test_attach_probe(void)
						 0 /* self pid */,
						 "/proc/self/exe",
						 uprobe_offset);
	if (CHECK(IS_ERR(uprobe_link), "attach_uprobe",
		  "err %ld\n", PTR_ERR(uprobe_link)))
	if (!ASSERT_OK_PTR(uprobe_link, "attach_uprobe"))
		goto cleanup;
	skel->links.handle_uprobe = uprobe_link;

@@ -113,8 +110,7 @@ void test_attach_probe(void)
						    -1 /* any pid */,
						    "/proc/self/exe",
						    uprobe_offset);
	if (CHECK(IS_ERR(uretprobe_link), "attach_uretprobe",
		  "err %ld\n", PTR_ERR(uretprobe_link)))
	if (!ASSERT_OK_PTR(uretprobe_link, "attach_uretprobe"))
		goto cleanup;
	skel->links.handle_uretprobe = uretprobe_link;

Loading