Skip to content

Commit

Permalink
unify whitespace in tests
Browse files Browse the repository at this point in the history
this massively improves legibility of the scripts

there are no functionality changes, all tests run same as before
  • Loading branch information
a1346054 committed Jul 15, 2022
1 parent 4ceed33 commit 3b3d3d3
Show file tree
Hide file tree
Showing 21 changed files with 392 additions and 387 deletions.
8 changes: 4 additions & 4 deletions src/tests/e2e-failure.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ baseline()
}

case $1 in
baseline|variant)
baseline;;
*)
fail "unknown test argument %s\n" "$1";;
baseline|variant)
baseline;;
*)
fail "unknown test argument %s\n" "$1";;
esac
8 changes: 4 additions & 4 deletions src/tests/e2e-success.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ baseline()
}

case $1 in
baseline|direct|variant)
baseline;;
*)
fail "unknown test argument %s\n" "$1";;
baseline|direct|variant)
baseline;;
*)
fail "unknown test argument %s\n" "$1";;
esac
188 changes: 97 additions & 91 deletions src/tests/e2e-test
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ dump_logs()
shift
testname=$(basename "$dir" .d)
for logfile in $dir/*.tmux.log; do
printf "travis_fold:start:%s-%s\n" "$testname" "$(basename "$logfile")"
cat "$logfile"
printf "travis_fold:end:%s-%s\n" "$testname" "$(basename "$logfile")"
printf "travis_fold:start:%s-%s\n" "$testname" "$(basename "$logfile")"
cat "$logfile"
printf "travis_fold:end:%s-%s\n" "$testname" "$(basename "$logfile")"
done
}

Expand Down Expand Up @@ -56,13 +56,12 @@ test_exitstatus()
exit "$status"
}


ssh_localhost_check()
{
ssh localhost :
if [ $? -ne 0 ]; then
error "ssh to localhost failed\n"
return 1
error "ssh to localhost failed\n"
return 1
fi
return 0
}
Expand All @@ -72,7 +71,7 @@ ssh_localhost_check()
mosh_client()
{
if [ -z "$MOSH_CLIENT" ] || [ -z "$MOSH_E2E_TEST" ]; then
test_error "mosh_client: variables missing\n"
test_error "mosh_client: variables missing\n"
fi
exec 2> "${MOSH_E2E_TEST}.client.stderr"
exec "$MOSH_CLIENT" $MOSH_CLIENT_ARGS "$@"
Expand All @@ -81,7 +80,7 @@ mosh_client()
mosh_server()
{
if [ -z "$MOSH_SERVER" ] || [ -z "$MOSH_E2E_TEST" ]; then
test_error "mosh_server: variables missing\n"
test_error "mosh_server: variables missing\n"
fi
exec 2> "${MOSH_E2E_TEST}.server.stderr"
exec "$MOSH_SERVER" new -vv $MOSH_SERVER_ARGS -@ "$@"
Expand All @@ -94,23 +93,23 @@ if [ -z "$srcdir" ]; then
else
srcdir="$(cd "$srcdir" && pwd)"
if [ $? -ne 0 ]; then
error "can't cd to srcdir: %s\n" "$srcdir"
exit 99
error "can't cd to srcdir: %s\n" "$srcdir"
exit 99
fi
fi

# Wrappers.
case "$(basename "$0")" in
mosh-client)
mosh_client "$@"
exit
;;
mosh-server)
mosh_server "$@"
exit
;;
*)
;;
mosh-client)
mosh_client "$@"
exit
;;
mosh-server)
mosh_server "$@"
exit
;;
*)
;;
esac

if [ $# -lt 2 ]; then
Expand Down Expand Up @@ -141,13 +140,12 @@ fi
rm -rf "${test_dir}"
mkdir "${test_dir}"


on_exit() {
rv=$?
if test $rv -ne 0; then
dump_logs "$test_dir" $test_args
if test "$rv" -ne 0; then
dump_logs "$test_dir" $test_args
fi
exit $rv
exit "$rv"
}
trap on_exit EXIT

Expand All @@ -156,30 +154,39 @@ server_tests=
compare_tests=
for i in $test_args; do
case $i in
baseline|direct|variant)
server_tests="$server_tests $i";;
verify|same|different)
compare_tests="$compare_tests $i";;
tmux)
tmux=1;;
client)
client=1;;
server)
server=1;;
post)
post=1;;
mosh-args)
mosh_args=$("${test_script}" mosh-args);;
client-args)
MOSH_CLIENT_ARGS=$("${test_script}" client-args)
export MOSH_CLIENT_ARGS;;
server-args)
MOSH_SERVER_ARGS=$("${test_script}" server-args)
export MOSH_SERVER_ARGS;;
*)
error 'unknown test type argument %s\n' "$i"
exit 99
;;
baseline|direct|variant)
server_tests="$server_tests $i"
;;
verify|same|different)
compare_tests="$compare_tests $i"
;;
tmux)
tmux=1
;;
client)
client=1
;;
server)
server=1
;;
post)
post=1
;;
mosh-args)
mosh_args=$("${test_script}" mosh-args)
;;
client-args)
MOSH_CLIENT_ARGS=$("${test_script}" client-args)
export MOSH_CLIENT_ARGS
;;
server-args)
MOSH_SERVER_ARGS=$("${test_script}" server-args)
export MOSH_SERVER_ARGS
;;
*)
error 'unknown test type argument %s\n' "$i"
exit 99
;;
esac
done

Expand All @@ -194,7 +201,7 @@ if [ -n "$server" ]; then
server_wrapper="\"${srcdir}/${test_script}\" server"
fi
tmux_stdin="${srcdir}/hold-stdin"
if [ -n "$tmux" ]; then
if [ -n "$tmux" ]; then
tmux_stdin="${test_script} tmux"
fi

Expand All @@ -209,7 +216,7 @@ for run in $server_tests; do
# XXX need to quote special chars in server pathname here somehow
sut="../../scripts/mosh --client=${srcdir}/mosh-client --server=${srcdir}/mosh-server --local --bind-server=127.0.0.1 ${mosh_args} 127.0.0.1"
if [ "$run" = "direct" ]; then
sut=""
sut=""
fi
# Actually execute code under test
# XXX tmux 1.8 requires shell command as a single arg; once we move to 2.0, undo these quotes
Expand All @@ -219,40 +226,39 @@ for run in $server_tests; do
${tmux_stdin} tmux -f /dev/null -S "${tmux_socket}" -C new-session -x 80 -y 24 "${srcdir}/print-exitstatus ${client_wrapper} ${sut} ${server_wrapper} \"${PWD}/${test_dir}/${run}\" \"${PWD}/${test_script} ${run}\"" > "${test_dir}/${run}.tmux.log"
rv=$?
rm -f "${tmux_socket}" "${test_dir}/tmux-socket"
if [ $rv -ne 0 ]; then
test_error "tmux failure on test %s\n" "$run"
if [ "$rv" -ne 0 ]; then
test_error "tmux failure on test %s\n" "$run"
fi
# Check for mosh failures
if ! grep -q "@@@ exitstatus: 0 @@@" "${test_dir}/${run}.tmux.log"; then
test_error "mosh-client had non-zero exitstatus\n"
test_error "mosh-client had non-zero exitstatus\n"
fi

# Check for server harness failures
if [ -z "$server" ]; then
if [ ! -s "${test_dir}/${run}.capture" ] \
|| [ ! -s "${test_dir}/${run}.exitstatus" ]; then
test_error "server harness failure on test %s\n" "$run"
fi
read -r server_rv < "${test_dir}/${run}.exitstatus"
if [ "$server_rv" -ne 0 ]; then
test_error "server harness exited with status %s\n" "$server_rv"
fi
if [ ! -s "${test_dir}/${run}.capture" ] || [ ! -s "${test_dir}/${run}.exitstatus" ]; then
test_error "server harness failure on test %s\n" "$run"
fi
read -r server_rv < "${test_dir}/${run}.exitstatus"
if [ "$server_rv" -ne 0 ]; then
test_error "server harness exited with status %s\n" "$server_rv"
fi
fi
if [ "${run}" != "direct" ]; then
# Check for "round-trip" failures
if grep -q "round-trip Instruction verification failed" "${test_dir}/${run}.server.stderr"; then
test_error "Round-trip Instruction verification failed on server during %s\n" "$run"
fi
# Check for 0-timeout select() issue
if egrep -q "(polls, rate limiting|consecutive polls)" "${test_dir}/${run}.server.stderr"; then
if [ "osx" != "${TRAVIS_OS_NAME}" ]; then
test_error "select() with zero timeout called too often on server during %s\n" "$run"
fi
fi
# Check for assert()
if egrep -q "assertion.*failed" "${test_dir}/${run}.server.stderr"; then
test_error "assertion during %s\n" "$run"
fi
# Check for "round-trip" failures
if grep -q "round-trip Instruction verification failed" "${test_dir}/${run}.server.stderr"; then
test_error "Round-trip Instruction verification failed on server during %s\n" "$run"
fi
# Check for 0-timeout select() issue
if grep -E -q "(polls, rate limiting|consecutive polls)" "${test_dir}/${run}.server.stderr"; then
if [ "osx" != "${TRAVIS_OS_NAME}" ]; then
test_error "select() with zero timeout called too often on server during %s\n" "$run"
fi
fi
# Check for assert()
if grep -E -q "assertion.*failed" "${test_dir}/${run}.server.stderr"; then
test_error "assertion during %s\n" "$run"
fi
fi
# XXX We'd also like to check for "target state Instruction
# verification failed", a new check, but tmux's lack of BCE
Expand All @@ -263,35 +269,35 @@ done
for compare in $compare_tests; do
log "Running server comparison %s.\n" "$compare"
# Compare captures
if [ "$compare" = verify ]; then
test1="direct"
test2="baseline"
if [ "$compare" = "verify" ]; then
test1="direct"
test2="baseline"
else
test1="baseline"
test2="variant"
test1="baseline"
test2="variant"
fi
if diff -q "${test_dir}/${test1}.capture" "${test_dir}/${test2}.capture"; then
differ=n
differ=n
else
differ=y
differ=y
fi
if [ "$compare" = different ]; then
desired=y
badresult=same
if [ "$compare" = "different" ]; then
desired=y
badresult=same
else
desired=n
badresult=different
desired=n
badresult=different
fi
if [ $differ != $desired ]; then
test_failure "Output is %s between tests %s and %s\n" "$badresult" "$test1" "$test2"
if [ "$differ" != "$desired" ]; then
test_failure "Output is %s between tests %s and %s\n" "$badresult" "$test1" "$test2"
fi
done

# Run a post script (usually a custom validation of results)
if [ -n "$post" ]; then
"${test_script}" post
status=$?
if [ $status -ne 0 ]; then
test_exitstatus $status "Post test failed with exitstatus %d\n" $status
if [ "$status" -ne 0 ]; then
test_exitstatus $status "Post test failed with exitstatus %d\n" $status
fi
fi
28 changes: 14 additions & 14 deletions src/tests/e2e-test-server
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
wait_for_clients()
{
if [ -z "$MOSH_E2E_WAIT" ]; then
return
return
fi
expected=$1
while true; do
n=$(tmux list-clients -F . | wc -l)
if [ $expected -eq 1 ]; then
if [ $n -eq 1 ]; then
return
fi
elif [ $n -ne 1 ]; then
return
fi
sleep 1
while true; do
n=$(tmux list-clients -F . | wc -l)
if [ "$expected" -eq 1 ]; then
if [ "$n" -eq 1 ]; then
return
fi
elif [ "$n" -ne 1 ]; then
return
fi
sleep 1
done
}

Expand All @@ -40,8 +40,8 @@ rm -f "$testname.capture" "$testname.exitstatus"
trap ":" TERM HUP QUIT # If the session closes on us, let the test we're running drive.
on_exit() {
rv=$?
echo $rv > "$testname.exitstatus"
exit $rv
echo "$rv" > "$testname.exitstatus"
exit "$rv"
}
trap on_exit EXIT
# check for tmux
Expand All @@ -65,7 +65,7 @@ wait_for_clients 1
i=0
while [ $i -lt 60 ]; do
if grep -q "@@@ server complete @@@" "$testname.tmux.log"; then
break
break
fi
i=$((i+1))
sleep 1
Expand Down
Loading

0 comments on commit 3b3d3d3

Please sign in to comment.