Skip to content

Commit

Permalink
selftests: fib_tests: Fix 'Command line is not complete' errors
Browse files Browse the repository at this point in the history
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: d69faad ("selftests: fib_tests: Add prefix route tests with metric")
Signed-off-by: David Ahern <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
dsahern authored and davem330 committed Apr 11, 2019
1 parent d370656 commit a5f6229
Showing 1 changed file with 40 additions and 54 deletions.
94 changes: 40 additions & 54 deletions tools/testing/selftests/net/fib_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,39 @@ run_cmd()
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
# expected to be the first step of a test
add_route6()
Expand Down Expand Up @@ -652,31 +685,7 @@ check_route6()
pfx=$1

out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
[ "${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
check_expected "${out}" "${expected}"
}

route_cleanup()
Expand Down Expand Up @@ -725,7 +734,7 @@ route_setup()
ip -netns ns2 addr add 172.16.103.2/24 dev veth4
ip -netns ns2 addr add 172.16.104.1/24 dev dummy1

set +ex
set +e
}

# assumption is that basic add of a single path route works
Expand Down Expand Up @@ -960,7 +969,8 @@ ipv6_addr_metric_test()
run_cmd "$IP li set dev dummy2 down"
rc=$?
if [ $rc -eq 0 ]; then
check_route6 ""
out=$($IP -6 ro ls match 2001:db8:104::/64)
check_expected "${out}" ""
rc=$?
fi
log_test $rc 0 "Prefix route removed on link down"
Expand Down Expand Up @@ -1091,38 +1101,13 @@ check_route()
local pfx
local expected="$1"
local out
local rc=0

set -- $expected
pfx=$1
[ "${pfx}" = "unreachable" ] && pfx=$2

out=$($IP ro ls match ${pfx})
[ "${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
check_expected "${out}" "${expected}"
}

# assumption is that basic add of a single path route works
Expand Down Expand Up @@ -1387,7 +1372,8 @@ ipv4_addr_metric_test()
run_cmd "$IP li set dev dummy2 down"
rc=$?
if [ $rc -eq 0 ]; then
check_route ""
out=$($IP ro ls match 172.16.104.0/24)
check_expected "${out}" ""
rc=$?
fi
log_test $rc 0 "Prefix route removed on link down"
Expand Down

0 comments on commit a5f6229

Please sign in to comment.