Skip to content

Commit 27bc865

Browse files
committed
Merge branch 'selftests-net-lib-small-fixes'
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/[email protected]/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 <[email protected]>
2 parents 0dcc53a + 84a8bc3 commit 27bc865

File tree

1 file changed

+9
-9
lines changed
  • tools/testing/selftests/net

1 file changed

+9
-9
lines changed

tools/testing/selftests/net/lib.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ksft_xfail=2
1515
ksft_skip=4
1616

1717
# namespace list created by setup_ns
18-
NS_LIST=""
18+
NS_LIST=()
1919

2020
##############################################################################
2121
# Helpers
@@ -27,6 +27,7 @@ __ksft_status_merge()
2727
local -A weights
2828
local weight=0
2929

30+
local i
3031
for i in "$@"; do
3132
weights[$i]=$((weight++))
3233
done
@@ -67,9 +68,7 @@ loopy_wait()
6768
while true
6869
do
6970
local out
70-
out=$("$@")
71-
local ret=$?
72-
if ((!ret)); then
71+
if out=$("$@"); then
7372
echo -n "$out"
7473
return 0
7574
fi
@@ -139,6 +138,7 @@ cleanup_ns()
139138
fi
140139

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

153153
cleanup_all_ns()
154154
{
155-
cleanup_ns $NS_LIST
155+
cleanup_ns "${NS_LIST[@]}"
156156
}
157157

158158
# setup netns with given names as prefix. e.g
@@ -161,7 +161,7 @@ setup_ns()
161161
{
162162
local ns=""
163163
local ns_name=""
164-
local ns_list=""
164+
local ns_list=()
165165
local ns_exist=
166166
for ns_name in "$@"; do
167167
# Some test may setup/remove same netns multi times
@@ -177,13 +177,13 @@ setup_ns()
177177

178178
if ! ip netns add "$ns"; then
179179
echo "Failed to create namespace $ns_name"
180-
cleanup_ns "$ns_list"
180+
cleanup_ns "${ns_list[@]}"
181181
return $ksft_skip
182182
fi
183183
ip -n "$ns" link set lo up
184-
! $ns_exist && ns_list="$ns_list $ns"
184+
! $ns_exist && ns_list+=("$ns")
185185
done
186-
NS_LIST="$NS_LIST $ns_list"
186+
NS_LIST+=("${ns_list[@]}")
187187
}
188188

189189
tc_rule_stats_get()

0 commit comments

Comments
 (0)