AtlatestRepositorysigil-wm
1
#!/usr/bin/env bash2
set -euo pipefail3
cd "$(dirname "$0")/.."4
make -j2 all build/protocol-client5
mkdir -p build/receipts6
runtime_dir=$(mktemp -d /tmp/sigil-wm-activation.XXXXXX)7
export XDG_RUNTIME_DIR="$runtime_dir" SIGIL_WM_REPL="$runtime_dir/repl"8
export WLR_BACKENDS=headless WLR_RENDERER=pixman WLR_HEADLESS_OUTPUTS=19
unset WAYLAND_DISPLAY DISPLAY10
server_pid= first_pid= second_pid=11
cleanup() {12
for child in "$second_pid" "$first_pid" "$server_pid"; do13
[[ -z $child ]] || kill "$child" 2>/dev/null || true14
[[ -z $child ]] || wait "$child" 2>/dev/null || true15
done16
rm -rf "$runtime_dir"17
}18
trap cleanup EXIT19
value() { bash scripts/msg "$SIGIL_WM_REPL" "$1"; }20
wait_value() {21
for ((attempt=0; attempt<100; attempt++)); do22
if value "$1" | grep -q '(value #t)'; then return; fi23
sleep 0.0524
done25
cat build/receipts/activation.log >&226
printf 'WAIT_FAILED=%s\n' "$1" >&227
return 128
}29
wait_count() {30
local count31
for ((attempt=0; attempt<200; attempt++)); do32
count=$(grep -c "$2" "$1" 2>/dev/null || true)33
if (( ${count:-0} >= $3 )); then return; fi34
sleep 0.0535
done36
tail -20 "$1" >&237
tail -15 build/receipts/activation.log >&238
return 139
}40
timeout 150 bash scripts/run-sigil -L src eval -f test/activation.sgl > build/receipts/activation.log 2>&1 &41
server_pid=$!42
wait_count build/receipts/activation.log '^WAYLAND_SOCKET=' 143
export WAYLAND_DISPLAY=activation-probe44
[[ -S $XDG_RUNTIME_DIR/activation-probe ]]45
timeout 30 bash scripts/run-sigil -L src eval -f test/socket-collision.sgl > build/receipts/socket-collision.log 2>&146
grep -q '^SOCKET_COLLISION=PASS' build/receipts/socket-collision.log47
mkfifo "$runtime_dir/first-control" "$runtime_dir/second-control"48
exec {first_control}<> "$runtime_dir/first-control"49
exec {second_control}<> "$runtime_dir/second-control"50
SIGIL_WM_CLIENT_ACTIVATION=1 timeout 130 build/protocol-client green 36000 < "$runtime_dir/first-control" > build/receipts/activation-first.log 2>&1 &51
first_pid=$!52
wait_value '(= (length windows) 1)'53
SIGIL_WM_CLIENT_CONTROL=1 timeout 130 build/protocol-client red 36000 < "$runtime_dir/second-control" > build/receipts/activation-second.log 2>&1 &54
second_pid=$!55
wait_value '(and (= (length windows) 2) (= (dict-ref (host-snapshot host) focus:) (cadr windows)))'56
wait_value '(>= configurations 3)'57
printf 'a\n' >&"$first_control"58
wait_value '(and (= (length activations) 1) (= (event-ref (car activations) id:) (car windows)) (not (event-ref (car activations) seat?:)) (= (event-ref (car activations) source:) 0) (= (dict-ref (host-snapshot host) focus:) (cadr windows)))'59
value '(define untrusted-copy (car activations))'60
value '(focus-window! host (car windows))'61
wait_value '(= (dict-ref (host-snapshot host) focus:) (car windows))'62
value '(begin (emulate-key! host 1 38 #t) (emulate-key! host 1 38 #f))'63
wait_count build/receipts/activation-first.log '^CLIENT_KEY=38,1' 164
printf 'v\n' >&"$first_control"65
wait_value '(and (= (length activations) 2) (event-ref (cadr activations) seat?:) (= (event-ref (cadr activations) source:) (car windows)) (> (event-ref (cadr activations) serial:) 0))'66
printf 'i\ns\n' >&"$first_control"67
wait_count build/receipts/activation-first.log '^CLIENT_ACTIVATION_DONE' 368
wait_count build/receipts/activation-first.log '^CLIENT_SYNC=s' 169
wait_value '(and (= (length activations) 2) (not (event-ref untrusted-copy seat?:)) (= (event-ref untrusted-copy source:) 0) (= (event-ref untrusted-copy serial:) 0))'70
serials=$(grep -c '^CLIENT_CONFIGURE_SERIAL=' build/receipts/activation-first.log)71
printf 'm\n' >&"$first_control"72
wait_value '(= maximizes 1)'73
wait_count build/receipts/activation-first.log '^CLIENT_CONFIGURE_SERIAL=' "$((serials+1))"74
wait_value '(let ((record (find (lambda (record) (= (dict-ref record id:) (car windows))) (dict-ref (host-snapshot host) windows:)))) (and (= (rect-width (dict-ref record committed:)) 300) (= (rect-height (dict-ref record committed:)) 300)))'75
printf 'q\n' >&"$first_control"76
wait "$first_pid"77
first_pid=78
wait_value '(= (length windows) 1)'79
sleep 0.280
printf 'q\n' >&"$second_control"81
wait "$second_pid"82
second_pid=83
wait_value '(and (null? windows) (= (host-statistic host 1) 0))'84
value '(stop-host! host)'85
wait "$server_pid"86
server_pid=87
grep -q '^ACTIVATION_HOST=PASS' build/receipts/activation.log88
[[ ! -S $XDG_RUNTIME_DIR/activation-probe ]]89
echo 'ACTIVATION=PASS real trusted untrusted invalid serial inert focus immutable facts explicit maximize socket validation collision ownership'