check_hotswap_keys.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env bash
  2. # Drives the control file's keys and the --list-* switches headlessly (headless_render.sh, LWE_HOTSWAP_AT_FRAME): every
  3. # group of keys is written to a control file that the engine reads on frame 3, the engine has to survive it and write
  4. # its screenshot; groups that change the picture have to change it against a run without a request. The list switches
  5. # have to print something and exit 0.
  6. # Usage: tools/check_hotswap_keys.sh <engine binary> [assets dir] [workshop content dir]
  7. # Exit code 0 when every group passes. Needs Pillow (python3 -I). SCENE_ID picks another scene, 3509578940 by default.
  8. set -uo pipefail
  9. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  10. BINARY=${1:?engine binary}
  11. ASSETS=${2:-/workspace/SteamLibrary/steamapps/common/wallpaper_engine/assets}
  12. CONTENT=${3:-/workspace/SteamLibrary/steamapps/workshop/content/431960}
  13. SCENE_ID=${SCENE_ID:-3509578940}
  14. SCENE="$CONTENT/$SCENE_ID"
  15. [ -d "$SCENE" ] || { echo "SKIP: wallpaper $SCENE_ID not in $CONTENT"; exit 0; }
  16. work=$(mktemp -d /tmp/lwe-hotswap-keys.XXXXXX)
  17. trap 'rm -rf "$work"' EXIT
  18. failed=0
  19. render () {
  20. local name=$1
  21. LWE_FIXED_TIMESTEP=0.1 LWE_HOTSWAP_AT_FRAME=3 HEADLESS_RENDER_DELAY=40 HEADLESS_RENDER_SIZE=800x450 \
  22. "$HERE/headless_render.sh" "$BINARY" "$work/$name.png" --assets-dir "$ASSETS" --silent \
  23. --control-file "$work/$name.ctl" "$SCENE" > "$work/$name.log" 2>&1
  24. }
  25. differs () {
  26. python3 -I - "$work/none.png" "$work/$1.png" <<'PY'
  27. import sys
  28. from PIL import Image, ImageChops
  29. a, b = (Image.open(path).convert('RGB') for path in sys.argv[1:3])
  30. bbox = ImageChops.difference(a, b).getbbox()
  31. sys.exit(0 if bbox else 1)
  32. PY
  33. }
  34. mkdir -p "$work/broken"
  35. echo '{"file":"gone.mp4","title":"broken","type":"video"}' > "$work/broken/project.json"
  36. : > "$work/none.ctl"
  37. render none || { echo "FAIL: baseline did not render"; tail -5 "$work/none.log"; exit 1; }
  38. # name|expects a different picture|keys
  39. groups=(
  40. "layout|yes|scaling=fit;zoom=1.6;offset=0.2,0.1"
  41. "colors|yes|corner-color=#ff0000;brightness=80;contrast=70;saturation=20;hue=30;color-options=on;flip=on"
  42. "filter|yes|image-filter=desperado;image-filter-strength=80;color-options=on"
  43. "timing|no|speed=2;volume=40;fps=30;disable-animations=on;disable-parallax=on;expand-canvas=on"
  44. "audio|no|ambient-volume=20;audio-sensitivity=*=2;hrtf=on;audio-screen=none"
  45. "power|no|fps-battery=15;idle-pause=5;hwdec=no"
  46. "xray|no|xray=full"
  47. "xray-off|no|xray=disabled"
  48. "objects|no|layers=1;disable-object=423;enable-object=424"
  49. "effects|no|effects=1;disable-effect=blur;enable-effect=shake"
  50. "property|no|property=nothing=1;property=other=0.5"
  51. "alignment|no|alignment-x=25;alignment-y=75;alignment-zoom=120"
  52. "unknown-screen|no|screen=no-such-output;scaling=fill;zoom=2"
  53. "garbage|no|zoom=wide;offset=3;brightness=900;nonsense=1;speed=-4;scaling=bogus"
  54. "misc|no|lock-pause=off;repair-assets=on;sound-volume=*=50;transition=fade;transition-duration=300;flip=off"
  55. "swap-scene|no|path=$CONTENT/3299228616;layers=1;disable-object=1;property=x=1;audio-sensitivity=*=2;sound-volume=*=0.5;video-start=none"
  56. "swap-bad-path|no|path=/nonexistent/wallpaper"
  57. "swap-broken-project|no|path=$work/broken;layers=1;disable-object=1;effects=1;disable-effect=blur;property=a=1;audio-sensitivity=*=2;sound-volume=*=0.5;brightness=60;video-start=0:01"
  58. "live-properties|no|property=_1=2;property=_12=0;property=_11=0.9,0.1,0.1;property=_2=1,0,0"
  59. "live-properties-bad|no|property=_1=banana;property=_12=maybe;property=_11=zz;property=nonexistent=1"
  60. "hrtf-bad|no|hrtf=sometimes"
  61. "hrtf-off|no|hrtf=off;audio-screen=default;ambient-volume=0"
  62. "battery-values|no|fps-battery=none;fps-battery=10;idle-pause=0;idle-pause=off;lock-pause=on"
  63. "swap-screen-bad|no|screen=no-such-output;path=$CONTENT/3299228616"
  64. "bad-switches|no|expand-canvas=maybe;repair-assets=maybe;disable-animations=maybe;audio-sensitivity=7=abc;lock-pause=maybe"
  65. "switches-on|no|expand-canvas=on;repair-assets=off;disable-animations=on"
  66. "garbage-values|no|offset=1,x;alignment=1,2,3;alignment=a,b,c,d;zoom=nan;corner-color=zzz;image-filter-strength=abc;volume=loud;fps=0;fps-battery=x;idle-pause=x;hwdec=banana;xray=bogus;speed=abc;brightness=x;contrast=x;saturation=x;hue=x;transition=bogus;transition-duration=x;sound-volume=bad;audio-sensitivity=bad;video-start=zz;layers=maybe"
  67. )
  68. for group in "${groups[@]}"; do
  69. IFS='|' read -r name changes keys <<< "$group"
  70. tr ';' '\n' <<< "$keys" > "$work/$name.ctl"
  71. if ! render "$name"; then
  72. echo "FAIL: $name: the engine did not survive $keys"
  73. tail -5 "$work/$name.log"
  74. failed=1
  75. elif [ "$changes" = yes ] && ! differs "$name"; then
  76. echo "FAIL: $name: the picture did not change"
  77. failed=1
  78. else
  79. echo "PASS: $name"
  80. fi
  81. done
  82. LWE_FIXED_TIMESTEP=0.1 LWE_HOTSWAP_AT_FRAME=3 HEADLESS_RENDER_DELAY=40 HEADLESS_RENDER_SIZE=800x450 \
  83. "$HERE/headless_render.sh" "$BINARY" "$work/unreadable.png" --assets-dir "$ASSETS" --silent \
  84. --control-file "$work/does-not-exist.ctl" "$SCENE" > "$work/unreadable.log" 2>&1 \
  85. && echo "PASS: unreadable control file" || { echo "FAIL: unreadable control file"; failed=1; }
  86. if command -v ffmpeg > /dev/null; then
  87. mkdir -p "$work/video"
  88. ffmpeg -loglevel error -f lavfi -i "color=c=green:s=320x180:r=30" -t 6 -c:v mpeg4 "$work/video/v.mp4"
  89. echo '{"file":"v.mp4","title":"v","type":"video"}' > "$work/video/project.json"
  90. videogroups=(
  91. "video-trim|video-start=0:01;video-end=0:04"
  92. "video-parts|video-segments=0:00-0:01,0:02-0:03"
  93. "video-seek|video-seek=0:02"
  94. "video-clear|video-segments=none;video-start=none;video-end=none"
  95. "video-bad|video-start=zz;video-end=-3;video-segments=garbage;video-seek=zz"
  96. )
  97. for group in "${videogroups[@]}"; do
  98. IFS='|' read -r name keys <<< "$group"
  99. tr ';' '\n' <<< "$keys" > "$work/$name.ctl"
  100. if LWE_FIXED_TIMESTEP=0.1 LWE_HOTSWAP_AT_FRAME=3 HEADLESS_RENDER_DELAY=40 HEADLESS_RENDER_SIZE=800x450 \
  101. "$HERE/headless_render.sh" "$BINARY" "$work/$name.png" --assets-dir "$ASSETS" --silent \
  102. --control-file "$work/$name.ctl" "$work/video" > "$work/$name.log" 2>&1; then
  103. echo "PASS: $name"
  104. else
  105. echo "FAIL: $name: the engine did not survive $keys"
  106. tail -5 "$work/$name.log"
  107. failed=1
  108. fi
  109. done
  110. fi
  111. # the same isolation as headless_render.sh: a private runtime dir and session bus, no desktop or audio server, no core
  112. # dump for the host's crash handler
  113. runtime="$work/runtime"
  114. mkdir -m 700 "$runtime"
  115. bus=unix:path=/nonexistent-bus
  116. if command -v dbus-daemon > /dev/null; then
  117. busPid=$(dbus-daemon --session --fork --print-pid --address="unix:path=$runtime/bus")
  118. bus="unix:path=$runtime/bus"
  119. trap 'kill $busPid 2> /dev/null; rm -rf "$work"' EXIT
  120. fi
  121. for list in --list-properties --list-objects --list-effects --list-fonts --list-audio-objects; do
  122. if output=$(
  123. ulimit -c 0
  124. env -u WAYLAND_DISPLAY -u WAYLAND_SOCKET -u DISPLAY -u KDE_FULL_SESSION -u KDE_SESSION_VERSION \
  125. -u DESKTOP_SESSION -u XDG_CURRENT_DESKTOP -u XDG_SESSION_DESKTOP XDG_RUNTIME_DIR="$runtime" \
  126. DBUS_SESSION_BUS_ADDRESS="$bus" PULSE_SERVER=unix:/nonexistent-pulse XDG_SESSION_TYPE=headless \
  127. timeout 60 "$BINARY" --assets-dir "$ASSETS" "$list" "$SCENE" 2>&1
  128. ) && [ -n "$output" ]; then
  129. echo "PASS: $list"
  130. else
  131. echo "FAIL: $list printed nothing or failed"
  132. failed=1
  133. fi
  134. done
  135. exit $failed