Subject: Re: [PATCH v3 bpf-next 5/5] selftests/bpf: add selftest for bpf_xdp_ct_add and bpf_ct_refresh_timeout kfunc

From: Lorenzo Bianconi <[email-masked]>
Date: Sat, 21 May 2022 11:56:16 +0200

> On Wed, May 18, 2022 at 3:44 AM Lorenzo Bianconi <[email-masked]> wrote:
> >
> > Introduce selftests for the following kfunc helpers:
> > - bpf_xdp_ct_add
> > - bpf_skb_ct_add
> > - bpf_ct_refresh_timeout
> >
> > Signed-off-by: Lorenzo Bianconi <[email-masked]>
> > ---
> >  .../testing/selftests/bpf/prog_tests/bpf_nf.c |  4 ++
> >  .../testing/selftests/bpf/progs/test_bpf_nf.c | 72 +++++++++++++++----
> >  2 files changed, 64 insertions(+), 12 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_nf.c b/tools/testing/selftests/bpf/prog_tests/bpf_nf.c
> > index dd30b1e3a67c..be6c5650892f 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/bpf_nf.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_nf.c
> > @@ -39,6 +39,10 @@ void test_bpf_nf_ct(int mode)
> >         ASSERT_EQ(skel->bss->test_enonet_netns_id, -ENONET, "Test ENONET for bad but valid netns_id");
> >         ASSERT_EQ(skel->bss->test_enoent_lookup, -ENOENT, "Test ENOENT for failed lookup");
> >         ASSERT_EQ(skel->bss->test_eafnosupport, -EAFNOSUPPORT, "Test EAFNOSUPPORT for invalid len__tuple");
> > +       ASSERT_EQ(skel->bss->test_add_entry, 0, "Test for adding new entry");
> > +       ASSERT_EQ(skel->bss->test_succ_lookup, 0, "Test for successful lookup");
> > +       ASSERT_TRUE(skel->bss->test_delta_timeout > 9 && skel->bss->test_delta_timeout <= 10,
> > +                   "Test for ct timeout update");
> 
> if/when this fails we'll have "true != false" message not knowing what
> was the actual value of skel->bss->test_delta_timeout.
> 
> This is equivalent to a much better:
> 
> ASSERT_GT(skel->bss->test_delta_timeout, 9, "ct_timeout1");
> ASSERT_LE(skel->bss->test_delta_timeout, 10, "ct_timeout2");

ack, I will fix it in the next version.

Regards,
Lorenzo

> 
> >  end:
> >         test_bpf_nf__destroy(skel);
> >  }
> 
> 
> [...]