mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
bpf: Add test ops for BPF_PROG_TYPE_TRACING
The current fexit and fentry tests rely on a different program to exercise the functions they attach to. Instead of doing this, implement the test operations for tracing which will also be used for BPF_MODIFY_RETURN in a subsequent patch. Also, clean up the fexit test to use the generated skeleton. Signed-off-by: KP Singh <kpsingh@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20200304191853.1529-7-kpsingh@chromium.org
This commit is contained in:
parent
aca228cd33
commit
da00d2f117
6 changed files with 67 additions and 76 deletions
|
@ -160,18 +160,37 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
|
|||
kfree(data);
|
||||
return ERR_PTR(-EFAULT);
|
||||
}
|
||||
if (bpf_fentry_test1(1) != 2 ||
|
||||
bpf_fentry_test2(2, 3) != 5 ||
|
||||
bpf_fentry_test3(4, 5, 6) != 15 ||
|
||||
bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
|
||||
bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
|
||||
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111) {
|
||||
kfree(data);
|
||||
return ERR_PTR(-EFAULT);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int bpf_prog_test_run_tracing(struct bpf_prog *prog,
|
||||
const union bpf_attr *kattr,
|
||||
union bpf_attr __user *uattr)
|
||||
{
|
||||
int err = -EFAULT;
|
||||
|
||||
switch (prog->expected_attach_type) {
|
||||
case BPF_TRACE_FENTRY:
|
||||
case BPF_TRACE_FEXIT:
|
||||
if (bpf_fentry_test1(1) != 2 ||
|
||||
bpf_fentry_test2(2, 3) != 5 ||
|
||||
bpf_fentry_test3(4, 5, 6) != 15 ||
|
||||
bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
|
||||
bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
|
||||
bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111)
|
||||
goto out;
|
||||
break;
|
||||
default:
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
out:
|
||||
trace_bpf_test_finish(&err);
|
||||
return err;
|
||||
}
|
||||
|
||||
static void *bpf_ctx_init(const union bpf_attr *kattr, u32 max_size)
|
||||
{
|
||||
void __user *data_in = u64_to_user_ptr(kattr->test.ctx_in);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue