From: Martin KaFai Lau <martin.lau@linux.dev>
To: Leon Hwang <hffilwlqm@gmail.com>
Cc: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com,
andrii@kernel.org, song@kernel.org, yhs@fb.com,
kpsingh@kernel.org, sdf@google.com, haoluo@google.com,
jolsa@kernel.org, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, hawk@kernel.org,
tangyeechou@gmail.com, kernel-patches-bot@fb.com,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [RESEND PATCH bpf-next v3 2/2] selftests/bpf: Add testcase for xdp attaching failure tracepoint
Date: Wed, 26 Jul 2023 14:52:45 -0700 [thread overview]
Message-ID: <d988118b-3e02-24e3-281a-cff821f7abef@linux.dev> (raw)
In-Reply-To: <20230720155228.5708-3-hffilwlqm@gmail.com>
On 7/20/23 8:52 AM, Leon Hwang wrote:
> Add a test case for the tracepoint of xdp attaching failure by bpf
> tracepoint when attach XDP to a device with invalid flags option.
>
> The bpf tracepoint retrieves error message from the tracepoint, and
> then put the error message to a perf buffer. The testing code receives
> error message from perf buffer, and then ASSERT "Invalid XDP flags for
> BPF link attachment".
>
> Signed-off-by: Leon Hwang <hffilwlqm@gmail.com>
> ---
> .../selftests/bpf/prog_tests/xdp_attach.c | 65 +++++++++++++++++++
> .../bpf/progs/test_xdp_attach_fail.c | 52 +++++++++++++++
> 2 files changed, 117 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_attach_fail.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_attach.c
> index fa3cac5488f5d..99f8d03f3c8bd 100644
> --- a/tools/testing/selftests/bpf/prog_tests/xdp_attach.c
> +++ b/tools/testing/selftests/bpf/prog_tests/xdp_attach.c
> @@ -1,5 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
> #include <test_progs.h>
> +#include "test_xdp_attach_fail.skel.h"
>
> #define IFINDEX_LO 1
> #define XDP_FLAGS_REPLACE (1U << 4)
> @@ -85,10 +86,74 @@ static void test_xdp_attach(const char *file)
> bpf_object__close(obj1);
> }
>
> +struct xdp_errmsg {
> + char msg[64];
> +};
> +
> +static void on_xdp_errmsg(void *ctx, int cpu, void *data, __u32 size)
> +{
> + struct xdp_errmsg *ctx_errmg = ctx, *tp_errmsg = data;
> +
> + memcpy(&ctx_errmg->msg, &tp_errmsg->msg, size);
> +}
> +
> +static const char tgt_errmsg[] = "Invalid XDP flags for BPF link attachment";
> +
> +static void test_xdp_attach_fail(const char *file)
The test crashed:
https://github.com/kernel-patches/bpf/actions/runs/5672753995/job/15373384795#step:6:8037
Please monitor the CI test result in the future.
> +{
> + __u32 duration = 0;
> + int err, fd_xdp, fd_link_xdp;
> + struct bpf_object *obj = NULL;
> + struct test_xdp_attach_fail *skel = NULL;
> + struct bpf_link *link = NULL;
> + struct perf_buffer *pb = NULL;
> + struct xdp_errmsg errmsg = {};
> +
> + LIBBPF_OPTS(bpf_link_create_opts, opts);
> +
> + skel = test_xdp_attach_fail__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "test_xdp_attach_fail_skel"))
> + goto out_close;
> +
> + link = bpf_program__attach_tracepoint(skel->progs.tp__xdp__bpf_xdp_link_attach_failed,
> + "xdp", "bpf_xdp_link_attach_failed");
> + if (!ASSERT_OK_PTR(link, "attach_tp"))
> + goto out_close;
> +
> + /* set up perf buffer */
> + pb = perf_buffer__new(bpf_map__fd(skel->maps.xdp_errmsg_pb), 1,
> + on_xdp_errmsg, NULL, &errmsg, NULL);
> +
> + err = bpf_prog_test_load(file, BPF_PROG_TYPE_XDP, &obj, &fd_xdp);
> + if (CHECK_FAIL(err))
> + goto out_close;
> +
> + opts.flags = 0xFF; // invalid flags to fail to attach XDP prog
> + fd_link_xdp = bpf_link_create(fd_xdp, IFINDEX_LO, BPF_XDP, &opts);
> + if (CHECK(fd_link_xdp != -22, "bpf_link_create_failed",
Please stay with the ASSERT_* macro.
--
pw-bot: cr
next prev parent reply other threads:[~2023-07-26 21:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 15:52 [RESEND PATCH bpf-next v3 0/2] bpf, xdp: Add tracepoint to xdp attaching failure Leon Hwang
2023-07-20 15:52 ` [RESEND PATCH bpf-next v3 1/2] " Leon Hwang
2023-07-20 15:52 ` [RESEND PATCH bpf-next v3 2/2] selftests/bpf: Add testcase for xdp attaching failure tracepoint Leon Hwang
2023-07-26 21:52 ` Martin KaFai Lau [this message]
2023-07-27 1:57 ` Leon Hwang
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=d988118b-3e02-24e3-281a-cff821f7abef@linux.dev \
--to=martin.lau@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=haoluo@google.com \
--cc=hawk@kernel.org \
--cc=hffilwlqm@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-patches-bot@fb.com \
--cc=kpsingh@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=tangyeechou@gmail.com \
--cc=yhs@fb.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).