AtlatestRepositorysigil-wm

sigil-wm / tree / scriptstest-output-management

1#!/usr/bin/env bash
2set -euo pipefail
3cd "$(dirname "$0")/.."
4: "${SIGIL_WM_OUTPUT_CLIENT:?set the external output protocol client path}"
5make -j2 all
6mkdir -p build/receipts
7runtime_dir=$(mktemp -d /tmp/sigil-wm-output-management.XXXXXX)
8export XDG_RUNTIME_DIR="$runtime_dir" SIGIL_WM_REPL="$runtime_dir/repl"
9export WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_HEADLESS_OUTPUTS=2
10unset WAYLAND_DISPLAY DISPLAY
11server_pid= client_pid=
12cleanup() {
13 for child in "$client_pid" "$server_pid"; do
14 [[ -z $child ]] || kill "$child" 2>/dev/null || true
15 [[ -z $child ]] || wait "$child" 2>/dev/null || true
16 done
17 rm -rf "$runtime_dir"
19trap cleanup EXIT
20value() { bash scripts/msg "$SIGIL_WM_REPL" "$1"; }
21wait_value() {
22 for ((attempt=0; attempt<100; attempt++)); do
23 if value "$1" | grep -q '(value #t)'; then return; fi
24 sleep 0.05
25 done
26 cat build/receipts/output-management.log >&2
27 return 1
29rejected() {
30 local result
31 set +e
32 timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" "$@" > build/receipts/output-refused.log 2>&1
33 result=$?
34 set -e
35 [[ $result != 0 && $result != 124 ]]
37timeout 100 bash scripts/run-sigil -L src eval -f test/output-management.sgl > build/receipts/output-management.log 2>&1 &
38server_pid=$!
39for ((attempt=0; attempt<300; attempt++)); do
40 if grep -q '^WAYLAND_SOCKET=' build/receipts/output-management.log; then break; fi
41 kill -0 "$server_pid" 2>/dev/null || break
42 sleep 0.05
43done
44grep -q '^WAYLAND_SOCKET=' build/receipts/output-management.log
45export WAYLAND_DISPLAY
46WAYLAND_DISPLAY=$(sed -n 's/^WAYLAND_SOCKET=//p' build/receipts/output-management.log | head -1)
47output_name=$(sed -n 's/^OUTPUT_NAME=//p' build/receipts/output-management.log | head -1)
48timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --dryrun --output "$output_name" --pos 50,60
49wait_value '(and (= (length outcomes) 1) (not (event-ref (car proposals) apply?:)) (= (dict-ref (car (dict-ref (host-snapshot host) outputs:)) x:) 0))'
50timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --output "$output_name" --pos 50,60
51wait_value '(and (= (length outcomes) 2) (= (dict-ref (car (dict-ref (host-snapshot host) outputs:)) x:) 50))'
52value '(set! accept? #f)'
53rejected --output "$output_name" --pos 100,120
54wait_value '(and (= (length outcomes) 3) (not (event-ref (car (reverse outcomes)) success?:)) (= (dict-ref (car (dict-ref (host-snapshot host) outputs:)) x:) 50))'
55value '(set! hold? #t)'
56rejected --dryrun --output "$output_name" --pos 100,120
57wait_value '(and (pair? retired) (= (host-statistic host 1) 0))'
58value '(define before-retire (length proposals))'
59timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --output "$output_name" --pos 100,120 > build/receipts/output-retire.log 2>&1 &
60client_pid=$!
61wait_value '(and (> (length proposals) before-retire) (> (host-statistic host 1) 0))'
62kill "$client_pid"
63wait "$client_pid" 2>/dev/null || true
64client_pid=
65wait_value '(= (host-statistic host 1) 0)'
66value '(define before-hotplug (length proposals))'
67timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --output "$output_name" --pos 100,120 > build/receipts/output-hotplug.log 2>&1 &
68client_pid=$!
69wait_value '(and (> (length proposals) before-hotplug) (> (host-statistic host 1) 0))'
70value '(remove-headless-output! host (car outputs))'
71set +e
72wait "$client_pid"
73result=$?
74set -e
75client_pid=
76[[ $result != 0 && $result != 124 ]]
77wait_value '(and (= (length (dict-ref (host-snapshot host) outputs:)) 1) (= (host-statistic host 1) 0))'
78value '(and (= (length (event-ref (car proposals) heads:)) 2) #t)' | grep -q '(value #t)'
79value '(stop-host! host)'
80wait "$server_pid"
81server_pid=
82grep -q '^OUTPUT_MANAGEMENT_HOST=PASS' build/receipts/output-management.log
83if grep -q 'event handler failed' build/receipts/output-management.log; then cat build/receipts/output-management.log >&2; exit 1; fi
84echo 'OUTPUT_MANAGEMENT=PASS real test apply refusal deadline client retirement hotplug immutable proposals zero ownership'