Commit e4525c9d authored by David Ahern's avatar David Ahern Committed by Greg Kroah-Hartman

selftests: fib_tests: Fix 'Command line is not complete' errors

[ Upstream commit a5f62298 ]

A couple of tests are verifying a route has been removed. The helper
expects the prefix as the first part of the expected output. When
checking that a route has been deleted the prefix is empty leading
to an invalid ip command:

  $ ip ro ls match
  Command line is not complete. Try option "help"

Fix by moving the comparison of expected output and output to a new
function that is used by both check_route and check_route6. Use the
new helper for the 2 checks on route removal.

Also, remove the reset of 'set -x' in route_setup which overrides the
user managed setting.

Fixes: d69faad7 ("selftests: fib_tests: Add prefix route tests with metric")
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 7828986b
...@@ -602,6 +602,39 @@ run_cmd() ...@@ -602,6 +602,39 @@ run_cmd()
return $rc return $rc
} }
check_expected()
{
local out="$1"
local expected="$2"
local rc=0
[ "${out}" = "${expected}" ] && return 0
if [ -z "${out}" ]; then
if [ "$VERBOSE" = "1" ]; then
printf "\nNo route entry found\n"
printf "Expected:\n"
printf " ${expected}\n"
fi
return 1
fi
# tricky way to convert output to 1-line without ip's
# messy '\'; this drops all extra white space
out=$(echo ${out})
if [ "${out}" != "${expected}" ]; then
rc=1
if [ "${VERBOSE}" = "1" ]; then
printf " Unexpected route entry. Have:\n"
printf " ${out}\n"
printf " Expected:\n"
printf " ${expected}\n\n"
fi
fi
return $rc
}
# add route for a prefix, flushing any existing routes first # add route for a prefix, flushing any existing routes first
# expected to be the first step of a test # expected to be the first step of a test
add_route6() add_route6()
...@@ -646,31 +679,7 @@ check_route6() ...@@ -646,31 +679,7 @@ check_route6()
local rc=0 local rc=0
out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//') out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
[ "${out}" = "${expected}" ] && return 0 check_expected "${out}" "${expected}"
if [ -z "${out}" ]; then
if [ "$VERBOSE" = "1" ]; then
printf "\nNo route entry found\n"
printf "Expected:\n"
printf " ${expected}\n"
fi
return 1
fi
# tricky way to convert output to 1-line without ip's
# messy '\'; this drops all extra white space
out=$(echo ${out})
if [ "${out}" != "${expected}" ]; then
rc=1
if [ "${VERBOSE}" = "1" ]; then
printf " Unexpected route entry. Have:\n"
printf " ${out}\n"
printf " Expected:\n"
printf " ${expected}\n\n"
fi
fi
return $rc
} }
route_cleanup() route_cleanup()
...@@ -714,7 +723,7 @@ route_setup() ...@@ -714,7 +723,7 @@ route_setup()
$IP addr add 172.16.103.2/24 dev veth4 $IP addr add 172.16.103.2/24 dev veth4
$IP addr add 172.16.104.1/24 dev dummy1 $IP addr add 172.16.104.1/24 dev dummy1
set +ex set +e
} }
# assumption is that basic add of a single path route works # assumption is that basic add of a single path route works
...@@ -949,7 +958,8 @@ ipv6_addr_metric_test() ...@@ -949,7 +958,8 @@ ipv6_addr_metric_test()
run_cmd "$IP li set dev dummy2 down" run_cmd "$IP li set dev dummy2 down"
rc=$? rc=$?
if [ $rc -eq 0 ]; then if [ $rc -eq 0 ]; then
check_route6 "" out=$($IP -6 ro ls match 2001:db8:104::/64)
check_expected "${out}" ""
rc=$? rc=$?
fi fi
log_test $rc 0 "Prefix route removed on link down" log_test $rc 0 "Prefix route removed on link down"
...@@ -1009,34 +1019,9 @@ check_route() ...@@ -1009,34 +1019,9 @@ check_route()
local pfx="172.16.104.0/24" local pfx="172.16.104.0/24"
local expected="$1" local expected="$1"
local out local out
local rc=0
out=$($IP ro ls match ${pfx}) out=$($IP ro ls match ${pfx})
[ "${out}" = "${expected}" ] && return 0 check_expected "${out}" "${expected}"
if [ -z "${out}" ]; then
if [ "$VERBOSE" = "1" ]; then
printf "\nNo route entry found\n"
printf "Expected:\n"
printf " ${expected}\n"
fi
return 1
fi
# tricky way to convert output to 1-line without ip's
# messy '\'; this drops all extra white space
out=$(echo ${out})
if [ "${out}" != "${expected}" ]; then
rc=1
if [ "${VERBOSE}" = "1" ]; then
printf " Unexpected route entry. Have:\n"
printf " ${out}\n"
printf " Expected:\n"
printf " ${expected}\n\n"
fi
fi
return $rc
} }
# assumption is that basic add of a single path route works # assumption is that basic add of a single path route works
...@@ -1301,7 +1286,8 @@ ipv4_addr_metric_test() ...@@ -1301,7 +1286,8 @@ ipv4_addr_metric_test()
run_cmd "$IP li set dev dummy2 down" run_cmd "$IP li set dev dummy2 down"
rc=$? rc=$?
if [ $rc -eq 0 ]; then if [ $rc -eq 0 ]; then
check_route "" out=$($IP ro ls match 172.16.104.0/24)
check_expected "${out}" ""
rc=$? rc=$?
fi fi
log_test $rc 0 "Prefix route removed on link down" log_test $rc 0 "Prefix route removed on link down"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment