Skip to content

Commit

Permalink
selftests: mptcp: userspace: refactor asserts
Browse files Browse the repository at this point in the history
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: Mat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Matthieu Baerts authored and Paolo Abeni committed Jan 26, 2023
1 parent f790ae0 commit 1c0b0ee
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions tools/testing/selftests/net/mptcp/userspace_pm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1c0b0ee

Please sign in to comment.