From: Alan Maguire <alan.maguire@oracle.com>
To: ast@kernel.org, andrii@kernel.org, eddyz87@gmail.com, qmo@kernel.org
Cc: jolsa@kernel.org, daniel@iogearbox.net, ihor.solodrai@linux.dev,
yonghong.song@linux.dev, song@kernel.org, martin.lau@linux.dev,
memxor@gmail.com, emil@etsalapatis.com, bpf@vger.kernel.org,
nsc@kernel.org, puranjay@kernel.org, yatsenko@meta.com,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH v4 bpf-next 10/11] selftests/bpf: Test bpftool dump of BTF location info
Date: Thu, 24 Sep 2026 12:14:27 +0100 [thread overview]
Message-ID: <20260924111428.75957-11-alan.maguire@oracle.com> (raw)
In-Reply-To: <20260924111428.75957-1-alan.maguire@oracle.com>
Add a bpftool raw BTF dump test covering LOC_PARAM, LOC_PROTO, and
LOCSEC types. Verify LOC_PARAM expressions, LOC_PROTO parameter values,
and LOCSEC function name, type id, and offset output.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Assisted-by: OpenAI Codex (GPT 5.6)
---
.../bpf/prog_tests/bpftool_btf_dump.c | 121 +++++++++++++++++-
1 file changed, 120 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
index d5b25302b0c8..bed506badc75 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
@@ -57,6 +57,57 @@ static struct btf *mk_btf(void)
return btf;
}
+static struct btf *mk_loc_btf(void)
+{
+ struct btf *btf;
+
+ btf = btf__new_empty();
+ if (!ASSERT_OK_PTR(btf, "new_empty"))
+ return NULL;
+
+ btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+ btf__add_func_proto(btf, 1);
+ btf__add_func_param(btf, "arg1", 1);
+ btf__add_func_param(btf, "arg2", 1);
+ btf__add_func_param(btf, "arg3", 1);
+ btf__add_func_param(btf, "arg4", 1);
+ btf__add_func_param(btf, "arg5", 1);
+ btf__add_func(btf, "foo", BTF_FUNC_STATIC, 2);
+
+ btf__add_loc_param(btf, 4, BTF_LOC_PARAM_REG);
+ btf__add_loc_param_value(btf, 1);
+ btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG |
+ BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET);
+ btf__add_loc_param_value(btf, 2);
+ btf__add_loc_param_value(btf, 0x10);
+ btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG |
+ BTF_LOC_PARAM_OFFSET | BTF_LOC_PARAM_SIGNED);
+ btf__add_loc_param_value(btf, BTF_LOC_PARAM_FBREG);
+ btf__add_loc_param_value(btf, -0x10);
+ btf__add_loc_param(btf, 8, BTF_LOC_PARAM_ADDR | BTF_LOC_PARAM_CONST);
+ btf__add_loc_param_value(btf, 0x9abcdef0);
+ btf__add_loc_param_value(btf, 0x12345678);
+ btf__add_loc_param(btf, 8, BTF_LOC_PARAM_CONST);
+ btf__add_loc_param_value(btf, 0xfeedface);
+ btf__add_loc_param_value(btf, 0xdeadbeef);
+ btf__add_loc_param(btf, 8, BTF_LOC_PARAM_REG |
+ BTF_LOC_PARAM_DEREF | BTF_LOC_PARAM_OFFSET |
+ BTF_LOC_PARAM_SIGNED);
+ btf__add_loc_param_value(btf, BTF_LOC_PARAM_FBREG);
+ btf__add_loc_param_value(btf, -0x20);
+ btf__add_loc_proto(btf);
+ btf__add_loc_proto_param(btf, 4);
+ btf__add_loc_proto_param(btf, 5);
+ btf__add_loc_proto_param(btf, 6);
+ btf__add_loc_proto_param(btf, 7);
+ btf__add_loc_proto_param(btf, 8);
+ btf__add_loc_proto_param(btf, 9);
+ btf__add_locsec(btf, "inline.text");
+ btf__add_locsec_loc(btf, 3, 10, 64);
+
+ return btf;
+}
+
static int btf_to_tmpfile(const struct btf *btf, char *path)
{
ssize_t written;
@@ -105,6 +156,26 @@ static char *dump_c(const char *btf_path, bool sorted)
return buf;
}
+static char *dump_raw(const char *btf_path)
+{
+ char args[MAX_BPFTOOL_CMD_LEN];
+ char *buf;
+ int err;
+
+ buf = malloc(DUMP_BUF_SZ);
+ if (!ASSERT_OK_PTR(buf, "alloc_dump"))
+ return NULL;
+
+ snprintf(args, sizeof(args), "btf dump file %s", btf_path);
+ err = get_bpftool_command_output(args, buf, DUMP_BUF_SZ);
+ if (!ASSERT_OK(err, "btf_dump_raw")) {
+ free(buf);
+ return NULL;
+ }
+
+ return buf;
+}
+
static char *read_expected(const char *path)
{
char *buf = NULL;
@@ -155,10 +226,46 @@ static void test_dump(const char *btf_path, bool sorted)
free(dump);
}
+static void test_loc_dump(const char *btf_path)
+{
+ const char expected[] =
+ "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\n"
+ "[2] FUNC_PROTO '(anon)' ret_type_id=1 vlen=5\n"
+ "\t'arg1' type_id=1\n"
+ "\t'arg2' type_id=1\n"
+ "\t'arg3' type_id=1\n"
+ "\t'arg4' type_id=1\n"
+ "\t'arg5' type_id=1\n"
+ "[3] FUNC 'foo' type_id=2 linkage=static\n"
+ "[4] LOC_PARAM '(anon)' size=4 flags=0x8 vlen=1 values='reg1'\n"
+ "[5] LOC_PARAM '(anon)' size=8 flags=0x38 vlen=2 values='*(reg2 + 0x10)'\n"
+ "[6] LOC_PARAM '(anon)' size=8 flags=0x29 vlen=2 values='fbreg - 0x10'\n"
+ "[7] LOC_PARAM '(anon)' size=8 flags=0x6 vlen=2 values='0x123456789abcdef0 (addr)'\n"
+ "[8] LOC_PARAM '(anon)' size=8 flags=0x2 vlen=2 values='0xdeadbeeffeedface'\n"
+ "[9] LOC_PARAM '(anon)' size=8 flags=0x39 vlen=2 values='*(fbreg - 0x20)'\n"
+ "[10] LOC_PROTO '(anon)' vlen=6\n"
+ "\ttype_id=4 value='reg1'\n"
+ "\ttype_id=5 value='*(reg2 + 0x10)'\n"
+ "\ttype_id=6 value='fbreg - 0x10'\n"
+ "\ttype_id=7 value='0x123456789abcdef0 (addr)'\n"
+ "\ttype_id=8 value='0xdeadbeeffeedface'\n"
+ "\ttype_id=9 value='*(fbreg - 0x20)'\n"
+ "[11] LOCSEC 'inline.text' vlen=1\n"
+ "\tname='foo' func_type_id=3 loc_proto_type_id=10 offset=64\n";
+ char *dump;
+
+ dump = dump_raw(btf_path);
+ if (!dump)
+ return;
+
+ ASSERT_OK(compare_text_to_expected(dump, expected), "cmp_loc_dump");
+ free(dump);
+}
+
void test_bpftool_btf_dump(void)
{
char path[PATH_MAX];
- struct btf *btf;
+ struct btf *btf = NULL;
btf = mk_btf();
if (!btf)
@@ -171,7 +278,19 @@ void test_bpftool_btf_dump(void)
test_dump(path, true);
if (test__start_subtest("c_unsorted"))
test_dump(path, false);
+ unlink(path);
+
+ btf__free(btf);
+
+ btf = mk_loc_btf();
+ if (!btf)
+ return;
+
+ if (btf_to_tmpfile(btf, path))
+ goto out_btf;
+ if (test__start_subtest("loc_dump"))
+ test_loc_dump(path);
unlink(path);
out_btf:
btf__free(btf);
--
2.43.5
next prev parent reply other threads:[~2026-09-24 11:15 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 11:14 [PATCH v4 bpf-next 00/11] Support inline functions in BTF Alan Maguire
2026-09-24 11:14 ` [PATCH v4 bpf-next 01/11] btf: Extend UAPI to support BTF location (inline site) info Alan Maguire
2026-09-24 12:12 ` bot+bpf-ci
2026-09-24 15:18 ` Alexei Starovoitov
2026-09-24 11:14 ` [PATCH v4 bpf-next 02/11] libbpf: Add support for BTF kinds LOC[_PARAM|_PROTO|SEC] Alan Maguire
2026-09-24 12:12 ` bot+bpf-ci
2026-09-24 11:14 ` [PATCH v4 bpf-next 03/11] selftests/bpf: Test helper support for BTF_KIND_LOC[_PARAM|_PROTO|SEC] Alan Maguire
2026-09-24 11:14 ` [PATCH v4 bpf-next 04/11] selftests/bpf: Add LOC_PARAM, LOC_PROTO, LOCSEC to field iter tests Alan Maguire
2026-09-24 11:14 ` [PATCH v4 bpf-next 05/11] selftests/bpf: Add LOC_PARAM, LOC_PROTO, LOCSEC to dedup split tests Alan Maguire
2026-09-24 11:14 ` [PATCH v4 bpf-next 06/11] selftests/bpf: BTF distill tests to ensure LOC[_PARAM|_PROTO] add to split BTF Alan Maguire
2026-09-24 11:56 ` bot+bpf-ci
2026-09-24 11:14 ` [PATCH v4 bpf-next 07/11] bpftool: Handle multi-split BTF by supporting multiple base BTFs Alan Maguire
2026-09-24 11:14 ` [PATCH v4 bpf-next 08/11] bpftool: Document support for multi-split BTF Alan Maguire
2026-09-24 11:14 ` [PATCH v4 bpf-next 09/11] bpftool: Add ability to dump LOC_PARAM, LOC_PROTO and LOCSEC Alan Maguire
2026-09-24 15:16 ` Alexei Starovoitov
2026-09-24 15:33 ` Alan Maguire
2026-09-24 16:02 ` Alexei Starovoitov
2026-09-24 11:14 ` Alan Maguire [this message]
2026-09-24 11:56 ` [PATCH v4 bpf-next 10/11] selftests/bpf: Test bpftool dump of BTF location info bot+bpf-ci
2026-09-24 11:14 ` [PATCH v4 bpf-next 11/11] Documentation/bpf: Describe new location-related BTF kinds Alan Maguire
2026-09-24 11:56 ` bot+bpf-ci
2026-09-24 12:19 ` sashiko-bot
2026-09-24 16:10 ` [PATCH v4 bpf-next 00/11] Support inline functions in BTF patchwork-bot+netdevbpf
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=20260924111428.75957-11-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--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=jolsa@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=nsc@kernel.org \
--cc=puranjay@kernel.org \
--cc=qmo@kernel.org \
--cc=song@kernel.org \
--cc=yatsenko@meta.com \
--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.