From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
yonghong.song@linux.dev, song@kernel.org, eddyz87@gmail.com,
me@manjusaka.me, leon.hwang@linux.dev, kernel-patches-bot@fb.com
Subject: [PATCH bpf-next v4 4/4] selftests/bpf: Add test case for freplace attachment failure log
Date: Mon, 24 Feb 2025 23:33:52 +0800 [thread overview]
Message-ID: <20250224153352.64689-5-leon.hwang@linux.dev> (raw)
In-Reply-To: <20250224153352.64689-1-leon.hwang@linux.dev>
This patch adds a selftest to verify that freplace attachment failure
produces meaningful log.
cd tools/testing/selftests/bpf/; ./test_progs -t attach_log
115 freplace_attach_log:OK
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
.../bpf/prog_tests/tracing_link_attach_log.c | 48 +++++++++++++++++++
1 file changed, 48 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/tracing_link_attach_log.c
diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_link_attach_log.c b/tools/testing/selftests/bpf/prog_tests/tracing_link_attach_log.c
new file mode 100644
index 0000000000000..92f770966f8cd
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_link_attach_log.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "tailcall_bpf2bpf1.skel.h"
+#include "freplace_global_func.skel.h"
+
+void test_freplace_attach_log(void)
+{
+ struct freplace_global_func *freplace_skel = NULL;
+ struct tailcall_bpf2bpf1 *tailcall_skel = NULL;
+ struct bpf_link *freplace_link = NULL;
+ struct bpf_program *prog;
+ char log_buf[64];
+ int err, prog_fd;
+ LIBBPF_OPTS(bpf_freplace_opts, freplace_opts,
+ .log_buf = log_buf,
+ .log_buf_size = sizeof(log_buf),
+ );
+
+ tailcall_skel = tailcall_bpf2bpf1__open_and_load();
+ if (!ASSERT_OK_PTR(tailcall_skel, "tailcall_bpf2bpf1__open_and_load"))
+ return;
+
+ freplace_skel = freplace_global_func__open();
+ if (!ASSERT_OK_PTR(freplace_skel, "freplace_global_func__open"))
+ goto out;
+
+ prog = freplace_skel->progs.new_test_pkt_access;
+ prog_fd = bpf_program__fd(tailcall_skel->progs.entry);
+ err = bpf_program__set_attach_target(prog, prog_fd, "entry");
+ if (!ASSERT_OK(err, "bpf_program__set_attach_target"))
+ goto out;
+
+ err = freplace_global_func__load(freplace_skel);
+ if (!ASSERT_OK(err, "freplace_global_func__load"))
+ goto out;
+
+ freplace_opts.prog = prog;
+ freplace_opts.target_prog_fd = prog_fd;
+ freplace_opts.attach_func_name = "subprog_tail";
+ freplace_link = bpf_program__attach_freplace_opts(&freplace_opts);
+ ASSERT_ERR_PTR(freplace_link, "bpf_program__attach_freplace");
+ ASSERT_STREQ(log_buf, "subprog_tail() is not a global function\n", "log_buf");
+
+out:
+ bpf_link__destroy(freplace_link);
+ freplace_global_func__destroy(freplace_skel);
+ tailcall_bpf2bpf1__destroy(tailcall_skel);
+}
--
2.47.1
prev parent reply other threads:[~2025-02-24 15:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-24 15:33 [PATCH bpf-next v4 0/4] bpf: Improve error reporting for freplace attachment failure Leon Hwang
2025-02-24 15:33 ` [PATCH bpf-next v4 1/4] bpf, verifier: Add missing newline of bpf_log in bpf_check_attach_target Leon Hwang
2025-02-24 15:33 ` [PATCH bpf-next v4 2/4] bpf: Improve error reporting for freplace attachment failure Leon Hwang
2025-02-24 19:41 ` Alexei Starovoitov
2025-02-24 22:08 ` Andrii Nakryiko
2025-02-25 13:59 ` Leon Hwang
2025-02-25 17:19 ` Andrii Nakryiko
2025-02-26 3:17 ` Alexei Starovoitov
2025-02-26 14:17 ` Leon Hwang
2025-02-25 13:50 ` Leon Hwang
2025-02-25 16:03 ` Alexei Starovoitov
2025-02-24 15:33 ` [PATCH bpf-next v4 3/4] bpf, libbpf: Capture error message of " Leon Hwang
2025-02-24 15:33 ` 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=20250224153352.64689-5-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=kernel-patches-bot@fb.com \
--cc=me@manjusaka.me \
--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