Skip to content

Commit 96feafd

Browse files
authored
Merge pull request #386 from smuppand/Display
fix(graphics): restore Weston runtime across DRM and Wayland test sequences
2 parents 8d08206 + 999c762 commit 96feafd

4 files changed

Lines changed: 246 additions & 48 deletions

File tree

Runner/suites/Multimedia/Display/igt-gpu-tools/core_auth/run.sh

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ if [ -z "$INIT_ENV" ]; then
1616
fi
1717

1818
# Only source if not already loaded (idempotent)
19-
if [ -z "$__INIT_ENV_LOADED" ]; then
19+
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
2020
# shellcheck disable=SC1090
2121
. "$INIT_ENV"
2222
fi
2323
# Always source functestlib.sh, using $TOOLS exported by init_env
2424
# shellcheck disable=SC1090,SC1091
2525
. "$TOOLS/functestlib.sh"
26+
# shellcheck disable=SC1090,SC1091
27+
. "$TOOLS/lib_display.sh"
2628

2729
TESTNAME="core_auth"
2830
result_file="./${TESTNAME}.res"
@@ -91,10 +93,21 @@ fi
9193

9294
log_info "Using core_auth binary at: $CORE_AUTH_CMD"
9395

94-
if ! weston_stop; then
95-
log_error "Failed to stop Weston"
96-
echo "$TESTNAME FAIL" > "$result_file"
97-
exit 1
96+
weston_stopped_by_test=0
97+
if command -v weston_is_running >/dev/null 2>&1; then
98+
if weston_is_running; then
99+
log_info "Weston is running, stopping it before $TESTNAME"
100+
if ! weston_stop; then
101+
log_error "Failed to stop Weston"
102+
echo "$TESTNAME FAIL" > "$result_file"
103+
exit 1
104+
fi
105+
weston_stopped_by_test=1
106+
else
107+
log_info "Weston is not running, no need to stop it"
108+
fi
109+
else
110+
log_info "weston_is_running helper not found, attempting to continue"
98111
fi
99112

100113
log_file="$test_path/core_auth_log.txt"
@@ -120,30 +133,62 @@ total_subtests=$((success_count + fail_count + skip_count))
120133

121134
log_info "Subtest Results: SUCCESS=$success_count, FAIL=$fail_count, SKIP=$skip_count, TOTAL=$total_subtests"
122135
log_info "results will be written to \"$result_file\""
123-
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
124136

125-
if [ "$RC" -ne 0 ]; then
126-
log_fail "$TESTNAME : Test Failed (exit code: $RC)"
127-
echo "$TESTNAME FAIL" > "$result_file"
128-
exit 1
137+
final_result="PASS"
138+
final_exit=0
139+
final_message=""
140+
141+
if [ "$RC" -eq 77 ]; then
142+
final_result="SKIP"
143+
final_exit=0
144+
final_message="$TESTNAME : Test Skipped (exit code: 77)"
145+
elif [ "$RC" -ne 0 ]; then
146+
final_result="FAIL"
147+
final_exit=1
148+
final_message="$TESTNAME : Test Failed (exit code: $RC)"
129149
elif [ "$fail_count" -gt 0 ]; then
130-
log_fail "$TESTNAME : Test Failed - $fail_count subtest(s) failed out of $total_subtests"
131-
echo "$TESTNAME FAIL" > "$result_file"
132-
exit 1
150+
final_result="FAIL"
151+
final_exit=1
152+
final_message="$TESTNAME : Test Failed - $fail_count subtest(s) failed out of $total_subtests"
133153
elif [ "$skip_count" -gt 0 ] && [ "$success_count" -eq 0 ]; then
134-
log_skip "$TESTNAME : Test Skipped - All $skip_count subtest(s) were skipped"
135-
echo "$TESTNAME SKIP" > "$result_file"
136-
exit 0
154+
final_result="SKIP"
155+
final_exit=0
156+
final_message="$TESTNAME : Test Skipped - All $skip_count subtest(s) were skipped"
137157
else
138158
if [ "$success_count" -gt 0 ]; then
139159
if [ "$skip_count" -gt 0 ]; then
140-
log_pass "$TESTNAME : Test Passed - $success_count subtest(s) succeeded, $skip_count skipped"
160+
final_message="$TESTNAME : Test Passed - $success_count subtest(s) succeeded, $skip_count skipped"
141161
else
142-
log_pass "$TESTNAME : Test Passed - All $success_count subtest(s) succeeded"
162+
final_message="$TESTNAME : Test Passed - All $success_count subtest(s) succeeded"
143163
fi
144164
else
145-
log_pass "$TESTNAME : Test Passed (return code $RC)"
165+
final_message="$TESTNAME : Test Passed (return code $RC)"
146166
fi
147-
echo "$TESTNAME PASS" > "$result_file"
148-
exit 0
149167
fi
168+
169+
if [ "$weston_stopped_by_test" -eq 1 ]; then
170+
log_info "Restoring Weston after $TESTNAME"
171+
if ! weston_restore_runtime 15; then
172+
log_error "Failed to restore Weston after $TESTNAME"
173+
final_result="FAIL"
174+
final_exit=1
175+
final_message="$TESTNAME : Test Failed - Weston restore failed after test execution"
176+
fi
177+
fi
178+
179+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
180+
181+
case "$final_result" in
182+
PASS)
183+
log_pass "$final_message"
184+
;;
185+
SKIP)
186+
log_skip "$final_message"
187+
;;
188+
*)
189+
log_fail "$final_message"
190+
;;
191+
esac
192+
193+
echo "$TESTNAME $final_result" > "$result_file"
194+
exit "$final_exit"

Runner/suites/Multimedia/Graphics/KMSCube/run.sh

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@ fi
9999
KMSCUBE_BIN="$(command -v kmscube 2>/dev/null || true)"
100100
log_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.
109106
if command -v display_is_cpu_renderer >/dev/null 2>&1; then
@@ -129,7 +126,14 @@ fi
129126
# Stop weston after gating too, because some helpers may have started it.
130127
if 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
133137
fi
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
166172
fi
@@ -185,26 +191,31 @@ FRAMES_RENDERED="$(
185191
[ "$EXPECTED_MIN" -lt 0 ] && EXPECTED_MIN=0
186192
log_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
201209
fi
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
207215
fi
208216

217+
log_pass "$TESTNAME : PASS"
218+
echo "$TESTNAME PASS" >"$RES_FILE"
219+
209220
log_info "------------------- Completed $TESTNAME Testcase ------------------"
210221
exit 0

Runner/suites/Multimedia/Graphics/weston-simple-egl/run.sh

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ if [ -n "$sock" ] && command -v adopt_wayland_env_from_socket >/dev/null 2>&1; t
161161
fi
162162
fi
163163

164+
# On base, do not start Weston here, but allow a short wait for an already
165+
# expected Weston runtime to come back after a previous DRM-exclusive test.
166+
if [ -z "$sock" ] && [ "$BUILD_FLAVOUR" = "base" ]; then
167+
if command -v weston_wait_ready >/dev/null 2>&1; then
168+
log_info "No usable Wayland socket yet on base build; waiting briefly for Weston runtime..."
169+
if weston_wait_ready 10; then
170+
if command -v discover_wayland_socket_anywhere >/dev/null 2>&1; then
171+
sock=$(discover_wayland_socket_anywhere | head -n 1 || true)
172+
fi
173+
if [ -n "$sock" ] && command -v adopt_wayland_env_from_socket >/dev/null 2>&1; then
174+
log_info "Base Weston runtime became ready: $sock"
175+
if ! adopt_wayland_env_from_socket "$sock"; then
176+
log_warn "Failed to adopt env from $sock after wait"
177+
fi
178+
fi
179+
fi
180+
fi
181+
fi
182+
164183
# If no usable socket yet:
165184
# - base: SKIP (do not try to start/stop Weston)
166185
# - overlay: try starting private Weston (helper) then re-discover/adopt
@@ -217,9 +236,23 @@ fi
217236

218237
if command -v wayland_connection_ok >/dev/null 2>&1; then
219238
if ! wayland_connection_ok; then
220-
log_fail "Wayland connection test failed; cannot run ${TESTNAME}."
221-
echo "${TESTNAME} SKIP" >"$RES_FILE"
222-
exit 0
239+
if [ "$BUILD_FLAVOUR" = "base" ] && command -v weston_wait_ready >/dev/null 2>&1; then
240+
log_warn "Initial Wayland connection test failed; waiting briefly and retrying..."
241+
if weston_wait_ready 5; then
242+
if command -v discover_wayland_socket_anywhere >/dev/null 2>&1; then
243+
sock=$(discover_wayland_socket_anywhere | head -n 1 || true)
244+
fi
245+
if [ -n "$sock" ] && command -v adopt_wayland_env_from_socket >/dev/null 2>&1; then
246+
adopt_wayland_env_from_socket "$sock" || true
247+
fi
248+
fi
249+
fi
250+
251+
if ! wayland_connection_ok; then
252+
log_fail "Wayland connection test failed; cannot run ${TESTNAME}."
253+
echo "${TESTNAME} SKIP" >"$RES_FILE"
254+
exit 0
255+
fi
223256
fi
224257
log_info "Wayland connection test: OK"
225258
else

Runner/utils/lib_display.sh

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,14 @@ wayland_debug_snapshot() {
595595
log_info "----- End snapshot: $tag -----"
596596
}
597597

598+
# Discover an available Wayland socket from common runtime locations.
599+
# Prefers user-session sockets first, then system-wide sockets such as /run/wayland-*.
598600
discover_wayland_socket_anywhere() {
599601
candidates=""
600602
if [ -n "${XDG_RUNTIME_DIR:-}" ]; then
601603
candidates="$candidates $XDG_RUNTIME_DIR"
602604
fi
603-
candidates="$candidates /dev/socket/weston /run/user/0 /run/user/1000"
605+
candidates="$candidates /run/user/1000 /run/user/0 /run /dev/socket/weston"
604606

605607
for dir in $candidates; do
606608
[ -d "$dir" ] || continue
@@ -665,6 +667,113 @@ wayland_connection_ok() {
665667
return 0
666668
}
667669

670+
# Return success if any real Weston/Wayland socket currently exists.
671+
# Checks discovered sockets first, then common fallback socket paths.
672+
weston_runtime_socket_exists() {
673+
weston_sock=""
674+
675+
if command -v discover_wayland_socket_anywhere >/dev/null 2>&1; then
676+
weston_sock=$(discover_wayland_socket_anywhere 2>/dev/null | head -n 1 || true)
677+
if [ -n "$weston_sock" ]; then
678+
return 0
679+
fi
680+
fi
681+
682+
for weston_sock in /run/wayland-* /run/user/0/wayland-* /run/user/1000/wayland-*; do
683+
[ -S "$weston_sock" ] || continue
684+
return 0
685+
done
686+
687+
return 1
688+
}
689+
690+
# Wait until Weston is usable by requiring both process presence and socket availability.
691+
# Returns 0 when ready, 1 after timeout seconds if Weston does not become ready.
692+
weston_wait_ready() {
693+
timeout="${1:-15}"
694+
i=0
695+
696+
while [ "$i" -lt "$timeout" ]; do
697+
weston_proc_ready=1
698+
weston_sock_ready=1
699+
700+
if command -v weston_is_running >/dev/null 2>&1; then
701+
if weston_is_running >/dev/null 2>&1; then
702+
weston_proc_ready=0
703+
fi
704+
else
705+
if command -v pgrep >/dev/null 2>&1; then
706+
if pgrep -x weston >/dev/null 2>&1; then
707+
weston_proc_ready=0
708+
fi
709+
fi
710+
fi
711+
712+
if weston_runtime_socket_exists; then
713+
weston_sock_ready=0
714+
fi
715+
716+
if [ "$weston_proc_ready" -eq 0 ] && [ "$weston_sock_ready" -eq 0 ]; then
717+
return 0
718+
fi
719+
720+
i=$((i + 1))
721+
sleep 1
722+
done
723+
724+
log_warn "weston_wait_ready: Weston did not become ready within ${timeout}s"
725+
return 1
726+
}
727+
728+
# Restore Weston runtime after a DRM-exclusive test stopped it.
729+
# Starts socket/service first, then falls back to weston_start, and waits until ready.
730+
weston_restore_runtime() {
731+
timeout="${1:-15}"
732+
733+
if command -v weston_is_running >/dev/null 2>&1; then
734+
if weston_is_running >/dev/null 2>&1 && weston_runtime_socket_exists; then
735+
return 0
736+
fi
737+
fi
738+
739+
if command -v systemctl >/dev/null 2>&1; then
740+
systemctl start weston.socket >/dev/null 2>&1 || true
741+
systemctl start weston.service >/dev/null 2>&1 || \
742+
systemctl start weston@root.service >/dev/null 2>&1 || true
743+
fi
744+
745+
if weston_wait_ready 3; then
746+
return 0
747+
fi
748+
749+
if command -v weston_start >/dev/null 2>&1; then
750+
weston_start >/dev/null 2>&1 || true
751+
fi
752+
753+
weston_wait_ready "$timeout"
754+
}
755+
756+
# Remove stale Wayland socket files only when Weston is not running.
757+
# Best-effort cleanup for common Weston runtime paths; ignores missing files
758+
# and permission errors. Intentionally does not touch /run/wayland-* because
759+
# that may be owned by systemd weston.socket on base builds.
760+
weston_cleanup_stale_sockets() {
761+
if weston_is_running; then
762+
return 0
763+
fi
764+
765+
for s in \
766+
/dev/socket/weston/wayland-* \
767+
/run/user/0/wayland-* \
768+
/run/user/1000/wayland-* \
769+
/tmp/wayland-* \
770+
"${XDG_RUNTIME_DIR:-/nonexistent}"/wayland-*; do
771+
[ -S "$s" ] || continue
772+
rm -f "$s" 2>/dev/null || true
773+
done
774+
775+
return 0
776+
}
668777
###############################################################################
669778
# Hz helpers
670779
###############################################################################

0 commit comments

Comments
 (0)