> On Oct 4, 2021, at 11:47 PM, andrii.nakryiko@xxxxxxxxx wrote: > > From: Andrii Nakryiko <andrii@xxxxxxxxxx> > > Add a test that validates that btf__add_btf() API is correctly copying > all the types from the source BTF into destination BTF object and > adjusts type IDs and string offsets properly. > > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > --- > .../selftests/bpf/prog_tests/btf_write.c | 86 +++++++++++++++++++ > 1 file changed, 86 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/btf_write.c b/tools/testing/selftests/bpf/prog_tests/btf_write.c > index aa4505618252..75fd280f75b2 100644 > --- a/tools/testing/selftests/bpf/prog_tests/btf_write.c > +++ b/tools/testing/selftests/bpf/prog_tests/btf_write.c > @@ -342,8 +342,94 @@ static void test_btf_add() > btf__free(btf); > } > > +static void test_btf_add_btf() > +{ > + struct btf *btf1 = NULL, *btf2 = NULL; > + int id; > + > + btf1 = btf__new_empty(); > + if (!ASSERT_OK_PTR(btf1, "btf1")) > + return; > + > + btf2 = btf__new_empty(); > + if (!ASSERT_OK_PTR(btf2, "btf2")) > + return; We need goto cleanup here, no? Thanks, Song