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 v3 4/4] selftests/bpf: Add test case for freplace attachment failure logging
Date: Mon, 17 Feb 2025 23:43:18 +0800 [thread overview]
Message-ID: <20250217154318.76145-5-leon.hwang@linux.dev> (raw)
In-Reply-To: <20250217154318.76145-1-leon.hwang@linux.dev>
This patch adds a selftest to verify that freplace attachment failure
produces meaningful logs.
cd tools/testing/selftests/bpf/; ./test_progs -t attach_log -v
test_freplace_attach_log:PASS:tailcall_bpf2bpf1__open_and_load 0 nsec
test_freplace_attach_log:PASS:freplace_global_func__open 0 nsec
test_freplace_attach_log:PASS:bpf_program__set_attach_target 0 nsec
test_freplace_attach_log:PASS:freplace_global_func__load 0 nsec
libbpf: prog 'new_test_pkt_access': failed to attach to freplace: -EINVAL
libbpf: prog 'new_test_pkt_access': attach log: subprog_tail() is not a global function
test_freplace_attach_log:PASS:bpf_program__attach_freplace 0 nsec
114 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 | 42 +++++++++++++++++++
1 file changed, 42 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..cfdcb9ebdd255
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_link_attach_log.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright Leon Hwang */
+
+#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;
+ int err, prog_fd;
+ LIBBPF_OPTS(bpf_link_create_opts, link_opts);
+
+ 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_link = bpf_program__attach_freplace(prog, prog_fd, "subprog_tail");
+ ASSERT_ERR_PTR(freplace_link, "bpf_program__attach_freplace");
+
+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-17 15:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-17 15:43 [PATCH bpf-next v3 0/4] bpf: Improve error reporting for freplace attachment failure Leon Hwang
2025-02-17 15:43 ` [PATCH bpf-next v3 1/4] bpf, verifier: Add missing newline of bpf_log in bpf_check_attach_target Leon Hwang
2025-02-17 15:43 ` [PATCH bpf-next v3 2/4] bpf: Improve error reporting for freplace attachment failure Leon Hwang
2025-02-18 3:01 ` Alexei Starovoitov
2025-02-18 3:29 ` Leon Hwang
2025-02-17 15:43 ` [PATCH bpf-next v3 3/4] bpf, libbpf: Capture and log " Leon Hwang
2025-02-17 15:43 ` 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=20250217154318.76145-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.