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() ...@@ -225,6 +225,36 @@ make_connection()
fi 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() verify_announce_event()
{ {
local evt=$1 local evt=$1
...@@ -250,15 +280,8 @@ verify_announce_event() ...@@ -250,15 +280,8 @@ verify_announce_event()
fi fi
dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt") dport=$(sed --unbuffered -n 's/.*\(dport:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[: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" ] && check_expected "type" "token" "addr" "dport" "id"
[ "$id" = "$e_id" ]
then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
} }
test_announce() test_announce()
...@@ -357,14 +380,8 @@ verify_remove_event() ...@@ -357,14 +380,8 @@ verify_remove_event()
type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt") type=$(sed --unbuffered -n 's/.*\(type:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
token=$(sed --unbuffered -n 's/.*\(token:\)\([[: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") id=$(sed --unbuffered -n 's/.*\(rem_id:\)\([[:digit:]]*\).*$/\2/p;q' "$evt")
if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] &&
[ "$id" = "$e_id" ] check_expected "type" "token" "id"
then
stdbuf -o0 -e0 printf "[OK]\n"
return 0
fi
stdbuf -o0 -e0 printf "[FAIL]\n"
exit 1
} }
test_remove() test_remove()
...@@ -519,16 +536,7 @@ verify_subflow_events() ...@@ -519,16 +536,7 @@ verify_subflow_events()
daddr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt") daddr=$(sed --unbuffered -n 's/.*\(daddr4:\)\([0-9.]*\).*$/\2/p;q' "$evt")
fi fi
if [ "$type" = "$e_type" ] && [ "$token" = "$e_token" ] && check_expected "type" "token" "daddr" "dport" "family" "saddr" "locid" "remid"
[ "$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
} }
test_subflows() test_subflows()
...@@ -881,15 +889,7 @@ verify_listener_events() ...@@ -881,15 +889,7 @@ verify_listener_events()
sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q') sed --unbuffered -n 's/.*\(saddr4:\)\([0-9.]*\).*$/\2/p;q')
fi fi
if [ $type ] && [ $type = $e_type ] && check_expected "type" "family" "saddr" "sport"
[ $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
} }
test_listener() 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