Skip to content

Commit c068ba9

Browse files
idoschPaolo Abeni
authored andcommitted
selftests: traceroute: Return correct value on failure
The test always returns success even if some tests were modified to fail. Fix by converting the test to use the appropriate library functions instead of using its own functions. Before: # ./traceroute.sh TEST: IPV6 traceroute [FAIL] TEST: IPV4 traceroute [ OK ] Tests passed: 1 Tests failed: 1 $ echo $? 0 After: # ./traceroute.sh TEST: IPv6 traceroute [FAIL] traceroute6 did not return 2000:102::2 TEST: IPv4 traceroute [ OK ] $ echo $? 1 Reviewed-by: Petr Machata <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4a8c416 commit c068ba9

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

tools/testing/selftests/net/traceroute.sh

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,6 @@ PAUSE_ON_FAIL=no
1010

1111
################################################################################
1212
#
13-
log_test()
14-
{
15-
local rc=$1
16-
local expected=$2
17-
local msg="$3"
18-
19-
if [ ${rc} -eq ${expected} ]; then
20-
printf "TEST: %-60s [ OK ]\n" "${msg}"
21-
nsuccess=$((nsuccess+1))
22-
else
23-
ret=1
24-
nfail=$((nfail+1))
25-
printf "TEST: %-60s [FAIL]\n" "${msg}"
26-
if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
27-
echo
28-
echo "hit enter to continue, 'q' to quit"
29-
read a
30-
[ "$a" = "q" ] && exit 1
31-
fi
32-
fi
33-
}
34-
3513
run_cmd()
3614
{
3715
local ns
@@ -210,9 +188,12 @@ run_traceroute6()
210188

211189
setup_traceroute6
212190

191+
RET=0
192+
213193
# traceroute6 host-2 from host-1 (expects 2000:102::2)
214194
run_cmd $h1 "traceroute6 2000:103::4 | grep -q 2000:102::2"
215-
log_test $? 0 "IPV6 traceroute"
195+
check_err $? "traceroute6 did not return 2000:102::2"
196+
log_test "IPv6 traceroute"
216197

217198
cleanup_traceroute6
218199
}
@@ -275,9 +256,12 @@ run_traceroute()
275256

276257
setup_traceroute
277258

259+
RET=0
260+
278261
# traceroute host-2 from host-1 (expects 1.0.1.1). Takes a while.
279262
run_cmd $h1 "traceroute 1.0.2.4 | grep -q 1.0.1.1"
280-
log_test $? 0 "IPV4 traceroute"
263+
check_err $? "traceroute did not return 1.0.1.1"
264+
log_test "IPv4 traceroute"
281265

282266
cleanup_traceroute
283267
}
@@ -294,9 +278,6 @@ run_tests()
294278
################################################################################
295279
# main
296280

297-
declare -i nfail=0
298-
declare -i nsuccess=0
299-
300281
while getopts :pv o
301282
do
302283
case $o in
@@ -308,5 +289,4 @@ done
308289

309290
run_tests
310291

311-
printf "\nTests passed: %3d\n" ${nsuccess}
312-
printf "Tests failed: %3d\n" ${nfail}
292+
exit "${EXIT_STATUS}"

0 commit comments

Comments
 (0)