[PATCH bpf-next v2 7/9] selftests/bpf: Verify tracing_multi link_create logs
From: Leon Hwang
Date: Sat Nov 14 2026 - 10:08:25 EST
Check the error code, log message, and reported log size for a zero or
excessive count, missing IDs, invalid flags, and a nonzero target FD.
Signed-off-by: Leon Hwang <leon.hwang@xxxxxxxxx>
---
.../selftests/bpf/prog_tests/tracing_link.c | 102 ++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_link.c b/tools/testing/selftests/bpf/prog_tests/tracing_link.c
index 28154fdd2f0c..49fd62478438 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_link.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_link.c
@@ -6,6 +6,7 @@
#include "xdp_dummy.skel.h"
#include "kprobe_write_ctx.skel.h"
#include "tracing_link_ctx.skel.h"
+#include "tracing_multi_fail.skel.h"
static void test_fentry_link_create_log(int target_fd, __u32 target_btf_id, int cookie,
enum bpf_attach_type attach_type,
@@ -325,3 +326,104 @@ void test_tracing_link_log(void)
if (test__start_subtest("freplace_ctx_size"))
test_log_freplace_ctx_size();
}
+
+static void test_tracing_multi_link_create_log(int target_fd, __u32 flags, const __u32 *ids,
+ __u32 cnt, int err_exp, const char *msg)
+{
+ struct tracing_multi_fail *skel;
+ char log_buf[128] = {};
+ int err, fd, prog_fd;
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = log_buf,
+ .size = sizeof(log_buf),
+ .level = 1,
+ );
+ LIBBPF_OPTS(bpf_link_create_opts, opts,
+ .log_opts = &log_opts,
+ .flags = flags,
+ .tracing_multi.ids = ids,
+ .tracing_multi.cnt = cnt,
+ );
+
+ skel = tracing_multi_fail__open();
+ if (!ASSERT_OK_PTR(skel, "tracing_multi_fail__open"))
+ return;
+
+ bpf_program__set_autoload(skel->progs.test_fentry_s, false);
+ err = tracing_multi_fail__load(skel);
+ if (!ASSERT_OK(err, "tracing_multi_fail__load"))
+ goto out;
+
+ prog_fd = bpf_program__fd(skel->progs.test_fentry);
+ fd = bpf_link_create(prog_fd, target_fd, BPF_TRACE_FENTRY_MULTI, &opts);
+ if (!ASSERT_LT(fd, 0, "bpf_link_create")) {
+ close(fd);
+ goto out;
+ }
+
+ ASSERT_EQ(fd, err_exp, "err");
+ ASSERT_STREQ(log_buf, msg, "log_buf");
+ ASSERT_EQ(log_opts.true_size, strlen(msg) + 1, "log_size");
+
+out:
+ tracing_multi_fail__destroy(skel);
+}
+
+static void test_multi_log_zero_count(void)
+{
+ const char *msg = "tracing_multi.cnt cannot be zero.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(0, 0, &id, 0, -EINVAL, msg);
+}
+
+static void test_multi_log_missing_ids(void)
+{
+ const char *msg = "tracing_multi.ids must be set.\n";
+
+ test_tracing_multi_link_create_log(0, 0, NULL, 1, -EINVAL, msg);
+}
+
+static void test_multi_log_excessive_count(void)
+{
+ const char *msg = "tracing_multi.cnt is too large.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(0, 0, &id, INT_MAX, -E2BIG, msg);
+}
+
+static void test_multi_log_invalid_flags(void)
+{
+ const char *msg = "Invalid flags.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(0, 1, &id, 1, -EINVAL, msg);
+}
+
+static void test_multi_log_invalid_target_fd(void)
+{
+ const char *msg = "Invalid target_fd.\n";
+ __u32 id = 0;
+
+ test_tracing_multi_link_create_log(-1, 0, &id, 1, -EINVAL, msg);
+}
+
+void test_tracing_multi_link_log(void)
+{
+#ifndef __x86_64__
+ test__skip();
+ return;
+#endif
+
+ if (test__start_subtest("zero_count"))
+ test_multi_log_zero_count();
+ if (test__start_subtest("missing_ids"))
+ test_multi_log_missing_ids();
+ if (test__start_subtest("excessive_count"))
+ test_multi_log_excessive_count();
+ if (test__start_subtest("invalid_flags"))
+ test_multi_log_invalid_flags();
+ if (test__start_subtest("invalid_target_fd"))
+ test_multi_log_invalid_target_fd();
+}
+
--
2.55.0