Skip to content

Commit 4866ae3

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]> Acked-by: Eduard Zingerman <[email protected]>
1 parent a803521 commit 4866ae3

File tree

1 file changed

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

1 file changed

+65
-0
lines changed

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7495,6 +7495,71 @@ 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+
* [3] typedef Foo -> func() Foo
7514+
* [4] func_proto() -> Foo
7515+
*/
7516+
BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */
7517+
BTF_FUNC_PROTO_ENC(1, 0), /* [2] */
7518+
BTF_TYPEDEF_ENC(NAME_NTH(1), 4), /* [3] */
7519+
BTF_FUNC_PROTO_ENC(3, 0), /* [4] */
7520+
BTF_END_RAW,
7521+
},
7522+
BTF_STR_SEC("\0Foo"),
7523+
},
7524+
.expect = {
7525+
.raw_types = {
7526+
BTF_TYPEDEF_ENC(NAME_NTH(1), 2), /* [1] */
7527+
BTF_FUNC_PROTO_ENC(1, 0), /* [2] */
7528+
BTF_END_RAW,
7529+
},
7530+
BTF_STR_SEC("\0Foo"),
7531+
},
7532+
},
7533+
{
7534+
.descr = "dedup: typedef",
7535+
/*
7536+
* // CU 1:
7537+
* typedef int foo;
7538+
*
7539+
* // CU 2:
7540+
* typedef int foo;
7541+
*/
7542+
.input = {
7543+
.raw_types = {
7544+
/* CU 1 */
7545+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7546+
BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7547+
/* CU 2 */
7548+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [3] */
7549+
BTF_TYPEDEF_ENC(NAME_NTH(1), 3), /* [4] */
7550+
BTF_END_RAW,
7551+
},
7552+
BTF_STR_SEC("\0foo"),
7553+
},
7554+
.expect = {
7555+
.raw_types = {
7556+
BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */
7557+
BTF_TYPEDEF_ENC(NAME_NTH(1), 1), /* [2] */
7558+
BTF_END_RAW,
7559+
},
7560+
BTF_STR_SEC("\0foo"),
7561+
},
7562+
},
74987563
{
74997564
.descr = "dedup: typedef tags",
75007565
.input = {

0 commit comments

Comments
 (0)