From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Steven Rostedt <rostedt@goodmis.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
KP Singh <kpsingh@kernel.org>,
Matt Bobrowski <matt@bobrowski.net>,
Shuah Khan <shuah@kernel.org>, Leon Hwang <leon.hwang@linux.dev>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH bpf-next v4 6/6] selftests/bpf: Test tracing and cgroup link creation logs
Date: Wed, 25 Nov 2026 22:31:38 +0800 [thread overview]
Message-ID: <20261125143138.47174-7-leon.hwang@linux.dev> (raw)
In-Reply-To: <20261125143138.47174-1-leon.hwang@linux.dev>
Check the errno, diagnostic text and reported log size for one failed
attachment each for tracing, tracing_multi, iter and cgroup links.
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
.../selftests/bpf/prog_tests/link_log.c | 85 +++++++++++++++++++
1 file changed, 85 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/link_log.c
diff --git a/tools/testing/selftests/bpf/prog_tests/link_log.c b/tools/testing/selftests/bpf/prog_tests/link_log.c
new file mode 100644
index 000000000000..8a05d6c48d9b
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/link_log.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+
+static const struct link_log_case {
+ const char *name;
+ enum bpf_prog_type type;
+ enum bpf_attach_type attach_type;
+ const char *func;
+ struct bpf_link_create_opts opts;
+ int err;
+ const char *msg;
+} tests[] = {
+ { "tracing", BPF_PROG_TYPE_TRACING, BPF_TRACE_FENTRY, "bpf_fentry_test1",
+ { .target_btf_id = 1 }, -EINVAL, "target_btf_id" },
+#ifdef __x86_64__
+ { "tracing_multi", BPF_PROG_TYPE_TRACING, BPF_TRACE_FENTRY_MULTI, NULL,
+ { .tracing_multi = { .ids = (const __u32[]){ ~0U }, .cnt = 1 } },
+ -EINVAL, "4294967295" },
+#endif
+ { "iter", BPF_PROG_TYPE_TRACING, BPF_TRACE_ITER, "bpf_map",
+ { .iter.len = sizeof(union bpf_iter_link_info) }, -EINVAL, "iter_info_len" },
+ { "cgroup", BPF_PROG_TYPE_CGROUP_SKB, BPF_CGROUP_INET_EGRESS, NULL,
+ { .cgroup.expected_revision = 2 }, -ESTALE, "revision" },
+};
+
+static void run_test(const struct link_log_case *test)
+{
+ const struct bpf_insn insns[] = {
+ BPF_MOV64_IMM(BPF_REG_0, 0),
+ BPF_EXIT_INSN(),
+ };
+ struct bpf_link_create_opts opts = test->opts;
+ int prog_fd, fd, btf_id, cg = -1;
+ LIBBPF_OPTS(bpf_prog_load_opts, load_opts,
+ .expected_attach_type = test->attach_type,
+ );
+ char buf[128] = {};
+ LIBBPF_OPTS(bpf_log_opts, log_opts,
+ .buf = buf,
+ .size = sizeof(buf),
+ .level = 1,
+ );
+
+ if (test->func) {
+ btf_id = libbpf_find_vmlinux_btf_id(test->func, test->attach_type);
+ if (!ASSERT_GT(btf_id, 0, "attach_btf_id"))
+ return;
+
+ load_opts.attach_btf_id = btf_id;
+ }
+
+ prog_fd = bpf_prog_load(test->type, NULL, "GPL", insns, ARRAY_SIZE(insns), &load_opts);
+ if (!ASSERT_OK_FD(prog_fd, "bpf_prog_load"))
+ return;
+
+ if (test->type == BPF_PROG_TYPE_CGROUP_SKB) {
+ cg = test__join_cgroup("/link_log");
+ if (!ASSERT_OK_FD(cg, "join_cgroup"))
+ goto out;
+ }
+
+ opts.sz = sizeof(opts);
+ opts.log_opts = &log_opts;
+ fd = bpf_link_create(prog_fd, cg < 0 ? 0 : cg, test->attach_type, &opts);
+ if (fd >= 0)
+ close(fd);
+
+ ASSERT_EQ(fd, test->err, "err");
+ ASSERT_HAS_SUBSTR(buf, test->msg, "log");
+ ASSERT_EQ(log_opts.true_size, strlen(buf) + 1, "true_size");
+
+ if (cg >= 0)
+ close(cg);
+out:
+ close(prog_fd);
+}
+
+void test_link_log(void)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(tests); i++)
+ if (test__start_subtest(tests[i].name))
+ run_test(&tests[i]);
+}
--
2.55.0
prev parent reply other threads:[~2026-11-25 14:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 14:31 [PATCH bpf-next v4 0/6] bpf: Add log support for tracing link_create Leon Hwang
2026-11-25 14:31 ` [PATCH bpf-next v4 1/6] " Leon Hwang
2026-11-25 14:31 ` [PATCH bpf-next v4 2/6] bpf: Add log support for tracing_multi link_create Leon Hwang
2026-11-25 14:31 ` [PATCH bpf-next v4 3/6] bpf: Add log support for iter link_create Leon Hwang
2026-11-25 14:31 ` [PATCH bpf-next v4 4/6] bpf: Add log support for cgroup prog link_create Leon Hwang
2026-11-25 14:31 ` [PATCH bpf-next v4 5/6] libbpf: Add log_opts support for BPF_TRACE_ITER Leon Hwang
2026-11-25 14:31 ` Leon Hwang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125143138.47174-7-leon.hwang@linux.dev \
--to=leon.hwang@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mathieu.desnoyers@efficios.com \
--cc=matt@bobrowski.net \
--cc=memxor@gmail.com \
--cc=mhiramat@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®