Re: [PATCH bpf-next v4 9/9] selftests/bpf: ringbuf_multi: test bpf_map__set_inner_map_fd

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

 



On Wed, Apr 7, 2021 at 11:14 PM Yauheni Kaliuta
<yauheni.kaliuta@xxxxxxxxxx> wrote:
>
> Test map__set_inner_map_fd() interaction with map-in-map
> initialization. Use hashmap of maps just to make it different to
> existing array of maps.
>
> Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@xxxxxxxxxx>
> ---
>  .../testing/selftests/bpf/prog_tests/ringbuf_multi.c  | 11 +++++++++++
>  .../testing/selftests/bpf/progs/test_ringbuf_multi.c  | 11 +++++++++++
>  2 files changed, 22 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
> index 159de99621c7..0e79a7d28361 100644
> --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
> +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c
> @@ -44,6 +44,7 @@ void test_ringbuf_multi(void)
>         struct ring_buffer *ringbuf = NULL;
>         int err;
>         int page_size = getpagesize();
> +       int proto_fd;
>
>         skel = test_ringbuf_multi__open();
>         if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
> @@ -61,10 +62,20 @@ void test_ringbuf_multi(void)
>         if (CHECK(err != 0, "bpf_map__set_max_entries", "bpf_map__set_max_entries failed\n"))
>                 goto cleanup;
>
> +       proto_fd = bpf_create_map(BPF_MAP_TYPE_RINGBUF, 0, 0, page_size, 0);
> +       if (CHECK(proto_fd == -1, "bpf_create_map", "bpf_create_map failed\n"))
> +               goto cleanup;
> +
> +       err = bpf_map__set_inner_map_fd(skel->maps.ringbuf_hash, proto_fd);
> +       if (CHECK(err != 0, "bpf_map__set_inner_map_fd", "bpf_map__set_inner_map_fd failed\n"))
> +               goto cleanup;
> +
>         err = test_ringbuf_multi__load(skel);
>         if (CHECK(err != 0, "skel_load", "skeleton load failed\n"))
>                 goto cleanup;
>
> +       close(proto_fd);
> +

This will leak FD if any of two previous CHECK()s fail. Fixed it up
while applying.

>         /* only trigger BPF program for current process */
>         skel->bss->pid = getpid();
>
> diff --git a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
> index 055c10b2ff80..197b86546dca 100644
> --- a/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
> +++ b/tools/testing/selftests/bpf/progs/test_ringbuf_multi.c
> @@ -30,6 +30,17 @@ struct {
>         },
>  };
>
> +struct {
> +       __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
> +       __uint(max_entries, 1);
> +       __type(key, int);
> +       __array(values, struct ringbuf_map);
> +} ringbuf_hash SEC(".maps") = {
> +       .values = {
> +               [0] = &ringbuf1,
> +       },
> +};
> +
>  /* inputs */
>  int pid = 0;
>  int target_ring = 0;
> --
> 2.31.1
>



[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