lkml.org 
[lkml]   [2021]   [Jul]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [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@linux.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@linux.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;
>

[...]

\
 
 \ /
  Last update: 2021-07-16 06:55    [W:0.060 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site