release_check.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #!/bin/bash
  2. # release_check.sh [--vm name]... [--candidate dir] [--app dir|.deb] [--no-overlay] - the release gate of
  3. # RELEASE_TESTING.md: every VM with a profile, one after the other, each from its golden disk (a throwaway overlay, see
  4. # `linuxvm.sh golden`), with guest_test.sh's checks (wallpapers, hotswap, pause on fullscreen, SIGKILL cleanup), the
  5. # frame checks, we_manager's install/launch/autostart (wem_check.sh) and update flow (update_check.sh). A failed check
  6. # is retried once. Writes reports/<date>/summary.md plus the screenshots and logs of every VM, exit code 1 when anything
  7. # failed. VMs are powered off afterwards, the overlay is thrown away (KEEP_VM=1 leaves the VM running to look at it).
  8. # --vm name only this profile (repeatable); default: every file in profiles/
  9. # --candidate dir folder with lwe-hints/ (the engine under test) copied over ~/lwe/lwe-hints in the guest
  10. # --app path we_manager's dist/linux-unpacked or a .deb; without it the we_manager checks are skipped
  11. # --engine-tarball the candidate's portable tarball, served to we_manager as the new engine release (update_check.sh)
  12. # --no-overlay run on the VM's disk as it is (a VM without a golden disk is run like this anyway)
  13. # A profile (profiles/<vm>.sh) sets: VM, SCREEN (as --screen-root names it), SHOT_CMD (command with $SHOT_FILE, or
  14. # host), FULLSCREEN_CMD / MAXIMIZE_CMD (open a fullscreen / maximized window), WEM (deb | app | none, how we_manager is installed), WEM_FLAGS,
  15. # WEM_LAUNCH (prefix of the we_manager start line, e.g. `systemd-run --user --scope -q` where an ssh session's end kills the app), LOGIN_PASSWORD (typed at a greeter without autologin), PREP (guest command run once the session is up, e.g. keeps the screen from locking), EXTRA (function name run last,
  16. # gets the VM name; prints PASS/FAIL lines).
  17. HERE=$(cd "$(dirname "$0")" && pwd)
  18. LINUXVM=${LINUXVM:-$HOME/.local/share/linuxvm}
  19. vms=() candidate="" app="" overlay=1 tarball=""
  20. while [ $# -gt 0 ]; do
  21. case $1 in
  22. --vm) vms+=("$2"); shift ;;
  23. --candidate) candidate=$2; shift ;;
  24. --app) app=$2; shift ;;
  25. --engine-tarball) tarball=$2; shift ;;
  26. --no-overlay) overlay=0 ;;
  27. *) sed -n '2,20p' "$0"; exit 2 ;;
  28. esac
  29. shift
  30. done
  31. [ ${#vms[@]} -gt 0 ] || for f in "$HERE"/profiles/*.sh; do vms+=("$(basename "$f" .sh)"); done
  32. report=${REPORT_DIR:-$HERE/reports/$(date +%F)}
  33. mkdir -p "$report"
  34. summary=$report/summary.md
  35. echo "# Release check $(date '+%F %H:%M')" > "$summary"
  36. [ -n "$candidate" ] && echo "Engine candidate: \`$candidate\`" >> "$summary"
  37. [ -n "$app" ] && echo "we_manager: \`$app\`" >> "$summary"
  38. total_status=0
  39. lv() { "$HERE/linuxvm.sh" "$@"; }
  40. sshv() { lv ssh "$VM" "$@" </dev/null; }
  41. wait_off() {
  42. for _ in $(seq 45); do
  43. [ -f "$LINUXVM/vms/$VM/qemu.pid" ] && kill -0 "$(cat "$LINUXVM/vms/$VM/qemu.pid")" 2>/dev/null || return 0
  44. sleep 2
  45. done
  46. lv kill "$VM"; sleep 2
  47. }
  48. # the guest_test.sh group a result line belongs to, empty when unknown (the whole run is repeated then)
  49. group_of() {
  50. case $1 in
  51. *"hotswap cycle"*|*"/shot-cycle-"*) echo cycle ;;
  52. *"hotswap video"*) echo video ;;
  53. *"multi monitor"*|*"first monitor"*|*"second monitor"*) echo multi ;;
  54. *automute*) echo automute ;;
  55. *"behavior:"*|*"hotswap:"*|*"fullscreen pause"*|*"maximized pause"*|*SIGKILL*|*"/hot-before.png"*|*"/hot-after.png"*) echo behavior ;;
  56. *"baseline screenshot"*|*"/shot-"[0-9]*".png"*) echo wallpapers ;;
  57. *) if [[ $1 =~ ^(PASS|FAIL|SKIP)\ [0-9]{8,10}: ]]; then echo wallpapers; fi ;;
  58. esac
  59. }
  60. runs() { [ -z "$ONLY" ] || [[ " $ONLY " == *" $1 "* ]]; }
  61. run_checks() {
  62. local out=/tmp/lwe-test
  63. lv scp "$VM" "$HERE/guest_test.sh" lwe/guest_test.sh
  64. lv scp "$VM" "$HERE/fullscreen_window.py" lwe/fullscreen_window.py
  65. lv scp "$VM" "$HERE/maximize_kde.sh" lwe/maximize_kde.sh
  66. sshv "rm -rf $out; mkdir -p $out"
  67. local shots=""
  68. if [ "$SHOT_CMD" = host ]; then "$HERE/host_shots.sh" "$VM" "$out" 900 >/dev/null 2>&1 & shots=$!; fi
  69. sshv ". ~/sessenv; BEHAVIOR=1 ONLY='$ONLY' SETTLE=${SETTLE:-25} LWE_ARGS='--screen-root $SCREEN' SHOT_CMD='$SHOT_CMD' FULLSCREEN_CMD='$FULLSCREEN_CMD' MAXIMIZE_CMD='$MAXIMIZE_CMD' MINIMIZE_CMD='$MINIMIZE_CMD' MULTI_SHOT_CMD='$MULTI_SHOT_CMD' ~/lwe/guest_test.sh"
  70. [ -n "$shots" ] && wait "$shots"
  71. local local_dir=$report/$VM/shots
  72. mkdir -p "$local_dir"
  73. scp -q -r -i "$LINUXVM/id_ed25519" -P "$(cat "$LINUXVM/vms/$VM/port")" -o StrictHostKeyChecking=no \
  74. -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR "lab@127.0.0.1:$out/*" "$local_dir/" 2>/dev/null
  75. local shot
  76. if [ -f "$local_dir/baseline.png" ]; then
  77. if runs wallpapers; then
  78. for shot in "$local_dir"/shot-[0-9]*.png; do [ -f "$shot" ] && python3 -I "$HERE/check_frame.py" --baseline "$local_dir/baseline.png" "$shot"; done
  79. fi
  80. if runs cycle; then
  81. for shot in "$local_dir"/shot-cycle-*.png; do [ -f "$shot" ] && python3 -I "$HERE/check_frame.py" --baseline "$local_dir/baseline.png" "$shot"; done
  82. fi
  83. fi
  84. runs video && [ -f "$local_dir/fresh-video.png" ] && [ -f "$local_dir/swap-video.png" ] \
  85. && python3 -I "$HERE/check_frame.py" --similar "$local_dir/fresh-video.png" "$local_dir/swap-video.png" 14 \
  86. | sed 's/^\(PASS\|FAIL\) /\1 hotswap video: /'
  87. if runs multi && [ -f "$local_dir/multi-geometry" ] && [ -f "$local_dir/multi-shot.png" ]; then
  88. read -r w1 w2 < "$local_dir/multi-geometry"
  89. split=$(python3 -c "print($w1 / ($w1 + $w2))")
  90. python3 -I "$HERE/check_frame.py" --crop "0,$split" --baseline "$local_dir/multi-baseline.png" "$local_dir/multi-shot.png" \
  91. | sed 's/^\(PASS\|FAIL\) /\1 first monitor: /'
  92. python3 -I "$HERE/check_frame.py" --crop "$split,1" --baseline "$local_dir/multi-baseline.png" "$local_dir/multi-shot.png" \
  93. | sed 's/^\(PASS\|FAIL\) /\1 second monitor: /'
  94. fi
  95. runs behavior && [ -f "$local_dir/hot-before.png" ] && python3 -I "$HERE/check_frame.py" --differ "$local_dir/hot-before.png" "$local_dir/hot-after.png"
  96. return 0
  97. }
  98. for VM in "${vms[@]}"; do
  99. unset POINTER WEM_FLAGS WEM_LAUNCH LOGIN_PASSWORD SCREEN SHOT_CMD FULLSCREEN_CMD MAXIMIZE_CMD MINIMIZE_CMD MULTI MULTI_SHOT_CMD WEM WEM_FLAGS PREP EXTRA SETTLE
  100. # shellcheck disable=SC1090
  101. . "$HERE/profiles/$VM.sh" || { echo "no profile for $VM"; continue; }
  102. export WEM_FLAGS WEM_LAUNCH # the we_manager scripts add them to its command line (COSMIC)
  103. mkdir -p "$report/$VM"
  104. log=$report/$VM/run.log
  105. echo "== $VM $(date +%T)"
  106. {
  107. if [ "$overlay" = 1 ] && [ -f "$LINUXVM/vms/$VM/golden.qcow2" ]; then lv fresh "$VM"; fi
  108. LINUXVM_OUTPUTS=${MULTI:+2} lv start "$VM"
  109. ready=0 logged_in=0
  110. for _ in $(seq 60); do
  111. # a greeter without autologin (COSMIC): type the password once the VM answers
  112. if [ -n "$LOGIN_PASSWORD" ] && [ $logged_in = 0 ] && sshv true 2>/dev/null; then
  113. sleep 25; lv type "$VM" "$LOGIN_PASSWORD"; lv keys "$VM" ret; logged_in=1
  114. fi
  115. lv scp "$VM" "$HERE/sessenv.sh" lwe/sessenv.sh 2>/dev/null && sshv "bash ~/lwe/sessenv.sh" >/dev/null 2>&1 && { ready=1; break; }
  116. sleep 5
  117. done
  118. if [ $ready = 0 ]; then echo "FAIL $VM: no desktop session within 5 minutes"; else
  119. # a golden disk keeps what an earlier run left: we_manager's autostart entry and playlist, stray engines
  120. sshv "pkill -x we-manager; pkill -x linux-wallpaper; rm -rf ~/.config/autostart/we-manager.desktop ~/.config/we-manager; true"
  121. [ -n "$PREP" ] && sshv ". ~/sessenv; $PREP"
  122. if [ -n "$candidate" ]; then
  123. sshv "rm -rf ~/lwe/lwe-hints.new"
  124. lv scp "$VM" "$candidate/lwe-hints" lwe/lwe-hints.new && sshv "rm -rf ~/lwe/lwe-hints && mv ~/lwe/lwe-hints.new ~/lwe/lwe-hints"
  125. fi
  126. for wp in wp-3471294034 wp-3818199837 wp-1367456719; do
  127. sshv "[ -d ~/lwe/$wp ]" || lv scp "$VM" "$LINUXVM/payload/$wp" lwe/
  128. done
  129. sleep 20
  130. ONLY="" run_checks > "$report/$VM/checks.txt" 2>&1
  131. fatal=0
  132. if grep -q '^FATAL' "$report/$VM/checks.txt"; then
  133. fatal=1
  134. echo "FATAL, the rest of the run for $VM is skipped"
  135. elif grep -q '^FAIL' "$report/$VM/checks.txt"; then
  136. retry="" full=0
  137. while IFS= read -r line; do
  138. g=$(group_of "$line")
  139. if [ -z "$g" ]; then full=1; elif [[ " $retry " != *" $g "* ]]; then retry="$retry $g"; fi
  140. done < <(grep '^FAIL' "$report/$VM/checks.txt")
  141. [ $full = 1 ] && retry=""
  142. echo "retrying the failed checks once (groups:${retry:- all})"
  143. sshv "pkill -f '[l]inux-wallpaperengine' 2>/dev/null; true"; sleep 5
  144. cp "$report/$VM/checks.txt" "$report/$VM/checks-first.txt"
  145. ONLY="${retry# }" run_checks > "$report/$VM/checks-retry.txt" 2>&1
  146. if [ -z "$retry" ]; then cp "$report/$VM/checks-retry.txt" "$report/$VM/checks.txt"; else
  147. while IFS= read -r line; do
  148. g=$(group_of "$line")
  149. [ -n "$g" ] && [[ " $retry " == *" $g "* ]] || echo "$line"
  150. done < "$report/$VM/checks-first.txt" > "$report/$VM/checks.txt"
  151. cat "$report/$VM/checks-retry.txt" >> "$report/$VM/checks.txt"
  152. fi
  153. fi
  154. if [ $fatal = 0 ] && [ "${POINTER:-1}" = 1 ]; then
  155. "$HERE/pointer_check.sh" "$VM" "$SCREEN" "$report/$VM/shots" > "$report/$VM/pointer.txt" 2>&1
  156. if grep -q '^FAIL' "$report/$VM/pointer.txt"; then
  157. cp "$report/$VM/pointer.txt" "$report/$VM/pointer-first.txt"
  158. "$HERE/pointer_check.sh" "$VM" "$SCREEN" "$report/$VM/shots" > "$report/$VM/pointer.txt" 2>&1
  159. fi
  160. grep -E '^(PASS|FAIL|SKIP)' "$report/$VM/pointer.txt" >> "$report/$VM/checks.txt"
  161. fi
  162. if [ $fatal = 0 ] && [ -n "$app" ] && [ "${WEM:-none}" != none ]; then
  163. # with the candidate's engine tarball the update check installs it (as a v99 release), we_manager's own
  164. # checks then run on it instead of the last published engine
  165. {
  166. [ -n "$tarball" ] && ENGINE_TARBALL=$tarball "$HERE/clean_install_check.sh" "$VM" "$app"
  167. ENGINE_TARBALL=$tarball "$HERE/update_check.sh" "$VM" "$app"
  168. SKIP_ENGINE_INSTALL=${tarball:+1} "$HERE/wem_check.sh" "$VM" "$app" "$SCREEN"
  169. } > "$report/$VM/wem.txt" 2>&1
  170. fi
  171. [ $fatal = 0 ] && [ -n "$EXTRA" ] && $EXTRA "$VM" > "$report/$VM/extra.txt" 2>&1
  172. sshv "cat /tmp/lwe-test/engine-*.log 2>/dev/null | tail -n 200" > "$report/$VM/engine-tail.log" 2>&1
  173. fi
  174. if [ -n "$KEEP_VM" ]; then echo "KEEP_VM set: $VM stays up for a look"; else
  175. sshv "sudo systemctl poweroff" >/dev/null 2>&1 || lv stop "$VM" >/dev/null 2>&1; wait_off
  176. [ "$overlay" = 1 ] && [ -f "$LINUXVM/vms/$VM/golden.qcow2" ] && lv fresh "$VM"
  177. fi
  178. } > "$log" 2>&1
  179. pass=$(cat "$report/$VM"/{checks,wem,extra}.txt 2>/dev/null | grep -c '^PASS')
  180. failed=$(cat "$report/$VM"/{checks,wem,extra}.txt 2>/dev/null | grep -E '^(FAIL|FATAL)'; grep -E '^(FAIL|FATAL)' "$log")
  181. {
  182. echo; echo "## $VM"
  183. if [ -z "$failed" ]; then echo "$pass checks passed."; else
  184. echo "$pass checks passed, failed:"; echo; echo "$failed" | sed 's/^/- /'; total_status=1
  185. fi
  186. for f in "$report/$VM"/{checks,wem,extra}.txt; do grep -h '^SKIP' "$f" 2>/dev/null | sed 's/^/- /'; done
  187. } >> "$summary"
  188. echo " $pass passed$([ -n "$failed" ] && echo ", FAILED")"
  189. done
  190. echo "report: $summary"
  191. exit $total_status