[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201218115320.396dbcfc@carbon>
Date: Fri, 18 Dec 2020 11:53:20 +0100
From: Jesper Dangaard Brouer <brouer@...hat.com>
To: bpf@...r.kernel.org
Cc: netdev@...r.kernel.org, Daniel Borkmann <borkmann@...earbox.net>,
Alexei Starovoitov <alexei.starovoitov@...il.com>,
maze@...gle.com, lmb@...udflare.com, shaun@...era.io,
Lorenzo Bianconi <lorenzo@...nel.org>, marek@...udflare.com,
John Fastabend <john.fastabend@...il.com>,
Jakub Kicinski <kuba@...nel.org>, eyal.birger@...il.com,
colrack@...il.com, brouer@...hat.com
Subject: Re: [PATCH bpf-next V9 7/7] bpf/selftests: tests using
bpf_check_mtu BPF-helper
On Thu, 17 Dec 2020 18:26:50 +0100
Jesper Dangaard Brouer <brouer@...hat.com> wrote:
> Adding selftest for BPF-helper bpf_check_mtu(). Making sure
> it can be used from both XDP and TC.
>
> Signed-off-by: Jesper Dangaard Brouer <brouer@...hat.com>
> ---
> tools/testing/selftests/bpf/prog_tests/check_mtu.c | 204 ++++++++++++++++++++
> tools/testing/selftests/bpf/progs/test_check_mtu.c | 196 +++++++++++++++++++
> 2 files changed, 400 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/check_mtu.c
> create mode 100644 tools/testing/selftests/bpf/progs/test_check_mtu.c
Will send V10 as I have an error in this selftests
> diff --git a/tools/testing/selftests/bpf/prog_tests/check_mtu.c b/tools/testing/selftests/bpf/prog_tests/check_mtu.c
> new file mode 100644
> index 000000000000..b5d0c3a9abe8
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/check_mtu.c
[...]
> +static void test_check_mtu_run_xdp(struct test_check_mtu *skel,
> + struct bpf_program *prog,
> + __u32 mtu_expect)
> +{
> + const char *prog_name = bpf_program__name(prog);
> + int retval_expect = XDP_PASS;
> + __u32 mtu_result = 0;
> + char buf[256];
> + int err;
> +
> + struct bpf_prog_test_run_attr tattr = {
> + .repeat = 1,
> + .data_in = &pkt_v4,
> + .data_size_in = sizeof(pkt_v4),
> + .data_out = buf,
> + .data_size_out = sizeof(buf),
> + .prog_fd = bpf_program__fd(prog),
> + };
> +
> + memset(buf, 0, sizeof(buf));
> +
> + err = bpf_prog_test_run_xattr(&tattr);
> + CHECK_ATTR(err != 0 || errno != 0, "bpf_prog_test_run",
^^^^^^^^^^^
You/I cannot use the check "errno != 0" here, as something else could
have set it earlier.
> + "prog_name:%s (err %d errno %d retval %d)\n",
> + prog_name, err, errno, tattr.retval);
> +
> + CHECK(tattr.retval != retval_expect, "retval",
> + "progname:%s unexpected retval=%d expected=%d\n",
> + prog_name, tattr.retval, retval_expect);
> +
> + /* Extract MTU that BPF-prog got */
> + mtu_result = skel->bss->global_bpf_mtu_xdp;
> + CHECK(mtu_result != mtu_expect, "MTU-compare-user",
> + "failed (MTU user:%d bpf:%d)", mtu_expect, mtu_result);
> +}
> +static void test_check_mtu_run_tc(struct test_check_mtu *skel,
> + struct bpf_program *prog,
> + __u32 mtu_expect)
> +{
[...]
> + err = bpf_prog_test_run_xattr(&tattr);
> + CHECK_ATTR(err != 0 || errno != 0, "bpf_prog_test_run",
> + "prog_name:%s (err %d errno %d retval %d)\n",
> + prog_name, err, errno, tattr.retval);
Same issue here.
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
Powered by blists - more mailing lists