[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZY6WeSmox6zwxM1-jfWkaomK-3R4+W6M4tg5J=Ti9ARQ@mail.gmail.com>
Date: Thu, 15 Jul 2021 21:53:57 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Shuyi Cheng <chengshuyi@...ux.alibaba.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, Martin Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
john fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
open list <linux-kernel@...r.kernel.org>,
kernel-janitors@...r.kernel.org
Subject: Re: [PATCH bpf-next v4 3/3] selftests/bpf: Switches existing
selftests to using open_opts for custom BTF
On Tue, Jul 13, 2021 at 5:43 AM Shuyi Cheng
<chengshuyi@...ux.alibaba.com> wrote:
>
> This patch mainly replaces the bpf_object_load_attr of
> the core_autosize.c and core_reloc.c files with bpf_object_open_opts.
>
> Signed-off-by: Shuyi Cheng <chengshuyi@...ux.alibaba.com>
> ---
> .../selftests/bpf/prog_tests/core_autosize.c | 22 ++++++++---------
> .../testing/selftests/bpf/prog_tests/core_reloc.c | 28 ++++++++++------------
> 2 files changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/core_autosize.c b/tools/testing/selftests/bpf/prog_tests/core_autosize.c
> index 981c251..d163342 100644
> --- a/tools/testing/selftests/bpf/prog_tests/core_autosize.c
> +++ b/tools/testing/selftests/bpf/prog_tests/core_autosize.c
> @@ -54,7 +54,7 @@ void test_core_autosize(void)
> int err, fd = -1, zero = 0;
> int char_id, short_id, int_id, long_long_id, void_ptr_id, id;
> struct test_core_autosize* skel = NULL;
> - struct bpf_object_load_attr load_attr = {};
> + struct bpf_object_open_opts open_opts = {};
> struct bpf_program *prog;
> struct bpf_map *bss_map;
> struct btf *btf = NULL;
> @@ -125,9 +125,11 @@ void test_core_autosize(void)
> fd = -1;
>
> /* open and load BPF program with custom BTF as the kernel BTF */
> - skel = test_core_autosize__open();
> + open_opts.btf_custom_path = btf_file;
> + open_opts.sz = sizeof(struct bpf_object_open_opts);
> + skel = test_core_autosize__open_opts(&open_opts);
> if (!ASSERT_OK_PTR(skel, "skel_open"))
> - return;
> + goto cleanup;
>
> /* disable handle_signed() for now */
> prog = bpf_object__find_program_by_name(skel->obj, "handle_signed");
> @@ -135,9 +137,7 @@ void test_core_autosize(void)
> goto cleanup;
> bpf_program__set_autoload(prog, false);
>
> - load_attr.obj = skel->obj;
> - load_attr.target_btf_path = btf_file;
> - err = bpf_object__load_xattr(&load_attr);
> + err = bpf_object__load(skel->obj);
> if (!ASSERT_OK(err, "prog_load"))
> goto cleanup;
>
> @@ -204,13 +204,13 @@ void test_core_autosize(void)
> skel = NULL;
>
> /* now re-load with handle_signed() enabled, it should fail loading */
> - skel = test_core_autosize__open();
> + open_opts.btf_custom_path = btf_file;
> + open_opts.sz = sizeof(struct bpf_object_open_opts);
For opts structs libbpf provides DECLARE_LIBBPF_OPTS macro for their
initialization which zeroes the struct out and sets its sz
automatically. So I'll switch to using that instead. All the rest
looks good.
> + skel = test_core_autosize__open_opts(&opts);
> if (!ASSERT_OK_PTR(skel, "skel_open"))
> - return;
> + goto cleanup;
>
> - load_attr.obj = skel->obj;
> - load_attr.target_btf_path = btf_file;
> - err = bpf_object__load_xattr(&load_attr);
> + err = bpf_object__load(skel);
> if (!ASSERT_ERR(err, "bad_prog_load"))
> goto cleanup;
>
[...]
Powered by blists - more mailing lists