Covers the following cases: - `__atribute__((btf_decl_tag("...")))` could be applied to structs and unions; - decl tag applied to an empty struct is printed on a single line; - decl tags with the same name could be applied to several structs; - several decl tags could be applied to the same struct; - attribute `packed` works fine with decl tags (it is a separate branch in `tools/lib/bpf/btf_dump.c:btf_dump_emit_attributes`. Signed-off-by: Eduard Zingerman <eddyz87@xxxxxxxxx> --- .../selftests/bpf/prog_tests/btf_dump.c | 1 + .../bpf/progs/btf_dump_test_case_decl_tag.c | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_decl_tag.c diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c index 24da335482d4..5f6ce7f1a801 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c @@ -21,6 +21,7 @@ static struct btf_dump_test_case { {"btf_dump: bitfields", "btf_dump_test_case_bitfields", true}, {"btf_dump: multidim", "btf_dump_test_case_multidim", false}, {"btf_dump: namespacing", "btf_dump_test_case_namespacing", false}, + {"btf_dump: decl_tag", "btf_dump_test_case_decl_tag", true}, }; static int btf_dump_all_types(const struct btf *btf, void *ctx) diff --git a/tools/testing/selftests/bpf/progs/btf_dump_test_case_decl_tag.c b/tools/testing/selftests/bpf/progs/btf_dump_test_case_decl_tag.c new file mode 100644 index 000000000000..470bbbb530dc --- /dev/null +++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_decl_tag.c @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +/* + * BTF-to-C dumper test for __atribute__((btf_decl_tag("..."))). + */ +/* ----- START-EXPECTED-OUTPUT ----- */ +struct empty_with_tag {} __attribute__((btf_decl_tag("a"))); + +struct one_tag { + int x; +} __attribute__((btf_decl_tag("b"))); + +struct same_tag { + int x; +} __attribute__((btf_decl_tag("b"))); + +struct two_tags { + int x; +} __attribute__((btf_decl_tag("a"))) __attribute__((btf_decl_tag("b"))); + +struct packed { + int x; + short y; +} __attribute__((packed)) __attribute__((btf_decl_tag("another_name"))); + +struct root_struct { + struct empty_with_tag a; + struct one_tag b; + struct same_tag c; + struct two_tags d; + struct packed e; +}; + +/* ------ END-EXPECTED-OUTPUT ------ */ + +int f(struct root_struct *s) +{ + return 0; +} -- 2.34.1