Skip to content

Commit 83e9394

Browse files
liuhangbindavem330
authored andcommitted
selftests/net/lib: no need to record ns name if it already exist
There is no need to add the name to ns_list again if the netns already recoreded. Fixes: 25ae948 ("selftests/net: add lib.sh") Signed-off-by: Hangbin Liu <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fd76e5c commit 83e9394

File tree

1 file changed

+4
-2
lines changed
  • tools/testing/selftests/net

1 file changed

+4
-2
lines changed

tools/testing/selftests/net/lib.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,17 @@ setup_ns()
127127
local ns=""
128128
local ns_name=""
129129
local ns_list=""
130+
local ns_exist=
130131
for ns_name in "$@"; do
131132
# Some test may setup/remove same netns multi times
132133
if unset ${ns_name} 2> /dev/null; then
133134
ns="${ns_name,,}-$(mktemp -u XXXXXX)"
134135
eval readonly ${ns_name}="$ns"
136+
ns_exist=false
135137
else
136138
eval ns='$'${ns_name}
137139
cleanup_ns "$ns"
138-
140+
ns_exist=true
139141
fi
140142

141143
if ! ip netns add "$ns"; then
@@ -144,7 +146,7 @@ setup_ns()
144146
return $ksft_skip
145147
fi
146148
ip -n "$ns" link set lo up
147-
ns_list="$ns_list $ns"
149+
! $ns_exist && ns_list="$ns_list $ns"
148150
done
149151
NS_LIST="$NS_LIST $ns_list"
150152
}

0 commit comments

Comments
 (0)