Re: [RFC PATCH bpf-next 3/3] selftests/bpf: Add case to test BPF_F_CPU

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

 



On Tue, Jun 24, 2025 at 9:55 AM Leon Hwang <leon.hwang@xxxxxxxxx> wrote:
>
> This patch adds test coverage for the new BPF_F_CPU flag support in
> percpu_array maps. The following APIs are exercised:
>
> * bpf_map_update_batch()
> * bpf_map_lookup_batch()
> * bpf_map_update_elem_opts()
> * bpf_map__update_elem_opts()
> * bpf_map_lookup_elem_opts()
> * bpf_map__lookup_elem_opts()
>
> cd tools/testing/selftests/bpf/
> ./test_progs -t percpu_alloc/cpu_flag_tests
> 251/5   percpu_alloc/cpu_flag_tests:OK
> 251     percpu_alloc:OK
> Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
>
> Signed-off-by: Leon Hwang <leon.hwang@xxxxxxxxx>
> ---
>  .../selftests/bpf/prog_tests/percpu_alloc.c   | 169 ++++++++++++++++++
>  .../selftests/bpf/progs/percpu_array_flag.c   |  24 +++
>  2 files changed, 193 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/progs/percpu_array_flag.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c b/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c
> index 343da65864d6..5727f4601b49 100644
> --- a/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c
> +++ b/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c
> @@ -3,6 +3,7 @@
>  #include "percpu_alloc_array.skel.h"
>  #include "percpu_alloc_cgrp_local_storage.skel.h"
>  #include "percpu_alloc_fail.skel.h"
> +#include "percpu_array_flag.skel.h"
>
>  static void test_array(void)
>  {
> @@ -115,6 +116,172 @@ static void test_failure(void) {
>         RUN_TESTS(percpu_alloc_fail);
>  }
>
> +static void test_cpu_flag(void)
> +{
> +       int map_fd, *keys = NULL, value_size, cpu, i, j, nr_cpus, err;
> +       size_t key_sz = sizeof(int), value_sz = sizeof(u64);
> +       struct percpu_array_flag *skel;
> +       u64 batch = 0, *values = NULL;
> +       const u64 value = 0xDEADC0DE;
> +       u32 count, max_entries;
> +       struct bpf_map *map;
> +       DECLARE_LIBBPF_OPTS(bpf_map_lookup_elem_opts, lookup_opts,
> +                           .flags = BPF_F_CPU,
> +                           .cpu = 0,
> +       );

use shorter LIBBPF_OPTS macro, please

> +       DECLARE_LIBBPF_OPTS(bpf_map_update_elem_opts, update_opts,
> +                           .flags = BPF_F_CPU,
> +                           .cpu = 0,
> +       );
> +       DECLARE_LIBBPF_OPTS(bpf_map_batch_opts, batch_opts,
> +                           .elem_flags = BPF_F_CPU,
> +                           .flags = 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