From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: andrii@kernel.org, daniel@iogearbox.net, kernel-team@fb.com,
yhs@fb.com, alan.maguire@oracle.com,
Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next 2/2] selftests/bpf: Tests for BTF_KIND_DECL_TAG dump in C format
Date: Thu, 3 Nov 2022 15:45:22 +0200 [thread overview]
Message-ID: <20221103134522.2764601-2-eddyz87@gmail.com> (raw)
In-Reply-To: <20221103134522.2764601-1-eddyz87@gmail.com>
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`;
- decl tag could be attached to typedef;
- decl tag could be attached to a struct field;
- decl tag could be attached to a struct field and a struct itself
simultaneously.
Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
.../selftests/bpf/prog_tests/btf_dump.c | 1 +
.../bpf/progs/btf_dump_test_case_decl_tag.c | 60 +++++++++++++++++++
2 files changed, 61 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..7a5af8b86065
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/btf_dump_test_case_decl_tag.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+
+/*
+ * BTF-to-C dumper test for __atribute__((btf_decl_tag("..."))).
+ */
+/* ----- START-EXPECTED-OUTPUT ----- */
+#if __has_attribute(btf_decl_tag)
+# define __btf_decl_tag(x) __attribute__((btf_decl_tag(x)))
+#else
+# define __btf_decl_tag(x)
+#endif
+
+struct empty_with_tag {} __btf_decl_tag("a");
+
+struct one_tag {
+ int x;
+} __btf_decl_tag("b");
+
+struct same_tag {
+ int x;
+} __btf_decl_tag("b");
+
+struct two_tags {
+ int x;
+} __btf_decl_tag("a") __btf_decl_tag("b");
+
+struct packed {
+ int x;
+ short y;
+} __attribute__((packed)) __btf_decl_tag("another_name");
+
+typedef int td_with_tag __btf_decl_tag("td");
+
+struct tags_on_fields {
+ int x __btf_decl_tag("t1");
+ int y;
+ int z __btf_decl_tag("t2") __btf_decl_tag("t3");
+};
+
+struct tag_on_field_and_struct {
+ int x __btf_decl_tag("t1");
+} __btf_decl_tag("t2");
+
+struct root_struct {
+ struct empty_with_tag a;
+ struct one_tag b;
+ struct same_tag c;
+ struct two_tags d;
+ struct packed e;
+ td_with_tag f;
+ struct tags_on_fields g;
+ struct tag_on_field_and_struct h;
+};
+
+/* ------ END-EXPECTED-OUTPUT ------ */
+
+int f(struct root_struct *s)
+{
+ return 0;
+}
--
2.34.1
next prev parent reply other threads:[~2022-11-03 13:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-03 13:45 [PATCH bpf-next 1/2] libbpf: __attribute__((btf_decl_tag("..."))) for btf dump in C format Eduard Zingerman
2022-11-03 13:45 ` Eduard Zingerman [this message]
2022-11-04 20:54 ` Andrii Nakryiko
2022-11-06 21:40 ` Eduard Zingerman
2022-11-07 22:52 ` Andrii Nakryiko
2022-11-07 15:35 ` Eduard Zingerman
2022-11-07 23:09 ` Andrii Nakryiko
2022-11-07 23:17 ` Eduard Zingerman
2022-11-08 0:54 ` Andrii Nakryiko
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=20221103134522.2764601-2-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=yhs@fb.com \
/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