test: tidy up integration tests

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/245/head
Jim Ramsay 2023-02-27 23:05:19 -05:00
parent 00d7a7bde3
commit f56c487456
1 changed files with 24 additions and 23 deletions

View File

@ -47,7 +47,7 @@ WAYVNC_BUILD_DIR=${WAYVNC_BUILD_DIR:-$(realpath "$REPO_ROOT/build")}
if [[ -d $WAYVNC_BUILD_DIR ]]; then if [[ -d $WAYVNC_BUILD_DIR ]]; then
export PATH=$WAYVNC_BUILD_DIR:$PATH export PATH=$WAYVNC_BUILD_DIR:$PATH
fi fi
echo "Looking for required binaries..." echo "Looking for required binaries..."
WAYVNC=${WAYVNC:-$(which wayvnc)} WAYVNC=${WAYVNC:-$(which wayvnc)}
WAYVNCCTL=${WAYVNCCTL:-$(which wayvncctl)} WAYVNCCTL=${WAYVNCCTL:-$(which wayvncctl)}
SWAY=${SWAY:-$(which sway)} SWAY=${SWAY:-$(which sway)}
@ -60,7 +60,14 @@ $VNCDO --version 2>/dev/null
export XDG_CONFIG_HOME=$INTEGRATION_ROOT/xdg_config export XDG_CONFIG_HOME=$INTEGRATION_ROOT/xdg_config
export XDG_RUNTIME_DIR=/tmp/wayvnc-integration-$$ export XDG_RUNTIME_DIR=/tmp/wayvnc-integration-$$
mkdir -p "$XDG_RUNTIME_DIR"
test_setup() {
[[ -d "$XDG_RUNTIME_DIR" ]] && rm -rf "$XDG_RUNTIME_DIR"
mkdir -p "$XDG_RUNTIME_DIR"
echo "=============================================="
echo "$*"
echo "=============================================="
}
TIMEOUT_COUNTER=0 TIMEOUT_COUNTER=0
TIMEOUT_MAXCOUNT=1 TIMEOUT_MAXCOUNT=1
@ -81,27 +88,14 @@ timeout_check() {
wait_until() { wait_until() {
timeout_init 10 timeout_init 10
local last local last
until last=$("$@" 2>&1); do until last=$(eval "$*" 2>&1); do
if ! timeout_check; then if ! timeout_check; then
echo "Timeout waiting for $*" >&2 echo "Timeout waiting for $*" >&2
printf "%s\n" "$last" >&2 printf "%s\n" "$last" >&2
return 1 return 1
fi fi
done done
printf "%s\n" "$last" [[ -z $last ]] || printf "%s\n" "$last"
}
wait_while() {
timeout_init 10
local last
while last=$("$@" 2>&1); do
if ! timeout_check; then
echo "Timeout waiting for $*" >&2
printf "%s\n" "$last" >&2
return 1
fi
done
printf "%s\n" "$last"
} }
SWAY_ENV=$XDG_RUNTIME_DIR/sway.env SWAY_ENV=$XDG_RUNTIME_DIR/sway.env
@ -113,7 +107,7 @@ start_sway() {
WLR_LIBINPUT_NO_DEVICES=1 \ WLR_LIBINPUT_NO_DEVICES=1 \
$SWAY &>"$SWAY_LOG" & $SWAY &>"$SWAY_LOG" &
SWAY_PID=$! SWAY_PID=$!
wait_until [ -f "$SWAY_ENV" ] >/dev/null wait_until [[ -f "$SWAY_ENV" ]] >/dev/null
WAYLAND_DISPLAY=$(grep ^WAYLAND_DISPLAY= "$SWAY_ENV" | cut -d= -f2-) WAYLAND_DISPLAY=$(grep ^WAYLAND_DISPLAY= "$SWAY_ENV" | cut -d= -f2-)
SWAYSOCK=$(grep ^SWAYSOCK= "$SWAY_ENV" | cut -d= -f2-) SWAYSOCK=$(grep ^SWAYSOCK= "$SWAY_ENV" | cut -d= -f2-)
export WAYLAND_DISPLAY SWAYSOCK export WAYLAND_DISPLAY SWAYSOCK
@ -125,6 +119,7 @@ stop_sway() {
echo "Stopping sway ($SWAY_PID)" echo "Stopping sway ($SWAY_PID)"
kill "$SWAY_PID" kill "$SWAY_PID"
unset SWAY_PID WAYLAND_DISPLAY SWAYSOCK unset SWAY_PID WAYLAND_DISPLAY SWAYSOCK
rm -f "$SWAY_ENV" || true
} }
WAYVNC_PID= WAYVNC_PID=
@ -133,7 +128,7 @@ WAYVNC_PORT=5999
start_wayvnc() { start_wayvnc() {
echo "Starting wayvnc..." echo "Starting wayvnc..."
WAYVNC_LOG=$XDG_RUNTIME_DIR/wayvnc.log WAYVNC_LOG=$XDG_RUNTIME_DIR/wayvnc.log
$WAYVNC -L debug "$WAYVNC_ADDRESS" "$WAYVNC_PORT" &>$WAYVNC_LOG & $WAYVNC "$@" -L debug "$WAYVNC_ADDRESS" "$WAYVNC_PORT" &>$WAYVNC_LOG &
WAYVNC_PID=$! WAYVNC_PID=$!
# Wait for the VNC listening port # Wait for the VNC listening port
echo " Started $WAYVNC_PID" echo " Started $WAYVNC_PID"
@ -141,7 +136,7 @@ start_wayvnc() {
-sTCP:LISTEN >/dev/null -sTCP:LISTEN >/dev/null
echo " Listening on $WAYVNC_ADDRESS:$WAYVNC_PORT" echo " Listening on $WAYVNC_ADDRESS:$WAYVNC_PORT"
# Wait for the control socket # Wait for the control socket
wait_until [ -S "$XDG_RUNTIME_DIR/wayvncctl" ] >/dev/null wait_until [[ -S "$XDG_RUNTIME_DIR/wayvncctl" ]] >/dev/null
echo " Control socket ready" echo " Control socket ready"
} }
@ -164,6 +159,7 @@ stop_wayvncctl_events() {
[[ -z $WAYVNCCTL_PID ]] && return 0 [[ -z $WAYVNCCTL_PID ]] && return 0
echo "Stopping wayvncctl event recorder ($WAYVNCCTL_PID)" echo "Stopping wayvncctl event recorder ($WAYVNCCTL_PID)"
kill "$WAYVNCCTL_PID" kill "$WAYVNCCTL_PID"
rm -f "$WAYVNCCTL_EVENTS" || true
unset WAYVNCCTL_PID unset WAYVNCCTL_PID
} }
@ -211,7 +207,7 @@ cleanup() {
cat "$VNCDO_LOG" cat "$VNCDO_LOG"
exit exit
fi fi
rm -rf $XDG_RUNTIME_DIR [[ -d "$XDG_RUNTIME_DIR" ]] && rm -rf "$XDG_RUNTIME_DIR"
} }
trap cleanup EXIT trap cleanup EXIT
@ -237,12 +233,16 @@ test_output_list_ipc() {
echo "ok" echo "ok"
} }
verify_wayvnc_exited() {
wait_until ! kill -0 $WAYVNC_PID >/dev/null
unset WAYVNC_PID
}
test_exit_ipc() { test_exit_ipc() {
echo "Checking wayvnc-exit command" echo "Checking wayvnc-exit command"
$WAYVNCCTL wayvnc-exit &>/dev/null $WAYVNCCTL wayvnc-exit &>/dev/null
wait_while kill -0 $WAYVNC_PID >/dev/null verify_wayvnc_exited
echo " wayvnc is shutdown" echo " wayvnc is shutdown"
unset WAYVNC_PID
echo "ok" echo "ok"
} }
@ -260,6 +260,7 @@ test_client_connect() {
} }
smoke_test() { smoke_test() {
test_setup "smoke test"
start_sway start_sway
start_wayvncctl_events start_wayvncctl_events
start_wayvnc start_wayvnc