Extend prog_tests/resolve_btfids.c to assert that resolve_btfids emits a BTF_KIND_DECL_TAG of name "bpf_kfunc" for each kfunc declared in the test BTF ID set. Add a small btf_has_decl_tag() helper that walks the output BTF looking for a matching decl tag (name + target FUNC + component_idx == -1). Signed-off-by: Ihor Solodrai --- .../selftests/bpf/prog_tests/resolve_btfids.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c index f6fd79b9dd23..7d9c3460cbed 100644 --- a/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c +++ b/tools/testing/selftests/bpf/prog_tests/resolve_btfids.c @@ -156,6 +156,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 (name && strcmp(name, tag_name) == 0) + return true; + } + return false; +} + void test_resolve_btfids(void) { __u32 *test_list, *test_lists[] = { test_list_local, test_list_global }; @@ -218,6 +240,12 @@ void test_resolve_btfids(void) test_kfunc_set.pairs[i].id, "kfunc_sort_check"); } + /* Check resolve_btfids emitted bpf_kfunc decl_tag for each kfunc */ + for (i = 0; i < ARRAY_SIZE(kfunc_symbols); i++) + ASSERT_TRUE(btf_has_decl_tag(btf, "bpf_kfunc", + kfunc_symbols[i].id), + kfunc_symbols[i].name); + out: btf__free(btf); } -- 2.54.0