]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Add cookies check for tracing fill_link_info test
authorTao Chen <chen.dylane@linux.dev>
Fri, 6 Jun 2025 16:58:15 +0000 (00:58 +0800)
committerAndrii Nakryiko <andrii@kernel.org>
Mon, 9 Jun 2025 23:45:17 +0000 (16:45 -0700)
Adding tests for getting cookie with fill_link_info for tracing.

Signed-off-by: Tao Chen <chen.dylane@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250606165818.3394397-2-chen.dylane@linux.dev
tools/testing/selftests/bpf/prog_tests/bpf_cookie.c

index 0774ae6c1becfd818802f791838494ca8fd07507..4a0670c056bad694076e20424a4b1e86f4f6ebde 100644 (file)
@@ -489,10 +489,28 @@ cleanup:
        bpf_link__destroy(link);
 }
 
+static int verify_tracing_link_info(int fd, u64 cookie)
+{
+       struct bpf_link_info info;
+       int err;
+       u32 len = sizeof(info);
+
+       err = bpf_link_get_info_by_fd(fd, &info, &len);
+       if (!ASSERT_OK(err, "get_link_info"))
+               return -1;
+
+       if (!ASSERT_EQ(info.type, BPF_LINK_TYPE_TRACING, "link_type"))
+               return -1;
+
+       ASSERT_EQ(info.tracing.cookie, cookie, "tracing_cookie");
+
+       return 0;
+}
+
 static void tracing_subtest(struct test_bpf_cookie *skel)
 {
        __u64 cookie;
-       int prog_fd;
+       int prog_fd, err;
        int fentry_fd = -1, fexit_fd = -1, fmod_ret_fd = -1;
        LIBBPF_OPTS(bpf_test_run_opts, opts);
        LIBBPF_OPTS(bpf_link_create_opts, link_opts);
@@ -507,6 +525,10 @@ static void tracing_subtest(struct test_bpf_cookie *skel)
        if (!ASSERT_GE(fentry_fd, 0, "fentry.link_create"))
                goto cleanup;
 
+       err = verify_tracing_link_info(fentry_fd, cookie);
+       if (!ASSERT_OK(err, "verify_tracing_link_info"))
+               goto cleanup;
+
        cookie = 0x20000000000000L;
        prog_fd = bpf_program__fd(skel->progs.fexit_test1);
        link_opts.tracing.cookie = cookie;