Skip to content

Commit 59365c8

Browse files
authored
Merge pull request #192 from smuppand/graphics
Added missing weston/wayland and display helpers with diagnostics
2 parents a7abd8d + 07e09f6 commit 59365c8

File tree

2 files changed

+802
-80
lines changed

2 files changed

+802
-80
lines changed

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

Lines changed: 95 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,128 @@
11
#!/bin/sh
22
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
33
# SPDX-License-Identifier: BSD-3-Clause-Clear
4+
#
45
# Validate weston-simple-egl runs under a working Wayland session.
5-
# - Robust Wayland env resolution (adopts socket & fixes XDG_RUNTIME_DIR perms)
6-
# - CI-friendly logs and PASS/FAIL semantics
7-
# - Optional FPS parsing if build prints it (lenient if not present)
6+
# - Wayland env resolution (adopts socket & fixes XDG_RUNTIME_DIR perms)
7+
# - CI-friendly logs and PASS/FAIL/SKIP semantics (0/1/2)
8+
# - Optional FPS parsing (best-effort)
89

910
# ---------- Source init_env and functestlib ----------
1011
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
1112
INIT_ENV=""
1213
SEARCH="$SCRIPT_DIR"
14+
1315
while [ "$SEARCH" != "/" ]; do
14-
if [ -f "$SEARCH/init_env" ]; then INIT_ENV="$SEARCH/init_env"; break; fi
16+
if [ -f "$SEARCH/init_env" ]; then
17+
INIT_ENV="$SEARCH/init_env"
18+
break
19+
fi
1520
SEARCH=$(dirname "$SEARCH")
1621
done
22+
1723
if [ -z "$INIT_ENV" ]; then
1824
echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2
1925
exit 1
2026
fi
21-
if [ -z "$__INIT_ENV_LOADED" ]; then
27+
28+
if [ -z "${__INIT_ENV_LOADED:-}" ]; then
2229
# shellcheck disable=SC1090
2330
. "$INIT_ENV"
31+
__INIT_ENV_LOADED=1
2432
fi
33+
2534
# shellcheck disable=SC1090,SC1091
2635
. "$TOOLS/functestlib.sh"
2736

2837
TESTNAME="weston-simple-egl"
29-
# Tunables (env override)
38+
39+
# ---------- Tunables (env override) ----------
3040
DURATION="${DURATION:-30s}" # how long to run the client
31-
STOP_GRACE="${STOP_GRACE:-3s}" # grace period on stop
32-
EXPECT_FPS="${EXPECT_FPS:-60}" # nominal refresh (used for logging)
41+
STOP_GRACE="${STOP_GRACE:-3s}" # grace period on stop (reserved for future)
42+
EXPECT_FPS="${EXPECT_FPS:-60}" # nominal refresh (used for logs)
3343
FPS_TOL_PCT="${FPS_TOL_PCT:-10}" # +/- tolerance %
3444
REQUIRE_FPS="${REQUIRE_FPS:-0}" # 1=require FPS lines & threshold; 0=best effort
3545

46+
# ---------- Paths / logs ----------
3647
test_path="$(find_test_case_by_name "$TESTNAME" 2>/dev/null || echo "$SCRIPT_DIR")"
37-
cd "$test_path" || exit 1
48+
if ! cd "$test_path"; then
49+
log_error "cd failed: $test_path"
50+
exit 1
51+
fi
52+
3853
RES_FILE="./$TESTNAME.res"
3954
LOG_FILE="./${TESTNAME}_run.log"
4055
rm -f "$RES_FILE" "$LOG_FILE"
4156

4257
log_info "--------------------------------------------------------------------------"
4358
log_info "------------------- Starting $TESTNAME Testcase --------------------------"
44-
# FIX #1: Use ASCII '+/-' and keep it in a normal string
59+
60+
# --- Platform details (robust logging; prefer helpers) ---
61+
if command -v detect_platform >/dev/null 2>&1; then
62+
detect_platform >/dev/null 2>&1 || true
63+
log_info "Platform Details: machine='${PLATFORM_MACHINE:-unknown}' target='${PLATFORM_TARGET:-unknown}' kernel='${PLATFORM_KERNEL:-}' arch='${PLATFORM_ARCH:-}'"
64+
else
65+
log_info "Platform Details: unknown"
66+
fi
67+
4568
log_info "Config: DURATION=$DURATION STOP_GRACE=$STOP_GRACE EXPECT_FPS=${EXPECT_FPS}+/-${FPS_TOL_PCT}% REQUIRE_FPS=$REQUIRE_FPS"
4669

47-
# Dependencies
48-
check_dependencies weston-simple-egl || {
49-
log_fail "$TESTNAME : weston-simple-egl binary not found in PATH"
70+
# ---------- Dependencies ----------
71+
if ! check_dependencies weston-simple-egl; then
72+
log_skip "$TESTNAME : SKIP (weston-simple-egl not found in PATH)"
5073
echo "$TESTNAME SKIP" > "$RES_FILE"
51-
exit 0
52-
}
74+
exit 2
75+
fi
76+
5377
BIN="$(command -v weston-simple-egl 2>/dev/null || true)"
5478
log_info "Using weston-simple-egl: ${BIN:-<none>}"
5579

56-
# Resolve Wayland socket:
57-
# 1) If current env points to a real socket, use it.
58-
sock=""
59-
if [ -n "$XDG_RUNTIME_DIR" ] && [ -n "$WAYLAND_DISPLAY" ] && [ -e "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]; then
60-
sock="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
61-
fi
80+
# ----- Display presence check (DP/HDMI/etc.) -----
81+
# Quick snapshot for debugging (lists DRM nodes, sysfs connectors, weston outputs)
82+
display_debug_snapshot "pre-display-check"
83+
84+
have_connector=0
6285

63-
# 2) Otherwise, scan common locations.
64-
if [ -z "$sock" ]; then
65-
for s in $(find_wayland_sockets); do
66-
if [ -e "$s" ]; then sock="$s"; break; fi
67-
done
86+
# sysfs-based summary (existing helper)
87+
sysfs_summary="$(display_connected_summary 2>/dev/null || printf '%s' '')"
88+
if [ -n "$sysfs_summary" ] && [ "$sysfs_summary" != "none" ]; then
89+
have_connector=1
90+
log_info "Connected display (sysfs): $sysfs_summary"
6891
fi
6992

70-
# 3) If still no socket, try to start Weston and wait a bit.
71-
if [ -z "$sock" ]; then
72-
if weston_is_running; then
73-
log_warn "Weston running but no Wayland socket visible; attempting to continue."
74-
else
75-
log_info "Weston not running. Attempting to start..."
76-
weston_start
77-
fi
78-
# Wait for socket to appear (up to ~5s)
79-
n=0
80-
while [ $n -lt 5 ] && [ -z "$sock" ]; do
81-
for s in $(find_wayland_sockets); do
82-
if [ -e "$s" ]; then sock="$s"; break; fi
83-
done
84-
[ -n "$sock" ] && break
85-
sleep 1
86-
n=$((n+1))
87-
done
93+
if [ "$have_connector" -eq 0 ]; then
94+
log_skip "$TESTNAME : SKIP (no connected display detected)"
95+
echo "$TESTNAME SKIP" > "$RES_FILE"
96+
exit 2
8897
fi
8998

90-
if [ -z "$sock" ]; then
99+
wayland_debug_snapshot "weston-simple-egl: start"
100+
101+
# ---------- Choose/adopt Wayland socket (using helper) ----------
102+
# Capture only the actual socket path from helper output (filter out logs)
103+
sock="$(
104+
wayland_choose_or_start 2>/dev/null \
105+
| grep -E '/(run/user/[0-9]+|tmp|dev/socket/weston)/wayland-[0-9]+$' \
106+
| tail -n 1
107+
)"
108+
if [ -n "$sock" ]; then
109+
log_info "Found Wayland socket: $sock"
110+
else
91111
log_fail "$TESTNAME : FAIL (no Wayland socket found after attempting to start Weston)"
92112
echo "$TESTNAME FAIL" > "$RES_FILE"
113+
wayland_debug_snapshot "weston-simple-egl: no-socket"
93114
exit 1
94115
fi
95116

96-
# Adopt env and fix runtime dir perms (done inside helper(s))
97-
adopt_wayland_env_from_socket "$sock"
98-
99-
# FIX #2: Avoid duplicate prints — helpers can log the chosen socket/env once.
100-
# If your helpers are quiet instead, uncomment the two lines below:
101-
# log_info "Selected Wayland socket: $sock"
102-
# log_info "Wayland env: XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR WAYLAND_DISPLAY=$WAYLAND_DISPLAY"
117+
adopt_wayland_env_from_socket "$sock" || log_warn "adopt_wayland_env_from_socket: invalid: $sock"
118+
log_info "Final Wayland env: XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-}<sep>WAYLAND_DISPLAY=${WAYLAND_DISPLAY:-}"
119+
# Replace <sep> to avoid confusion in CI logs:
120+
# shellcheck disable=SC2016
121+
printf '%s\n' "" | sed 's/.*/[DBG] (env adopted)/' >/dev/null 2>&1 || true
103122

123+
# ---------- Sanity check Wayland connectivity ----------
104124
if wayland_connection_ok; then
105-
log_info "Wayland connection test: OK (wayland-info/env)"
125+
log_info "Wayland connection test: OK"
106126
else
107127
log_fail "$TESTNAME : FAIL (Wayland connection test failed)"
108128
print_path_meta "$XDG_RUNTIME_DIR" | sed 's/^/[DBG] /'
@@ -111,22 +131,25 @@ else
111131
exit 1
112132
fi
113133

114-
# Try to enable FPS prints if supported by the client build (best effort).
134+
# Try to enable FPS prints if supported by the client (best effort).
115135
export SIMPLE_EGL_FPS=1
116136
export WESTON_SIMPLE_EGL_FPS=1
117137

118-
# Run the client for DURATION with a stopwatch for CI logs.
119-
log_info "Running weston-simple-egl for $DURATION ..."
138+
# ---------- Run the client ----------
139+
log_info "Launching weston-simple-egl for $DURATION "
120140
start_ts="$(date +%s 2>/dev/null || echo 0)"
141+
121142
if command -v run_with_timeout >/dev/null 2>&1; then
143+
log_info "Using helper: run_with_timeout"
122144
run_with_timeout "$DURATION" weston-simple-egl >"$LOG_FILE" 2>&1
123145
rc=$?
124146
else
125147
if command -v timeout >/dev/null 2>&1; then
148+
log_info "Using coreutils timeout"
126149
timeout "$DURATION" weston-simple-egl >"$LOG_FILE" 2>&1
127150
rc=$?
128151
else
129-
# Last resort: background and sleep.
152+
log_info "No timeout helpers; running in background with manual sleep-stop"
130153
sh -c 'weston-simple-egl' >"$LOG_FILE" 2>&1 &
131154
pid=$!
132155
# DURATION like "30s" → "30"
@@ -138,31 +161,31 @@ else
138161
rc=143
139162
fi
140163
fi
164+
141165
end_ts="$(date +%s 2>/dev/null || echo 0)"
142166
elapsed=$(( end_ts - start_ts ))
143167
[ "$elapsed" -lt 0 ] && elapsed=0
168+
log_info "Client finished: rc=$rc elapsed=${elapsed}s"
144169

145-
# FPS parsing (best effort)
170+
# ---------- FPS parsing (best effort) ----------
146171
fps="-"
147172
fps_line="$(grep -E '([Ff][Pp][Ss]|frames per second|^fps:)' "$LOG_FILE" 2>/dev/null | tail -n 1)"
148173
if [ -n "$fps_line" ]; then
149-
# Extract last numeric token (integer or float)
150-
fps="$(printf '%s\n' "$fps_line" | awk '{
151-
for (i=NF;i>=1;i--) if ($i ~ /^[0-9]+(\.[0-9]+)?$/) {print $i; exit}
152-
}')"
174+
fps="$(printf '%s\n' "$fps_line" | awk '{ for (i=NF;i>=1;i--) if ($i ~ /^[0-9]+(\.[0-9]+)?$/) {print $i; exit} }')"
153175
[ -z "$fps" ] && fps="-"
154176
fi
155177

156-
# CI debugging summary
157178
log_info "Result summary: rc=$rc elapsed=${elapsed}s fps=${fps} (expected ~${EXPECT_FPS}+/-${FPS_TOL_PCT}%)"
158-
# Quick duration gate: must have run at least (DURATION-1) seconds to be considered OK.
179+
180+
# ---------- Gating ----------
159181
dur_s="$(printf '%s' "$DURATION" | sed -n 's/^\([0-9][0-9]*\)s$/\1/p')"
160182
[ -z "$dur_s" ] && dur_s="$DURATION"
161183
min_ok=$(( dur_s - 1 ))
162184
[ "$min_ok" -lt 0 ] && min_ok=0
163185

164186
final="PASS"
165187

188+
# Must have run ~DURATION seconds
166189
if [ "$elapsed" -lt "$min_ok" ]; then
167190
final="FAIL"
168191
log_fail "$TESTNAME : FAIL (exited after ${elapsed}s; expected ~${dur_s}s) — rc=$rc"
@@ -174,7 +197,6 @@ if [ "$final" = "PASS" ] && [ "$REQUIRE_FPS" -eq 1 ]; then
174197
final="FAIL"
175198
log_fail "$TESTNAME : FAIL (no FPS lines found but REQUIRE_FPS=1)"
176199
else
177-
# Integer-only tolerance check (portable)
178200
lo=$(( (EXPECT_FPS * (100 - FPS_TOL_PCT)) / 100 ))
179201
hi=$(( (EXPECT_FPS * (100 + FPS_TOL_PCT)) / 100 ))
180202
fps_int="$(printf '%s' "$fps" | cut -d. -f1)"
@@ -185,13 +207,21 @@ if [ "$final" = "PASS" ] && [ "$REQUIRE_FPS" -eq 1 ]; then
185207
fi
186208
fi
187209

210+
# ---------- Epilogue / exit codes ----------
188211
case "$final" in
189212
PASS)
190213
log_pass "$TESTNAME : PASS"
191214
echo "$TESTNAME PASS" > "$RES_FILE"
192215
exit 0
193216
;;
217+
SKIP)
218+
# (Not used here, but keeping consistent mapping)
219+
log_skip "$TESTNAME : SKIP"
220+
echo "$TESTNAME SKIP" > "$RES_FILE"
221+
exit 2
222+
;;
194223
*)
224+
log_fail "$TESTNAME : FAIL"
195225
echo "$TESTNAME FAIL" > "$RES_FILE"
196226
exit 1
197227
;;

0 commit comments

Comments
 (0)