Skip to content

Commit eb76899

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: add btf_dedup test for VOID equivalence check
This patch adds specific test exposing bug in btf_dedup_is_equiv() when comparing candidate VOID type to a non-VOID canonical type. It's important for canonical type to be anonymous, otherwise name equality check will do the right thing and will exit early. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 9ec71c1 commit eb76899

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tools/testing/selftests/bpf/test_btf.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5776,6 +5776,53 @@ const struct btf_dedup_test dedup_tests[] = {
57765776
.dedup_table_size = 1, /* force hash collisions */
57775777
},
57785778
},
5779+
{
5780+
.descr = "dedup: void equiv check",
5781+
/*
5782+
* // CU 1:
5783+
* struct s {
5784+
* struct {} *x;
5785+
* };
5786+
* // CU 2:
5787+
* struct s {
5788+
* int *x;
5789+
* };
5790+
*/
5791+
.input = {
5792+
.raw_types = {
5793+
/* CU 1 */
5794+
BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
5795+
BTF_PTR_ENC(1), /* [2] ptr -> [1] */
5796+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
5797+
BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
5798+
/* CU 2 */
5799+
BTF_PTR_ENC(0), /* [4] ptr -> void */
5800+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
5801+
BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
5802+
BTF_END_RAW,
5803+
},
5804+
BTF_STR_SEC("\0s\0x"),
5805+
},
5806+
.expect = {
5807+
.raw_types = {
5808+
/* CU 1 */
5809+
BTF_STRUCT_ENC(0, 0, 1), /* [1] struct {} */
5810+
BTF_PTR_ENC(1), /* [2] ptr -> [1] */
5811+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [3] struct s */
5812+
BTF_MEMBER_ENC(NAME_NTH(2), 2, 0),
5813+
/* CU 2 */
5814+
BTF_PTR_ENC(0), /* [4] ptr -> void */
5815+
BTF_STRUCT_ENC(NAME_NTH(1), 1, 8), /* [5] struct s */
5816+
BTF_MEMBER_ENC(NAME_NTH(2), 4, 0),
5817+
BTF_END_RAW,
5818+
},
5819+
BTF_STR_SEC("\0s\0x"),
5820+
},
5821+
.opts = {
5822+
.dont_resolve_fwds = false,
5823+
.dedup_table_size = 1, /* force hash collisions */
5824+
},
5825+
},
57795826
{
57805827
.descr = "dedup: all possible kinds (no duplicates)",
57815828
.input = {

0 commit comments

Comments
 (0)