From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>
Subject: Re: [PATCH bpf-next 1/2] bpf: selftests: get rid of CHECK macro in xdp_adjust_tail.c
Date: Wed, 19 Jan 2022 22:54:56 +0100 [thread overview]
Message-ID: <YeiIsGwk8XUcpJDu@lore-desk> (raw)
In-Reply-To: <CAEf4BzafyO6ZnESn_hk56FX6MZoHdfTU6e33_FECv91Y7GFnew@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2448 bytes --]
> On Wed, Jan 19, 2022 at 8:58 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> >
> > Rely on ASSERT* macros and get rid of deprecated CHECK ones in
> > xdp_adjust_tail bpf selftest.
> >
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > ---
> > .../bpf/prog_tests/xdp_adjust_tail.c | 62 +++++++------------
> > 1 file changed, 23 insertions(+), 39 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> > index 3f5a17c38be5..dffa21b35503 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_adjust_tail.c
> > @@ -11,22 +11,19 @@ static void test_xdp_adjust_tail_shrink(void)
> > char buf[128];
> >
> > err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
> > - if (CHECK_FAIL(err))
> > + if (ASSERT_OK(err, "test_xdp_adjust_tail_shrink"))
> > return;
> >
> > err = bpf_prog_test_run(prog_fd, 1, &pkt_v4, sizeof(pkt_v4),
> > buf, &size, &retval, &duration);
> >
> > - CHECK(err || retval != XDP_DROP,
> > - "ipv4", "err %d errno %d retval %d size %d\n",
> > - err, errno, retval, size);
> > + ASSERT_OK(err || retval != XDP_DROP, "ipv4");
>
> it's better to do such checks as two ASSERTS: ASSERT_OK(err) and
> ASSERT_EQ(retval, XDP_DROP). It will give much more meaningful error
> messages and I think is easier to follow.
ack, I will fix it in v2.
>
> >
> > expect_sz = sizeof(pkt_v6) - 20; /* Test shrink with 20 bytes */
> > err = bpf_prog_test_run(prog_fd, 1, &pkt_v6, sizeof(pkt_v6),
> > buf, &size, &retval, &duration);
> > - CHECK(err || retval != XDP_TX || size != expect_sz,
> > - "ipv6", "err %d errno %d retval %d size %d expect-size %d\n",
> > - err, errno, retval, size, expect_sz);
> > + ASSERT_OK(err || retval != XDP_TX || size != expect_sz, "ipv6");
>
> same as above, old CHECK printed all those values so it was ok-ish to
> combine checks. With ASSERT_XXX() let's do each error condition check
> separately. Same for all the rest below.
ack, I will fix it in v2.
Regards,
Lorenzo
>
> > +
> > bpf_object__close(obj);
> > }
> >
>
> [...]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2022-01-19 21:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-19 16:58 [PATCH bpf-next 0/2] rely on ASSERT marcos in xdp_bpf2bpf.c/xdp_adjust_tail.c Lorenzo Bianconi
2022-01-19 16:58 ` [PATCH bpf-next 1/2] bpf: selftests: get rid of CHECK macro in xdp_adjust_tail.c Lorenzo Bianconi
2022-01-19 18:52 ` Andrii Nakryiko
2022-01-19 21:54 ` Lorenzo Bianconi [this message]
2022-01-19 16:58 ` [PATCH bpf-next 2/2] bpf: selftests: get rid of CHECK macro in xdp_bpf2bpf.c Lorenzo Bianconi
2022-01-19 18:54 ` Andrii Nakryiko
2022-01-19 21:53 ` Lorenzo Bianconi
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=YeiIsGwk8XUcpJDu@lore-desk \
--to=lorenzo@kernel.org \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).