release_check.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 (a lane runs its VMs one after the other, the gate uses 4 lanes with `--vm`; every VM takes one of MAXVMS=5 slots from vm_slots.sh first), 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, the desktop icons check (desktop_icons_check.sh, we_manager's overlay on Plasma), 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. # --quick for daily runs: the engine level groups (video, automute) only on profiles with FULL_ENGINE=1, the hotswap
  14. # cycle only its first 3 swaps elsewhere; the release candidate gets the full run
  15. # A profile (profiles/<vm>.sh) sets: VM, SCREEN (as --screen-root names it), SHOT_CMD (command with $SHOT_FILE, or
  16. # host), FULLSCREEN_CMD / MAXIMIZE_CMD (open a fullscreen / maximized window), WEM (deb | app | none, how we_manager is installed), WEM_FLAGS,
  17. # 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), BOOT_PREP (guest command run as soon as ssh answers, before the session is awaited: Zorin's Xorg profile switches GDM there), PREP (guest command run once the session is up, e.g. keeps the screen from locking), EXTRA (function name run last,
  18. # gets the VM name; prints PASS/FAIL lines).
  19. HERE=$(cd "$(dirname "$0")" && pwd)
  20. LINUXVM=${LINUXVM:-$HOME/.local/share/linuxvm}
  21. vms=() candidate="" app="" overlay=1 tarball="" quick=0
  22. while [ $# -gt 0 ]; do
  23. case $1 in
  24. --vm) vms+=("$2"); shift ;;
  25. --candidate) candidate=$2; shift ;;
  26. --app) app=$2; shift ;;
  27. --engine-tarball) tarball=$2; shift ;;
  28. --no-overlay) overlay=0 ;;
  29. --quick) quick=1 ;;
  30. *) sed -n '2,20p' "$0"; exit 2 ;;
  31. esac
  32. shift
  33. done
  34. [ ${#vms[@]} -gt 0 ] || for f in "$HERE"/profiles/*.sh; do vms+=("$(basename "$f" .sh)"); done
  35. report=${REPORT_DIR:-$HERE/reports/$(date +%F)}
  36. mkdir -p "$report"
  37. summary=$report/summary.md
  38. echo "# Release check $(date '+%F %H:%M')" > "$summary"
  39. [ -n "$candidate" ] && echo "Engine candidate: \`$candidate\`" >> "$summary"
  40. [ -n "$app" ] && echo "we_manager: \`$app\`" >> "$summary"
  41. total_status=0
  42. . "$HERE/vm_slots.sh"
  43. lv() { "$HERE/linuxvm.sh" "$@"; }
  44. sshv() { lv ssh "$VM" "$@" </dev/null; }
  45. wait_off() {
  46. for _ in $(seq 45); do
  47. [ -f "$LINUXVM/vms/$VM/qemu.pid" ] && kill -0 "$(cat "$LINUXVM/vms/$VM/qemu.pid")" 2>/dev/null || return 0
  48. sleep 2
  49. done
  50. lv kill "$VM"; sleep 2
  51. }
  52. # the guest_test.sh group a result line belongs to, empty when unknown (the whole run is repeated then)
  53. group_of() {
  54. case $1 in
  55. "TIME "*) set -- $1; echo "$2" ;;
  56. *"hotswap cycle"*|*"/shot-cycle-"*) echo cycle ;;
  57. *"hotswap video"*) echo video ;;
  58. *"multi monitor"*|*"first monitor"*|*"second monitor"*) echo multi ;;
  59. *"automute ignore"*) echo automuteignore ;;
  60. *transition*) echo transition ;;
  61. *automute*) echo automute ;;
  62. *"behavior:"*|*"hotswap:"*|*"fullscreen pause"*|*"maximized pause"*|*SIGKILL*|*"/hot-before.png"*|*"/hot-after.png"*) echo behavior ;;
  63. *"baseline screenshot"*|*"/shot-"[0-9]*".png"*) echo wallpapers ;;
  64. *) if [[ $1 =~ ^(PASS|FAIL|SKIP)\ [0-9]{8,10}: ]]; then echo wallpapers; fi ;;
  65. esac
  66. }
  67. tmark() { echo "$1 $((SECONDS - T_LAST))" >> "$report/$VM/timing.txt"; T_LAST=$SECONDS; }
  68. runs() { [ -z "$ONLY" ] || [[ " $ONLY " == *" $1 "* ]]; }
  69. run_checks() {
  70. local out=/tmp/lwe-test
  71. lv scp "$VM" "$HERE/guest_test.sh" lwe/guest_test.sh
  72. lv scp "$VM" "$HERE/fullscreen_window.py" lwe/fullscreen_window.py
  73. lv scp "$VM" "$HERE/maximize_kde.sh" lwe/maximize_kde.sh
  74. [ -n "$HIDE" ] && lv scp "$VM" "$HERE/hide_steam_kde.sh" lwe/hide_steam_kde.sh
  75. sshv "rm -rf $out; mkdir -p $out"
  76. local shots=""
  77. if [ "$SHOT_CMD" = host ]; then "$HERE/host_shots.sh" "$VM" "$out" 900 >/dev/null 2>&1 & shots=$!; fi
  78. sshv ". ~/sessenv; BEHAVIOR=1 AUTOMUTE_IGNORE='${AUTOMUTE_IGNORE:-}' CYCLE_UPTO='${CYCLE_UPTO:-}' ${RETRY_WALLPAPERS:+WALLPAPERS='$RETRY_WALLPAPERS'} 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"
  79. [ -n "$shots" ] && wait "$shots"
  80. local local_dir=$report/$VM/shots
  81. mkdir -p "$local_dir"
  82. scp -q -r -i "$LINUXVM/id_ed25519" -P "$(cat "$LINUXVM/vms/$VM/port")" -o StrictHostKeyChecking=no \
  83. -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR "lab@127.0.0.1:$out/*" "$local_dir/" 2>/dev/null
  84. local shot
  85. if [ -f "$local_dir/baseline.png" ]; then
  86. if runs wallpapers; then
  87. 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
  88. fi
  89. if runs cycle; then
  90. for shot in "$local_dir"/shot-cycle-*.png; do [ -f "$shot" ] && python3 -I "$HERE/check_frame.py" --baseline "$local_dir/baseline.png" "$shot"; done
  91. fi
  92. if runs windowbg; then
  93. for shot in "$local_dir"/shot-windowbg-*.png; do [ -f "$shot" ] && python3 -I "$HERE/check_frame.py" --baseline "$local_dir/baseline.png" "$shot"; done
  94. fi
  95. if runs wallpapers || runs cycle || runs windowbg; then
  96. local id
  97. for shot in "$local_dir"/shot-[0-9]*.png "$local_dir"/shot-cycle-*.png "$local_dir"/shot-windowbg-*.png; do
  98. [ -f "$shot" ] || continue
  99. id=${shot##*-}; id=${id%.png}
  100. [ -f "$HERE/reference/$id.png" ] && python3 -I "$HERE/check_frame.py" --reference "$HERE/reference/$id.png" "$shot"
  101. done
  102. fi
  103. fi
  104. runs video && [ -f "$local_dir/fresh-video.png" ] && [ -f "$local_dir/swap-video.png" ] \
  105. && python3 -I "$HERE/check_frame.py" --similar "$local_dir/fresh-video.png" "$local_dir/swap-video.png" 14 \
  106. | sed 's/^\(PASS\|FAIL\) /\1 hotswap video: /'
  107. if runs multi && [ -f "$local_dir/multi-geometry" ] && [ -f "$local_dir/multi-shot.png" ]; then
  108. read -r w1 w2 < "$local_dir/multi-geometry"
  109. split=$(python3 -c "print($w1 / ($w1 + $w2))")
  110. python3 -I "$HERE/check_frame.py" --crop "0,$split" --baseline "$local_dir/multi-baseline.png" "$local_dir/multi-shot.png" \
  111. | sed 's/^\(PASS\|FAIL\) /\1 first monitor: /'
  112. python3 -I "$HERE/check_frame.py" --crop "$split,1" --baseline "$local_dir/multi-baseline.png" "$local_dir/multi-shot.png" \
  113. | sed 's/^\(PASS\|FAIL\) /\1 second monitor: /'
  114. fi
  115. runs transition && [ -f "$local_dir/tr-half.ppm" ] && [ -f "$local_dir/tr-half-old.ppm" ] && [ -f "$local_dir/tr-half-new.ppm" ] \
  116. && python3 -I "$HERE/check_frame.py" --blend "$local_dir/tr-half-old.ppm" "$local_dir/tr-half-new.ppm" "$local_dir/tr-half.ppm" \
  117. | sed 's/^\(PASS\|FAIL\|SKIP\) /\1 transition: /'
  118. 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"
  119. return 0
  120. }
  121. for VM in "${vms[@]}"; do
  122. take_slot
  123. unset AUTOMUTE_IGNORE FULL_ENGINE HIDE POINTER POINTER_DOCK_XY WEM_FLAGS WEM_LAUNCH LOGIN_PASSWORD SCREEN SHOT_CMD FULLSCREEN_CMD MAXIMIZE_CMD MINIMIZE_CMD MULTI MULTI_SHOT_CMD WEM WEM_FLAGS PREP BOOT_PREP EXTRA SETTLE ICONS
  124. # shellcheck disable=SC1090
  125. . "$HERE/profiles/$VM.sh" || { echo "no profile for $VM"; release_slot; continue; }
  126. export WEM_FLAGS WEM_LAUNCH # the we_manager scripts add them to its command line (COSMIC)
  127. mkdir -p "$report/$VM"
  128. log=$report/$VM/run.log
  129. echo "== $VM $(date +%T)"
  130. : > "$report/$VM/timing.txt"; T_START=$SECONDS; T_LAST=$SECONDS
  131. {
  132. if [ "$overlay" = 1 ] && [ -f "$LINUXVM/vms/$VM/golden.qcow2" ]; then lv fresh "$VM"; fi
  133. LINUXVM_OUTPUTS=${MULTI:+2} lv start "$VM"
  134. ready=0 logged_in=0
  135. if [ -n "$BOOT_PREP" ]; then
  136. for _ in $(seq 60); do sshv true 2>/dev/null && break; sleep 3; done
  137. sshv "$BOOT_PREP"
  138. fi
  139. for _ in $(seq 60); do
  140. # a greeter without autologin (COSMIC): type the password once the VM answers
  141. if [ -n "$LOGIN_PASSWORD" ] && [ $logged_in = 0 ] && sshv true 2>/dev/null; then
  142. sleep 25; lv type "$VM" "$LOGIN_PASSWORD"; lv keys "$VM" ret; logged_in=1
  143. fi
  144. lv scp "$VM" "$HERE/sessenv.sh" lwe/sessenv.sh 2>/dev/null && sshv "bash ~/lwe/sessenv.sh" >/dev/null 2>&1 && { ready=1; break; }
  145. sleep 5
  146. done
  147. if [ $ready = 0 ]; then echo "FAIL $VM: no desktop session within 5 minutes"; else
  148. # a golden disk keeps what an earlier run left: we_manager's autostart entry and playlist, stray engines
  149. sshv "pkill -x we-manager; pkill -x linux-wallpaper; rm -rf ~/.config/autostart/we-manager.desktop ~/.config/we-manager; true"
  150. [ -n "$HIDE" ] && lv scp "$VM" "$HERE/hide_steam_kde.sh" lwe/hide_steam_kde.sh
  151. [ -n "$PREP" ] && sshv ". ~/sessenv; $PREP"
  152. if [ -n "$candidate" ]; then
  153. sshv "rm -rf ~/lwe/lwe-hints.new"
  154. lv scp "$VM" "$candidate/lwe-hints" lwe/lwe-hints.new && sshv "rm -rf ~/lwe/lwe-hints && mv ~/lwe/lwe-hints.new ~/lwe/lwe-hints"
  155. fi
  156. for wp in wp-3471294034 wp-3818199837 wp-1367456719; do
  157. sshv "[ -d ~/lwe/$wp ]" || lv scp "$VM" "$LINUXVM/payload/$wp" lwe/
  158. done
  159. sleep 20
  160. sshv ". ~/sessenv; pkill -x we-manager; sleep 3; pkill -x we-manager; true"
  161. if [ -n "$HIDE" ]; then lv scp "$VM" "$HERE/hide_steam_kde.sh" lwe/hide_steam_kde.sh; sshv ". ~/sessenv; bash ~/lwe/hide_steam_kde.sh"; fi
  162. tmark boot
  163. first_only="" CYCLE_UPTO=""
  164. if [ $quick = 1 ] && [ "${FULL_ENGINE:-0}" != 1 ]; then first_only="wallpapers behavior cycle transition multi windowbg"; CYCLE_UPTO=3; fi
  165. ONLY="$first_only" run_checks > "$report/$VM/checks.txt" 2>&1
  166. CYCLE_UPTO=""
  167. tmark checks
  168. fatal=0
  169. if grep -q '^FATAL' "$report/$VM/checks.txt"; then
  170. fatal=1
  171. echo "FATAL, the rest of the run for $VM is skipped"
  172. elif grep -q '^FAIL' "$report/$VM/checks.txt"; then
  173. retry="" full=0 RETRY_WALLPAPERS="" cycle_upto=0
  174. while IFS= read -r line; do
  175. g=$(group_of "$line")
  176. if [ -z "$g" ]; then full=1; elif [[ " $retry " != *" $g "* ]]; then retry="$retry $g"; fi
  177. case $g in
  178. wallpapers)
  179. id=$(grep -oE '(shot-|^FAIL )[0-9]{8,10}' <<< "$line" | grep -oE '[0-9]{8,10}' | head -1)
  180. if [ -z "$id" ]; then RETRY_WALLPAPERS=all; elif [ "$RETRY_WALLPAPERS" != all ] && [[ " $RETRY_WALLPAPERS " != *" $id "* ]]; then RETRY_WALLPAPERS="$RETRY_WALLPAPERS $id"; fi ;;
  181. cycle)
  182. step=$(grep -oE '(shot-cycle-|hotswap cycle step )[0-9]+' <<< "$line" | grep -oE '[0-9]+$' | head -1)
  183. if [ -z "$step" ]; then cycle_upto=99; elif [ "$step" -gt "$cycle_upto" ]; then cycle_upto=$step; fi ;;
  184. esac
  185. done < <(grep '^FAIL' "$report/$VM/checks.txt")
  186. [ $full = 1 ] && retry=""
  187. [ "$RETRY_WALLPAPERS" = all ] && RETRY_WALLPAPERS=""
  188. RETRY_WALLPAPERS=${RETRY_WALLPAPERS# }
  189. CYCLE_UPTO=""; [ "$cycle_upto" -gt 0 ] && [ "$cycle_upto" -lt 99 ] && CYCLE_UPTO=$cycle_upto
  190. [ -n "$retry" ] && [[ " $retry " != *" wallpapers "* ]] && RETRY_WALLPAPERS=""
  191. echo "retrying the failed checks once (groups:${retry:- all}${RETRY_WALLPAPERS:+, wallpapers $RETRY_WALLPAPERS}${CYCLE_UPTO:+, cycle up to step $CYCLE_UPTO})"
  192. sshv "pkill -f '[l]inux-wallpaperengine' 2>/dev/null; true"; sleep 5
  193. cp "$report/$VM/checks.txt" "$report/$VM/checks-first.txt"
  194. ONLY="${retry# }" run_checks > "$report/$VM/checks-retry.txt" 2>&1
  195. if [ -z "$retry" ]; then cp "$report/$VM/checks-retry.txt" "$report/$VM/checks.txt"; else
  196. while IFS= read -r line; do
  197. g=$(group_of "$line")
  198. if [ -n "$g" ] && [[ " $retry " == *" $g "* ]]; then
  199. replaced=1
  200. case $g in
  201. wallpapers)
  202. if [ -n "$RETRY_WALLPAPERS" ] && [[ $line != TIME* ]]; then
  203. replaced=0
  204. for id in $RETRY_WALLPAPERS; do [[ $line == *"$id"* ]] && replaced=1; done
  205. fi ;;
  206. cycle)
  207. if [ -n "$CYCLE_UPTO" ] && [[ $line != TIME* ]]; then
  208. step=$(grep -oE '(shot-cycle-|hotswap cycle step )[0-9]+' <<< "$line" | grep -oE '[0-9]+$' | head -1)
  209. [ -n "$step" ] && [ "$step" -gt "$CYCLE_UPTO" ] && replaced=0
  210. fi ;;
  211. esac
  212. [ $replaced = 1 ] && continue
  213. fi
  214. echo "$line"
  215. done < "$report/$VM/checks-first.txt" > "$report/$VM/checks.txt"
  216. cat "$report/$VM/checks-retry.txt" >> "$report/$VM/checks.txt"
  217. awk '!seen[$0]++' "$report/$VM/checks.txt" > "$report/$VM/checks.merged" && mv "$report/$VM/checks.merged" "$report/$VM/checks.txt"
  218. fi
  219. RETRY_WALLPAPERS="" CYCLE_UPTO=""
  220. fi
  221. [ -f "$report/$VM/checks-retry.txt" ] && tmark retry
  222. if [ $fatal = 0 ] && [ "${POINTER:-1}" = 1 ]; then
  223. POINTER_DOCK_XY=${POINTER_DOCK_XY:-} "$HERE/pointer_check.sh" "$VM" "$SCREEN" "$report/$VM/shots" > "$report/$VM/pointer.txt" 2>&1
  224. if grep -q '^FAIL' "$report/$VM/pointer.txt"; then
  225. cp "$report/$VM/pointer.txt" "$report/$VM/pointer-first.txt"
  226. POINTER_DOCK_XY=${POINTER_DOCK_XY:-} "$HERE/pointer_check.sh" "$VM" "$SCREEN" "$report/$VM/shots" > "$report/$VM/pointer.txt" 2>&1
  227. fi
  228. grep -E '^(PASS|FAIL|SKIP)' "$report/$VM/pointer.txt" >> "$report/$VM/checks.txt"
  229. fi
  230. tmark pointer
  231. if [ $fatal = 0 ] && [ "${ICONS:-1}" = 1 ]; then
  232. sshv "pkill -f '[l]inux-wallpaperengine' 2>/dev/null; true"; sleep 3
  233. "$HERE/desktop_icons_check.sh" "$VM" "$SCREEN" > "$report/$VM/icons.txt" 2>&1
  234. if grep -q '^FAIL' "$report/$VM/icons.txt"; then
  235. cp "$report/$VM/icons.txt" "$report/$VM/icons-first.txt"
  236. "$HERE/desktop_icons_check.sh" "$VM" "$SCREEN" > "$report/$VM/icons.txt" 2>&1
  237. fi
  238. grep -E '^(PASS|FAIL|SKIP)' "$report/$VM/icons.txt" >> "$report/$VM/checks.txt"
  239. fi
  240. tmark icons
  241. if [ $fatal = 0 ] && [ -n "$app" ] && [ "${WEM:-none}" != none ]; then
  242. # with the candidate's engine tarball the update check installs it (as a v99 release), we_manager's own
  243. # checks then run on it instead of the last published engine
  244. {
  245. [ -n "$tarball" ] && ENGINE_TARBALL=$tarball "$HERE/clean_install_check.sh" "$VM" "$app"
  246. ENGINE_TARBALL=$tarball "$HERE/update_check.sh" "$VM" "$app"
  247. SKIP_ENGINE_INSTALL=${tarball:+1} "$HERE/wem_check.sh" "$VM" "$app" "$SCREEN"
  248. } > "$report/$VM/wem.txt" 2>&1
  249. fi
  250. tmark wem
  251. [ $fatal = 0 ] && [ -n "$EXTRA" ] && $EXTRA "$VM" > "$report/$VM/extra.txt" 2>&1
  252. tmark extra
  253. sshv "cat /tmp/lwe-test/engine-*.log 2>/dev/null | tail -n 200" > "$report/$VM/engine-tail.log" 2>&1
  254. fi
  255. if [ -n "$KEEP_VM" ]; then echo "KEEP_VM set: $VM stays up for a look"; else
  256. sshv "sudo systemctl poweroff" >/dev/null 2>&1 || lv stop "$VM" >/dev/null 2>&1; wait_off
  257. [ "$overlay" = 1 ] && [ -f "$LINUXVM/vms/$VM/golden.qcow2" ] && lv fresh "$VM"
  258. fi
  259. tmark shutdown
  260. } > "$log" 2>&1
  261. pass=$(cat "$report/$VM"/{checks,wem,extra}.txt 2>/dev/null | grep -c '^PASS')
  262. failed=$(cat "$report/$VM"/{checks,wem,extra}.txt 2>/dev/null | grep -E '^(FAIL|FATAL)'; grep -E '^(FAIL|FATAL)' "$log")
  263. {
  264. echo; echo "## $VM"
  265. if [ -z "$failed" ]; then echo "$pass checks passed."; else
  266. echo "$pass checks passed, failed:"; echo; echo "$failed" | sed 's/^/- /'; total_status=1
  267. fi
  268. for f in "$report/$VM"/{checks,wem,extra}.txt; do grep -h '^SKIP' "$f" 2>/dev/null | sed 's/^/- /'; done
  269. echo "- time $((SECONDS - T_START)) s: $(awk '{printf "%s%s %d", (NR > 1 ? ", " : ""), $1, $2}' "$report/$VM/timing.txt"); groups: $(grep -h '^TIME' "$report/$VM/checks.txt" 2>/dev/null | awk '{printf "%s%s %d", (NR > 1 ? ", " : ""), $2, $3}')"
  270. } >> "$summary"
  271. echo " $pass passed$([ -n "$failed" ] && echo ", FAILED")"
  272. release_slot
  273. done
  274. echo "report: $summary"
  275. exit $total_status