]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
selftests/bpf: Fix flaky selftest lwt_redirect/lwt_reroute
authorYonghong Song <yonghong.song@linux.dev>
Mon, 5 Feb 2024 05:29:14 +0000 (21:29 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 4 Oct 2024 14:29:19 +0000 (16:29 +0200)
[ Upstream commit e7f31873176a345d72ca77c7b4da48493ccd9efd ]

Recently, when running './test_progs -j', I occasionally hit the
following errors:

  test_lwt_redirect:PASS:pthread_create 0 nsec
  test_lwt_redirect_run:FAIL:netns_create unexpected error: 256 (errno 0)
  #142/2   lwt_redirect/lwt_redirect_normal_nomac:FAIL
  #142     lwt_redirect:FAIL
  test_lwt_reroute:PASS:pthread_create 0 nsec
  test_lwt_reroute_run:FAIL:netns_create unexpected error: 256 (errno 0)
  test_lwt_reroute:PASS:pthread_join 0 nsec
  #143/2   lwt_reroute/lwt_reroute_qdisc_dropped:FAIL
  #143     lwt_reroute:FAIL

The netns_create() definition looks like below:

  #define NETNS "ns_lwt"
  static inline int netns_create(void)
  {
        return system("ip netns add " NETNS);
  }

One possibility is that both lwt_redirect and lwt_reroute create
netns with the same name "ns_lwt" which may cause conflict. I tried
the following example:
  $ sudo ip netns add abc
  $ echo $?
  0
  $ sudo ip netns add abc
  Cannot create namespace file "/var/run/netns/abc": File exists
  $ echo $?
  1
  $

The return code for above netns_create() is 256. The internet search
suggests that the return value for 'ip netns add ns_lwt' is 1, which
matches the above 'sudo ip netns add abc' example.

This patch tried to use different netns names for two tests to avoid
'ip netns add <name>' failure.

I ran './test_progs -j' 10 times and all succeeded with
lwt_redirect/lwt_reroute tests.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Tested-by: Eduard Zingerman <eddyz87@gmail.com>
Link: https://lore.kernel.org/bpf/20240205052914.1742687-1-yonghong.song@linux.dev
Stable-dep-of: 16b795cc5952 ("selftests/bpf: Fix redefinition errors compiling lwt_reroute.c")
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/testing/selftests/bpf/prog_tests/lwt_helpers.h
tools/testing/selftests/bpf/prog_tests/lwt_redirect.c
tools/testing/selftests/bpf/prog_tests/lwt_reroute.c

index 61333f2a03f91f2f1b64bdd38d879fb3d48b80c1..68c08309dbc823ec34f9bf2bfed3d9476bdd20ee 100644 (file)
@@ -27,8 +27,6 @@
                        }                                                     \
        })
 
-#define NETNS "ns_lwt"
-
 static inline int netns_create(void)
 {
        return system("ip netns add " NETNS);
index ea326e26656f5de8d97231b9293a0b18b0ab6071..7b458ae5f0f8560565fdfb0dc7a35ee41dff32fe 100644 (file)
@@ -53,6 +53,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 
+#define NETNS "ns_lwt_redirect"
 #include "lwt_helpers.h"
 #include "test_progs.h"
 #include "network_helpers.h"
index f4bb2d5fcae0a029b8af906c3b9ea80c8b4f90b7..c104f07f1b0bc03f84ee9da60e9f5dda9c3bd324 100644 (file)
@@ -48,6 +48,7 @@
  *  For case 2, force UDP packets to overflow fq limit. As long as kernel
  *  is not crashed, it is considered successful.
  */
+#define NETNS "ns_lwt_reroute"
 #include "lwt_helpers.h"
 #include "network_helpers.h"
 #include <linux/net_tstamp.h>