Message ID | 20220222074524.1027060-3-xukuohai@huawei.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | libbpf: Fix btf dump error for BTF_KIND_FWD | expand |
On Mon, Feb 21, 2022 at 11:41 PM Xu Kuohai <xukuohai@huawei.com> wrote: > > Update btf_dump test case for conflict FWD and STRUCT name. > > Signed-off-by: Xu Kuohai <xukuohai@huawei.com> Acked-by: Song Liu <songliubraving@fb.com> > --- > tools/testing/selftests/bpf/prog_tests/btf_dump.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c > index 9e26903f9170..2539a8f8b098 100644 > --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c > +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c > @@ -150,6 +150,8 @@ static void test_btf_dump_incremental(void) > * > * enum { VAL = 1 }; > * > + * struct s; > + * > * struct s { int x; }; > * > */ > @@ -161,8 +163,11 @@ static void test_btf_dump_incremental(void) > id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED); > ASSERT_EQ(id, 2, "int_id"); > > + id = btf__add_fwd(btf, "s", BTF_FWD_STRUCT); > + ASSERT_EQ(id, 3, "fwd_id"); > + > id = btf__add_struct(btf, "s", 4); > - ASSERT_EQ(id, 3, "struct_id"); > + ASSERT_EQ(id, 4, "struct_id"); > err = btf__add_field(btf, "x", 2, 0, 0); > ASSERT_OK(err, "field_ok"); > > @@ -178,6 +183,8 @@ static void test_btf_dump_incremental(void) > " VAL = 1,\n" > "};\n" > "\n" > +"struct s;\n" > +"\n" > "struct s {\n" > " int x;\n" > "};\n\n", "c_dump1"); > @@ -199,7 +206,7 @@ static void test_btf_dump_incremental(void) > fseek(dump_buf_file, 0, SEEK_SET); > > id = btf__add_struct(btf, "s", 4); > - ASSERT_EQ(id, 4, "struct_id"); > + ASSERT_EQ(id, 5, "struct_id"); > err = btf__add_field(btf, "x", 1, 0, 0); > ASSERT_OK(err, "field_ok"); > err = btf__add_field(btf, "s", 3, 32, 0); > -- > 2.30.2 >
On Mon, Feb 21, 2022 at 11:34 PM Xu Kuohai <xukuohai@huawei.com> wrote: > > Update btf_dump test case for conflict FWD and STRUCT name. > > Signed-off-by: Xu Kuohai <xukuohai@huawei.com> > --- Would be good to also add enum forward declaration case, just in case (see patch #1) > tools/testing/selftests/bpf/prog_tests/btf_dump.c | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c > index 9e26903f9170..2539a8f8b098 100644 > --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c > +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c > @@ -150,6 +150,8 @@ static void test_btf_dump_incremental(void) > * > * enum { VAL = 1 }; > * > + * struct s; > + * > * struct s { int x; }; > * > */ > @@ -161,8 +163,11 @@ static void test_btf_dump_incremental(void) > id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED); > ASSERT_EQ(id, 2, "int_id"); > > + id = btf__add_fwd(btf, "s", BTF_FWD_STRUCT); > + ASSERT_EQ(id, 3, "fwd_id"); > + > id = btf__add_struct(btf, "s", 4); > - ASSERT_EQ(id, 3, "struct_id"); > + ASSERT_EQ(id, 4, "struct_id"); > err = btf__add_field(btf, "x", 2, 0, 0); > ASSERT_OK(err, "field_ok"); > > @@ -178,6 +183,8 @@ static void test_btf_dump_incremental(void) > " VAL = 1,\n" > "};\n" > "\n" > +"struct s;\n" > +"\n" > "struct s {\n" > " int x;\n" > "};\n\n", "c_dump1"); > @@ -199,7 +206,7 @@ static void test_btf_dump_incremental(void) > fseek(dump_buf_file, 0, SEEK_SET); > > id = btf__add_struct(btf, "s", 4); > - ASSERT_EQ(id, 4, "struct_id"); > + ASSERT_EQ(id, 5, "struct_id"); > err = btf__add_field(btf, "x", 1, 0, 0); > ASSERT_OK(err, "field_ok"); > err = btf__add_field(btf, "s", 3, 32, 0); > -- > 2.30.2 >
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c index 9e26903f9170..2539a8f8b098 100644 --- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c +++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c @@ -150,6 +150,8 @@ static void test_btf_dump_incremental(void) * * enum { VAL = 1 }; * + * struct s; + * * struct s { int x; }; * */ @@ -161,8 +163,11 @@ static void test_btf_dump_incremental(void) id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED); ASSERT_EQ(id, 2, "int_id"); + id = btf__add_fwd(btf, "s", BTF_FWD_STRUCT); + ASSERT_EQ(id, 3, "fwd_id"); + id = btf__add_struct(btf, "s", 4); - ASSERT_EQ(id, 3, "struct_id"); + ASSERT_EQ(id, 4, "struct_id"); err = btf__add_field(btf, "x", 2, 0, 0); ASSERT_OK(err, "field_ok"); @@ -178,6 +183,8 @@ static void test_btf_dump_incremental(void) " VAL = 1,\n" "};\n" "\n" +"struct s;\n" +"\n" "struct s {\n" " int x;\n" "};\n\n", "c_dump1"); @@ -199,7 +206,7 @@ static void test_btf_dump_incremental(void) fseek(dump_buf_file, 0, SEEK_SET); id = btf__add_struct(btf, "s", 4); - ASSERT_EQ(id, 4, "struct_id"); + ASSERT_EQ(id, 5, "struct_id"); err = btf__add_field(btf, "x", 1, 0, 0); ASSERT_OK(err, "field_ok"); err = btf__add_field(btf, "s", 3, 32, 0);
Update btf_dump test case for conflict FWD and STRUCT name. Signed-off-by: Xu Kuohai <xukuohai@huawei.com> --- tools/testing/selftests/bpf/prog_tests/btf_dump.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)