From: "Eelco Chaudron" <echaudro@redhat.com>
To: "Lorenzo Bianconi" <lorenzo@kernel.org>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, davem@davemloft.net,
sameehj@amazon.com, kuba@kernel.org, john.fastabend@gmail.com,
daniel@iogearbox.net, ast@kernel.org, shayagr@amazon.com,
brouer@redhat.com, lorenzo.bianconi@redhat.com,
dsahern@kernel.org
Subject: Re: [PATCH v3 net-next 10/12] bpf: add xdp multi-buffer selftest
Date: Thu, 01 Oct 2020 09:43:29 +0200 [thread overview]
Message-ID: <E0F803BD-597D-42E8-8C17-197A99D8F4CB@redhat.com> (raw)
In-Reply-To: <fb036cd7830a6db1ea9d68f8a987bb0004ccb8d6.1601478613.git.lorenzo@kernel.org>
On 30 Sep 2020, at 17:42, Lorenzo Bianconi wrote:
> Introduce xdp multi-buffer selftest for the following ebpf helpers:
> - bpf_xdp_get_frags_total_size
> - bpf_xdp_get_frag_count
>
> Co-developed-by: Eelco Chaudron <echaudro@redhat.com>
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
> .../testing/selftests/bpf/prog_tests/xdp_mb.c | 77
> +++++++++++++++++++
> .../selftests/bpf/progs/test_xdp_multi_buff.c | 24 ++++++
> 2 files changed, 101 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_mb.c
> create mode 100644
> tools/testing/selftests/bpf/progs/test_xdp_multi_buff.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_mb.c
> b/tools/testing/selftests/bpf/prog_tests/xdp_mb.c
> new file mode 100644
> index 000000000000..8cfe7253bf2a
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_mb.c
> @@ -0,0 +1,77 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <unistd.h>
> +#include <linux/kernel.h>
> +#include <test_progs.h>
> +#include <network_helpers.h>
> +
> +#include "test_xdp_multi_buff.skel.h"
> +
> +static void test_xdp_mb_check_len(void)
> +{
> + int test_sizes[] = { 128, 4096, 9000 };
> + struct test_xdp_multi_buff *pkt_skel;
> + char *pkt_in = NULL, *pkt_out = NULL;
> + __u32 duration = 0, retval, size;
> + int err, pkt_fd, i;
> +
> + /* Load XDP program */
> + pkt_skel = test_xdp_multi_buff__open_and_load();
> + if (CHECK(!pkt_skel, "pkt_skel_load", "test_xdp_mb skeleton
> failed\n"))
> + goto out;
> +
> + /* Allocate resources */
> + pkt_out = malloc(test_sizes[ARRAY_SIZE(test_sizes) - 1]);
> + pkt_in = malloc(test_sizes[ARRAY_SIZE(test_sizes) - 1]);
> + if (CHECK(!pkt_in || !pkt_out, "malloc",
> + "Failed malloc, in = %p, out %p\n", pkt_in, pkt_out))
> + goto out;
> +
> + pkt_fd = bpf_program__fd(pkt_skel->progs._xdp_check_mb_len);
> + if (pkt_fd < 0)
> + goto out;
> +
> + /* Run test for specific set of packets */
> + for (i = 0; i < ARRAY_SIZE(test_sizes); i++) {
> + int frag_count;
> +
> + /* Run test program */
> + err = bpf_prog_test_run(pkt_fd, 1, &pkt_in, test_sizes[i],
Small bug, should be:
err = bpf_prog_test_run(pkt_fd, 1, pkt_in, test_sizes[i],
> + pkt_out, &size, &retval, &duration);
> +
> + if (CHECK(err || retval != XDP_PASS, // || size != test_sizes[i],
> + "test_run", "err %d errno %d retval %d size %d[%d]\n",
> + err, errno, retval, size, test_sizes[i]))
> + goto out;
> +
> + /* Verify test results */
> + frag_count = DIV_ROUND_UP(
> + test_sizes[i] - pkt_skel->data->test_result_xdp_len,
> + getpagesize());
> +
> + if (CHECK(pkt_skel->data->test_result_frag_count != frag_count,
> + "result", "frag_count = %llu != %u\n",
> + pkt_skel->data->test_result_frag_count, frag_count))
> + goto out;
> +
> + if (CHECK(pkt_skel->data->test_result_frag_len != test_sizes[i] -
> + pkt_skel->data->test_result_xdp_len,
> + "result", "frag_len = %llu != %llu\n",
> + pkt_skel->data->test_result_frag_len,
> + test_sizes[i] - pkt_skel->data->test_result_xdp_len))
> + goto out;
> + }
> +out:
> + if (pkt_out)
> + free(pkt_out);
> + if (pkt_in)
> + free(pkt_in);
> +
> + test_xdp_multi_buff__destroy(pkt_skel);
> +}
> +
> +void test_xdp_mb(void)
> +{
> + if (test__start_subtest("xdp_mb_check_len_frags"))
> + test_xdp_mb_check_len();
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_xdp_multi_buff.c
> b/tools/testing/selftests/bpf/progs/test_xdp_multi_buff.c
> new file mode 100644
> index 000000000000..1a46e0925282
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_xdp_multi_buff.c
> @@ -0,0 +1,24 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/bpf.h>
> +#include <linux/if_ether.h>
> +#include <bpf/bpf_helpers.h>
> +#include <stdint.h>
> +
> +__u64 test_result_frag_len = UINT64_MAX;
> +__u64 test_result_frag_count = UINT64_MAX;
> +__u64 test_result_xdp_len = UINT64_MAX;
> +
> +SEC("xdp_check_mb_len")
> +int _xdp_check_mb_len(struct xdp_md *xdp)
> +{
> + void *data_end = (void *)(long)xdp->data_end;
> + void *data = (void *)(long)xdp->data;
> +
> + test_result_xdp_len = (__u64)(data_end - data);
> + test_result_frag_len = bpf_xdp_get_frags_total_size(xdp);
> + test_result_frag_count = bpf_xdp_get_frag_count(xdp);
> + return XDP_PASS;
> +}
> +
> +char _license[] SEC("license") = "GPL";
> --
> 2.26.2
next prev parent reply other threads:[~2020-10-01 7:43 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 15:41 [PATCH v3 net-next 00/12] mvneta: introduce XDP multi-buffer support Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 01/12] xdp: introduce mb in xdp_buff/xdp_frame Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 02/12] xdp: initialize xdp_buff mb bit to 0 in all XDP drivers Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 03/12] net: mvneta: update mb bit before passing the xdp buffer to eBPF layer Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 04/12] xdp: add multi-buff support to xdp_return_{buff/frame} Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 05/12] net: mvneta: add multi buffer support to XDP_TX Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 06/12] bpf: helpers: add multibuffer support Lorenzo Bianconi
2020-09-30 19:11 ` Alexei Starovoitov
2020-10-01 9:47 ` Jesper Dangaard Brouer
2020-10-01 15:05 ` Lorenzo Bianconi
2020-10-01 15:40 ` Alexei Starovoitov
2020-10-01 15:44 ` Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 07/12] samples/bpf: add bpf program that uses xdp mb helpers Lorenzo Bianconi
2020-09-30 15:41 ` [PATCH v3 net-next 08/12] bpf: move user_size out of bpf_test_init Lorenzo Bianconi
2020-09-30 15:42 ` [PATCH v3 net-next 09/12] bpf: introduce multibuff support to bpf_prog_test_run_xdp() Lorenzo Bianconi
2020-09-30 15:42 ` [PATCH v3 net-next 10/12] bpf: add xdp multi-buffer selftest Lorenzo Bianconi
2020-10-01 7:43 ` Eelco Chaudron [this message]
2020-09-30 15:42 ` [PATCH v3 net-next 11/12] net: mvneta: enable jumbo frames for XDP Lorenzo Bianconi
2020-09-30 15:42 ` [PATCH v3 net-next 12/12] bpf: cpumap: introduce xdp multi-buff support Lorenzo Bianconi
2020-09-30 16:31 ` [PATCH v3 net-next 00/12] mvneta: introduce XDP multi-buffer support Jakub Kicinski
2020-09-30 16:39 ` Lorenzo Bianconi
2020-09-30 21:40 ` Jakub Kicinski
2020-09-30 19:47 ` John Fastabend
2020-10-01 9:04 ` 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=E0F803BD-597D-42E8-8C17-197A99D8F4CB@redhat.com \
--to=echaudro@redhat.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=lorenzo.bianconi@redhat.com \
--cc=lorenzo@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sameehj@amazon.com \
--cc=shayagr@amazon.com \
/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).