host_shots.sh 1.5 KB

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. # host_shots.sh <vm> <guest out dir> [seconds] - serves the "SHOT_CMD=host" requests of guest_test.sh: whenever the guest
  3. # creates <file>.png.want, takes a screenshot of the VM's display (the same VNC socket `linuxvm.sh shot` uses) and copies
  4. # it into the guest as <file>.png, and clicks the screen's centre for every <file>.click (focus for a test window). Runs until the seconds (default 900) are over or the guest's test run has finished
  5. # (the guest creates <out dir>/done).
  6. HERE=$(cd "$(dirname "$0")" && pwd)
  7. vm=$1 out=$2 limit=${3:-900}
  8. tmp=$(mktemp -d)
  9. end=$((SECONDS + limit))
  10. while [ $SECONDS -lt $end ]; do
  11. wanted=$("$HERE/linuxvm.sh" ssh "$vm" "find $out -maxdepth 1 \\( -name '*.want' -o -name '*.click' \\) 2>/dev/null; [ -e $out/done ] && echo DONE" </dev/null 2>/dev/null)
  12. echo "$wanted" | grep -q '^DONE$' && break
  13. # a window the test opened needs the focus (GNOME holds back new windows of background processes): click it
  14. for click in $(echo "$wanted" | grep '\.click$'); do
  15. "$HERE/linuxvm.sh" pointer "$vm" 960 540 >/dev/null && "$HERE/linuxvm.sh" click "$vm" >/dev/null
  16. "$HERE/linuxvm.sh" ssh "$vm" "rm -f $click" </dev/null
  17. done
  18. for want in $(echo "$wanted" | grep '\.want$'); do
  19. name=$(basename "${want%.want}")
  20. "$HERE/linuxvm.sh" shot "$vm" "$tmp/$name" && "$HERE/linuxvm.sh" scp "$vm" "$tmp/$name" "${want%.want}" \
  21. && "$HERE/linuxvm.sh" ssh "$vm" "rm -f $want" </dev/null
  22. done
  23. sleep 1
  24. done
  25. rm -rf "$tmp"