Add an arena_autobind_manual subtest to struct_ops_arena. It marks every program of struct_ops_arena_autobind as MANUAL, prepares the object, then loads each program with bpf_program__load() and checks that it is bound to the arena before unloading it. This is the same check arena_autobind_clone does for bpf_program__clone(). Also reword the arena_autobind_clone() comment, which no longer refers to veristat. Signed-off-by: Andrey Grodzovsky --- .../bpf/prog_tests/test_struct_ops_arena.c | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c index e7580b9f0fc2..a8bd10bab5dd 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c +++ b/tools/testing/selftests/bpf/prog_tests/test_struct_ops_arena.c @@ -192,9 +192,9 @@ static void arena_autobind(void) } /* - * The same binding through bpf_object__prepare() and bpf_program__clone(), the - * way veristat loads a program: the arena takes slot 0 of a continuous - * fd_array, next to the module BTF of the kfunc the trigger calls. + * The same binding through bpf_object__prepare() and bpf_program__clone(), + * the arena takes slot 0 of a continuous fd_array, next to the module BTF + * of the kfunc the trigger calls. */ static void arena_autobind_clone(void) { @@ -225,6 +225,46 @@ static void arena_autobind_clone(void) struct_ops_arena_autobind__destroy(skel); } +/* + * The same binding through BPF_PROG_LOAD_STRATEGY_MANUAL: every program is + * loaded with bpf_program__load() after bpf_object__prepare() and unloaded + * again, the way veristat loads programs. + */ +static void arena_autobind_manual(void) +{ + struct struct_ops_arena_autobind *skel; + struct bpf_map_info info = {}; + __u32 len = sizeof(info); + struct bpf_program *prog; + int err; + + skel = struct_ops_arena_autobind__open(); + if (!ASSERT_OK_PTR(skel, "struct_ops_arena_autobind__open")) + return; + + bpf_object__for_each_program(prog, skel->obj) { + err = bpf_program__set_load_strategy(prog, BPF_PROG_LOAD_STRATEGY_MANUAL); + if (!ASSERT_OK(err, "set_load_strategy")) + goto out; + } + err = bpf_object__prepare(skel->obj); + if (!ASSERT_OK(err, "prepare")) + goto out; + err = bpf_map_get_info_by_fd(bpf_map__fd(skel->maps.arena), &info, &len); + if (!ASSERT_OK(err, "arena_info")) + goto out; + bpf_object__for_each_program(prog, skel->obj) { + err = bpf_program__load(prog); + if (!ASSERT_OK(err, bpf_program__name(prog))) + continue; + assert_prog_map(bpf_program__fd(prog), info.id, bpf_program__name(prog)); + bpf_program__unload(prog); + ASSERT_LT(bpf_program__fd(prog), 0, "unloaded"); + } +out: + struct_ops_arena_autobind__destroy(skel); +} + /* * An arena exclusive to a program is bound to that program all the same: the * kernel checks an exclusive map against the digest of the final program, so @@ -315,6 +355,8 @@ void serial_test_struct_ops_arena(void) arena_autobind(); if (test__start_subtest("arena_autobind_clone")) arena_autobind_clone(); + if (test__start_subtest("arena_autobind_manual")) + arena_autobind_manual(); if (test__start_subtest("arena_autobind_excl")) arena_autobind_excl(); #else -- 2.34.1