Re: [PATCH bpf-next v3 3/3] selftests/bpf: Add libbpf_probe_bpf_kfunc API selftests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 24, 2025 at 6:44 AM Tao Chen <chen.dylane@xxxxxxxxx> wrote:
>
> Add selftests for prog_kfunc feature probing.
>  ./test_progs -t libbpf_probe_kfuncs
>  #153     libbpf_probe_kfuncs:OK
>  Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
>
> Signed-off-by: Tao Chen <chen.dylane@xxxxxxxxx>
> ---
>  .../selftests/bpf/prog_tests/libbpf_probes.c  | 35 +++++++++++++++++++
>  1 file changed, 35 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> index 4ed46ed58a7b..d9d69941f694 100644
> --- a/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> +++ b/tools/testing/selftests/bpf/prog_tests/libbpf_probes.c
> @@ -126,3 +126,38 @@ void test_libbpf_probe_helpers(void)
>                 ASSERT_EQ(res, d->supported, buf);
>         }
>  }
> +
> +void test_libbpf_probe_kfuncs(void)
> +{
> +       int ret, kfunc_id;
> +       char *kfunc = "bpf_cpumask_create";
> +       struct btf *btf;
> +
> +       btf = btf__parse("/sys/kernel/btf/vmlinux", NULL);
> +       if (!ASSERT_OK_PTR(btf, "btf_parse"))
> +               return;
> +
> +       kfunc_id = btf__find_by_name_kind(btf, kfunc, BTF_KIND_FUNC);
> +       if (!ASSERT_GT(kfunc_id, 0, kfunc))
> +               goto cleanup;
> +
> +       /* prog BPF_PROG_TYPE_SYSCALL supports kfunc bpf_cpumask_create */
> +       ret = libbpf_probe_bpf_kfunc(BPF_PROG_TYPE_SYSCALL, kfunc_id, 0, NULL);
> +       ASSERT_EQ(ret, 1, kfunc);
> +
> +       /* prog BPF_PROG_TYPE_KPROBE does not support kfunc bpf_cpumask_create */
> +       ret = libbpf_probe_bpf_kfunc(BPF_PROG_TYPE_KPROBE, kfunc_id, 0, NULL);
> +       ASSERT_EQ(ret, 0, kfunc);
> +
> +       /* invalid kfunc id */
> +       ret = libbpf_probe_bpf_kfunc(BPF_PROG_TYPE_KPROBE, -1, 0, NULL);
> +       ASSERT_EQ(ret, 0, "invalid kfunc id:-1");
> +
> +       /* invalid prog type */
> +       ret = libbpf_probe_bpf_kfunc(100000, kfunc_id, 0, NULL);
> +       if (!ASSERT_LE(ret, 0, "invalid prog type:100000"))

we have ASSERT_ERR(), wouldn't it work here?


let's also add a test for kfunc in module (we have bpf_testmod, we
should be able to test something out of there)

> +               goto cleanup;
> +
> +cleanup:
> +       btf__free(btf);
> +}
> --
> 2.43.0
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux