From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Martin KaFai Lau <martin.lau@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v3 4/4] selftests/bpf: Test verifier warning logging
Date: Sat, 18 Apr 2026 19:16:59 +0200 [thread overview]
Message-ID: <20260418171701.610025-5-memxor@gmail.com> (raw)
In-Reply-To: <20260418171701.610025-1-memxor@gmail.com>
Add coverage for explicit verifier warning logging and for libbpf's
default warning flush path while keeping the warning bit private to the
test.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
.../bpf/prog_tests/kfunc_implicit_args.c | 92 +++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c b/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
index 5e4793c9c29a..f92a27d76455 100644
--- a/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
+++ b/tools/testing/selftests/bpf/prog_tests/kfunc_implicit_args.c
@@ -4,7 +4,99 @@
#include <test_progs.h>
#include "kfunc_implicit_args.skel.h"
+#define TEST_BPF_LOG_LEVEL_WARN (1U << 4)
+
+static size_t libbpf_log_pos;
+static char libbpf_log_buf[4096];
+static bool libbpf_log_error;
+
+static int libbpf_print_cb(enum libbpf_print_level level, const char *fmt, va_list args)
+{
+ int emitted_cnt;
+ size_t left_cnt;
+
+ (void)level;
+
+ left_cnt = sizeof(libbpf_log_buf) - libbpf_log_pos;
+ emitted_cnt = vsnprintf(libbpf_log_buf + libbpf_log_pos, left_cnt, fmt, args);
+ if (emitted_cnt < 0 || emitted_cnt + 1 > left_cnt) {
+ libbpf_log_error = true;
+ return 0;
+ }
+
+ libbpf_log_pos += emitted_cnt;
+ return 0;
+}
+
+static void select_legacy_impl_prog(struct kfunc_implicit_args *skel)
+{
+ struct bpf_program *prog;
+
+ bpf_object__for_each_program(prog, skel->obj)
+ bpf_program__set_autoload(prog,
+ prog == skel->progs.test_kfunc_implicit_arg_legacy_impl);
+}
+
+static void test_warn_bit(void)
+{
+ struct kfunc_implicit_args *skel;
+ char log_buf[4096] = {};
+ int err;
+
+ skel = kfunc_implicit_args__open();
+ if (!ASSERT_OK_PTR(skel, "skel_open"))
+ return;
+
+ select_legacy_impl_prog(skel);
+ bpf_program__set_log_buf(skel->progs.test_kfunc_implicit_arg_legacy_impl,
+ log_buf, sizeof(log_buf));
+ bpf_program__set_log_level(skel->progs.test_kfunc_implicit_arg_legacy_impl,
+ TEST_BPF_LOG_LEVEL_WARN);
+
+ err = kfunc_implicit_args__load(skel);
+ ASSERT_OK(err, "skel_load");
+ ASSERT_OK_PTR(strstr(log_buf, "uses deprecated kfunc bpf_kfunc_implicit_arg_legacy_impl()"),
+ "warning_msg");
+ ASSERT_NULL(strstr(log_buf, "processed "), "no_verbose_log");
+
+ kfunc_implicit_args__destroy(skel);
+}
+
+static void test_default_warning_flush(void)
+{
+ libbpf_print_fn_t old_print_cb = libbpf_set_print(libbpf_print_cb);
+ struct kfunc_implicit_args *skel = NULL;
+ int err;
+
+ libbpf_log_pos = 0;
+ libbpf_log_buf[0] = '\0';
+ libbpf_log_error = false;
+
+ skel = kfunc_implicit_args__open();
+ if (!ASSERT_OK_PTR(skel, "skel_open"))
+ goto cleanup;
+
+ select_legacy_impl_prog(skel);
+
+ err = kfunc_implicit_args__load(skel);
+ ASSERT_OK(err, "skel_load");
+ ASSERT_FALSE(libbpf_log_error, "libbpf_log_error");
+ ASSERT_OK_PTR(strstr(libbpf_log_buf, "-- BEGIN PROG LOAD WARNINGS --"), "warn_banner");
+ ASSERT_OK_PTR(strstr(libbpf_log_buf,
+ "uses deprecated kfunc bpf_kfunc_implicit_arg_legacy_impl()"),
+ "warn_msg");
+ ASSERT_NULL(strstr(libbpf_log_buf, "-- BEGIN PROG LOAD LOG --"), "no_verbose_log");
+
+cleanup:
+ kfunc_implicit_args__destroy(skel);
+ libbpf_set_print(old_print_cb);
+}
+
void test_kfunc_implicit_args(void)
{
RUN_TESTS(kfunc_implicit_args);
+ if (test__start_subtest("warn_bit"))
+ test_warn_bit();
+ if (test__start_subtest("default_warning_flush"))
+ test_default_warning_flush();
}
--
2.52.0
next prev parent reply other threads:[~2026-04-18 17:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-18 17:16 [PATCH bpf-next v3 0/4] Add support to emit verifier warnings Kumar Kartikeya Dwivedi
2026-04-18 17:16 ` [PATCH bpf-next v3 1/4] bpf: Add support for verifier warning messages Kumar Kartikeya Dwivedi
2026-04-18 17:42 ` sashiko-bot
2026-04-18 20:33 ` Kumar Kartikeya Dwivedi
2026-04-20 13:37 ` Mykyta Yatsenko
2026-04-20 15:26 ` Kumar Kartikeya Dwivedi
2026-04-18 17:16 ` [PATCH bpf-next v3 2/4] bpf: Introduce __bpf_kfunc_mark_deprecated annotation Kumar Kartikeya Dwivedi
2026-04-18 18:06 ` sashiko-bot
2026-04-18 20:34 ` Kumar Kartikeya Dwivedi
2026-04-20 14:21 ` Mykyta Yatsenko
2026-04-20 15:27 ` Kumar Kartikeya Dwivedi
2026-04-20 18:15 ` David Faust
2026-04-20 18:19 ` Kumar Kartikeya Dwivedi
2026-04-18 17:16 ` [PATCH bpf-next v3 3/4] libbpf: Request verifier warnings for object loads Kumar Kartikeya Dwivedi
2026-04-18 18:35 ` sashiko-bot
2026-04-18 20:38 ` Kumar Kartikeya Dwivedi
2026-04-20 13:57 ` Mykyta Yatsenko
2026-04-20 15:23 ` Kumar Kartikeya Dwivedi
2026-04-20 15:49 ` Alexei Starovoitov
2026-04-18 17:16 ` Kumar Kartikeya Dwivedi [this message]
2026-04-18 18:45 ` [PATCH bpf-next v3 4/4] selftests/bpf: Test verifier warning logging sashiko-bot
2026-04-18 20:39 ` Kumar Kartikeya Dwivedi
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=20260418171701.610025-5-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=kernel-team@meta.com \
--cc=kkd@meta.com \
--cc=martin.lau@kernel.org \
/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