All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, andrii@kernel.org, daniel@iogearbox.net,
	menglong8.dong@gmail.com, Leon Hwang <leon.hwang@linux.dev>
Subject: [RFC PATCH bpf-next 5/5] selftests/bpf: Add case to test freplace attach failure log
Date: Mon, 28 Jul 2025 22:23:46 +0800	[thread overview]
Message-ID: <20250728142346.95681-6-leon.hwang@linux.dev> (raw)
In-Reply-To: <20250728142346.95681-1-leon.hwang@linux.dev>

Test the new libbpf API 'bpf_program__attach_freplace_log()':

 cd tools/testing/selftests/bpf/
 ./test_progs -t tracing_failure/freplace_attach_log
 #468/3   tracing_failure/freplace_attach_log:OK
 #468     tracing_failure:OK
 Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
---
 .../bpf/prog_tests/tracing_failure.c          | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
index a222df765bc3..05c3a5a9db2a 100644
--- a/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
+++ b/tools/testing/selftests/bpf/prog_tests/tracing_failure.c
@@ -2,6 +2,8 @@
 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
 #include <test_progs.h>
 #include "tracing_failure.skel.h"
+#include "tailcall_bpf2bpf1.skel.h"
+#include "freplace_global_func.skel.h"
 
 static void test_bpf_spin_lock(bool is_spin_lock)
 {
@@ -28,10 +30,51 @@ static void test_bpf_spin_lock(bool is_spin_lock)
 	tracing_failure__destroy(skel);
 }
 
+static 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;
+
+	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;
+
+	log_buf[0] = '\0';
+	freplace_link = bpf_program__attach_freplace_log(prog, prog_fd, "subprog_tail", log_buf,
+							 sizeof(log_buf));
+	ASSERT_ERR_PTR(freplace_link, "bpf_program__attach_freplace_log");
+	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);
+}
+
 void test_tracing_failure(void)
 {
 	if (test__start_subtest("bpf_spin_lock"))
 		test_bpf_spin_lock(true);
 	if (test__start_subtest("bpf_spin_unlock"))
 		test_bpf_spin_lock(false);
+	if (test__start_subtest("freplace_attach_log"))
+		test_freplace_attach_log();
 }
-- 
2.50.1


      parent reply	other threads:[~2025-07-28 14:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-28 14:23 [RFC PATCH bpf-next 0/5] bpf: Extend bpf syscall with common attributes support Leon Hwang
2025-07-28 14:23 ` [RFC PATCH bpf-next 1/5] " Leon Hwang
2025-07-29  3:43   ` kernel test robot
2025-07-29  3:55     ` Leon Hwang
2025-07-28 14:23 ` [RFC PATCH bpf-next 2/5] libbpf: Add support for extended bpf syscall Leon Hwang
2025-07-28 14:23 ` [RFC PATCH bpf-next 3/5] bpf: Report freplace attach failure reason via extended syscall Leon Hwang
2025-07-31 16:32   ` Alexei Starovoitov
2025-08-01 13:45     ` Leon Hwang
2025-07-28 14:23 ` [RFC PATCH bpf-next 4/5] libbpf: Capture error message on freplace attach failure Leon Hwang
2025-07-28 14:23 ` 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=20250728142346.95681-6-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=menglong8.dong@gmail.com \
    /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.