AtlatestRepositorysigil-ui
1#!/bin/sh
2# Live tests for (sigil ui wayland) against a headless sway.
3#
4# Starts sway with the headless backend and the pixman renderer in a fresh
5# runtime directory, so it never touches a running session, builds the
6# virtual input driver, runs test/wayland/live.sgl, and stops sway.
7#
8# Needs: sway, swaymsg and grim on PATH; libwayland-client and libxkbcommon
9# (found by soname, or set SIGIL_UI_LIBWAYLAND_CLIENT and
10# SIGIL_UI_LIBXKBCOMMON); a C compiler for the driver (CC, else zig).
12# test/wayland/run all live tests
13# test/wayland/run FILE... other test files against the same compositor
14# SIGIL=/path/to/sigil test/wayland/run
15set -eu
16root=$(cd "$(dirname "$0")/../.." && pwd)
17here="$root/test/wayland"
18SIGIL=${SIGIL:-sigil}
20for tool in sway swaymsg grim wl-copy wl-paste; do
21 command -v "$tool" >/dev/null || { echo "run: $tool is not on PATH" >&2; exit 2; }
22done
24# The libraries, where the dynamic loader would not find them by soname.
25for dir in ${GUIX_ENVIRONMENT:+"$GUIX_ENVIRONMENT/lib"} "$HOME/.guix-home/profile/lib" \
26 /run/current-system/profile/lib; do
27 if [ -z "${SIGIL_UI_LIBWAYLAND_CLIENT:-}" ] && [ -e "$dir/libwayland-client.so.0" ]; then
28 SIGIL_UI_LIBWAYLAND_CLIENT="$dir/libwayland-client.so.0"
29 fi
30 if [ -z "${SIGIL_UI_LIBXKBCOMMON:-}" ] && [ -e "$dir/libxkbcommon.so.0" ]; then
31 SIGIL_UI_LIBXKBCOMMON="$dir/libxkbcommon.so.0"
32 fi
33 if [ -z "${SIGIL_UI_LIBWAYLAND_CURSOR:-}" ] && [ -e "$dir/libwayland-cursor.so.0" ]; then
34 SIGIL_UI_LIBWAYLAND_CURSOR="$dir/libwayland-cursor.so.0"
35 fi
36done
37export SIGIL_UI_LIBWAYLAND_CLIENT SIGIL_UI_LIBXKBCOMMON SIGIL_UI_LIBWAYLAND_CURSOR
39# A short runtime directory: a Wayland socket path must fit in 108 bytes.
40runtime=$(mktemp -d /tmp/sigil-ui-wl.XXXXXX)
41chmod 700 "$runtime"
42sway_pid=
43cleanup() {
44 if [ -n "$sway_pid" ]; then kill "$sway_pid" 2>/dev/null || true; wait "$sway_pid" 2>/dev/null || true; fi
45 rm -rf "$runtime"
47trap cleanup EXIT INT TERM
49# The driver. When it cannot start as built (a glibc binary from zig on a
50# system whose loader is not at the standard path), it runs through the
51# loader sway itself uses.
52driver="$runtime/input-driver"
53cflags="-std=c11 -O1 -Wall -Wextra -Werror -Wno-unused-parameter -I$root/native/wayland -I$root/native/wayland/include -I$here"
54if [ -n "${CC:-}" ] || command -v cc >/dev/null; then
55 ${CC:-cc} $cflags "$here/input-driver.c" -ldl -o "$driver"
56else
57 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"
60fi
61SIGIL_UI_TEST_DRIVER="$driver"
62if ! "$driver" --probe >/dev/null 2>&1; then
63 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; }
67fi
68export SIGIL_UI_TEST_DRIVER
70cat > "$runtime/sway.conf" <<EOF
71output HEADLESS-1 resolution 1280x800 position 0 0 scale 1
72xwayland disable
73default_border none
74default_floating_border none
75focus_follows_mouse no
76EOF
78env -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 &
81sway_pid=$!
83socket=
84i=0
85while [ $i -lt 100 ]; do
86 socket=$(cd "$runtime" && ls wayland-[0-9]* 2>/dev/null | grep -v lock | head -n 1) || true
87 sock=$(ls "$runtime"/sway-ipc.*.sock 2>/dev/null | head -n 1) || true
88 [ -n "$socket" ] && [ -n "$sock" ] && break
89 kill -0 "$sway_pid" 2>/dev/null || { cat "$runtime/sway.log" >&2; echo "run: sway exited" >&2; exit 2; }
90 sleep 0.1
91 i=$((i + 1))
92done
93[ -n "$socket" ] && [ -n "$sock" ] || { cat "$runtime/sway.log" >&2; echo "run: sway did not start" >&2; exit 2; }
95export XDG_RUNTIME_DIR="$runtime" WAYLAND_DISPLAY="$socket" SWAYSOCK="$sock"
96export SIGIL_UI_TEST_OUTPUT=HEADLESS-1 SIGIL_UI_TEST_SHOTS="$runtime"
97"$SIGIL" "$root/scripts/make-cursor-fixture.sgl" "$runtime/cursor-fixtures"
98export SIGIL_UI_TEST_CURSOR_ROOT="$runtime/cursor-fixtures"
99echo "run: sway $(sway --version | cut -d' ' -f3) headless at $runtime/$socket"
100cd "$root"
101status=0
102[ $# -gt 0 ] || set -- "$here/live.sgl" "$here/bridge.sgl" "$here/configure-live.sgl"
103"$SIGIL" test "$@" || status=$?
104if [ "$status" -ne 0 ]; then
105 echo "run: live tests failed ($status); sway log:" >&2
106 tail -n 20 "$runtime/sway.log" >&2
107fi
108exit "$status"