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>,
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>, David Vernet <void@manifault.com>,
Tejun Heo <tj@kernel.org>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/4] selftests/bpf: Add tests for ring__consume_n and ring_buffer__consume_n
Date: Sun, 7 Apr 2024 10:09:47 +0200 [thread overview]
Message-ID: <ZhJUy6nWFOFi8oT_@gpd> (raw)
In-Reply-To: <CAEf4BzaR4zqUpDmj44KNLdpJ=Tpa97GrvzuzVNO5nM6b7oWd1w@mail.gmail.com>
On Sat, Apr 06, 2024 at 10:52:10AM -0700, Andrii Nakryiko wrote:
> On Sat, Apr 6, 2024 at 10:39 AM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
> >
> > On Sat, Apr 6, 2024 at 2:20 AM Andrea Righi <andrea.righi@canonical.com> wrote:
> > >
> > > Add tests for new API ring__consume_n() and ring_buffer__consume_n().
> > >
> > > Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> > > ---
> > > tools/testing/selftests/bpf/prog_tests/ringbuf.c | 8 ++++++++
> > > 1 file changed, 8 insertions(+)
> > >
> > > diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> > > index 48c5695b7abf..33aba7684ab9 100644
> > > --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> > > +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c
> > > @@ -304,10 +304,18 @@ static void ringbuf_subtest(void)
> > > err = ring_buffer__consume(ringbuf);
> > > CHECK(err < 0, "rb_consume", "failed: %d\b", err);
> > >
> > > + /* try to consume up to one item */
> > > + err = ring_buffer__consume_n(ringbuf, 1);
> > > + CHECK(err < 0 || err > 1, "rb_consume_n", "failed: %d\b", err);
> > > +
> > > /* also consume using ring__consume to make sure it works the same */
> > > err = ring__consume(ring);
> > > ASSERT_GE(err, 0, "ring_consume");
> > >
> > > + /* try to consume up to one item */
> > > + err = ring__consume_n(ring, 1);
> > > + CHECK(err < 0 || err > 1, "ring_consume_n", "failed: %d\b", err);
> > > +
> >
> > Did you actually run this test? There is ring_buffer__consume() and
> > ring__consume() calls right before your added calls, so consume_n will
> > return zero.
> >
> > I dropped this broken patch. Please send a proper test as a follow up.
>
> Sorry, technically, it's not broken, it just doesn't test much (CHECK
> conditions confused me, I didn't realize you allow zero initially). We
> will never consume anything and the result will be zero, which isn't
> very meaningful.
>
> "Interesting" test would set up things so that we have >1 item in
> ringbuf and we consume exactly one at a time, because that's the new
> logic you added.
>
> I think it will be simpler to add a dedicated and simpler ringbuf test
> for this, where you can specify how many items to submit, and then do
> a bunch of consume/consume_n invocations, checking exact results.
>
> Plus, please don't add new CHECK() uses, use ASSERT_XXX() ones instead.
>
> I've applied first three patches because they look correct and it's
> good to setup libbpf 1.5 dev cycle, but please do follow up with a
> better test. Thanks.
Yeah, sorry, I tried to add a minimal test to the existing one, but I
agree that it not very meaningful.
I already have a better dedicated test case for this
(https://github.com/arighi/ebpf-maps/blob/libbpf-consume-n/src/main.c#L118),
I just need to integrate it in the kselftest properly (and maybe
pre-generate more than N records in the ring buffer, so that we can
better test if the limit works as expected).
I'll send another patch to add a proper test case.
Thanks for applying the other patches!
-Andrea
>
> >
> > > /* 3 rounds, 2 samples each */
> > > cnt = atomic_xchg(&sample_cnt, 0);
> > > CHECK(cnt != 6, "cnt", "exp %d samples, got %d\n", 6, cnt);
> > > --
> > > 2.43.0
> > >
next prev parent reply other threads:[~2024-04-07 8:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-06 9:15 [PATCH v4 0/4] libbpf: API to partially consume items from ringbuffer Andrea Righi
2024-04-06 9:15 ` [PATCH v4 1/4] libbpf: Start v1.5 development cycle Andrea Righi
2024-04-06 9:15 ` [PATCH v4 2/4] libbpf: ringbuf: allow to consume up to a certain amount of items Andrea Righi
2024-04-06 17:41 ` Andrii Nakryiko
2024-04-06 9:15 ` [PATCH v4 3/4] libbpf: Add ring__consume_n / ring_buffer__consume_n Andrea Righi
2024-04-06 9:15 ` [PATCH v4 4/4] selftests/bpf: Add tests for ring__consume_n and ring_buffer__consume_n Andrea Righi
2024-04-06 17:39 ` Andrii Nakryiko
2024-04-06 17:52 ` Andrii Nakryiko
2024-04-07 8:09 ` Andrea Righi [this message]
2024-04-06 17:50 ` [PATCH v4 0/4] libbpf: API to partially consume items from ringbuffer patchwork-bot+netdevbpf
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=ZhJUy6nWFOFi8oT_@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=sdf@google.com \
--cc=song@kernel.org \
--cc=tj@kernel.org \
--cc=void@manifault.com \
--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