Thread (10 messages) flat view 10 messages, 2 authors, 2021-07-17

Re: [PATCH bpf-next v4 3/3] selftests/bpf: Switches existing selftests to using open_opts for custom BTF

From: Andrii Nakryiko <hidden>
Date: 2021-07-16 04:54:12
Also in: bpf, kernel-janitors, lkml

On Tue, Jul 13, 2021 at 5:43 AM Shuyi Cheng
[off-list ref] wrote:
quoted hunk ↗ jump to hunk
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 <redacted>
---
 .../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;
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help