guest_test.sh 21 KB

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