Skip to content

Commit

Permalink
selftests/bpf: Fix flaky selftest lwt_redirect/lwt_reroute
Browse files Browse the repository at this point in the history
[ Upstream commit e7f3187 ]

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)
  deepin-community#142/2   lwt_redirect/lwt_redirect_normal_nomac:FAIL
  deepin-community#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
  deepin-community#143/2   lwt_reroute/lwt_reroute_qdisc_dropped:FAIL
  deepin-community#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 <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Tested-by: Eduard Zingerman <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Stable-dep-of: 16b795cc5952 ("selftests/bpf: Fix redefinition errors compiling lwt_reroute.c")
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Yonghong Song authored and Avenger-285714 committed Oct 6, 2024
1 parent 6433b9d commit 531ba19
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 2 deletions.
2 changes: 0 additions & 2 deletions tools/testing/selftests/bpf/prog_tests/lwt_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
} \
})

#define NETNS "ns_lwt"

static inline int netns_create(void)
{
return system("ip netns add " NETNS);
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/lwt_redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/bpf/prog_tests/lwt_reroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 531ba19

Please sign in to comment.