AtlatestRepositorysigil-ui
1
#!/bin/sh2
# Live tests for (sigil ui wayland) against a headless sway.3
#4
# Starts sway with the headless backend and the pixman renderer in a fresh5
# runtime directory, so it never touches a running session, builds the6
# virtual input driver, runs test/wayland/live.sgl, and stops sway.7
#8
# Needs: sway, swaymsg and grim on PATH; libwayland-client and libxkbcommon9
# (found by soname, or set SIGIL_UI_LIBWAYLAND_CLIENT and10
# SIGIL_UI_LIBXKBCOMMON); a C compiler for the driver (CC, else zig).11
#12
# test/wayland/run all live tests13
# test/wayland/run FILE... other test files against the same compositor14
# SIGIL=/path/to/sigil test/wayland/run15
set -eu16
root=$(cd "$(dirname "$0")/../.." && pwd)17
here="$root/test/wayland"18
SIGIL=${SIGIL:-sigil}20
for tool in sway swaymsg grim wl-copy wl-paste; do21
command -v "$tool" >/dev/null || { echo "run: $tool is not on PATH" >&2; exit 2; }22
done24
# The libraries, where the dynamic loader would not find them by soname.25
for dir in ${GUIX_ENVIRONMENT:+"$GUIX_ENVIRONMENT/lib"} "$HOME/.guix-home/profile/lib" \26
/run/current-system/profile/lib; do27
if [ -z "${SIGIL_UI_LIBWAYLAND_CLIENT:-}" ] && [ -e "$dir/libwayland-client.so.0" ]; then28
SIGIL_UI_LIBWAYLAND_CLIENT="$dir/libwayland-client.so.0"29
fi30
if [ -z "${SIGIL_UI_LIBXKBCOMMON:-}" ] && [ -e "$dir/libxkbcommon.so.0" ]; then31
SIGIL_UI_LIBXKBCOMMON="$dir/libxkbcommon.so.0"32
fi33
if [ -z "${SIGIL_UI_LIBWAYLAND_CURSOR:-}" ] && [ -e "$dir/libwayland-cursor.so.0" ]; then34
SIGIL_UI_LIBWAYLAND_CURSOR="$dir/libwayland-cursor.so.0"35
fi36
done37
export SIGIL_UI_LIBWAYLAND_CLIENT SIGIL_UI_LIBXKBCOMMON SIGIL_UI_LIBWAYLAND_CURSOR39
# A short runtime directory: a Wayland socket path must fit in 108 bytes.40
runtime=$(mktemp -d /tmp/sigil-ui-wl.XXXXXX)41
chmod 700 "$runtime"42
sway_pid=43
cleanup() {44
if [ -n "$sway_pid" ]; then kill "$sway_pid" 2>/dev/null || true; wait "$sway_pid" 2>/dev/null || true; fi45
rm -rf "$runtime"46
}47
trap cleanup EXIT INT TERM49
# The driver. When it cannot start as built (a glibc binary from zig on a50
# system whose loader is not at the standard path), it runs through the51
# loader sway itself uses.52
driver="$runtime/input-driver"53
cflags="-std=c11 -O1 -Wall -Wextra -Werror -Wno-unused-parameter -I$root/native/wayland -I$root/native/wayland/include -I$here"54
if [ -n "${CC:-}" ] || command -v cc >/dev/null; then55
${CC:-cc} $cflags "$here/input-driver.c" -ldl -o "$driver"56
else57
zig=${ZIG:-$(command -v zig || echo "${SIGIL_HOME:-$HOME/.sigil}/toolchain/zig/zig")}58
[ -x "$zig" ] || { echo "run: no C compiler (set CC or ZIG)" >&2; exit 2; }59
"$zig" cc -target "$(uname -m)-linux-gnu.2.28" $cflags "$here/input-driver.c" -ldl -o "$driver"60
fi61
SIGIL_UI_TEST_DRIVER="$driver"62
if ! "$driver" --probe >/dev/null 2>&1; then63
loader=$(file -L "$(command -v sway)" | sed -n 's/.*interpreter \([^,]*\),.*/\1/p')64
[ -x "$loader" ] || { echo "run: cannot find the dynamic loader for the driver" >&2; exit 2; }65
SIGIL_UI_TEST_DRIVER="$loader $driver"66
$SIGIL_UI_TEST_DRIVER --probe || { echo "run: the input driver does not start" >&2; exit 2; }67
fi68
export SIGIL_UI_TEST_DRIVER70
cat > "$runtime/sway.conf" <<EOF71
output HEADLESS-1 resolution 1280x800 position 0 0 scale 172
xwayland disable73
default_border none74
default_floating_border none75
focus_follows_mouse no76
EOF78
env -u WAYLAND_DISPLAY -u DISPLAY -u SWAYSOCK XDG_RUNTIME_DIR="$runtime" \79
WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_LIBINPUT_NO_DEVICES=1 \80
sway -c "$runtime/sway.conf" > "$runtime/sway.log" 2>&1 &81
sway_pid=$!83
socket=84
i=085
while [ $i -lt 100 ]; do86
socket=$(cd "$runtime" && ls wayland-[0-9]* 2>/dev/null | grep -v lock | head -n 1) || true87
sock=$(ls "$runtime"/sway-ipc.*.sock 2>/dev/null | head -n 1) || true88
[ -n "$socket" ] && [ -n "$sock" ] && break89
kill -0 "$sway_pid" 2>/dev/null || { cat "$runtime/sway.log" >&2; echo "run: sway exited" >&2; exit 2; }90
sleep 0.191
i=$((i + 1))92
done93
[ -n "$socket" ] && [ -n "$sock" ] || { cat "$runtime/sway.log" >&2; echo "run: sway did not start" >&2; exit 2; }95
export XDG_RUNTIME_DIR="$runtime" WAYLAND_DISPLAY="$socket" SWAYSOCK="$sock"96
export SIGIL_UI_TEST_OUTPUT=HEADLESS-1 SIGIL_UI_TEST_SHOTS="$runtime"97
"$SIGIL" "$root/scripts/make-cursor-fixture.sgl" "$runtime/cursor-fixtures"98
export SIGIL_UI_TEST_CURSOR_ROOT="$runtime/cursor-fixtures"99
echo "run: sway $(sway --version | cut -d' ' -f3) headless at $runtime/$socket"100
cd "$root"101
status=0102
[ $# -gt 0 ] || set -- "$here/live.sgl" "$here/bridge.sgl" "$here/configure-live.sgl"103
"$SIGIL" test "$@" || status=$?104
if [ "$status" -ne 0 ]; then105
echo "run: live tests failed ($status); sway log:" >&2106
tail -n 20 "$runtime/sway.log" >&2107
fi108
exit "$status"