Files
looking-glass-2/host/tests/test-multimon.sh
T
donny faaf63bc93
build / client (Debug, map[cc:clang cxx:clang++], libdecor) (push) Failing after 20s
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 20s
build / client (Debug, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 20s
build / client (Release, map[cc:clang cxx:clang++], libdecor) (push) Failing after 19s
build / client (Release, map[cc:clang cxx:clang++], xdg-shell) (push) Failing after 20s
build / module (push) Failing after 16s
build / client (Release, map[cc:gcc cxx:g++], libdecor) (push) Failing after 19s
build / client (Release, map[cc:gcc cxx:g++], xdg-shell) (push) Failing after 19s
build / host-linux (push) Failing after 18s
build / host-windows-cross (push) Failing after 18s
build / obs (clang) (push) Failing after 19s
build / docs (push) Failing after 3s
build / obs (gcc) (push) Failing after 19s
build / host-windows-native (push) Canceled after 0s
build / idd (push) Canceled after 0s
common: make the atlas repack shared and testable
Moves the per-display copy out of the XCB backend into common so it can
be unit tested directly and reused by other backends. The test uses a
unique value per source pixel, so a copy landing at the wrong offset
cannot pass by coincidence, and checks truncation against guard bytes.

Also adds a scripted end-to-end test and teaches the verification tool
to report a blank capture source as a skip rather than a failure.
2026-07-28 07:31:13 +00:00

129 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# End to end test of multi-monitor capture and atlas packing.
#
# Runs a virtual X server with three RandR monitors defined over one screen,
# paints a distinct pattern into each monitor's region, then has the host
# capture it and checks that every display's pixels arrive at the right place
# in the packed atlas.
#
# Usage: test-multimon.sh <build-dir> <work-dir>
set -u
HOST_BIN="${1:-host/build/looking-glass-host}"
VERIFY_BIN="${2:-lg-verify-atlas}"
WORK="${3:-/tmp/lg-multimon-test}"
DISP=:99
SHM=/dev/shm/looking-glass-test
SCREEN_W=1920
SCREEN_H=1080
MON_W=640
# each monitor gets its own primary colour so a misplaced copy is obvious
COLOURS=(red green blue)
NAMES=(TEST-1 TEST-2 TEST-3)
cleanup() {
[ -n "${HOST_PID:-}" ] && kill "$HOST_PID" 2>/dev/null
[ -n "${XVFB_PID:-}" ] && kill "$XVFB_PID" 2>/dev/null
rm -f "$SHM"
}
trap cleanup EXIT
mkdir -p "$WORK"
rm -rf "${WORK:?}"/*
echo "== starting virtual X server =="
Xvfb $DISP -screen 0 ${SCREEN_W}x${SCREEN_H}x24 +extension RANDR > "$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"
cat "$WORK/xvfb.log"
exit 1
fi
echo "== defining 3 monitors =="
for i in 0 1 2; do
X=$((i * MON_W))
DISPLAY=$DISP xrandr --setmonitor "${NAMES[$i]}" \
${MON_W}/170x${SCREEN_H}/280+${X}+0 none || {
echo "FAIL: could not define monitor ${NAMES[$i]}"; exit 1; }
done
DISPLAY=$DISP xrandr --listmonitors
echo "== painting a distinct pattern per monitor =="
# a gradient gives within-region variation, so a region that is left untouched
# (flat colour) is distinguishable from one that was really copied
ARGS=()
for i in 0 1 2; do
convert -size ${MON_W}x${SCREEN_H} \
gradient:"${COLOURS[$i]}"-black "$WORK/mon$i.png"
ARGS+=("$WORK/mon$i.png")
done
convert "${ARGS[@]}" +append "$WORK/desktop.png"
DISPLAY=$DISP display -window root "$WORK/desktop.png" 2>/dev/null &
sleep 2
echo "== starting host =="
rm -f "$SHM"
truncate -s 128M "$SHM"
DISPLAY=$DISP "$HOST_BIN" app:capture=XCB app:shmFile="$SHM" \
> "$WORK/host.log" 2>&1 &
HOST_PID=$!
sleep 3
if ! kill -0 "$HOST_PID" 2>/dev/null; then
echo "FAIL: host exited"
tail -20 "$WORK/host.log"
exit 1
fi
grep -E "Multi-monitor|TEST-" "$WORK/host.log" || true
echo
echo "== verifying the packed atlas =="
"$VERIFY_BIN" "$SHM" "$WORK"
VERIFY_RC=$?
echo
echo "== checking each display carries its own colour =="
RC=0
for i in 0 1 2; do
PPM="$WORK/display-$i-${NAMES[$i]}.ppm"
if [ ! -f "$PPM" ]; then
echo " [FAIL] ${NAMES[$i]}: no image written"
RC=1
continue
fi
# the dominant channel must be the colour painted into that monitor
read -r R G B <<< "$(convert "$PPM" -resize 1x1! -format "%[fx:r] %[fx:g] %[fx:b]" info:)"
case $i in
0) OK=$(awk -v r="$R" -v g="$G" -v b="$B" \
'BEGIN{print (r>g && r>b) ? 1 : 0}') ; WANT=red ;;
1) OK=$(awk -v r="$R" -v g="$G" -v b="$B" \
'BEGIN{print (g>r && g>b) ? 1 : 0}') ; WANT=green ;;
2) OK=$(awk -v r="$R" -v g="$G" -v b="$B" \
'BEGIN{print (b>r && b>g) ? 1 : 0}') ; WANT=blue ;;
esac
if [ "$OK" = "1" ]; then
echo " [PASS] ${NAMES[$i]} is $WANT dominant (r=$R g=$G b=$B)"
else
echo " [FAIL] ${NAMES[$i]} should be $WANT dominant (r=$R g=$G b=$B)"
RC=1
fi
done
echo
if [ $VERIFY_RC -eq 0 ] && [ $RC -eq 0 ]; then
echo "MULTI-MONITOR TEST PASSED"
exit 0
fi
echo "MULTI-MONITOR TEST FAILED"
exit 1