[PATCH mptcp-next v4 1/6] selftests/bpf: use random netns name for mptcp

Geliang Tang posted 6 patches 1 year, 8 months ago
Maintainers: Matthieu Baerts <matthieu.baerts@tessares.net>, Mat Martineau <martineau@kernel.org>, Andrii Nakryiko <andrii@kernel.org>, Mykola Lysenko <mykolal@fb.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Martin KaFai Lau <martin.lau@linux.dev>, Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>, John Fastabend <john.fastabend@gmail.com>, KP Singh <kpsingh@kernel.org>, Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>, Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>, Hangbin Liu <liuhangbin@gmail.com>
[PATCH mptcp-next v4 1/6] selftests/bpf: use random netns name for mptcp
Posted by Geliang Tang 1 year, 8 months ago
Use rand() to generate a random netns name instead of using the fixed
name "mptcp_ns" for every test.

Fixes: 02d6a057c7be ("selftests/bpf: run mptcp in a dedicated netns")
Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c
index de8b6c68fc30..8040997e4aef 100644
--- a/tools/testing/selftests/bpf/prog_tests/mptcp.c
+++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c
@@ -11,7 +11,7 @@
 #include "mptcp_bpf_rr.skel.h"
 #include "mptcp_bpf_red.skel.h"
 
-#define NS_TEST "mptcp_ns"
+char NS_TEST[32];
 
 #ifndef TCP_CA_NAME_MAX
 #define TCP_CA_NAME_MAX	16
@@ -151,6 +151,8 @@ static void test_base(void)
 	if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup"))
 		return;
 
+	srand(time(NULL));
+	snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand());
 	SYS(fail, "ip netns add %s", NS_TEST);
 	SYS(fail, "ip -net %s link set dev lo up", NS_TEST);
 
-- 
2.35.3
Re: [PATCH mptcp-next v4 1/6] selftests/bpf: use random netns name for mptcp
Posted by Matthieu Baerts 1 year, 8 months ago
Hi Geliang,

On 18/05/2023 00:29, Geliang Tang wrote:
> Use rand() to generate a random netns name instead of using the fixed
> name "mptcp_ns" for every test.
> 
> Fixes: 02d6a057c7be ("selftests/bpf: run mptcp in a dedicated netns")

If we add the "Fixes" tag, it somehow means the previous behaviour was
buggy. I agree that it is better to do what you did here just in case
the previous netns has not been removed when re-launching the same test
multiple time (what a CI would not do I guess) but I also see that most
(all?) other BPF tests creating netns' use a fixed name.

I hope you don't mind if I then remove this Fixes tag when applying the
patch.

While at it, I will also explain the reason why this patch is needed,
something like:

  By doing that, we can re-launch the test even if there was an issue
  removing the previous netns or if by accident, a netns with this
  generic name already existed on the system. Note that using a
  different name each will also help adding more subtests in future
  commits.

Cheers,
Matt
-- 
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net