Skip to content

Commit

Permalink
Merge branch 'selftests-net-lib-small-fixes'
Browse files Browse the repository at this point in the history
Matthieu Baerts says:

====================
selftests: net: lib: small fixes

While looking at using 'lib.sh' for the MPTCP selftests [1], we found
some small issues with 'lib.sh'. Here they are:

- Patch 1: fix 'errexit' (set -e) support with busywait. 'errexit' is
  supported in some functions, not all. A fix for v6.8+.

- Patch 2: avoid confusing error messages linked to the cleaning part
  when the netns setup fails. A fix for v6.8+.

- Patch 3: set a variable as local to avoid accidentally changing the
  value of a another one with the same name on the caller side. A fix
  for v6.10-rc1+.

Link: https://lore.kernel.org/mptcp/5f4615c3-0621-43c5-ad25-55747a4350ce@kernel.org/T/ [1]
====================

Link: https://lore.kernel.org/r/20240605-upstream-net-20240605-selftests-net-lib-fixes-v1-0-b3afadd368c9@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jun 6, 2024
2 parents 0dcc53a + 84a8bc3 commit 27bc865
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tools/testing/selftests/net/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ksft_xfail=2
ksft_skip=4

# namespace list created by setup_ns
NS_LIST=""
NS_LIST=()

##############################################################################
# Helpers
Expand All @@ -27,6 +27,7 @@ __ksft_status_merge()
local -A weights
local weight=0

local i
for i in "$@"; do
weights[$i]=$((weight++))
done
Expand Down Expand Up @@ -67,9 +68,7 @@ loopy_wait()
while true
do
local out
out=$("$@")
local ret=$?
if ((!ret)); then
if out=$("$@"); then
echo -n "$out"
return 0
fi
Expand Down Expand Up @@ -139,6 +138,7 @@ cleanup_ns()
fi

for ns in "$@"; do
[ -z "${ns}" ] && continue
ip netns delete "${ns}" &> /dev/null
if ! busywait $BUSYWAIT_TIMEOUT ip netns list \| grep -vq "^$ns$" &> /dev/null; then
echo "Warn: Failed to remove namespace $ns"
Expand All @@ -152,7 +152,7 @@ cleanup_ns()

cleanup_all_ns()
{
cleanup_ns $NS_LIST
cleanup_ns "${NS_LIST[@]}"
}

# setup netns with given names as prefix. e.g
Expand All @@ -161,7 +161,7 @@ setup_ns()
{
local ns=""
local ns_name=""
local ns_list=""
local ns_list=()
local ns_exist=
for ns_name in "$@"; do
# Some test may setup/remove same netns multi times
Expand All @@ -177,13 +177,13 @@ setup_ns()

if ! ip netns add "$ns"; then
echo "Failed to create namespace $ns_name"
cleanup_ns "$ns_list"
cleanup_ns "${ns_list[@]}"
return $ksft_skip
fi
ip -n "$ns" link set lo up
! $ns_exist && ns_list="$ns_list $ns"
! $ns_exist && ns_list+=("$ns")
done
NS_LIST="$NS_LIST $ns_list"
NS_LIST+=("${ns_list[@]}")
}

tc_rule_stats_get()
Expand Down

0 comments on commit 27bc865

Please sign in to comment.