#!/bin/bash # guest_test.sh - run inside a VM's desktop session by release_check.sh (or by hand): starts each test wallpaper with the # engine under test, takes a screenshot, checks the engine survived and stopped cleanly. One "PASS|FAIL " line per # check, screenshots in $OUT. Needs the session environment (sessenv) sourced first. # LWE_DIR folder with lwe-hints/ (the engine), assets/ and wp-/ folders # LWE_ARGS how the engine is told where to draw, e.g. "--screen-root Virtual-1" or "--window 0x0x1920x1080" # SHOT_CMD screenshot command with $SHOT_FILE as the file, e.g. 'gnome-screenshot -f $SHOT_FILE'; the value # host asks the host instead (COSMIC's portal asks for permission on every call): the script creates # $SHOT_FILE.want and waits for $SHOT_FILE, host_shots.sh takes the picture through the VM's display # WALLPAPERS ids to run, default: scene with parallax, scene with particles, two web items # SETTLE seconds to wait for the first frames (default 25), the checks that do not compare frames at a fixed time # go on as soon as the engine says it draws (a few seconds more, web pages need longer) # ONLY space separated check groups to run (wallpapers behavior video cycle automute multi windowbg), default all # MINIMIZE_CMD minimizes the test window (X11): the engine paused by a fullscreen window must resume once it is hidden # MULTI_SHOT_CMD screenshot command that captures every monitor (the VM was started with a second output): turns on # the multi monitor check, the wallpaper must show on both screens # resolved: the engine's command line shows the real path (/var/home on Fedora Atomic systems) LWE_DIR=$(realpath "${LWE_DIR:-$HOME/lwe}") ENGINE=$LWE_DIR/lwe-hints/linux-wallpaperengine # says which way a web wallpaper gets its frames export LWE_WEB_STATS=1 OUT=${OUT:-/tmp/lwe-test} WALLPAPERS=${WALLPAPERS-"1111948150 1120596121 1078208425 834237690"} SETTLE=${SETTLE:-25} mkdir -p "$OUT" rm -f "$OUT/done" status=0 want() { [ -z "$ONLY" ] || [[ " $ONLY " == *" $1 "* ]]; } settle() { local log=$1 id=$2 extra=6 waited=0 rest if grep -qi '"type"[[:space:]]*:[[:space:]]*"web"' "$LWE_DIR/wp-$id/project.json" 2>/dev/null; then extra=16; fi while [ "$waited" -lt "$SETTLE" ] && ! grep -q "drawing at scale" "$log" 2>/dev/null; do sleep 1; waited=$((waited + 1)); done rest=$((SETTLE - waited)) [ "$rest" -gt "$extra" ] && rest=$extra [ "$rest" -gt 0 ] && sleep "$rest" return 0 } pass() { echo "PASS $1"; } fail() { echo "FAIL $1"; status=1; } engine_pids() { pgrep -f "^$LWE_DIR/lwe-hints/linux-wallpaperengine.[b]in"; } take_shot() { if [ "$SHOT_CMD" = host ]; then touch "$1.want" for _ in $(seq 120); do [ -s "$1" ] && break; sleep 1; done else eval "$SHOT_CMD" > "$2" 2>&1 fi } stop_engine() { for p in $(engine_pids); do kill "$p"; done for _ in $(seq 20); do engine_pids >/dev/null || return 0; sleep 0.5; done for p in $(engine_pids); do kill -9 "$p"; done return 1 } stop_engine total=0 bad_start=0 if want wallpapers; then # the desktop without a wallpaper, the reference check_frame.py compares the others to sleep 2 SHOT_FILE=$OUT/baseline.png rm -f "$SHOT_FILE" take_shot "$SHOT_FILE" "$OUT/baseline.log" if [ -s "$SHOT_FILE" ]; then pass "baseline screenshot taken"; else fail "no baseline screenshot"; fi for id in $WALLPAPERS; do dir=$LWE_DIR/wp-$id [ -d "$dir" ] || { fail "$id: wallpaper folder missing"; continue; } log=$OUT/engine-$id.log # shellcheck disable=SC2086 (setsid nohup "$ENGINE" --assets-dir "$LWE_DIR/assets" $LWE_ARGS "$dir" > "$log" 2>&1 < /dev/null &) settle "$log" "$id" total=$((total + 1)) if engine_pids >/dev/null; then pass "$id: engine running"; else fail "$id: engine exited"; bad_start=$((bad_start + 1)); fi 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 if grep -qi '"type"[[:space:]]*:[[:space:]]*"web"' "$dir/project.json" 2>/dev/null; then # --web-frames auto picks dmabuf frames on a Wayland session with EGL; a fallback means it did not work there if grep -q "restarting the web host with shared memory frames" "$log"; then fail "$id: dmabuf web frames fell back to shared memory" elif grep -q "frames arrive as dmabufs" "$log"; then pass "$id: web frames arrive as dmabufs" else pass "$id: web frames through shared memory"; fi fi SHOT_FILE=$OUT/shot-$id.png rm -f "$SHOT_FILE" take_shot "$SHOT_FILE" "$OUT/shot-$id.log" if [ -s "$SHOT_FILE" ]; then pass "$id: screenshot taken"; else fail "$id: no screenshot"; fi if stop_engine; then pass "$id: engine stopped on SIGTERM"; else fail "$id: engine needed SIGKILL"; fi 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 done if [ "$total" -gt 0 ] && [ "$bad_start" -eq "$total" ]; then echo "FATAL: the engine did not stay running on any of the $total wallpapers, the other checks are skipped" touch "$OUT/done"; exit 1 fi fi # the test window's own command line is the pattern: toolkits start helpers and detach, the shell's pid is not enough stop_fullscreen_window() { [ -n "$STOP_CMD" ] && pkill -f -- "^${STOP_CMD%% *}.*${STOP_CMD#* }" 2>/dev/null pkill -f "lwe-fullscreen-test|fullscreen_window.py|maximize_kde.sh|konsole -e sleep" 2>/dev/null return 0 } # wait_for_log : true once more lines than that contain the text wait_for_log() { for _ in $(seq "$3"); do [ "$(grep -c "$2" "$1")" -gt "$4" ] && return 0 sleep 1 done return 1 } # pause_check