Skip to content

Commit 9d19a12

Browse files
yonghong-songAlexei Starovoitov
authored and
Alexei Starovoitov
committed
selftests/bpf: Add BTF_KIND_DECL_TAG typedef unit tests
Test good and bad variants of typedef BTF_KIND_DECL_TAG encoding. Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent bd16dee commit 9d19a12

File tree

1 file changed

+36
-0
lines changed
  • tools/testing/selftests/bpf/prog_tests

1 file changed

+36
-0
lines changed

tools/testing/selftests/bpf/prog_tests/btf.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,6 +3903,42 @@ static struct btf_raw_test raw_tests[] = {
39033903
.btf_load_err = true,
39043904
.err_str = "Invalid component_idx",
39053905
},
3906+
{
3907+
.descr = "decl_tag test #13, typedef, well-formed",
3908+
.raw_types = {
3909+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3910+
BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
3911+
BTF_DECL_TAG_ENC(NAME_TBD, 2, -1),
3912+
BTF_END_RAW,
3913+
},
3914+
BTF_STR_SEC("\0t\0tag"),
3915+
.map_type = BPF_MAP_TYPE_ARRAY,
3916+
.map_name = "tag_type_check_btf",
3917+
.key_size = sizeof(int),
3918+
.value_size = 4,
3919+
.key_type_id = 1,
3920+
.value_type_id = 1,
3921+
.max_entries = 1,
3922+
},
3923+
{
3924+
.descr = "decl_tag test #14, typedef, invalid component_idx",
3925+
.raw_types = {
3926+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
3927+
BTF_TYPEDEF_ENC(NAME_TBD, 1), /* [2] */
3928+
BTF_DECL_TAG_ENC(NAME_TBD, 2, 0),
3929+
BTF_END_RAW,
3930+
},
3931+
BTF_STR_SEC("\0local\0tag"),
3932+
.map_type = BPF_MAP_TYPE_ARRAY,
3933+
.map_name = "tag_type_check_btf",
3934+
.key_size = sizeof(int),
3935+
.value_size = 4,
3936+
.key_type_id = 1,
3937+
.value_type_id = 1,
3938+
.max_entries = 1,
3939+
.btf_load_err = true,
3940+
.err_str = "Invalid component_idx",
3941+
},
39063942

39073943
}; /* struct btf_raw_test raw_tests[] */
39083944

0 commit comments

Comments
 (0)