Commit 1c0b0ee2 authored by Matthieu Baerts's avatar Matthieu Baerts Committed by Paolo Abeni

selftests: mptcp: userspace: refactor asserts

Instead of having a long list of conditions to check, it is possible to
give a list of variable names to compare with their 'e_XXX' version.

This will ease the introduction of the following commit which will print
which condition has failed (if any).
Reviewed-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent f790ae03
......@@ -225,6 +225,36 @@ make_connection()
fi
}
# $1: var name
check_expected_one()
{
local var="${1}"
local exp="e_${var}"
[ "${!var}" = "${!exp}" ]
}
# $@: all var names to check
check_expected()
{
local ret=0
local var
for var in "${@}"
do
check_expected_one "${var}" || ret=1
done
if [ ${ret} -eq 0 ]
then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
}
verify_announce_event()
{
local evt=$1
......@@ -250,15 +280,8 @@ verify_announce_event()
fi
dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
[ "$addr" = "$e_addr" ] && [ "$dport" = "$e_dport" ] &&
[ "$id" = "$e_id" ]
then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
check_expected "type" "token" "addr" "dport" "id"
}
test_announce()
......@@ -357,14 +380,8 @@ verify_remove_event()
type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
token=$(sed --unbuffered -n 's/.*\(token:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
[ "$id" = "$e_id" ]
then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
check_expected "type" "token" "id"
}
test_remove()
......@@ -519,16 +536,7 @@ verify_subflow_events()
daddr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
fi
if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
[ "$daddr" = "$e_daddr" ] && [ "$e_dport" = "$dport" ] &&
[ "$family" = "$e_family" ] && [ "$saddr" = "$e_saddr" ] &&
[ "$e_locid" = "$locid" ] && [ "$e_remid" = "$remid" ]
then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
check_expected "type" "token" "daddr" "dport" "family" "saddr" "locid" "remid"
}
test_subflows()
......@@ -881,15 +889,7 @@ verify_listener_events()
sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
fi
if [ $type ] && [ $type = $e_type ] &&
[ $family ] && [ $family = $e_family ] &&
[ $saddr ] && [ $saddr = $e_saddr ] &&
[ $sport ] && [ $sport = $e_sport ]; then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
check_expected "type" "family" "saddr" "sport"
}
test_listener()
......
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