From: Yonghong Song <yonghong.song@linux.dev>
To: Martin KaFai Lau <martin.lau@linux.dev>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@meta.com
Subject: Re: [PATCH bpf-next] selftests/bpf: Remove "&>" usage in the selftests
Date: Fri, 26 Jan 2024 20:56:18 -0800 [thread overview]
Message-ID: <879d5e4f-f20d-460b-9fb3-e362c0324ca2@linux.dev> (raw)
In-Reply-To: <20240127025017.950825-1-martin.lau@linux.dev>
On 1/26/24 6:50 PM, Martin KaFai Lau wrote:
> From: Martin KaFai Lau <martin.lau@kernel.org>
>
> In s390, CI reported that the sock_iter_batch selftest
> hits this error very often:
>
> 2024-01-26T16:56:49.3091804Z Bind /proc/self/ns/net -> /run/netns/sock_iter_batch_netns failed: No such file or directory
> 2024-01-26T16:56:49.3149524Z Cannot remove namespace file "/run/netns/sock_iter_batch_netns": No such file or directory
> 2024-01-26T16:56:49.3772213Z test_sock_iter_batch:FAIL:ip netns add sock_iter_batch_netns unexpected error: 256 (errno 0)
>
> It happens very often in s390 but Manu also noticed it happens very
> sparsely in other arch also.
>
> It turns out the default dash shell does not recognize "&>"
Not sure whether it is feasible or not. But is it possible
for all our test VMs we run '/bin/bash' before everyting else
so we have a uniform bash environment so we do not need to
worry about other shells?
> as a redirection operator, so the command went to the background.
> In the sock_iter_batch selftest, the "ip netns delete" went
> into background and then race with the following "ip netns add"
> command.
>
> This patch replaces the "&> /dev/null" usage with ">/dev/null 2>&1"
> and does this redirection in the SYS_NOFAIL macro instead of doing
> it individually by its caller. The SYS_NOFAIL callers do not care
> about failure, so it is no harm to do this redirection even if
> some of the existing callers do not redirect to /dev/null now.
>
> It touches different test files, so I skipped the Fixes tags
> in this patch. Some of the changed tests do not use "&>"
> but they use the SYS_NOFAIL, so these tests are also
> changed to avoid doing its own redirection because
> SYS_NOFAIL does it internally now.
>
> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
> ---
> .../selftests/bpf/prog_tests/decap_sanity.c | 2 +-
> .../selftests/bpf/prog_tests/fib_lookup.c | 2 +-
> .../selftests/bpf/prog_tests/ip_check_defrag.c | 4 ++--
> .../selftests/bpf/prog_tests/lwt_redirect.c | 2 +-
> .../selftests/bpf/prog_tests/lwt_reroute.c | 2 +-
> tools/testing/selftests/bpf/prog_tests/mptcp.c | 2 +-
> .../selftests/bpf/prog_tests/sock_destroy.c | 2 +-
> .../selftests/bpf/prog_tests/sock_iter_batch.c | 4 ++--
> .../selftests/bpf/prog_tests/test_tunnel.c | 18 +++++++++---------
> tools/testing/selftests/bpf/test_progs.h | 7 ++++++-
> 10 files changed, 25 insertions(+), 20 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/decap_sanity.c b/tools/testing/selftests/bpf/prog_tests/decap_sanity.c
> index 5c0ebe6ba866..dcb9e5070cc3 100644
> --- a/tools/testing/selftests/bpf/prog_tests/decap_sanity.c
> +++ b/tools/testing/selftests/bpf/prog_tests/decap_sanity.c
> @@ -72,6 +72,6 @@ void test_decap_sanity(void)
> bpf_tc_hook_destroy(&qdisc_hook);
> close_netns(nstoken);
> }
> - SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null");
> + SYS_NOFAIL("ip netns del " NS_TEST);
> decap_sanity__destroy(skel);
> }
[...]
> diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
> index 2f9f6f250f17..80df51244886 100644
> --- a/tools/testing/selftests/bpf/test_progs.h
> +++ b/tools/testing/selftests/bpf/test_progs.h
> @@ -385,10 +385,15 @@ int test__join_cgroup(const char *path);
> goto goto_label; \
> })
>
> +#define ALL_TO_DEV_NULL " >/dev/null 2>&1"
> +
> #define SYS_NOFAIL(fmt, ...) \
> ({ \
> char cmd[1024]; \
> - snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
> + int n; \
> + n = snprintf(cmd, sizeof(cmd), fmt, ##__VA_ARGS__); \
> + if (n < sizeof(cmd) && sizeof(cmd) - n >= sizeof(ALL_TO_DEV_NULL)) \
> + strcat(cmd, ALL_TO_DEV_NULL); \
> system(cmd); \
> })
>
next prev parent reply other threads:[~2024-01-27 4:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-27 2:50 [PATCH bpf-next] selftests/bpf: Remove "&>" usage in the selftests Martin KaFai Lau
2024-01-27 4:56 ` Yonghong Song [this message]
2024-01-27 6:14 ` Martin KaFai Lau
2024-01-27 6:27 ` Yonghong Song
2024-01-27 6:08 ` Martin KaFai Lau
2024-01-29 20:50 ` patchwork-bot+netdevbpf
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=879d5e4f-f20d-460b-9fb3-e362c0324ca2@linux.dev \
--to=yonghong.song@linux.dev \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@meta.com \
--cc=martin.lau@linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.