From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9341AC433EF for ; Wed, 16 Feb 2022 18:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237362AbiBPSVX (ORCPT ); Wed, 16 Feb 2022 13:21:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:46912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236822AbiBPSVW (ORCPT ); Wed, 16 Feb 2022 13:21:22 -0500 Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 373F21C55B0; Wed, 16 Feb 2022 10:21:10 -0800 (PST) Received: by mail-il1-x12b.google.com with SMTP id k18so414555ils.11; Wed, 16 Feb 2022 10:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ceCMWbh50/66jZx1xnt7I1BjFS8HnV/WnrUpiH5ABZQ=; b=pR+8gufuTKBgV3oqoVCAUjEKP4M7llkkrsO29IVIRnNCQMI7KF9OA+ldij1qKWJuZU I4IMZB5VgaK0ZFPrmEl7D5V3Qcti+DBdmQ7179vFkU4ytUuFiZymXS5sJ1YcDFcqrZxJ CLsK1r6gJajzwYJlFZQPT3mmmQ6HNiSbpDTCcQ0ZhZmUDMGnmfP51y8olFhRwXcs4Xgh BEEzlF/IWeUJBb3Xee2gnT8K+UBaJxd15zmlQF2afUzwjvnYQ4G7fTojOqQnViuYc2IY qWMoJQLTTY7C3LfL4zsoefdRL6z/M5zAApAX3LNEcLnLfl37kWrQK5GNr+iQiUw9+v4e 3NQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ceCMWbh50/66jZx1xnt7I1BjFS8HnV/WnrUpiH5ABZQ=; b=eusZLVZs7jFMRdF9JMzVUot5l8GIirooFBOPOOtJ2GfFq4xLhrSKpyQe4HZTih2Jlu Fwt/crlhikwWmw+2Q4QkRaZJZRq0T3szIXA16+gRoTdawWDj0rb1GPslGaQe34u4iGEI y5z/6p4oFJ7Au18c4Jv09Mdg7C1Lt6cgFi5Cy74oXc8+mdls94lKHTw1S5ht65FsFJyd ovHP67mTgVKHkIhs1/RSPZ4bWsSmCWPk6UsjuGgcZFX3oRplj/NSxNeigYWYfrRjoQhK RzYQ4AB2SgXwCqxejgSth46KyUZL7nZSMTdnlj5fGbs3s168xOKFPdp656xC8HsVOa3i pbFw== X-Gm-Message-State: AOAM533y7V9AYUNJLlmQpLeAJi+89WkzpbMGN59WQ7cO+DWBZ6DdIPVR A8k7io8Krx9JLSu4k2tXwPjqfsDEQaoYhv3XBjw= X-Google-Smtp-Source: ABdhPJwM2qA7iV3+VdmujHCpHNDB6X0sQ6SjoLcgkJ4pIQgll17+QtrCisJKMJqapeZ55C3dr4sFjoETXT2IcNQ8hvU= X-Received: by 2002:a05:6e02:503:b0:2bf:a929:4dc3 with SMTP id d3-20020a056e02050300b002bfa9294dc3mr2596084ils.98.1645035669605; Wed, 16 Feb 2022 10:21:09 -0800 (PST) MIME-Version: 1.0 References: <20220215225856.671072-1-mauricio@kinvolk.io> <20220215225856.671072-8-mauricio@kinvolk.io> In-Reply-To: <20220215225856.671072-8-mauricio@kinvolk.io> From: Andrii Nakryiko Date: Wed, 16 Feb 2022 10:20:58 -0800 Message-ID: Subject: Re: [PATCH bpf-next v7 7/7] selftests/bpf: Test "bpftool gen min_core_btf" To: =?UTF-8?Q?Mauricio_V=C3=A1squez?= Cc: Networking , bpf , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Quentin Monnet , Rafael David Tinoco , Lorenzo Fontana , Leonardo Di Donato Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Tue, Feb 15, 2022 at 2:59 PM Mauricio V=C3=A1squez = wrote: > > This commit reuses the core_reloc test to check if the BTF files > generated with "bpftool gen min_core_btf" are correct. This introduces > test_core_btfgen() that runs all the core_reloc tests, but this time > the source BTF files are generated by using "bpftool gen min_core_btf". > > The goal of this test is to check that the generated files are usable, > and not to check if the algorithm is creating an optimized BTF file. > > Signed-off-by: Mauricio V=C3=A1squez > Signed-off-by: Rafael David Tinoco > Signed-off-by: Lorenzo Fontana > Signed-off-by: Leonardo Di Donato > --- > .../selftests/bpf/prog_tests/core_reloc.c | 50 ++++++++++++++++++- > 1 file changed, 48 insertions(+), 2 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/core_reloc.c b/tools/= testing/selftests/bpf/prog_tests/core_reloc.c > index 68e4c8dafa00..fa2908879c77 100644 > --- a/tools/testing/selftests/bpf/prog_tests/core_reloc.c > +++ b/tools/testing/selftests/bpf/prog_tests/core_reloc.c > @@ -2,6 +2,7 @@ > #include > #include "progs/core_reloc_types.h" > #include "bpf_testmod/bpf_testmod.h" > +#include > #include > #include > #include > @@ -836,13 +837,27 @@ static size_t roundup_page(size_t sz) > return (sz + page_size - 1) / page_size * page_size; > } > > -void test_core_reloc(void) > +static int run_btfgen(const char *src_btf, const char *dst_btf, const ch= ar *objpath) > +{ > + char command[4096]; > + int n; > + > + n =3D snprintf(command, sizeof(command), > + "./tools/build/bpftool/bpftool gen min_core_btf %s %= s %s", > + src_btf, dst_btf, objpath); > + if (n < 0 || n >=3D sizeof(command)) > + return -1; > + > + return system(command); > +} > + > +static void run_core_reloc_tests(bool use_btfgen) > { > const size_t mmap_sz =3D roundup_page(sizeof(struct data)); > DECLARE_LIBBPF_OPTS(bpf_object_open_opts, open_opts); > struct core_reloc_test_case *test_case; > const char *tp_name, *probe_name; > - int err, i, equal; > + int err, i, equal, fd; > struct bpf_link *link =3D NULL; > struct bpf_map *data_map; > struct bpf_program *prog; > @@ -854,6 +869,7 @@ void test_core_reloc(void) > my_pid_tgid =3D getpid() | ((uint64_t)syscall(SYS_gettid) << 32); > > for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) { > + char btf_file[] =3D "/tmp/core_reloc.btf.XXXXXX"; > test_case =3D &test_cases[i]; > if (!test__start_subtest(test_case->case_name)) > continue; > @@ -863,6 +879,25 @@ void test_core_reloc(void) > continue; > } > > + /* generate a "minimal" BTF file and use it as source */ > + if (use_btfgen) { > + if (!test_case->btf_src_file || test_case->fails)= { > + test__skip(); > + continue; > + } > + > + fd =3D mkstemp(btf_file); > + if (CHECK(fd < 0, "btf_tmp", "failed to create fi= le: %d\n", fd)) > + goto cleanup; no new CHECK()s, please > + close(fd); /* we only need the path */ > + err =3D run_btfgen(test_case->btf_src_file, btf_f= ile, > + test_case->bpf_obj_file); > + if (!ASSERT_OK(err, "run_btfgen")) > + goto cleanup; > + > + test_case->btf_src_file =3D btf_file; > + } > + > if (test_case->setup) { > err =3D test_case->setup(test_case); > if (CHECK(err, "test_setup", "test #%d setup fail= ed: %d\n", i, err)) > @@ -954,8 +989,19 @@ void test_core_reloc(void) > CHECK_FAIL(munmap(mmap_data, mmap_sz)); > mmap_data =3D NULL; > } > + remove(btf_file); would be a bit safer to do unlink() here instead of remove, but it's probably fine as is (I didn't touch this part) > bpf_link__destroy(link); > link =3D NULL; > bpf_object__close(obj); > } > } > + > +void test_core_reloc(void) > +{ > + run_core_reloc_tests(false); > +} > + > +void test_core_btfgen(void) > +{ > + run_core_reloc_tests(true); > +} > -- > 2.25.1 >