guest_test.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. # wait_for_log <file> <text> <seconds> <lines of it seen before>: true once more lines than that contain the text
  62. wait_for_log() {
  63. for _ in $(seq "$3"); do
  64. [ "$(grep -c "$2" "$1")" -gt "$4" ] && return 0
  65. sleep 1
  66. done
  67. return 1
  68. }
  69. # behaviour checks, BEHAVIOR=1: hotswap, pause on fullscreen, SIGKILL leaves no helper
  70. if [ "${BEHAVIOR:-0}" = 1 ]; then
  71. A=${HOTSWAP_FROM:-1120596121}
  72. B=${HOTSWAP_TO:-1111948150}
  73. ctl=$OUT/control
  74. : > "$ctl"
  75. # shellcheck disable=SC2086
  76. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS --control-file "$ctl" "$LWE_DIR/wp-$A" > "$OUT/engine-behavior.log" 2>&1 < /dev/null &)
  77. sleep "$SETTLE"
  78. pid=$(engine_pids | head -1)
  79. if [ -z "$pid" ]; then fail "behavior: engine did not start"; else
  80. SHOT_FILE=$OUT/hot-before.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/hot-before.log"
  81. echo "path=$LWE_DIR/wp-$B" > "$ctl"
  82. kill -USR1 "$pid"
  83. sleep 15
  84. if grep -q "Hotswapping wallpaper to" "$OUT/engine-behavior.log"; then pass "hotswap: engine took the new wallpaper"; else fail "hotswap: no hotswap in the log"; fi
  85. if kill -0 "$pid" 2>/dev/null; then pass "hotswap: same process still running"; else fail "hotswap: engine exited"; fi
  86. SHOT_FILE=$OUT/hot-after.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/hot-after.log"
  87. # back to the first wallpaper so the CPU numbers are of a scene with particles
  88. echo "path=$LWE_DIR/wp-$A" > "$ctl"; kill -USR1 "$pid"; sleep 12
  89. if [ -n "$FULLSCREEN_CMD" ]; then
  90. log=$OUT/engine-behavior.log
  91. paused_before=$(grep -c "Paused: windows" "$log"); resumed_before=$(grep -c "Resumed" "$log")
  92. eval "$FULLSCREEN_CMD" > "$OUT/fullscreen-window.log" 2>&1 &
  93. fs_pid=$!
  94. if grep -q "Fullscreen detection not supported" "$log"; then
  95. echo "SKIP fullscreen pause: the compositor has no fullscreen detection"
  96. elif wait_for_log "$log" "Paused: windows" 45 "$paused_before"; then
  97. pass "fullscreen pause: engine paused"
  98. kill "$fs_pid" 2>/dev/null; pkill -f "lwe-fullscreen-test|fullscreen_window.py" 2>/dev/null
  99. if wait_for_log "$log" "Resumed" 45 "$resumed_before"; then pass "fullscreen pause: engine resumed"; else fail "fullscreen pause: no resume after the window closed"; fi
  100. else
  101. fail "fullscreen pause: no pause within 45s of a fullscreen window"
  102. fi
  103. kill "$fs_pid" 2>/dev/null; pkill -f "lwe-fullscreen-test|fullscreen_window.py" 2>/dev/null
  104. else
  105. echo "SKIP fullscreen pause: no FULLSCREEN_CMD for this desktop"
  106. fi
  107. stop_engine
  108. fi
  109. # SIGKILL: the web host must not outlive the engine
  110. # shellcheck disable=SC2086
  111. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS "$LWE_DIR/wp-1078208425" > "$OUT/engine-kill.log" 2>&1 < /dev/null &)
  112. sleep "$SETTLE"
  113. pid=$(engine_pids | head -1)
  114. helpers_before=$(pgrep -fc "[l]inux-wallpaperengine-web-helper")
  115. kill -9 "$pid" 2>/dev/null
  116. sleep 8
  117. helpers_after=$(pgrep -fc "[l]inux-wallpaperengine-web-helper")
  118. if [ "$helpers_before" -gt 0 ] && [ "$helpers_after" -eq 0 ]; then pass "SIGKILL: $helpers_before web host processes ended with the engine"
  119. elif [ "$helpers_before" -eq 0 ]; then fail "SIGKILL: no web host was running to begin with"
  120. else fail "SIGKILL: $helpers_after of $helpers_before web host processes left behind"; pkill -f "linux-wallpaperengine-web-helper"; fi
  121. fi
  122. touch "$OUT/done"
  123. exit $status