mirror of https://github.com/wolfSSL/wolfssh.git
wolfsshd: name the tmux session per test run
sshd_term_size_test.sh drives the client through a tmux session named for the port it was given. The name used to be the constant "test", which is shared across everything the user runs, so two concurrent runs fought over one session and each EXIT trap killed the other's.pull/1215/merge
parent
bb5d7dc2e9
commit
071a07a27d
|
|
@ -15,6 +15,12 @@ if [ -z "$1" ] || [ -z "$2" ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# The tmux session name is shared across everything this user runs, so it is
|
||||
# derived from the port this run was given rather than being the constant
|
||||
# "test": two concurrent runs of the suite would otherwise fight over one
|
||||
# session and the EXIT trap below would kill the other run's.
|
||||
TMUX_SESSION="wolfsshd_test_$2"
|
||||
|
||||
# Check if tmux is available
|
||||
which tmux
|
||||
RESULT=$?
|
||||
|
|
@ -25,20 +31,20 @@ fi
|
|||
|
||||
# tear down the tmux session on any exit, so a timeout failure does not
|
||||
# leave a stale session that breaks the next run with "duplicate session"
|
||||
trap 'tmux kill-session -t test 2>/dev/null || true' EXIT
|
||||
trap 'tmux kill-session -t "$TMUX_SESSION" 2>/dev/null || true' EXIT
|
||||
|
||||
# Wait until the remote shell produces some output (i.e. a prompt), so the
|
||||
# SSH session is known to be up before keys are sent to it. CI runners can
|
||||
# take several seconds to get through key exchange and login.
|
||||
wait_for_session() {
|
||||
for _ in $(seq 1 10); do
|
||||
if tmux capture-pane -p -t test | grep -q '[^[:space:]]'; then
|
||||
if tmux capture-pane -p -t "$TMUX_SESSION" | grep -q '[^[:space:]]'; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
echo "Timed out waiting for SSH session output"
|
||||
tmux capture-pane -p -t test
|
||||
tmux capture-pane -p -t "$TMUX_SESSION"
|
||||
return 1
|
||||
}
|
||||
|
||||
|
|
@ -50,30 +56,30 @@ get_size_line() {
|
|||
# Re-send the query each pass in case the shell was not yet ready to
|
||||
# read input on an earlier pass; tail -n 1 below tolerates the extra
|
||||
# numeric line a repeat can produce.
|
||||
tmux send-keys -t test 'echo;echo $COLUMNS $LINES;echo'
|
||||
tmux send-keys -t test 'ENTER'
|
||||
tmux send-keys -t "$TMUX_SESSION" 'echo;echo $COLUMNS $LINES;echo'
|
||||
tmux send-keys -t "$TMUX_SESSION" 'ENTER'
|
||||
sleep 1
|
||||
SIZE_LINE=$(tmux capture-pane -p -t test | tr -d '\r' | \
|
||||
SIZE_LINE=$(tmux capture-pane -p -t "$TMUX_SESSION" | tr -d '\r' | \
|
||||
grep -E '^[0-9]+[[:space:]]+[0-9]+[[:space:]]*$' | tail -n 1)
|
||||
if [ -n "$SIZE_LINE" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
echo "Timed out waiting for terminal size output"
|
||||
tmux capture-pane -p -t test
|
||||
tmux capture-pane -p -t "$TMUX_SESSION"
|
||||
return 1
|
||||
}
|
||||
|
||||
echo "Creating tmux session at $PWD with command :"
|
||||
echo "tmux new-session -d -s test \"$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\"\""
|
||||
tmux new-session -d -s test "$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\""
|
||||
echo "tmux new-session -d -s $TMUX_SESSION \"$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\"\""
|
||||
tmux new-session -d -s "$TMUX_SESSION" "$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\""
|
||||
echo "Result of tmux new-session = $?"
|
||||
|
||||
wait_for_session || exit 1
|
||||
|
||||
COL=`tmux display -p -t test '#{pane_width}'`
|
||||
ROW=`tmux display -p -t test '#{pane_height}'`
|
||||
echo "tmux 'test' session has COL = ${COL} and ROW = ${ROW}"
|
||||
COL=`tmux display -p -t "$TMUX_SESSION" '#{pane_width}'`
|
||||
ROW=`tmux display -p -t "$TMUX_SESSION" '#{pane_height}'`
|
||||
echo "tmux $TMUX_SESSION session has COL = ${COL} and ROW = ${ROW}"
|
||||
|
||||
# get the terminals columns and lines
|
||||
get_size_line || exit 1
|
||||
|
|
@ -94,20 +100,20 @@ fi
|
|||
# resize tmux after connection is open is not working @TODO
|
||||
#tmux set-window-option -g aggressive-resize
|
||||
#printf '\e[8;50;100t'
|
||||
#tmux resize-pane -x 50 -y 10 -t test
|
||||
#tmux resize-pane -x 50 -y 10 -t "$TMUX_SESSION"
|
||||
|
||||
# close down the SSH session
|
||||
tmux send-keys -t test 'exit'
|
||||
tmux send-keys -t test 'ENTER'
|
||||
tmux send-keys -t "$TMUX_SESSION" 'exit'
|
||||
tmux send-keys -t "$TMUX_SESSION" 'ENTER'
|
||||
|
||||
# kill off the session if it's still running, but don't error out if the session
|
||||
# has already closed down
|
||||
tmux kill-session -t test
|
||||
tmux kill-session -t "$TMUX_SESSION"
|
||||
set -e
|
||||
|
||||
echo "Starting another session with a smaller window size"
|
||||
echo "tmux new-session -d -x 50 -y 10 -s test \"$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\"\""
|
||||
tmux new-session -d -x 50 -y 10 -s test "$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\""
|
||||
echo "tmux new-session -d -x 50 -y 10 -s $TMUX_SESSION \"$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\"\""
|
||||
tmux new-session -d -x 50 -y 10 -s "$TMUX_SESSION" "$TEST_CLIENT -q -t -u $USER -i $PRIVATE_KEY -j $PUBLIC_KEY -h \"$1\" -p \"$2\""
|
||||
|
||||
wait_for_session || exit 1
|
||||
|
||||
|
|
@ -128,10 +134,10 @@ if [ "10" != "$ROW_FOUND" ]; then
|
|||
fi
|
||||
|
||||
# close down the SSH session
|
||||
tmux send-keys -t test 'exit'
|
||||
tmux send-keys -t test 'ENTER'
|
||||
tmux send-keys -t "$TMUX_SESSION" 'exit'
|
||||
tmux send-keys -t "$TMUX_SESSION" 'ENTER'
|
||||
set +e
|
||||
tmux kill-session -t test
|
||||
tmux kill-session -t "$TMUX_SESSION"
|
||||
|
||||
popd
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue