Add a regression test for a nested struct whose first member is zero
and second member is non-zero.

This verifies that struct and union zero detection continues checking
later members instead of treating the entire nested value as zero.

Signed-off-by: Luis Vieira <[email protected]>
---
 tools/testing/selftests/bpf/prog_tests/btf_dump.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c 
b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
index 17fa44cb9c91..5a5ee001ac8b 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
@@ -1146,6 +1146,11 @@ static void test_btf_dump_struct_data(struct btf *btf, 
struct btf_dump *d,
                           "(union bpf_iter_link_info){.map = (struct){.map_fd 
= (__u32)1,},.cgroup = (struct){.order = (enum 
bpf_cgroup_iter_order)BPF_CGROUP_ITER_SELF_ONLY,.cgroup_fd = (__u32)1,},.task = 
(struct){.tid = (__u32)1,.pid = (__u32)1,},}",
                           { .cgroup = { .order = 1, .cgroup_fd = 1, }});
 
+       /* nested structs with zero first member and non-zero second member */
+       TEST_BTF_DUMP_DATA(btf, d, "union", str, union bpf_iter_link_info, 
BTF_F_COMPACT,
+                          "(union bpf_iter_link_info){.cgroup = 
(struct){.cgroup_fd = (__u32)1,},.task = (struct){.pid = (__u32)1,},}",
+                          { .cgroup = { .cgroup_fd = 1 }});
+
        /* struct skb with nested structs/unions; because type output is so
         * complex, we don't do a string comparison, just verify we return
         * the type size as the amount of data displayed.

-- 
2.43.0


Reply via email to