Files
looking-glass-2/host/tests/test-compose.sh
T
donny e35d51ea39
build / client (Debug, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / client (Debug, map[cc:gcc cxx:g++], libdecor) (push) Failing after 34s
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 44s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 27s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 22s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / module (push) Failing after 19s
build / host-linux (push) Failing after 21s
build / host-windows-cross (push) Failing after 21s
build / obs (clang) (push) Failing after 21s
build / docs (push) Failing after 13s
build / obs (gcc) (push) Failing after 20s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
client: fix the composed desktop being rendered upside down
The composition pass flipped Y when writing into its framebuffer, but the
desktop shader that samples it treats row 0 as the top, so the composed
desktop reached the screen inverted. The layout metadata was correct
throughout, which is why the geometry checks never caught it.

Adds a rendering test that catches this class of bug: a synthetic host
publishes three displays stacked vertically in the atlas but laid out in a
row on the desktop, and the client is rendered into a virtual X server and
sampled. Each display carries a marker in its top left corner, so an
inverted or transposed composition fails even though the colours would
otherwise land in the right places.
2026-07-28 08:00:37 +00:00

158 lines
4.5 KiB
Bash
Executable File

#!/bin/bash
# Verifies the client's multi-display composition by rendering it for real.
#
# A synthetic host publishes three displays packed as a vertical stack in the
# atlas but laid out as a horizontal row on the virtual desktop. The client is
# rendered into a virtual X server and the result is sampled: getting the
# colours in the right places proves the composition used the layout rather
# than simply drawing the packed frame.
#
# Usage: test-compose.sh <fake-host-bin> <client-bin> [work-dir]
set -u
FAKE="${1:?fake host binary required}"
CLIENT="${2:?client binary required}"
WORK="${3:-/tmp/lg-compose-test}"
DISP=:99
SHM=/dev/shm/lg-compose-test
VIEW_W=960
VIEW_H=240
cleanup() {
[ -n "${CLIENT_PID:-}" ] && kill "$CLIENT_PID" 2>/dev/null
[ -n "${FAKE_PID:-}" ] && kill "$FAKE_PID" 2>/dev/null
[ -n "${XVFB_PID:-}" ] && kill "$XVFB_PID" 2>/dev/null
rm -f "$SHM"
}
trap cleanup EXIT
mkdir -p "$WORK"
rm -f "$WORK"/*.png
echo "== starting virtual X server =="
Xvfb $DISP -screen 0 1024x320x24 > "$WORK/xvfb.log" 2>&1 &
XVFB_PID=$!
sleep 2
if ! DISPLAY=$DISP xrandr --query > /dev/null 2>&1; then
echo "FAIL: virtual X server did not start"; exit 1
fi
echo "== starting synthetic host =="
rm -f "$SHM"
truncate -s 64M "$SHM"
"$FAKE" "$SHM" > "$WORK/fake.log" 2>&1 &
FAKE_PID=$!
sleep 2
grep -E "^atlas|desktop \+" "$WORK/fake.log"
echo "== starting client =="
# force the X11 backend so the output can be captured from the X root
env -u WAYLAND_DISPLAY DISPLAY=$DISP "$CLIENT" \
-f "$SHM" -s \
win:size=${VIEW_W}x${VIEW_H} win:autoResize=no win:borderless=yes \
win:position=0x0 app:display=all \
> "$WORK/client.log" 2>&1 &
CLIENT_PID=$!
sleep 6
if ! kill -0 "$CLIENT_PID" 2>/dev/null; then
echo "FAIL: client exited"
tail -15 "$WORK/client.log"
exit 1
fi
grep -E "Composing|Showing" "$WORK/client.log" || true
echo "== capturing the rendered output =="
if ! DISPLAY=$DISP import -window root "$WORK/render.png" 2>"$WORK/import.log"; then
echo "FAIL: could not capture the X root"
cat "$WORK/import.log"
exit 1
fi
# sample a point and report the dominant channel
sample() {
convert "$WORK/render.png" -format "%[pixel:p{$1,$2}]" info:
}
dominant() {
local px; px=$(convert "$WORK/render.png" -crop 1x1+$1+$2 +repage \
-format "%[fx:r] %[fx:g] %[fx:b]" info:)
read -r r g b <<< "$px"
awk -v r="$r" -v g="$g" -v b="$b" 'BEGIN{
if (r>0.8 && g>0.8 && b>0.8) { print "white"; exit }
if (r>g && r>b) { print "red" ; exit }
if (g>r && g>b) { print "green"; exit }
if (b>r && b>g) { print "blue" ; exit }
print "none" }'
}
echo
echo "== checking composition =="
RC=0
check() {
local x=$1 y=$2 want=$3 what=$4
local got; got=$(dominant "$x" "$y")
if [ "$got" = "$want" ]; then
echo " [PASS] $what at ($x,$y) is $got"
else
echo " [FAIL] $what at ($x,$y) is $got, expected $want"
RC=1
fi
}
# each display's body, sampled well clear of the corner marker
check 160 150 red "FAKE-0 (leftmost on the desktop)"
check 480 150 green "FAKE-1 (middle on the desktop)"
check 800 150 blue "FAKE-2 (rightmost on the desktop)"
# the marker sits in each display's top left, proving orientation
check 15 15 white "FAKE-0 corner marker"
check 335 15 white "FAKE-1 corner marker"
check 655 15 white "FAKE-2 corner marker"
# just right of each marker must be that display's colour, not the next one's
check 60 15 red "FAKE-0 beside its marker"
check 380 15 green "FAKE-1 beside its marker"
echo
echo "== checking single display selection =="
kill "$CLIENT_PID" 2>/dev/null
wait "$CLIENT_PID" 2>/dev/null
# selecting one display must show only that display, filling the view
env -u WAYLAND_DISPLAY DISPLAY=$DISP "$CLIENT" \
-f "$SHM" -s \
win:size=320x240 win:autoResize=no win:borderless=yes \
win:position=0x0 app:display=1 \
> "$WORK/client-single.log" 2>&1 &
CLIENT_PID=$!
sleep 6
if ! kill -0 "$CLIENT_PID" 2>/dev/null; then
echo " [FAIL] client exited when selecting one display"
RC=1
else
grep -E "Showing guest display" "$WORK/client-single.log" || true
DISPLAY=$DISP import -window root "$WORK/render.png" 2>/dev/null
# the whole view is now FAKE-1, so it is green with its marker at the origin
check 160 120 green "selected display body"
check 15 15 white "selected display corner marker"
check 60 15 green "selected display beside its marker"
check 300 230 green "selected display far corner"
fi
echo
echo " rendered output: $WORK/render.png"
echo
if [ $RC -eq 0 ]; then
echo "COMPOSITION TEST PASSED"
else
echo "COMPOSITION TEST FAILED"
fi
exit $RC