vinix-ports / tests / x11 / headless.sh
39 lines · 39 sloc · 1.3 KB · c3731b2aba091a48e212aa203a7b7926d9ba66b6
Raw
1#!/bin/sh
2set -eu
3export PATH=/bin:/usr/bin:/sbin:/usr/sbin HOME=/tmp
4export DISPLAY=:71 XAUTHORITY=/tmp/vinix-x11.Xauthority
5server=
6finish() {
7 status=$?
8 if [ "$status" -ne 0 ]; then
9 echo 'Vinix headless X11 guest check failed'
10 if [ -f /tmp/xvfb.log ]; then cat /tmp/xvfb.log; fi
11 fi
12 if [ -n "$server" ]; then kill "$server" 2>/dev/null || true; fi
13 /sbin/poweroff -f
14}
15trap finish EXIT
16mkdir -p /tmp
17# This fixed cookie belongs to an isolated guest display with TCP disabled.
18xauth -q -f "$XAUTHORITY" add "$DISPLAY" MIT-MAGIC-COOKIE-1 0123456789abcdef0123456789abcdef
19Xvfb "$DISPLAY" -auth "$XAUTHORITY" -nolisten tcp -noreset -screen 0 128x128x24 >/tmp/xvfb.log 2>&1 &
20server=$!
21attempt=0
22until xset q >/tmp/xset.log 2>&1; do
23 kill -0 "$server"
24 attempt=$((attempt + 1))
25 [ "$attempt" -lt 20 ]
26 sleep 1
27done
28/x11-client --display
29printf 'Vinix.sidecar: tested\n' >/tmp/xresources
30xrdb -nocpp -load /tmp/xresources
31xrdb -query >/tmp/xresources-query
32grep -E '^Vinix\.sidecar:[[:space:]]*tested$' /tmp/xresources-query
33: >/tmp/empty.Xauthority
34if XAUTHORITY=/tmp/empty.Xauthority xset q >/tmp/unauthorized.log 2>&1; then
35 echo 'Xvfb accepted an unauthenticated client'
36 exit 1
37fi
38echo 'Packaged Xvfb, Xauth, Xlib, xset and xrdb guest checks passed.'
39echo 'VPAC FIXTURE GUEST PASS'
40