#!/bin/sh # Boot a built root filesystem under QEMU and photograph the desktop. # # scripts/guitest.sh [max-seconds] the full image (card/) # GUITEST_CARD=card-soho-safe scripts/guitest.sh 1500 another tree # GUITEST_XCLICK='787 135' scripts/guitest.sh 1500 tap points first (here, # the PROGRAMS tab) # GUITEST_KEYS='ret' scripts/guitest.sh 1500 press keys, photographing # after each # GUITEST_NET=1 ... give the guest a network: # QEMU's user-mode NAT, with # this Mac at 10.0.2.2 # GUITEST_RUN_ROOT='cmd' ... run a command as root once the # session is up (output: root-run.log) # GUITEST_RUN='cmd' ... run a command as lx in the # session before any taps # GUITEST_FETCH='/home/lx/x /tmp/y' ... copy guest files out # afterwards # GUITEST_SETTLE=60 ... seconds to wait after the # taps (default 20) # # Writes qemu/psionlx-[-tapped|-driven].png, plus the session's process # list, X session log, diagnostics and first-boot configuration log beside it # as qemu/-*.txt/.log. # # The emulator boots Debian's versatile kernel with qemu/initramfs.gz, which # runs /guitest.sh from the root filesystem in preference to /build.sh; this # script writes that file into a COPY of the image with debugfs. It waits for # a ready marker on the serial console rather than a fixed time, because a # soho tree configures 22 packages on its first boot before X starts. # # Things that have cost time here: # * debugfs "write" silently does nothing if the file exists; rm first. # * DISPLAY must be exported before 99psion-session, or every client dies # and the screen stays black -- which looks exactly like a crash. # * Psion's image runs Xepson, which needs the netBook Pro's Epson display # controller. QEMU has none, so the test copy -- never an image -- is lent # the pre-soho tree's Xfbdev. Both link the same libraries. # * That X server takes its pointer from tslib, which accepts only a # touchscreen, so QEMU's mouse cannot click anything. GUITEST_XCLICK runs # a tiny XTEST client inside the guest instead (build/job-xclick.sh; lent # to the test copy with the libXtst Psion's image lacks). # * Editing this file while a run is using it breaks that run: the shell # reads its script as it goes. # * With GUITEST_NET, the guest's broadcasts to 255.255.255.255 never leave # QEMU, but its subnet broadcast (10.0.2.255) arrives at this Mac's # loopback -- which is how PsionNet's discovery can be tested here. set -e W=$(cd "$(dirname "$0")/.." && pwd) WAIT=${1:-900} CARD=${GUITEST_CARD:-card} CARD_TAG=$CARD DBG=${E2FS:-}/debugfs for d in /opt/homebrew/opt/e2fsprogs/sbin /usr/local/opt/e2fsprogs/sbin /sbin /usr/sbin; do [ -x "$DBG" ] || DBG=$d/debugfs done # one run at a time: two runs share gui.ext2, gui.log and the QMP socket if pgrep -f "qemu-system-arm.*gui.ext2" >/dev/null; then echo "ERROR: another guitest run is still using the emulator"; exit 1 fi cp "$W/$CARD/rootfs.ext2" "$W/qemu/gui.ext2" cat > /tmp/guitest-inner.sh <<'GT' #!/bin/sh exec > /diag.log 2>&1 set -x B=/bin/busybox $B mount -t proc proc /proc 2>/dev/null $B mount -t sysfs sysfs /sys 2>/dev/null for s in /etc/init.d/populate-var.sh /etc/init.d/populate-var /etc/init.d/lxuser.sh; do [ -x "$s" ] && $B sh "$s" start done $B mkdir -p /var/tmp /var/log /tmp; $B chmod 1777 /tmp /var/tmp # first boot: an OE image leaves package configuration to S98configure if [ -x /etc/rcS.d/S98configure ]; then echo GUITEST_CONFIGURING > /dev/console $B sh /etc/rcS.d/S98configure > /configure.log 2>&1 fi if [ -f /guitest-net ]; then $B ifconfig eth0 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255 up $B route add default gw 10.0.2.2 fi /usr/bin/Xfbdev -screen 800x600x16 -dpi 100 -br -pn -ac :0 2>/xfbdev.log & $B sleep 8 export DISPLAY=:0 $B sh /etc/X11/Xinit.d/99psion-session & $B sleep 75 if [ -f /guitest-run-root.sh ]; then $B sh /guitest-run-root.sh > /root-run.log 2>&1 $B sleep 5 fi if [ -f /guitest-run.sh ]; then su lx -c "HOME=/home/lx DISPLAY=:0 sh /guitest-run.sh" > /run.log 2>&1 & $B sleep 30 fi if [ -x /guitest-xclick ]; then LD_LIBRARY_PATH=/guitest-lib /guitest-xclick $(cat /guitest-xclick.args) > /xclick.log 2>&1 fi $B sleep $(cat /guitest-settle 2>/dev/null || echo 20) $B ps w > /psion-ps.txt 2>&1 $B cp /var/tmp/xsession-errors.lx /psion-xerr.txt 2>/dev/null $B sync echo GUITEST_READY > /dev/console $B sleep 600 GT $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 < /tmp/guitest-xclick.args $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 < /tmp/guitest-net $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 < /tmp/guitest-run-root.sh $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 < /tmp/guitest-run.sh $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 < /tmp/guitest-settle $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 </dev/null | grep -q Inode; then $DBG -w -f /dev/stdin "$W/qemu/gui.ext2" >/dev/null 2>&1 < /dev/null 2>&1 & QP=$! python3 - "$WAIT" "$W/qemu/gui.log" <<'PY' import socket, json, sys, time, os deadline = time.time() + int(sys.argv[1]) while time.time() < deadline: try: if b'GUITEST_READY' in open(sys.argv[2], 'rb').read(): break except OSError: pass time.sleep(5) else: print(' (timed out waiting for GUITEST_READY; screenshot taken anyway)') s = socket.socket(socket.AF_UNIX); s.connect('/tmp/qmp.sock') f = s.makefile('rw'); f.readline() def qmp(cmd, **args): f.write(json.dumps({"execute": cmd, "arguments": args} if args else {"execute": cmd}) + "\n") f.flush() while True: # skip asynchronous events r = json.loads(f.readline()) if 'return' in r or 'error' in r: return r qmp("qmp_capabilities") # GUITEST_KEYS presses each chord in turn (QEMU qcodes joined by '-', e.g. # ctrl-pgdn), photographing after each one as psionlx--driven-key.png. for n, chord in enumerate(os.environ.get('GUITEST_KEYS', '').split(), 1): r = qmp("send-key", keys=[{"type": "qcode", "data": k} for k in chord.split('-')]) if 'error' in r: print(' send-key:', r['error']) time.sleep(12) qmp("screendump", filename=f"/tmp/psionlx-key{n}.ppm") print(f' pressed {chord}') r = qmp("screendump", filename="/tmp/psionlx.ppm"); s.close() if 'error' in r: print(' screendump:', r['error']) PY python3 -c "from PIL import Image; Image.open('/tmp/psionlx.ppm').convert('RGB').save('$W/qemu/psionlx-$CARD_TAG.png')" for k in /tmp/psionlx-key*.ppm; do [ -e "$k" ] || continue n=$(basename "$k" .ppm | sed 's/psionlx-//') python3 -c "from PIL import Image; Image.open('$k').convert('RGB').save('$W/qemu/psionlx-$CARD_TAG-$n.png')" rm -f "$k" done kill $QP 2>/dev/null || true sleep 2 for f in psion-ps.txt psion-xerr.txt diag.log configure.log xfbdev.log xclick.log run.log root-run.log; do rm -f "$W/qemu/$CARD-$f" $DBG -R "dump /$f $W/qemu/$CARD-$f" gui.ext2 >/dev/null 2>&1 done for f in $GUITEST_FETCH; do rm -f "$W/qemu/$CARD-fetched-$(basename "$f")" $DBG -R "dump $f $W/qemu/$CARD-fetched-$(basename "$f")" gui.ext2 >/dev/null 2>&1 [ -s "$W/qemu/$CARD-fetched-$(basename "$f")" ] && echo "== fetched $f" || echo "== could not fetch $f" done echo "== $W/qemu/psionlx-$CARD_TAG.png" echo "== session processes:" grep -aE 'matchbox|gpe-|minimix|applet' "$W/qemu/$CARD-psion-ps.txt" 2>/dev/null | sed 's/^/ /'