check_signals_after_video_change.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # Checks that SIGINT and SIGTERM still reach the engine's handler after a video was replaced: libmpv resets both to
  3. # their defaults when a player is destroyed, which made a plain kill end the engine without its exit handlers once a
  4. # playlist had moved on. Plays a two item video sequence playlist (3 videos reload within 10 s), then reads the signal
  5. # mask of the process and sends SIGTERM.
  6. # Usage: tools/check_signals_after_video_change.sh <engine binary> [assets dir]
  7. set -euo pipefail
  8. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  9. BINARY=$(readlink -f "${1:?engine binary}")
  10. ASSETS=${2:-/workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets}
  11. command -v ffmpeg > /dev/null || { echo "SKIP: no ffmpeg"; exit 0; }
  12. work=$(mktemp -d /tmp/lwe-signals.XXXXXX)
  13. trap 'pkill -f "[-]-window 0x0x640x360 --screenshot $work" || true; rm -rf "$work"' EXIT
  14. steam="$work/home/.steam/steam/steamapps/common/wallpaper_engine"
  15. mkdir -p "$steam"
  16. ln -s "$ASSETS" "$steam/assets"
  17. for name in a b; do
  18. mkdir -p "$work/$name"
  19. ffmpeg -loglevel error -f lavfi -i "color=c=red:s=320x180:r=30" -t 2 -c:v mpeg4 "$work/$name/v.mp4"
  20. echo "{\"file\":\"v.mp4\",\"title\":\"$name\",\"type\":\"video\"}" > "$work/$name/project.json"
  21. done
  22. printf '{"steamuser":{"general":{"playlists":[{"name":"p","items":["%s","%s"],"settings":{"mode":"timer","delay":60,"order":"sequential","videosequence":true}}]}}}\n' \
  23. "$work/a/project.json" "$work/b/project.json" > "$steam/config.json"
  24. HOME="$work/home" HEADLESS_RENDER_SIZE=640x360 HEADLESS_RENDER_DELAY=100000 HEADLESS_RENDER_TIMEOUT=40 \
  25. "$HERE/headless_render.sh" "$BINARY" "$work/shot.png" --assets-dir "$ASSETS" --fps 30 --silent --playlist p \
  26. > "$work/log" 2>&1 < /dev/null &
  27. sleep 12
  28. engine=""
  29. for pid in $(pgrep -f "[-]-window 0x0x640x360 --screenshot $work"); do
  30. [ "$(cat /proc/"$pid"/comm)" = linux-wallpaper ] && engine=$pid
  31. done
  32. [ -n "$engine" ] || { echo "FAIL: the engine is not running"; exit 1; }
  33. loads=$(grep -c 'VO: ' "$work/log" || true)
  34. mask=$(awk '/SigCgt/ { print $2 }' /proc/"$engine"/status)
  35. kill -TERM "$engine"
  36. sleep 4
  37. if [ "$loads" -ge 3 ] && (( (16#$mask & 0x4002) == 0x4002 )) && grep -q 'Stop requested' "$work/log"; then
  38. echo "PASS: SIGINT and SIGTERM handled after $loads video loads"
  39. else
  40. echo "FAIL: $loads loads, caught signals $mask, stop requested lines: $(grep -c 'Stop requested' "$work/log")"
  41. exit 1
  42. fi