AtlatestRepositorysigil-wm
1
#!/usr/bin/env bash2
set -euo pipefail3
cd "$(dirname "$0")/.."4
: "${SIGIL_WM_OUTPUT_CLIENT:?set the external output protocol client path}"5
make -j2 all6
mkdir -p build/receipts7
runtime_dir=$(mktemp -d /tmp/sigil-wm-output-management.XXXXXX)8
export XDG_RUNTIME_DIR="$runtime_dir" SIGIL_WM_REPL="$runtime_dir/repl"9
export WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_HEADLESS_OUTPUTS=210
unset WAYLAND_DISPLAY DISPLAY11
server_pid= client_pid=12
cleanup() {13
for child in "$client_pid" "$server_pid"; do14
[[ -z $child ]] || kill "$child" 2>/dev/null || true15
[[ -z $child ]] || wait "$child" 2>/dev/null || true16
done17
rm -rf "$runtime_dir"18
}19
trap cleanup EXIT20
value() { bash scripts/msg "$SIGIL_WM_REPL" "$1"; }21
wait_value() {22
for ((attempt=0; attempt<100; attempt++)); do23
if value "$1" | grep -q '(value #t)'; then return; fi24
sleep 0.0525
done26
cat build/receipts/output-management.log >&227
return 128
}29
rejected() {30
local result31
set +e32
timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" "$@" > build/receipts/output-refused.log 2>&133
result=$?34
set -e35
[[ $result != 0 && $result != 124 ]]36
}37
timeout 100 bash scripts/run-sigil -L src eval -f test/output-management.sgl > build/receipts/output-management.log 2>&1 &38
server_pid=$!39
for ((attempt=0; attempt<300; attempt++)); do40
if grep -q '^WAYLAND_SOCKET=' build/receipts/output-management.log; then break; fi41
kill -0 "$server_pid" 2>/dev/null || break42
sleep 0.0543
done44
grep -q '^WAYLAND_SOCKET=' build/receipts/output-management.log45
export WAYLAND_DISPLAY46
WAYLAND_DISPLAY=$(sed -n 's/^WAYLAND_SOCKET=//p' build/receipts/output-management.log | head -1)47
output_name=$(sed -n 's/^OUTPUT_NAME=//p' build/receipts/output-management.log | head -1)48
timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --dryrun --output "$output_name" --pos 50,6049
wait_value '(and (= (length outcomes) 1) (not (event-ref (car proposals) apply?:)) (= (dict-ref (car (dict-ref (host-snapshot host) outputs:)) x:) 0))'50
timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --output "$output_name" --pos 50,6051
wait_value '(and (= (length outcomes) 2) (= (dict-ref (car (dict-ref (host-snapshot host) outputs:)) x:) 50))'52
value '(set! accept? #f)'53
rejected --output "$output_name" --pos 100,12054
wait_value '(and (= (length outcomes) 3) (not (event-ref (car (reverse outcomes)) success?:)) (= (dict-ref (car (dict-ref (host-snapshot host) outputs:)) x:) 50))'55
value '(set! hold? #t)'56
rejected --dryrun --output "$output_name" --pos 100,12057
wait_value '(and (pair? retired) (= (host-statistic host 1) 0))'58
value '(define before-retire (length proposals))'59
timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --output "$output_name" --pos 100,120 > build/receipts/output-retire.log 2>&1 &60
client_pid=$!61
wait_value '(and (> (length proposals) before-retire) (> (host-statistic host 1) 0))'62
kill "$client_pid"63
wait "$client_pid" 2>/dev/null || true64
client_pid=65
wait_value '(= (host-statistic host 1) 0)'66
value '(define before-hotplug (length proposals))'67
timeout 8 "$SIGIL_WM_OUTPUT_CLIENT" --output "$output_name" --pos 100,120 > build/receipts/output-hotplug.log 2>&1 &68
client_pid=$!69
wait_value '(and (> (length proposals) before-hotplug) (> (host-statistic host 1) 0))'70
value '(remove-headless-output! host (car outputs))'71
set +e72
wait "$client_pid"73
result=$?74
set -e75
client_pid=76
[[ $result != 0 && $result != 124 ]]77
wait_value '(and (= (length (dict-ref (host-snapshot host) outputs:)) 1) (= (host-statistic host 1) 0))'78
value '(and (= (length (event-ref (car proposals) heads:)) 2) #t)' | grep -q '(value #t)'79
value '(stop-host! host)'80
wait "$server_pid"81
server_pid=82
grep -q '^OUTPUT_MANAGEMENT_HOST=PASS' build/receipts/output-management.log83
if grep -q 'event handler failed' build/receipts/output-management.log; then cat build/receipts/output-management.log >&2; exit 1; fi84
echo 'OUTPUT_MANAGEMENT=PASS real test apply refusal deadline client retirement hotplug immutable proposals zero ownership'