[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzYO=yo15WidtJqe_QaMrj+h7VUyufw7xN2XS0GG8Xh8fQ@mail.gmail.com>
Date: Thu, 25 Apr 2024 11:47:07 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Andrea Righi <andrea.righi@...onical.com>
Cc: Andrii Nakryiko <andrii@...nel.org>, Eduard Zingerman <eddyz87@...il.com>,
Mykola Lysenko <mykolal@...com>, Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
Martin KaFai Lau <martin.lau@...ux.dev>, Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>, John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>, Stanislav Fomichev <sdf@...gle.com>, Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>, Shuah Khan <shuah@...nel.org>, linux-kernel@...r.kernel.org,
bpf@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: Re: [PATCH v3] selftests/bpf: Add ring_buffer__consume_n test.
On Thu, Apr 25, 2024 at 7:06 AM Andrea Righi <andrea.righi@...onical.com> wrote:
>
> Add a testcase for the ring_buffer__consume_n() API.
>
> The test produces multiple samples in a ring buffer, using a
> sys_getpid() fentry prog, and consumes them from user-space in batches,
> rather than consuming all of them greedily, like ring_buffer__consume()
> does.
>
> Link: https://lore.kernel.org/lkml/CAEf4BzaR4zqUpDmj44KNLdpJ=Tpa97GrvzuzVNO5nM6b7oWd1w@mail.gmail.com
> Signed-off-by: Andrea Righi <andrea.righi@...onical.com>
> ---
> tools/testing/selftests/bpf/Makefile | 2 +-
> .../selftests/bpf/prog_tests/ringbuf.c | 64 +++++++++++++++++++
> .../selftests/bpf/progs/test_ringbuf_n.c | 47 ++++++++++++++
> 3 files changed, 112 insertions(+), 1 deletion(-)
> create mode 100644 tools/testing/selftests/bpf/progs/test_ringbuf_n.c
>
> ChangeLog v2 -> v3:
> - move skel_n inside ringbuf_n_subtest()
>
> ChangeLog v1 -> v2:
> - replace CHECK() with ASSERT_EQ()
> - fix skel -> skel_n
> - drop unused "seq" field from struct sample
>
[...]
> + /* Produce N_TOT_SAMPLES samples in the ring buffer by calling getpid() */
> + skel_n->bss->value = SAMPLE_VALUE;
> + for (i = 0; i < N_TOT_SAMPLES; i++)
> + syscall(__NR_getpgid);
> +
> + /* Consume all samples from the ring buffer in batches of N_SAMPLES */
> + for (i = 0; i < N_TOT_SAMPLES; i += err) {
> + err = ring_buffer__consume_n(ringbuf, N_SAMPLES);
> + ASSERT_EQ(err, N_SAMPLES, "rb_consume");
if something goes wrong and err is < 0, we might end up with a very
long loop. I changed this to:
if (!ASSERT_EQ(...))
goto cleanup_ringbuf;
to avoid this problem
> + }
> +
> +cleanup_ringbuf:
> + ring_buffer__free(ringbuf);
> +cleanup:
> + test_ringbuf_n_lskel__destroy(skel_n);
> +}
> +
[...]
Powered by blists - more mailing lists