Skip to content

Commit 709fcd7

Browse files
committed
functestlib: improve Wayland/Weston helpers for socket discovery and env adoption
Add/strengthen weston_is_running and connection probe utilities Ensure XDG_RUNTIME_DIR creation/permissions handling for private Weston sessions Standardize restart/start flows via weston_pick_env_or_start / overlay start helpers Improve logging and resilience for CI runs without introducing new bashisms Signed-off-by: Srikanth Muppandam <smuppand@qti.qualcomm.com>
1 parent 12c66e4 commit 709fcd7

File tree

1 file changed

+104
-90
lines changed

1 file changed

+104
-90
lines changed

Runner/utils/functestlib.sh

Lines changed: 104 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,28 +1303,41 @@ ensure_wayland_runtime_dir_perms() {
13031303
# Prefers `wayland-info` with a short timeout; otherwise validates socket presence.
13041304
# Also enforces/fixes XDG_RUNTIME_DIR permissions so clients won’t reject it.
13051305
wayland_connection_ok() {
1306+
sock=""
1307+
13061308
# Sanity-check the socket path first.
13071309
if [ -z "$XDG_RUNTIME_DIR" ] || [ -z "$WAYLAND_DISPLAY" ]; then
13081310
log_warn "wayland_connection_ok: XDG_RUNTIME_DIR or WAYLAND_DISPLAY not set"
1309-
elif [ ! -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]; then
1310-
log_warn "wayland_connection_ok: no Wayland socket at $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
1311-
return 1
13121311
else
1313-
log_info "wayland_connection_ok: using socket $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
1312+
sock="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY"
1313+
if [ ! -S "$sock" ]; then
1314+
log_warn "wayland_connection_ok: no Wayland socket at $sock"
1315+
return 1
1316+
fi
1317+
log_info "wayland_connection_ok: using socket $sock"
13141318
fi
1315-
1319+
13161320
if command -v wayland-info >/dev/null 2>&1; then
13171321
log_info "Probing Wayland with: wayland-info"
1318-
wayland-info >/dev/null 2>&1 && return 0
1322+
wayland-info >/dev/null 2>&1
1323+
rc=$?
1324+
[ "$rc" -eq 0 ] && return 0
1325+
# Accept common “killed by timeout/signal” cases as OK (best-effort probe)
1326+
[ "$rc" -eq 143 ] && return 0
1327+
[ "$rc" -eq 124 ] && return 0
13191328
return 1
13201329
fi
1321-
1330+
13221331
if command -v weston-info >/dev/null 2>&1; then
13231332
log_info "Probing Wayland with: weston-info"
1324-
weston-info >/dev/null 2>&1 && return 0
1333+
weston-info >/dev/null 2>&1
1334+
rc=$?
1335+
[ "$rc" -eq 0 ] && return 0
1336+
[ "$rc" -eq 143 ] && return 0
1337+
[ "$rc" -eq 124 ] && return 0
13251338
return 1
13261339
fi
1327-
1340+
13281341
if command -v weston-simple-egl >/dev/null 2>&1; then
13291342
log_info "Probing Wayland by briefly starting weston-simple-egl"
13301343
(
@@ -1333,27 +1346,26 @@ wayland_connection_ok() {
13331346
)
13341347
pid="$(cat "/tmp/.wsegl.$$" 2>/dev/null || echo '')"
13351348
rm -f "/tmp/.wsegl.$$" 2>/dev/null || true
1336-
1349+
13371350
i=0
13381351
while [ "$i" -lt 2 ]; do
13391352
sleep 1
13401353
i=$((i + 1))
13411354
done
1342-
1355+
13431356
if [ -n "$pid" ]; then
13441357
kill "$pid" 2>/dev/null || true
13451358
fi
13461359
# If it started at all, consider the connection OK (best effort).
13471360
return 0
13481361
fi
1349-
1362+
13501363
# Last resort: trust socket existence alone.
1351-
if [ -n "$XDG_RUNTIME_DIR" ] && [ -n "$WAYLAND_DISPLAY" ] &&
1352-
[ -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ]; then
1364+
if [ -n "$sock" ] && [ -S "$sock" ]; then
13531365
log_info "No probe tools present; accepting socket existence as OK."
13541366
return 0
13551367
fi
1356-
1368+
13571369
return 1
13581370
}
13591371
# Very verbose snapshot for debugging (processes, sockets, env, perms).
@@ -1422,6 +1434,63 @@ print_path_meta() {
14221434
###############################################################################
14231435
# DRM / Display helpers (portable, minimal-build friendly)
14241436
###############################################################################
1437+
# Best-effort: return current mode for a DRM connector using debugfs state.
1438+
# Input : full connector name like "card0-HDMI-A-1"
1439+
# Output: "1920x1080@60.00" (or "1920x1080@60") or "-" if unknown/unavailable
1440+
display_connector_cur_mode() {
1441+
full="$1"
1442+
[ -n "$full" ] || { echo "-"; return; }
1443+
1444+
card="${full%%-*}" # card0
1445+
con="${full#*-}" # HDMI-A-1
1446+
idx="${card#card}" # 0
1447+
1448+
state="/sys/kernel/debug/dri/${idx}/state"
1449+
1450+
# debugfs may not be mounted; best-effort mount (ignore failures)
1451+
if [ ! -r "$state" ] && [ -r /proc/mounts ] && command -v mount >/dev/null 2>&1; then
1452+
if ! grep -q " /sys/kernel/debug " /proc/mounts 2>/dev/null; then
1453+
mount -t debugfs debugfs /sys/kernel/debug 2>/dev/null || true
1454+
fi
1455+
fi
1456+
1457+
[ -r "$state" ] || { echo "-"; return; }
1458+
1459+
awk -v CON="$con" '
1460+
BEGIN { crtc=""; in_conn=0; in_crtc=0; mode=""; vr=""; active="" }
1461+
1462+
# Connector block -> capture bound CRTC id
1463+
$0 ~ /^connector/ {
1464+
in_conn=0
1465+
if ($0 ~ CON) in_conn=1
1466+
}
1467+
in_conn && $0 ~ /crtc/ {
1468+
if (match($0, /[0-9]+/, m)) crtc=m[0]
1469+
}
1470+
in_conn && $0 ~ /^$/ { in_conn=0 }
1471+
1472+
# CRTC block -> capture active + mode + refresh
1473+
crtc != "" && $0 ~ /^crtc/ {
1474+
in_crtc=0
1475+
if ($0 ~ ("crtc " crtc)) in_crtc=1
1476+
}
1477+
in_crtc && $0 ~ /active/ {
1478+
if ($0 ~ /(yes|true|1)/) active="1"
1479+
}
1480+
in_crtc && $0 ~ /mode/ {
1481+
if (match($0, /[0-9]+x[0-9]+/, m)) mode=m[0]
1482+
}
1483+
in_crtc && ($0 ~ /vrefresh/ || $0 ~ /refresh/) {
1484+
if (match($0, /[0-9]+(\.[0-9]+)?/, m)) vr=m[0]
1485+
}
1486+
in_crtc && $0 ~ /^$/ { in_crtc=0 }
1487+
1488+
END {
1489+
if (crtc == "" || mode == "" || active != "1") { print "-"; exit }
1490+
if (vr != "") print mode "@" vr
1491+
else print mode
1492+
}' "$state" 2>/dev/null || echo "-"
1493+
}
14251494

14261495
# Echo lines: "<name>\t<status>\t<type>\t<modes>\t<first_mode>"
14271496
# Example: "card0-HDMI-A-1 connected HDMI-A 9 1920x1080"
@@ -1433,31 +1502,42 @@ display_list_connectors() {
14331502
name="$(basename "$d")"
14341503
status="$(tr -d '\r\n' <"$d/status" 2>/dev/null)"
14351504

1505+
# enabled (best-effort; may not exist on some kernels)
1506+
enabled="unknown"
1507+
if [ -f "$d/enabled" ]; then
1508+
enabled="$(tr -d '\r\n' <"$d/enabled" 2>/dev/null)"
1509+
[ -z "$enabled" ] && enabled="unknown"
1510+
fi
1511+
14361512
# Derive connector type from name: cardX-<TYPE>-N
1437-
# Strip "cardN-" prefix and trailing "-N" index.
14381513
typ="$(printf '%s' "$name" \
14391514
| sed -n 's/^card[0-9]\+-\([A-Za-z0-9+]\+\(-[A-Za-z0-9+]\+\)*\)-[0-9]\+/\1/p')"
14401515
[ -z "$typ" ] && typ="unknown"
14411516

14421517
# Modes
14431518
modes_file="$d/modes"
14441519
if [ -f "$modes_file" ]; then
1445-
# wc output can have spaces on BusyBox; trim
14461520
mc="$(wc -l <"$modes_file" 2>/dev/null | tr -d '[:space:]')"
14471521
[ -z "$mc" ] && mc=0
14481522
fm="$(head -n 1 "$modes_file" 2>/dev/null | tr -d '\r\n')"
1523+
[ -z "$fm" ] && fm="<none>"
14491524
else
14501525
mc=0
1451-
fm=""
1526+
fm="<none>"
14521527
fi
14531528

1454-
printf '%s\t%s\t%s\t%s\t%s\n' "$name" "$status" "$typ" "$mc" "$fm"
1529+
# Current mode (best-effort via debugfs helper)
1530+
cur="$(display_connector_cur_mode "$name")"
1531+
[ -z "$cur" ] && cur="-"
1532+
1533+
# NOTE: 7 columns: name status enabled typ mc fm cur
1534+
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\n' \
1535+
"$name" "$status" "$enabled" "$typ" "$mc" "$fm" "$cur"
14551536
found=1
14561537
done
14571538
[ "$found" -eq 1 ] || return 1
14581539
return 0
14591540
}
1460-
14611541
# Return 0 if any connector is connected; else 1
14621542
display_any_attached() {
14631543
for d in /sys/class/drm/*-*; do
@@ -1539,85 +1619,19 @@ display_debug_snapshot() {
15391619
ctx="$1"
15401620
[ -z "$ctx" ] && ctx="display-snapshot"
15411621
log_info "----- Display snapshot: $ctx -----"
1542-
1543-
# DRM nodes (no ls; iterate)
1544-
nodes=""
1545-
for f in /dev/dri/card* /dev/dri/renderD*; do
1546-
if [ -e "$f" ]; then
1547-
if [ -z "$nodes" ]; then nodes="$f"; else nodes="$nodes $f"; fi
1548-
fi
1549-
done
1550-
if [ -n "$nodes" ]; then
1551-
log_info "DRM nodes: $nodes"
1552-
else
1553-
log_warn "No /dev/dri/* nodes found."
1554-
fi
1555-
1556-
# Connectors
1557-
have=0
1558-
# shellcheck disable=SC2039
1559-
while IFS="$(printf '\t')" read -r name status typ mc fm; do
1560-
have=1
1561-
if [ -n "$fm" ]; then
1562-
log_info "DRM: ${name} status=${status} type=${typ} modes=${mc} first=${fm}"
1563-
else
1564-
log_info "DRM: ${name} status=${status} type=${typ} modes=${mc}"
1565-
fi
1566-
done <<EOF
1567-
$(display_list_connectors 2>/dev/null || true)
1568-
EOF
1569-
[ "$have" -eq 1 ] || log_warn "No DRM connectors in /sys/class/drm."
1570-
1571-
# Summary + weston outputs (if any)
1572-
sum="$(display_connected_summary 2>/dev/null || echo none)"
1573-
log_info "Connected summary: $sum"
1574-
display_weston_outputs | while IFS= read -r l; do
1575-
[ -n "$l" ] && log_info "$l"
1576-
done
1577-
1578-
log_info "----- End display snapshot: $ctx -----"
1579-
}
1580-
1581-
display_debug_snapshot() {
1582-
ctx="$1"
1583-
[ -z "$ctx" ] && ctx="display-snapshot"
1584-
log_info "----- Display snapshot: $ctx -----"
1585-
1586-
# DRM nodes
1587-
nodes=""
1588-
for f in /dev/dri/card* /dev/dri/renderD*; do
1589-
[ -e "$f" ] && nodes="${nodes:+$nodes }$f"
1590-
done
1591-
if [ -n "$nodes" ]; then
1592-
log_info "DRM nodes: $nodes"
1593-
else
1594-
log_warn "No /dev/dri/* nodes found."
1595-
fi
15961622

1597-
# Sysfs connectors (expects display_list_connectors to print tab-separated fields)
15981623
have=0
1599-
while IFS="$(printf '\t')" read -r name status typ mc fm; do
1624+
while IFS="$(printf '\t')" read -r name status enabled typ mc fm cur; do
16001625
[ -n "$name" ] || continue
16011626
have=1
1602-
if [ -n "$fm" ]; then
1603-
log_info "DRM: ${name} status=${status} type=${typ} modes=${mc} first=${fm}"
1604-
else
1605-
log_info "DRM: ${name} status=${status} type=${typ} modes=${mc}"
1606-
fi
1627+
[ -z "$fm" ] && fm="<none>"
1628+
[ -z "$cur" ] && cur="-"
1629+
log_info "DRM: ${name} status=${status} enabled=${enabled} type=${typ} modes=${mc} first=${fm} cur=${cur}"
16071630
done <<EOF
16081631
$(display_list_connectors 2>/dev/null || true)
16091632
EOF
16101633
[ "$have" -eq 1 ] || log_warn "No DRM connectors in /sys/class/drm."
16111634

1612-
# Connected summary (sysfs)
1613-
sum="$(display_connected_summary 2>/dev/null || echo none)"
1614-
log_info "Connected summary (sysfs): $sum"
1615-
1616-
# Optional weston outputs (existing helper)
1617-
display_weston_outputs | while IFS= read -r l; do
1618-
[ -n "$l" ] && log_info "$l"
1619-
done
1620-
16211635
log_info "----- End display snapshot: $ctx -----"
16221636
}
16231637

0 commit comments

Comments
 (0)