guest_test.sh 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. # guest_test.sh - run inside a VM's desktop session by release_check.sh (or by hand): starts each test wallpaper with the
  3. # engine under test, takes a screenshot, checks the engine survived and stopped cleanly. One "PASS|FAIL <check>" line per
  4. # check, screenshots in $OUT. Needs the session environment (sessenv) sourced first.
  5. # LWE_DIR folder with lwe-hints/ (the engine), assets/ and wp-<workshop id>/ folders
  6. # LWE_ARGS how the engine is told where to draw, e.g. "--screen-root Virtual-1" or "--window 0x0x1920x1080"
  7. # SHOT_CMD screenshot command with $SHOT_FILE as the file, e.g. 'gnome-screenshot -f $SHOT_FILE'; the value
  8. # host asks the host instead (COSMIC's portal asks for permission on every call): the script creates
  9. # $SHOT_FILE.want and waits for $SHOT_FILE, host_shots.sh takes the picture through the VM's display
  10. # WALLPAPERS ids to run, default: scene with parallax, scene with particles, two web items
  11. # SETTLE seconds to wait for the first frames (default 25)
  12. # resolved: the engine's command line shows the real path (/var/home on Fedora Atomic systems)
  13. LWE_DIR=$(realpath "${LWE_DIR:-$HOME/lwe}")
  14. ENGINE=$LWE_DIR/lwe-hints/linux-wallpaperengine
  15. OUT=${OUT:-/tmp/lwe-test}
  16. WALLPAPERS=${WALLPAPERS:-"1111948150 1120596121 1078208425 834237690"}
  17. SETTLE=${SETTLE:-25}
  18. mkdir -p "$OUT"
  19. rm -f "$OUT/done"
  20. status=0
  21. pass() { echo "PASS $1"; }
  22. fail() { echo "FAIL $1"; status=1; }
  23. engine_pids() { pgrep -f "^$LWE_DIR/lwe-hints/linux-wallpaperengine.[b]in"; }
  24. take_shot() {
  25. if [ "$SHOT_CMD" = host ]; then
  26. touch "$1.want"
  27. for _ in $(seq 60); do [ -s "$1" ] && break; sleep 1; done
  28. else
  29. eval "$SHOT_CMD" > "$2" 2>&1
  30. fi
  31. }
  32. stop_engine() {
  33. for p in $(engine_pids); do kill "$p"; done
  34. for _ in $(seq 20); do engine_pids >/dev/null || return 0; sleep 0.5; done
  35. for p in $(engine_pids); do kill -9 "$p"; done
  36. return 1
  37. }
  38. stop_engine
  39. # the desktop without a wallpaper, the reference check_frame.py compares the others to
  40. sleep 2
  41. SHOT_FILE=$OUT/baseline.png
  42. rm -f "$SHOT_FILE"
  43. take_shot "$SHOT_FILE" "$OUT/baseline.log"
  44. if [ -s "$SHOT_FILE" ]; then pass "baseline screenshot taken"; else fail "no baseline screenshot"; fi
  45. for id in $WALLPAPERS; do
  46. dir=$LWE_DIR/wp-$id
  47. [ -d "$dir" ] || { fail "$id: wallpaper folder missing"; continue; }
  48. log=$OUT/engine-$id.log
  49. # shellcheck disable=SC2086
  50. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS "$dir" > "$log" 2>&1 < /dev/null &)
  51. sleep "$SETTLE"
  52. if engine_pids >/dev/null; then pass "$id: engine running after ${SETTLE}s"; else fail "$id: engine exited"; fi
  53. if grep -qiE "segmentation|SIGSEGV|terminate called|Aborted|core dumped" "$log"; then fail "$id: crash text in the log"; else pass "$id: no crash text in the log"; fi
  54. SHOT_FILE=$OUT/shot-$id.png
  55. rm -f "$SHOT_FILE"
  56. take_shot "$SHOT_FILE" "$OUT/shot-$id.log"
  57. if [ -s "$SHOT_FILE" ]; then pass "$id: screenshot taken"; else fail "$id: no screenshot"; fi
  58. if stop_engine; then pass "$id: engine stopped on SIGTERM"; else fail "$id: engine needed SIGKILL"; fi
  59. if pgrep -f "[l]inux-wallpaperengine-web-helper" >/dev/null; then fail "$id: web helper left behind"; else pass "$id: no web helper left behind"; fi
  60. done
  61. touch "$OUT/done"
  62. exit $status