Re: [PATCH v4 4/4] selftests/bpf: Add tests for ring__consume_n and ring_buffer__consume_n

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

 



On Sat, Apr 6, 2024 at 10:39 AM Andrii Nakryiko
<andrii.nakryiko@xxxxxxxxx> wrote:
>
> On Sat, Apr 6, 2024 at 2:20 AM Andrea Righi <andrea.righi@xxxxxxxxxxxxx> wrote:
> >
> > Add tests for new API ring__consume_n() and ring_buffer__consume_n().
> >
> > Signed-off-by: Andrea Righi <andrea.righi@xxxxxxxxxxxxx>
> > ---
> >  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.

>
> >         /* 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
> >





[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