]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Add tracing multi attach fails test
authorJiri Olsa <jolsa@kernel.org>
Sat, 6 Jun 2026 12:39:51 +0000 (14:39 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 7 Jun 2026 17:03:03 +0000 (10:03 -0700)
Adding tests for attach fails on tracing multi link.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20260606123955.345967-27-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/prog_tests/tracing_multi.c
tools/testing/selftests/bpf/progs/tracing_multi_fail.c [new file with mode: 0644]

index 05683b8d068068eadcc2bba7a23f64821be13c73..7e1bb071ce2acc1b346b384e102bad334b6c4710 100644 (file)
@@ -8,6 +8,7 @@
 #include "tracing_multi_module.skel.h"
 #include "tracing_multi_intersect.skel.h"
 #include "tracing_multi_session.skel.h"
+#include "tracing_multi_fail.skel.h"
 #include "trace_helpers.h"
 
 static __u64 bpf_fentry_test_cookies[] = {
@@ -498,6 +499,99 @@ cleanup:
        tracing_multi_session__destroy(skel);
 }
 
+static void test_attach_api_fails(void)
+{
+       LIBBPF_OPTS(bpf_tracing_multi_opts, opts);
+       static const char * const func[] = {
+               "bpf_fentry_test2",
+       };
+       struct tracing_multi_fail *skel = NULL;
+       __u32 ids[2] = {}, *ids2 = NULL;
+       __u64 cookies[2];
+
+       skel = tracing_multi_fail__open_and_load();
+       if (!ASSERT_OK_PTR(skel, "tracing_multi_fail__open_and_load"))
+               return;
+
+       /* fail#1 (libbpf) pattern and opts NULL */
+       skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+                                               NULL, NULL);
+       if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_1"))
+               goto cleanup;
+
+       /* fail#2 (libbpf) pattern and ids */
+       LIBBPF_OPTS_RESET(opts,
+               .ids = ids,
+               .cnt = 2,
+       );
+
+       skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+                                               "bpf_fentry_test*", &opts);
+       if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_2"))
+               goto cleanup;
+
+       /* fail#3 (libbpf) pattern and cookies */
+       LIBBPF_OPTS_RESET(opts,
+               .ids = NULL,
+               .cnt = 2,
+               .cookies = cookies,
+       );
+
+       skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+                                               "bpf_fentry_test*", &opts);
+       if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_3"))
+               goto cleanup;
+
+       /* fail#4 (libbpf) bogus pattern */
+       skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+                                               "bpf_not_really_a_function*", NULL);
+       if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_4"))
+               goto cleanup;
+
+       /* fail#5 (kernel) abnormal cnt */
+       LIBBPF_OPTS_RESET(opts,
+               .ids = ids,
+               .cnt = INT_MAX,
+       );
+
+       skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+                                               NULL, &opts);
+       if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -E2BIG, "fail_5"))
+               goto cleanup;
+
+       /* fail#6 (kernel) attach sleepable program to not-allowed function */
+       ids2 = get_ids(func, 1, NULL);
+       if (!ASSERT_OK_PTR(ids2, "get_ids"))
+               goto cleanup;
+
+       LIBBPF_OPTS_RESET(opts,
+               .ids = ids2,
+               .cnt = 1,
+       );
+
+       skel->links.test_fentry_s = bpf_program__attach_tracing_multi(skel->progs.test_fentry_s,
+                                               NULL, &opts);
+       if (!ASSERT_EQ(libbpf_get_error(skel->links.test_fentry_s), -EINVAL, "fail_6"))
+               goto cleanup;
+
+       /* fail#7 (kernel) attach with duplicate id */
+       ids[0] = ids2[0];
+       ids[1] = ids2[0];
+
+       LIBBPF_OPTS_RESET(opts,
+               .ids = ids,
+               .cnt = 2,
+       );
+
+       skel->links.test_fentry = bpf_program__attach_tracing_multi(skel->progs.test_fentry,
+                                               NULL, &opts);
+       ASSERT_EQ(libbpf_get_error(skel->links.test_fentry), -EINVAL, "fail_7");
+
+cleanup:
+       tracing_multi_fail__destroy(skel);
+       free(ids2);
+}
+
 void test_tracing_multi_test(void)
 {
 #ifndef __x86_64__
@@ -523,4 +617,6 @@ void test_tracing_multi_test(void)
                test_link_api_ids(true);
        if (test__start_subtest("session"))
                test_session();
+       if (test__start_subtest("attach_api_fails"))
+               test_attach_api_fails();
 }
diff --git a/tools/testing/selftests/bpf/progs/tracing_multi_fail.c b/tools/testing/selftests/bpf/progs/tracing_multi_fail.c
new file mode 100644 (file)
index 0000000..7f0375f
--- /dev/null
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("fentry.multi")
+int BPF_PROG(test_fentry)
+{
+       return 0;
+}
+
+SEC("fentry.multi.s")
+int BPF_PROG(test_fentry_s)
+{
+       return 0;
+}