public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrea Righi <andrea.righi@canonical.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Mykola Lysenko <mykolal@fb.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
	linux-kernel@vger.kernel.org, bpf@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3] selftests/bpf: Add ring_buffer__consume_n test.
Date: Thu, 25 Apr 2024 22:12:33 +0200	[thread overview]
Message-ID: <Ziq5MVRnraMPzGMS@gpd> (raw)
In-Reply-To: <CAEf4BzYO=yo15WidtJqe_QaMrj+h7VUyufw7xN2XS0GG8Xh8fQ@mail.gmail.com>

On Thu, Apr 25, 2024 at 11:47:07AM -0700, Andrii Nakryiko wrote:
> On Thu, Apr 25, 2024 at 7:06 AM Andrea Righi <andrea.righi@canonical.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@canonical.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

Looks good, tested, just in case, and it works a expected.

Thanks!
-Andrea

> 
> > +       }
> > +
> > +cleanup_ringbuf:
> > +       ring_buffer__free(ringbuf);
> > +cleanup:
> > +       test_ringbuf_n_lskel__destroy(skel_n);
> > +}
> > +
> 
> [...]

      reply	other threads:[~2024-04-25 20:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 14:06 [PATCH v3] selftests/bpf: Add ring_buffer__consume_n test Andrea Righi
2024-04-25 17:15 ` Jiri Olsa
2024-04-25 18:47 ` Andrii Nakryiko
2024-04-25 20:12   ` Andrea Righi [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ziq5MVRnraMPzGMS@gpd \
    --to=andrea.righi@canonical.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox