guest_test.sh 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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), the checks that do not compare frames at a fixed time
  12. # go on as soon as the engine says it draws (a few seconds more, web pages need longer)
  13. # ONLY space separated check groups to run (wallpapers behavior video cycle automute multi windowbg), default all
  14. # MINIMIZE_CMD minimizes the test window (X11): the engine paused by a fullscreen window must resume once it is hidden
  15. # MULTI_SHOT_CMD screenshot command that captures every monitor (the VM was started with a second output): turns on
  16. # the multi monitor check, the wallpaper must show on both screens
  17. # resolved: the engine's command line shows the real path (/var/home on Fedora Atomic systems)
  18. LWE_DIR=$(realpath "${LWE_DIR:-$HOME/lwe}")
  19. ENGINE=$LWE_DIR/lwe-hints/linux-wallpaperengine
  20. # says which way a web wallpaper gets its frames
  21. export LWE_WEB_STATS=1
  22. OUT=${OUT:-/tmp/lwe-test}
  23. WALLPAPERS=${WALLPAPERS-"1111948150 1120596121 1078208425 834237690"}
  24. SETTLE=${SETTLE:-25}
  25. mkdir -p "$OUT"
  26. rm -f "$OUT/done"
  27. status=0
  28. want() { [ -z "$ONLY" ] || [[ " $ONLY " == *" $1 "* ]]; }
  29. settle() {
  30. local log=$1 id=$2 extra=6 waited=0 rest
  31. if grep -qi '"type"[[:space:]]*:[[:space:]]*"web"' "$LWE_DIR/wp-$id/project.json" 2>/dev/null; then extra=16; fi
  32. while [ "$waited" -lt "$SETTLE" ] && ! grep -q "drawing at scale" "$log" 2>/dev/null; do sleep 1; waited=$((waited + 1)); done
  33. rest=$((SETTLE - waited))
  34. [ "$rest" -gt "$extra" ] && rest=$extra
  35. [ "$rest" -gt 0 ] && sleep "$rest"
  36. return 0
  37. }
  38. pass() { echo "PASS $1"; }
  39. fail() { echo "FAIL $1"; status=1; }
  40. engine_pids() { pgrep -f "^$LWE_DIR/lwe-hints/linux-wallpaperengine.[b]in"; }
  41. take_shot() {
  42. if [ "$SHOT_CMD" = host ]; then
  43. touch "$1.want"
  44. for _ in $(seq 120); do [ -s "$1" ] && break; sleep 1; done
  45. else
  46. eval "$SHOT_CMD" > "$2" 2>&1
  47. fi
  48. }
  49. stop_engine() {
  50. for p in $(engine_pids); do kill "$p"; done
  51. for _ in $(seq 20); do engine_pids >/dev/null || return 0; sleep 0.5; done
  52. for p in $(engine_pids); do kill -9 "$p"; done
  53. return 1
  54. }
  55. stop_engine
  56. total=0 bad_start=0
  57. if want wallpapers; then
  58. # the desktop without a wallpaper, the reference check_frame.py compares the others to
  59. sleep 2
  60. SHOT_FILE=$OUT/baseline.png
  61. rm -f "$SHOT_FILE"
  62. take_shot "$SHOT_FILE" "$OUT/baseline.log"
  63. if [ -s "$SHOT_FILE" ]; then pass "baseline screenshot taken"; else fail "no baseline screenshot"; fi
  64. for id in $WALLPAPERS; do
  65. dir=$LWE_DIR/wp-$id
  66. [ -d "$dir" ] || { fail "$id: wallpaper folder missing"; continue; }
  67. log=$OUT/engine-$id.log
  68. # shellcheck disable=SC2086
  69. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS "$dir" > "$log" 2>&1 < /dev/null &)
  70. settle "$log" "$id"
  71. total=$((total + 1))
  72. if engine_pids >/dev/null; then pass "$id: engine running"; else fail "$id: engine exited"; bad_start=$((bad_start + 1)); fi
  73. 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
  74. if grep -qi '"type"[[:space:]]*:[[:space:]]*"web"' "$dir/project.json" 2>/dev/null; then
  75. # --web-frames auto picks dmabuf frames on a Wayland session with EGL; a fallback means it did not work there
  76. if grep -q "restarting the web host with shared memory frames" "$log"; then fail "$id: dmabuf web frames fell back to shared memory"
  77. elif grep -q "frames arrive as dmabufs" "$log"; then pass "$id: web frames arrive as dmabufs"
  78. else pass "$id: web frames through shared memory"; fi
  79. fi
  80. SHOT_FILE=$OUT/shot-$id.png
  81. rm -f "$SHOT_FILE"
  82. take_shot "$SHOT_FILE" "$OUT/shot-$id.log"
  83. if [ -s "$SHOT_FILE" ]; then pass "$id: screenshot taken"; else fail "$id: no screenshot"; fi
  84. if stop_engine; then pass "$id: engine stopped on SIGTERM"; else fail "$id: engine needed SIGKILL"; fi
  85. 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
  86. done
  87. if [ "$total" -gt 0 ] && [ "$bad_start" -eq "$total" ]; then
  88. echo "FATAL: the engine did not stay running on any of the $total wallpapers, the other checks are skipped"
  89. touch "$OUT/done"; exit 1
  90. fi
  91. fi
  92. # the test window's own command line is the pattern: toolkits start helpers and detach, the shell's pid is not enough
  93. stop_fullscreen_window() {
  94. [ -n "$STOP_CMD" ] && pkill -f -- "^${STOP_CMD%% *}.*${STOP_CMD#* }" 2>/dev/null
  95. pkill -f "lwe-fullscreen-test|fullscreen_window.py|maximize_kde.sh|konsole -e sleep" 2>/dev/null
  96. return 0
  97. }
  98. # wait_for_log <file> <text> <seconds> <lines of it seen before>: true once more lines than that contain the text
  99. wait_for_log() {
  100. for _ in $(seq "$3"); do
  101. [ "$(grep -c "$2" "$1")" -gt "$4" ] && return 0
  102. sleep 1
  103. done
  104. return 1
  105. }
  106. # pause_check <label> <command>: a window opened by the command must pause the engine (a "Paused: windows" log line) and
  107. # closing it must resume it. An empty command is skipped.
  108. pause_check() {
  109. local label=$1 cmd=$2 log=$OUT/engine-behavior.log
  110. if [ -z "$cmd" ]; then echo "SKIP $label pause: no command for this desktop"; return; fi
  111. STOP_CMD=$cmd
  112. stop_fullscreen_window
  113. local paused_before resumed_before fs_pid
  114. paused_before=$(grep -c "Paused: windows" "$log"); resumed_before=$(grep -c "Resumed" "$log")
  115. eval "$cmd" > "$OUT/$label-window.log" 2>&1 &
  116. fs_pid=$!
  117. sleep 2
  118. if [ "$SHOT_CMD" = host ]; then
  119. touch "$OUT/focus.click"
  120. for _ in $(seq 10); do [ -e "$OUT/focus.click" ] || break; sleep 1; done
  121. fi
  122. if ! kill -0 "$fs_pid" 2>/dev/null; then
  123. fail "$label pause: the test window did not start ($(head -c 150 "$OUT/$label-window.log" | tr '\n' ' '))"
  124. elif grep -q "Fullscreen detection not supported" "$log"; then
  125. echo "SKIP $label pause: the compositor has no window state detection"
  126. elif wait_for_log "$log" "Paused: windows" 45 "$paused_before"; then
  127. pass "$label pause: engine paused"
  128. local minimized_resumed=0
  129. if [ "$label" = fullscreen ] && [ -n "$MINIMIZE_CMD" ]; then
  130. if command -v xdotool >/dev/null; then
  131. eval "$MINIMIZE_CMD" > "$OUT/minimize.log" 2>&1
  132. if wait_for_log "$log" "Resumed" 20 "$resumed_before"; then pass "$label pause: engine resumed once the window was minimized"; minimized_resumed=1
  133. else fail "$label pause: still paused with the window minimized"; fi
  134. resumed_before=$(grep -c "Resumed" "$log")
  135. else
  136. echo "SKIP $label pause: no xdotool to minimize the window"
  137. fi
  138. fi
  139. kill "$fs_pid" 2>/dev/null; stop_fullscreen_window
  140. if [ $minimized_resumed = 1 ]; then :
  141. elif wait_for_log "$log" "Resumed" 45 "$resumed_before"; then pass "$label pause: engine resumed"; else fail "$label pause: no resume after the window closed"; fi
  142. else
  143. fail "$label pause: no pause within 45s of a $label window"
  144. {
  145. echo "--- state at the failed $label check, $(date +%T)"
  146. echo "window processes:"; pgrep -fa "konsole|fullscreen_window|maximize_kde" | cut -c1-120
  147. echo "engine bus names:"; busctl --user list 2>/dev/null | grep -i linuxwallpaper
  148. echo "kwin scripts left in the runtime dir:"; ls "$XDG_RUNTIME_DIR" 2>/dev/null | grep -E "^lwe-"
  149. echo "engine log tail:"; grep -v '^ALSA' "$log" | tail -5 | cut -c1-160
  150. if command -v gdbus >/dev/null && gdbus introspect --session --dest org.kde.KWin --object-path /Scripting >/dev/null 2>&1; then
  151. echo "KWin's window list:"
  152. diag=$(mktemp /tmp/lwe-diag-XXXXXX.js)
  153. echo 'for (const w of workspace.windowList()) print("LWEDIAG", w.resourceClass, w.caption, "fs=" + w.fullScreen, "max=" + (w.maximizeMode), "min=" + w.minimized, "out=" + (w.output ? w.output.name : "none"), "desktops=" + w.desktops.length, "normal=" + w.normalWindow);' > "$diag"
  154. id=$(gdbus call --session --dest org.kde.KWin --object-path /Scripting --method org.kde.kwin.Scripting.loadScript "$diag" lwe-diag | tr -dc 0-9)
  155. gdbus call --session --dest org.kde.KWin --object-path "/Scripting/Script$id" --method org.kde.kwin.Script.run >/dev/null 2>&1
  156. sleep 1
  157. journalctl --user -b --no-pager 2>/dev/null | grep LWEDIAG | tail -12 | cut -c1-220
  158. gdbus call --session --dest org.kde.KWin --object-path /Scripting --method org.kde.kwin.Scripting.unloadScript lwe-diag >/dev/null 2>&1
  159. rm -f "$diag"
  160. fi
  161. } >> "$OUT/pause-diagnostics.txt" 2>&1
  162. fi
  163. kill "$fs_pid" 2>/dev/null; stop_fullscreen_window
  164. sleep 3
  165. }
  166. hotswap_video_check() {
  167. local A=3471294034 B=3818199837 ctl=$OUT/control-video pid
  168. if [ ! -d "$LWE_DIR/wp-$A" ] || [ ! -d "$LWE_DIR/wp-$B" ]; then echo "SKIP hotswap video: wallpapers $A and $B missing"; return; fi
  169. : > "$ctl"
  170. # shellcheck disable=SC2086
  171. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS --control-file "$ctl" "$LWE_DIR/wp-$A" > "$OUT/engine-swapvideo.log" 2>&1 < /dev/null &)
  172. sleep "$SETTLE"
  173. pid=$(engine_pids | head -1)
  174. if [ -z "$pid" ]; then fail "hotswap video: engine did not start"; return; fi
  175. echo "path=$LWE_DIR/wp-$B" > "$ctl"
  176. kill -USR1 "$pid"
  177. sleep 20
  178. SHOT_FILE=$OUT/swap-video.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/swap-video.log"
  179. stop_engine
  180. # shellcheck disable=SC2086
  181. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS "$LWE_DIR/wp-$B" > "$OUT/engine-freshvideo.log" 2>&1 < /dev/null &)
  182. sleep "$SETTLE"
  183. SHOT_FILE=$OUT/fresh-video.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/fresh-video.log"
  184. stop_engine
  185. }
  186. peak_in() { awk -v a="$1" -v b="$2" '$1 >= a && $1 < b && $2 > m { m = $2 } END { print m + 0 }' "$OUT/audio-timeline.txt"; }
  187. automute_check() {
  188. local id=3471294034 win_pid="" base muted back pmuted pback
  189. if [ ! -d "$LWE_DIR/wp-$id" ]; then echo "SKIP automute: wallpaper $id missing"; return; fi
  190. if ! command -v parec >/dev/null || ! command -v paplay >/dev/null || ! pactl info >/dev/null 2>&1; then
  191. echo "SKIP automute: no pulse tools or server in this guest"; return
  192. fi
  193. cat > "$OUT/peak.py" <<'PY'
  194. import struct, subprocess, sys, time
  195. p = subprocess.Popen(["parec", "-d", "@DEFAULT_SINK@.monitor", "--format=s16le", "--rate=8000", "--channels=1",
  196. "--latency-msec=50"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
  197. t0 = time.time()
  198. while time.time() - t0 < float(sys.argv[1]):
  199. d = p.stdout.read(800)
  200. if not d:
  201. break
  202. s = struct.unpack("<%dh" % (len(d) // 2), d)
  203. print("%.1f %d" % (time.time() - t0, max(abs(x) for x in s)), flush=True)
  204. p.kill()
  205. PY
  206. python3 -c "
  207. import wave
  208. w = wave.open('$OUT/silence.wav', 'w'); w.setnchannels(2); w.setsampwidth(2); w.setframerate(44100)
  209. w.writeframes(b'\0' * 44100 * 4 * 12); w.close()"
  210. # shellcheck disable=SC2086
  211. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS --automute "$LWE_DIR/wp-$id" > "$OUT/engine-automute.log" 2>&1 < /dev/null &)
  212. sleep "$SETTLE"
  213. python3 "$OUT/peak.py" 48 > "$OUT/audio-timeline.txt" 2>/dev/null &
  214. local mon=$!
  215. sleep 5
  216. paplay "$OUT/silence.wav" &
  217. sleep 17
  218. if [ -n "$FULLSCREEN_CMD" ]; then
  219. STOP_CMD=$FULLSCREEN_CMD; stop_fullscreen_window
  220. eval "$FULLSCREEN_CMD" > "$OUT/automute-window.log" 2>&1 &
  221. win_pid=$!
  222. sleep 8
  223. paplay "$OUT/silence.wav" &
  224. sleep 18
  225. else
  226. sleep 26
  227. fi
  228. wait "$mon" 2>/dev/null
  229. # a fullscreen window counts as sound for automute, the other app stopping can only be seen once the window is gone
  230. kill "$win_pid" 2>/dev/null; stop_fullscreen_window; sleep 4; stop_engine
  231. pkill -x paplay 2>/dev/null
  232. base=$(peak_in 1 5)
  233. if [ "$base" -lt 50 ]; then echo "SKIP automute: the wallpaper's music is not audible on this guest's default sink (peak $base)"; return; fi
  234. muted=$(peak_in 8 16); back=$(peak_in 18 22)
  235. if [ "$muted" -le 30 ]; then pass "automute: muted while another app plays (peak $muted, $base before)"; else fail "automute: not muted while another app plays (peak $muted)"; fi
  236. if [ "$back" -gt $((base / 4)) ]; then pass "automute: music back within 5s of the other app stopping (peak $back)"; else fail "automute: music not back 1.5-5s after the other app stopped (peak $back)"; fi
  237. if [ -n "$FULLSCREEN_CMD" ]; then
  238. # the scene's own music is silent while the wallpaper is paused, so what is checked is the engine's state: the log
  239. # lines of the second player come while the "Paused: windows" state holds
  240. local log=$OUT/engine-automute.log paused_line started stopped
  241. paused_line=$(grep -n "Paused: windows" "$log" | head -1 | cut -d: -f1)
  242. started=$(grep -n "Automute: another app is playing" "$log" | tail -1 | cut -d: -f1)
  243. stopped=$(grep -n "Automute: other apps stopped" "$log" | tail -1 | cut -d: -f1)
  244. if [ -z "$paused_line" ]; then echo "SKIP automute while paused: the engine was not paused by the window"
  245. elif [ "$(grep -c "Automute: another app is playing" "$log")" -ge 2 ] && [ "$started" -gt "$paused_line" ]; then pass "automute: another app's sound noticed while the wallpaper is paused"
  246. else fail "automute: another app's sound not noticed while the wallpaper is paused"; fi
  247. if [ -n "$paused_line" ] && [ -n "$stopped" ] && [ "$stopped" -gt "$started" ]; then pass "automute: the other app stopping noticed while the wallpaper is paused"
  248. else fail "automute: the other app stopping not noticed while the wallpaper is paused"; fi
  249. fi
  250. }
  251. hotswap_cycle_check() {
  252. local order="1120596121 1367456719 1078208425 1111948150 834237690 1367456719 1120596121"
  253. local ctl=$OUT/control-cycle log=$OUT/engine-cycle.log id pid n=0 swaps type helpers bad bad_before wait_s
  254. for id in $order; do
  255. if [ ! -d "$LWE_DIR/wp-$id" ]; then echo "SKIP hotswap cycle: wallpaper $id missing"; return; fi
  256. done
  257. : > "$ctl"
  258. # shellcheck disable=SC2086
  259. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS --control-file "$ctl" "$LWE_DIR/wp-${order%% *}" > "$log" 2>&1 < /dev/null &)
  260. settle "$log" "${order%% *}"
  261. pid=$(engine_pids | head -1)
  262. if [ -z "$pid" ]; then fail "hotswap cycle: engine did not start"; return; fi
  263. for id in ${order#* }; do
  264. n=$((n + 1))
  265. if grep -qi '"type"[[:space:]]*:[[:space:]]*"web"' "$LWE_DIR/wp-$id/project.json"; then type=web; wait_s=20
  266. elif grep -qi '"type"[[:space:]]*:[[:space:]]*"video"' "$LWE_DIR/wp-$id/project.json"; then type=video; wait_s=12
  267. else type=scene; wait_s=12; fi
  268. swaps=$(grep -c "Hotswapping wallpaper to" "$log")
  269. bad_before=$(grep -ciE "terminate called|segmentation|fatal|exception" "$log")
  270. echo "path=$LWE_DIR/wp-$id" > "$ctl"
  271. kill -USR1 "$pid"
  272. for _ in $(seq 40); do [ "$(grep -c "Hotswapping wallpaper to" "$log")" -gt "$swaps" ] && break; sleep 0.5; done
  273. sleep "$wait_s"
  274. if ! kill -0 "$pid" 2>/dev/null; then fail "hotswap cycle step $n ($type $id): the engine exited"; return; fi
  275. if [ "$(grep -c "Hotswapping wallpaper to" "$log")" -le "$swaps" ]; then fail "hotswap cycle step $n ($type $id): no hotswap in the log"; stop_engine; return; fi
  276. helpers=$(pgrep -fc "[l]inux-wallpaperengine-web-helper")
  277. if [ "$type" = web ] && [ "$helpers" -eq 0 ]; then fail "hotswap cycle step $n ($type $id): no web host is running"; stop_engine; return; fi
  278. if [ "$type" != web ] && [ "$helpers" -gt 0 ]; then sleep 8; helpers=$(pgrep -fc "[l]inux-wallpaperengine-web-helper")
  279. if [ "$helpers" -gt 0 ]; then fail "hotswap cycle step $n ($type $id): $helpers web host processes left behind"; stop_engine; return; fi
  280. fi
  281. bad=$(grep -ciE "terminate called|segmentation|fatal|exception" "$log")
  282. if [ "$bad" -gt "$bad_before" ]; then fail "hotswap cycle step $n ($type $id): $((bad - bad_before)) new error lines in the log"; stop_engine; return; fi
  283. SHOT_FILE=$OUT/shot-cycle-$n-$id.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/cycle-$n.log"
  284. pass "hotswap cycle step $n: $type $id"
  285. done
  286. stop_engine
  287. }
  288. window_background_check() {
  289. local id=1120596121 log=$OUT/engine-windowbg.log geometry
  290. [ "${XDG_SESSION_TYPE:-}" = x11 ] && command -v xrandr >/dev/null || return 0
  291. [ -d "$LWE_DIR/wp-$id" ] || { echo "SKIP window background: wallpaper $id missing"; return 0; }
  292. geometry=$(xrandr | sed -n 's/^[^ ]* connected \(primary \)\?\([0-9]*\)x\([0-9]*\)+\([0-9]*\)+\([0-9]*\).*/\4x\5x\2x\3/p' | head -1)
  293. [ -n "$geometry" ] || { echo "SKIP window background: no output geometry from xrandr"; return 0; }
  294. # shellcheck disable=SC2086
  295. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" --window "$geometry" --window-background "$LWE_DIR/wp-$id" > "$log" 2>&1 < /dev/null &)
  296. settle "$log" "$id"
  297. if engine_pids >/dev/null; then pass "window background: engine running"; else fail "window background: engine exited"; return 0; fi
  298. SHOT_FILE=$OUT/shot-windowbg-$id.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/windowbg.log"
  299. if [ -s "$SHOT_FILE" ]; then pass "window background: screenshot taken"; else fail "window background: no screenshot"; fi
  300. if stop_engine; then pass "window background: engine stopped on SIGTERM"; else fail "window background: engine needed SIGKILL"; fi
  301. }
  302. multi_monitor_check() {
  303. local id=1111948150 w1 w2
  304. [ -n "$MULTI_SHOT_CMD" ] || return
  305. if ! command -v xrandr >/dev/null; then echo "SKIP multi monitor: no xrandr"; return; fi
  306. for f in /sys/class/drm/card*-Virtual-2/status; do echo on | sudo tee "$f" >/dev/null 2>&1; done
  307. sleep 2
  308. w1=$(xrandr | sed -n 's/^Virtual-1 connected[^0-9]*\([0-9]*\)x[0-9]*+.*/\1/p' | head -1)
  309. if [ -z "$w1" ] || ! xrandr | grep -q '^Virtual-2 connected'; then echo "SKIP multi monitor: the guest has no second output"; return; fi
  310. xrandr --output Virtual-1 --auto --pos 0x0 --output Virtual-2 --auto --pos "${w1}x0"
  311. sleep 4
  312. w2=$(xrandr | sed -n 's/^Virtual-2 connected[^0-9]*\([0-9]*\)x[0-9]*+.*/\1/p' | head -1)
  313. echo "$w1 $w2" > "$OUT/multi-geometry"
  314. SHOT_FILE=$OUT/multi-baseline.png; rm -f "$SHOT_FILE"; eval "$MULTI_SHOT_CMD" > "$OUT/multi-baseline.log" 2>&1
  315. # shellcheck disable=SC2086
  316. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" --screen-root Virtual-1 --screen-root Virtual-2 "$LWE_DIR/wp-$id" > "$OUT/engine-multi.log" 2>&1 < /dev/null &)
  317. settle "$OUT/engine-multi.log" "$id"
  318. if engine_pids >/dev/null; then pass "multi monitor: engine running on two screens"; else fail "multi monitor: engine exited"; fi
  319. SHOT_FILE=$OUT/multi-shot.png; rm -f "$SHOT_FILE"; eval "$MULTI_SHOT_CMD" > "$OUT/multi-shot.log" 2>&1
  320. if [ -s "$SHOT_FILE" ] && [ -s "$OUT/multi-baseline.png" ]; then pass "multi monitor: screenshots of both screens taken"; else fail "multi monitor: no screenshot ($(head -c 120 "$OUT/multi-shot.log" | tr '\n' ' '))"; fi
  321. stop_engine
  322. xrandr --output Virtual-2 --off
  323. }
  324. # behaviour checks, BEHAVIOR=1: hotswap, pause on fullscreen, SIGKILL leaves no helper
  325. if [ "${BEHAVIOR:-0}" = 1 ] && want behavior; then
  326. A=${HOTSWAP_FROM:-1120596121}
  327. B=${HOTSWAP_TO:-1111948150}
  328. ctl=$OUT/control
  329. : > "$ctl"
  330. # shellcheck disable=SC2086
  331. (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 &)
  332. settle "$OUT/engine-behavior.log" "$A"
  333. pid=$(engine_pids | head -1)
  334. if [ -z "$pid" ]; then fail "behavior: engine did not start"; else
  335. SHOT_FILE=$OUT/hot-before.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/hot-before.log"
  336. echo "path=$LWE_DIR/wp-$B" > "$ctl"
  337. kill -USR1 "$pid"
  338. sleep 15
  339. 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
  340. if kill -0 "$pid" 2>/dev/null; then pass "hotswap: same process still running"; else fail "hotswap: engine exited"; fi
  341. SHOT_FILE=$OUT/hot-after.png; rm -f "$SHOT_FILE"; take_shot "$SHOT_FILE" "$OUT/hot-after.log"
  342. # back to the first wallpaper so the CPU numbers are of a scene with particles
  343. echo "path=$LWE_DIR/wp-$A" > "$ctl"; kill -USR1 "$pid"; sleep 12
  344. pause_check "fullscreen" "$FULLSCREEN_CMD"
  345. pause_check "maximized" "$MAXIMIZE_CMD"
  346. stop_engine
  347. fi
  348. # SIGKILL: the web host must not outlive the engine
  349. # shellcheck disable=SC2086
  350. (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS "$LWE_DIR/wp-1078208425" > "$OUT/engine-kill.log" 2>&1 < /dev/null &)
  351. settle "$OUT/engine-kill.log" 1078208425
  352. pid=$(engine_pids | head -1)
  353. helpers_before=$(pgrep -fc "[l]inux-wallpaperengine-web-helper")
  354. kill -9 "$pid" 2>/dev/null
  355. sleep 8
  356. helpers_after=$(pgrep -fc "[l]inux-wallpaperengine-web-helper")
  357. if [ "$helpers_before" -gt 0 ] && [ "$helpers_after" -eq 0 ]; then pass "SIGKILL: $helpers_before web host processes ended with the engine"
  358. elif [ "$helpers_before" -eq 0 ]; then fail "SIGKILL: no web host was running to begin with"
  359. else fail "SIGKILL: $helpers_after of $helpers_before web host processes left behind"; pkill -f "linux-wallpaperengine-web-helper"; fi
  360. fi
  361. if [ "${BEHAVIOR:-0}" = 1 ]; then
  362. want video && hotswap_video_check
  363. want cycle && hotswap_cycle_check
  364. want automute && automute_check
  365. want multi && multi_monitor_check
  366. want windowbg && window_background_check
  367. fi
  368. touch "$OUT/done"
  369. exit $status