Re: [PATCH bpf-next V9 7/7] bpf/selftests: tests using bpf_check_mtu BPF-helper

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

 



On Thu, 17 Dec 2020 18:26:50 +0100
Jesper Dangaard Brouer <brouer@xxxxxxxxxx> 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@xxxxxxxxxx>
> ---
>  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




[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