summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorIhor Solodrai <ihor.solodrai@linux.dev>2026-08-06 20:20:28 -0700
committerEduard Zingerman <eddyz87@gmail.com>2026-08-06 22:01:28 -0700
commit9f3881ecad886bbcd7b69355bc14a6deb071672c (patch)
tree78a4be9b67174c2293b4a018fe4b42949859e29b /tools/testing
parent692393104909ee14686488995ad5009a618fb0c7 (diff)
downloadlinux-9f3881ecad886bbcd7b69355bc14a6deb071672c.tar.gz
linux-9f3881ecad886bbcd7b69355bc14a6deb071672c.zip
selftests/bpf: Verify decl tags emission in resolve_btfids test
Extend test_resolve_btfids() to assert that resolve_btfids emits a BTF_KIND_DECL_TAG named "bpf_kfunc" for every kfunc, and "bpf_fastcall" for kfuncs marked KF_FASTCALL. Add a btf_has_decl_tag() helper that scans the output BTF for a decl tag matching name and target. Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://patch.msgid.link/20260807032029.78092-6-ihor.solodrai@linux.dev Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/resolve_btfids.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
index 8482f00046d4..732cfed35e1c 100644
--- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
+++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c
@@ -12,6 +12,8 @@
#define BTF_DATA_FILE "resolve_btfids.test.o.BTF"
+#define DECL_TAG_FASTCALL "bpf_fastcall"
+#define DECL_TAG_KFUNC "bpf_kfunc"
#define TYPE_ATTR_ARENA "address_space(1)"
#ifndef KF_FASTCALL
@@ -176,6 +178,28 @@ static int resolve_symbols(struct btf *btf)
return 0;
}
+static bool btf_has_decl_tag(struct btf *btf, const char *tag_name, s32 target_id)
+{
+ const struct btf_type *t;
+ const char *name;
+ int nr, id;
+
+ nr = btf__type_cnt(btf);
+ for (id = 1; id < nr; id++) {
+ t = btf__type_by_id(btf, id);
+ if (!btf_is_decl_tag(t))
+ continue;
+ if (t->type != (__u32)target_id)
+ continue;
+ if (btf_decl_tag(t)->component_idx != -1)
+ continue;
+ name = btf__name_by_offset(btf, t->name_off);
+ if (strcmp(name, tag_name) == 0)
+ return true;
+ }
+ return false;
+}
+
static void check_kfunc_set(struct btf_id_set8 *set)
{
unsigned int i, j;
@@ -260,6 +284,22 @@ void test_resolve_btfids(void)
check_kfunc_set(&test_kfunc_set);
check_kfunc_set(&test_kfunc_set_rev);
+ /* Check resolve_btfids emitted a bpf_kfunc decl_tag for each kfunc */
+ for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+ ASSERT_TRUE(btf_has_decl_tag(btf, DECL_TAG_KFUNC,
+ kfunc_symbols[i].id),
+ kfunc_symbols[i].name);
+ }
+
+ /* Check resolve_btfids emitted bpf_fastcall for KF_FASTCALL kfuncs */
+ for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) {
+ if (kfunc_symbols[i].flags & KF_FASTCALL) {
+ ASSERT_TRUE(btf_has_decl_tag(btf, DECL_TAG_FASTCALL,
+ kfunc_symbols[i].id),
+ kfunc_symbols[i].name);
+ }
+ }
+
/*
* Check resolve_btfids wrapped exactly the arena-flagged return/args
* with the address_space(1) type attribute, and left other