9999KMSCUBE_BIN=" $( command -v kmscube 2> /dev/null || true) "
100100log_info " Using kmscube: ${KMSCUBE_BIN:- <not found>} "
101101
102- # --- Track Weston state (restore at end if needed) ---------------------------
103- weston_was_running=0
104- if weston_is_running; then
105- weston_was_running=1
106- fi
102+ # --- Track whether this test stopped Weston ----------------------------------
103+ weston_stopped_by_test=0
107104# --- GPU acceleration gating (avoid auto/Wayland for kmscube) ----------------
108105# KMSCube is a DRM/KMS test. Using "auto" can start/adopt Weston and steal DRM master.
109106if command -v display_is_cpu_renderer > /dev/null 2>&1 ; then
129126# Stop weston after gating too, because some helpers may have started it.
130127if weston_is_running; then
131128 log_info " Weston is running, stopping it so kmscube can modeset (DRM master)"
132- weston_stop > /dev/null 2>&1 || true
129+ if weston_stop > /dev/null 2>&1 ; then
130+ weston_stopped_by_test=1
131+ else
132+ log_warn " weston_stop returned non-zero, re-checking Weston state"
133+ if ! weston_is_running; then
134+ weston_stopped_by_test=1
135+ fi
136+ fi
133137fi
134138
135139# Double-check and be strict: kmscube will fail if weston still holds DRM master.
@@ -157,10 +161,12 @@ if kmscube --count="${FRAME_COUNT}" >"$LOG_FILE" 2>&1; then :; else
157161 unset EGL_PLATFORM
158162 fi
159163
160- # Restore Weston if it was running before
161- if [ " $weston_was_running " -eq 1 ]; then
162- log_info " Restarting Weston after failure"
163- weston_start > /dev/null 2>&1 || true
164+ # Restore Weston if we stopped it
165+ if [ " $weston_stopped_by_test " -eq 1 ]; then
166+ log_info " Restoring Weston after failure"
167+ if ! weston_restore_runtime 15; then
168+ log_error " Failed to restore Weston runtime after $TESTNAME failure"
169+ fi
164170 fi
165171 exit 1
166172fi
@@ -185,26 +191,31 @@ FRAMES_RENDERED="$(
185191[ " $EXPECTED_MIN " -lt 0 ] && EXPECTED_MIN=0
186192log_info " kmscube reported: Rendered ${FRAMES_RENDERED} frames (requested ${FRAME_COUNT} , min acceptable ${EXPECTED_MIN} )"
187193
194+ # --- Restore Weston if we stopped it -----------------------------------------
195+ restore_failed=0
196+ if [ " $weston_stopped_by_test " -eq 1 ]; then
197+ log_info " Restoring Weston after $TESTNAME completion"
198+ if ! weston_restore_runtime 15; then
199+ restore_failed=1
200+ log_error " Failed to restore Weston runtime after $TESTNAME "
201+ fi
202+ fi
203+
188204# --- Verdict -----------------------------------------------------------------
189- if [ " $FRAMES_RENDERED " -ge " $EXPECTED_MIN " ]; then
190- log_pass " $TESTNAME : PASS"
191- echo " $TESTNAME PASS" > " $RES_FILE "
192- else
205+ if [ " $FRAMES_RENDERED " -lt " $EXPECTED_MIN " ]; then
193206 log_fail " $TESTNAME : FAIL (rendered ${FRAMES_RENDERED} < ${EXPECTED_MIN} )"
194207 echo " $TESTNAME FAIL" > " $RES_FILE "
195-
196- if [ " $weston_was_running " -eq 1 ]; then
197- log_info " Restarting Weston after failure"
198- weston_start > /dev/null 2>&1 || true
199- fi
200208 exit 1
201209fi
202210
203- # --- Restore Weston if we stopped it -----------------------------------------
204- if [ " $weston_was_running " -eq 1 ] ; then
205- log_info " Restarting Weston after $TESTNAME completion "
206- weston_start > /dev/null 2>&1 || true
211+ if [ " $restore_failed " -ne 0 ] ; then
212+ log_fail " $TESTNAME : FAIL (rendered ${FRAMES_RENDERED} , but Weston restore failed) "
213+ echo " $TESTNAME FAIL " > " $RES_FILE "
214+ exit 1
207215fi
208216
217+ log_pass " $TESTNAME : PASS"
218+ echo " $TESTNAME PASS" > " $RES_FILE "
219+
209220log_info " ------------------- Completed $TESTNAME Testcase ------------------"
210221exit 0
0 commit comments