Skip to content

Commit 1f5ea17

Browse files
Paul HousselKernel Patches Daemon
authored andcommitted
selftests/bpf: add BTF dedup tests for recursive typedef definitions
Add several ./test_progs tests: 1. btf/dedup:recursive typedef ensures that deduplication no longer fails on recursive typedefs. 2. btf/dedup:typedef ensures that typedefs are deduplicated correctly just as they were before this patch. Signed-off-by: Paul Houssel <[email protected]>
1 parent 7cdb3d3 commit 1f5ea17

File tree

1 file changed

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

1 file changed

+61
-0
lines changed

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7495,6 +7495,67 @@ static struct btf_dedup_test dedup_tests[] = {
74957495
BTF_STR_SEC("\0t\0m1\0m2\0tag1\0tag2\0tag3"),
74967496
},
74977497
},
7498+
{
7499+
.descr = "dedup: recursive typedef",
7500+
/*
7501+
* This test simulates a recursive typedef, which in GO is defined as such:
7502+
*
7503+
* type Foo func() Foo
7504+
*
7505+
* In BTF terms, this is represented as a TYPEDEF referencing
7506+
* a FUNC_PROTO that returns the same TYPEDEF.
7507+
*/
7508+
.input = {
7509+
.raw_types = {
7510+
/*
7511+
* [1] typedef Foo -> func() Foo
7512+
* [2] func_proto() -> Foo
7513+
*/
7514+
BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */
7515+
BTF_FUNC_PROTO_ENC(1, 0), /* [2] */
7516+
BTF_END_RAW,
7517+
},
7518+
BTF_STR_SEC("\0Foo"),
7519+
},
7520+
.expect = {
7521+
.raw_types = {
7522+
BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */
7523+
BTF_FUNC_PROTO_ENC(1, 0), /* [2] */
7524+
BTF_END_RAW,
7525+
},
7526+
BTF_STR_SEC("\0Foo"),
7527+
},
7528+
},
7529+
{
7530+
.descr = "dedup: typedef",
7531+
/*
7532+
* // CU 1:
7533+
* typedef int foo;
7534+
*
7535+
* // CU 2:
7536+
* typedef int foo;
7537+
*/
7538+
.input = {
7539+
.raw_types = {
7540+
/* CU 1 */
7541+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7542+
BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7543+
/* CU 2 */
7544+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [3] */
7545+
BTF_TYPEDEF_ENC(NAME_NTH(1), 3), /* [4] */
7546+
BTF_END_RAW,
7547+
},
7548+
BTF_STR_SEC("\0foo"),
7549+
},
7550+
.expect = {
7551+
.raw_types = {
7552+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7553+
BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7554+
BTF_END_RAW,
7555+
},
7556+
BTF_STR_SEC("\0foo"),
7557+
},
7558+
},
74987559
{
74997560
.descr = "dedup: typedef tags",
75007561
.input = {

0 commit comments

Comments
 (0)