1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/tools/testing/selftests/bpf/prog_tests/trampoline_count.c
Menglong Dong 5e9cf77d81 selftests/bpf: add testcase for TRACING with 6+ arguments
Add fentry_many_args.c and fexit_many_args.c to test the fentry/fexit
with 7/11 arguments. As this feature is not supported by arm64 yet, we
disable these testcases for arm64 in DENYLIST.aarch64. We can combine
them with fentry_test.c/fexit_test.c when arm64 is supported too.

Correspondingly, add bpf_testmod_fentry_test7() and
bpf_testmod_fentry_test11() to bpf_testmod.c

Meanwhile, add bpf_modify_return_test2() to test_run.c to test the
MODIFY_RETURN with 7 arguments.

Add bpf_testmod_test_struct_arg_7/bpf_testmod_test_struct_arg_7 in
bpf_testmod.c to test the struct in the arguments.

And the testcases passed on x86_64:

./test_progs -t fexit
Summary: 5/14 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t fentry
Summary: 3/2 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t modify_return
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

./test_progs -t tracing_struct
Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: Menglong Dong <imagedong@tencent.com>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20230713040738.1789742-4-imagedong@tencent.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-07-13 16:04:56 -07:00

100 lines
2.4 KiB
C

// SPDX-License-Identifier: GPL-2.0-only
#define _GNU_SOURCE
#include <test_progs.h>
struct inst {
struct bpf_object *obj;
struct bpf_link *link;
};
static struct bpf_program *load_prog(char *file, char *name, struct inst *inst)
{
struct bpf_object *obj;
struct bpf_program *prog;
int err;
obj = bpf_object__open_file(file, NULL);
if (!ASSERT_OK_PTR(obj, "obj_open_file"))
return NULL;
inst->obj = obj;
err = bpf_object__load(obj);
if (!ASSERT_OK(err, "obj_load"))
return NULL;
prog = bpf_object__find_program_by_name(obj, name);
if (!ASSERT_OK_PTR(prog, "obj_find_prog"))
return NULL;
return prog;
}
/* TODO: use different target function to run in concurrent mode */
void serial_test_trampoline_count(void)
{
char *file = "test_trampoline_count.bpf.o";
char *const progs[] = { "fentry_test", "fmod_ret_test", "fexit_test" };
int bpf_max_tramp_links, err, i, prog_fd;
struct bpf_program *prog;
struct bpf_link *link;
struct inst *inst;
LIBBPF_OPTS(bpf_test_run_opts, opts);
bpf_max_tramp_links = get_bpf_max_tramp_links();
if (!ASSERT_GE(bpf_max_tramp_links, 1, "bpf_max_tramp_links"))
return;
inst = calloc(bpf_max_tramp_links + 1, sizeof(*inst));
if (!ASSERT_OK_PTR(inst, "inst"))
return;
/* attach 'allowed' trampoline programs */
for (i = 0; i < bpf_max_tramp_links; i++) {
prog = load_prog(file, progs[i % ARRAY_SIZE(progs)], &inst[i]);
if (!prog)
goto cleanup;
link = bpf_program__attach(prog);
if (!ASSERT_OK_PTR(link, "attach_prog"))
goto cleanup;
inst[i].link = link;
}
/* and try 1 extra.. */
prog = load_prog(file, "fmod_ret_test", &inst[i]);
if (!prog)
goto cleanup;
/* ..that needs to fail */
link = bpf_program__attach(prog);
if (!ASSERT_ERR_PTR(link, "attach_prog")) {
inst[i].link = link;
goto cleanup;
}
/* with E2BIG error */
if (!ASSERT_EQ(libbpf_get_error(link), -E2BIG, "E2BIG"))
goto cleanup;
if (!ASSERT_EQ(link, NULL, "ptr_is_null"))
goto cleanup;
/* and finally execute the probe */
prog_fd = bpf_program__fd(prog);
if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd"))
goto cleanup;
err = bpf_prog_test_run_opts(prog_fd, &opts);
if (!ASSERT_OK(err, "bpf_prog_test_run_opts"))
goto cleanup;
ASSERT_EQ(opts.retval & 0xffff, 33, "bpf_modify_return_test.result");
ASSERT_EQ(opts.retval >> 16, 2, "bpf_modify_return_test.side_effect");
cleanup:
for (; i >= 0; i--) {
bpf_link__destroy(inst[i].link);
bpf_object__close(inst[i].obj);
}
free(inst);
}