From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 5/9] selftests/bpf: test libbpf API function btf__add_tag()
Date: Tue, 7 Sep 2021 16:01:16 -0700 [thread overview]
Message-ID: <20210907230116.1959597-1-yhs@fb.com> (raw)
In-Reply-To: <20210907230050.1957493-1-yhs@fb.com>
Add btf_write tests with btf__add_tag() function.
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/testing/selftests/bpf/btf_helpers.c | 7 +++++-
.../selftests/bpf/prog_tests/btf_write.c | 23 +++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index b692e6ead9b5..20dc8f4cb884 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -24,11 +24,12 @@ static const char * const btf_kind_str_mapping[] = {
[BTF_KIND_VAR] = "VAR",
[BTF_KIND_DATASEC] = "DATASEC",
[BTF_KIND_FLOAT] = "FLOAT",
+ [BTF_KIND_TAG] = "TAG",
};
static const char *btf_kind_str(__u16 kind)
{
- if (kind > BTF_KIND_DATASEC)
+ if (kind > BTF_KIND_TAG)
return "UNKNOWN";
return btf_kind_str_mapping[kind];
}
@@ -177,6 +178,10 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
case BTF_KIND_FLOAT:
fprintf(out, " size=%u", t->size);
break;
+ case BTF_KIND_TAG:
+ fprintf(out, " type_id=%u, comp_id=%d",
+ t->type, btf_kflag(t) ? -1 : (int)btf_tag(t)->comp_id);
+ break;
default:
break;
}
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_write.c b/tools/testing/selftests/bpf/prog_tests/btf_write.c
index 022c7d89d6f4..d20db7814ed1 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_write.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_write.c
@@ -281,5 +281,28 @@ void test_btf_write() {
"[17] DATASEC 'datasec1' size=12 vlen=1\n"
"\ttype_id=1 offset=4 size=8", "raw_dump");
+ /* TAG */
+ id = btf__add_tag(btf, "tag1", -1, 16);
+ ASSERT_EQ(id, 18, "tag_id");
+ t = btf__type_by_id(btf, 18);
+ ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "tag1", "tag_name");
+ ASSERT_EQ(btf_kind(t), BTF_KIND_TAG, "tag_kind");
+ ASSERT_EQ(btf_kflag(t), true, "tag_kflag");
+ ASSERT_EQ(t->type, 16, "tag_type");
+ ASSERT_EQ(btf_tag(t)->comp_id, 0, "tag_comp_id");
+ ASSERT_STREQ(btf_type_raw_dump(btf, 18),
+ "[18] TAG 'tag1' type_id=16, comp_id=-1", "raw_dump");
+
+ id = btf__add_tag(btf, "tag2", 1, 14);
+ ASSERT_EQ(id, 19, "tag_id");
+ t = btf__type_by_id(btf, 19);
+ ASSERT_STREQ(btf__str_by_offset(btf, t->name_off), "tag2", "tag_name");
+ ASSERT_EQ(btf_kind(t), BTF_KIND_TAG, "tag_kind");
+ ASSERT_EQ(btf_kflag(t), false, "tag_kflag");
+ ASSERT_EQ(t->type, 14, "tag_type");
+ ASSERT_EQ(btf_tag(t)->comp_id, 1, "tag_comp_id");
+ ASSERT_STREQ(btf_type_raw_dump(btf, 19),
+ "[19] TAG 'tag2' type_id=14, comp_id=1", "raw_dump");
+
btf__free(btf);
}
--
2.30.2
next prev parent reply other threads:[~2021-09-07 23:01 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-07 23:00 [PATCH bpf-next 0/9] bpf: add support for new btf kind BTF_KIND_TAG Yonghong Song
2021-09-07 23:00 ` [PATCH bpf-next 1/9] bpf: " Yonghong Song
2021-09-09 5:09 ` Andrii Nakryiko
2021-09-10 15:55 ` Yonghong Song
2021-09-07 23:01 ` [PATCH bpf-next 2/9] libbpf: rename btf_{hash,equal}_int to btf_{hash,equal}_int_tag Yonghong Song
2021-09-09 5:10 ` Andrii Nakryiko
2021-09-07 23:01 ` [PATCH bpf-next 3/9] libbpf: add support for BTF_KIND_TAG Yonghong Song
2021-09-09 5:26 ` Andrii Nakryiko
2021-09-10 16:04 ` Yonghong Song
2021-09-07 23:01 ` [PATCH bpf-next 4/9] bpftool: " Yonghong Song
2021-09-09 5:28 ` Andrii Nakryiko
2021-09-09 5:33 ` Andrii Nakryiko
2021-09-10 16:38 ` Yonghong Song
2021-09-10 18:05 ` Andrii Nakryiko
2021-09-10 16:04 ` Yonghong Song
2021-09-07 23:01 ` Yonghong Song [this message]
2021-09-09 5:35 ` [PATCH bpf-next 5/9] selftests/bpf: test libbpf API function btf__add_tag() Andrii Nakryiko
2021-09-10 16:39 ` Yonghong Song
2021-09-07 23:01 ` [PATCH bpf-next 6/9] selftests/bpf: add BTF_KIND_TAG unit tests Yonghong Song
2021-09-07 23:01 ` [PATCH bpf-next 7/9] selftests/bpf: test BTF_KIND_TAG for deduplication Yonghong Song
2021-09-07 23:01 ` [PATCH bpf-next 8/9] selftests/bpf: add a test with a bpf program with btf_tag attributes Yonghong Song
2021-09-09 5:39 ` Andrii Nakryiko
2021-09-07 23:01 ` [PATCH bpf-next 9/9] docs/bpf: add documentation for BTF_KIND_TAG Yonghong Song
2021-09-09 5:42 ` Andrii Nakryiko
2021-09-10 16:40 ` Yonghong Song
2021-09-10 18:05 ` Andrii Nakryiko
2021-09-09 22:45 ` [PATCH bpf-next 0/9] bpf: add support for new btf kind BTF_KIND_TAG Jose E. Marchesi
2021-09-09 23:30 ` Yonghong Song
2021-09-10 2:19 ` Jose E. Marchesi
2021-09-10 7:04 ` Yonghong Song
2021-09-10 8:31 ` Jose E. Marchesi
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=20210907230116.1959597-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@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