|
| 1 | +#!/bin/sh |
| 2 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
| 3 | +# SPDX-License-Identifier: BSD-3-Clause-Clear |
| 4 | +# |
| 5 | +# Validate weston-flower runs under a working Wayland session. |
| 6 | +# - Wayland env resolution (adopts socket & fixes XDG_RUNTIME_DIR perms) |
| 7 | +# - Optional Wayland protocol validation via WAYLAND_DEBUG capture |
| 8 | +# - Optional screenshot-delta validation when tools and permissions allow |
| 9 | +# - CI-friendly PASS FAIL SKIP semantics, always exits 0 |
| 10 | + |
| 11 | +# ---------- Source init_env and functestlib ---------- |
| 12 | +SCRIPT_DIR="$( |
| 13 | + cd "$(dirname "$0")" || exit 1 |
| 14 | + pwd |
| 15 | +)" |
| 16 | +INIT_ENV="" |
| 17 | +SEARCH="$SCRIPT_DIR" |
| 18 | + |
| 19 | +while [ "$SEARCH" != "/" ]; do |
| 20 | + if [ -f "$SEARCH/init_env" ]; then |
| 21 | + INIT_ENV="$SEARCH/init_env" |
| 22 | + break |
| 23 | + fi |
| 24 | + SEARCH=$(dirname "$SEARCH") |
| 25 | +done |
| 26 | + |
| 27 | +if [ -z "$INIT_ENV" ]; then |
| 28 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +if [ -z "${__INIT_ENV_LOADED:-}" ]; then |
| 33 | + # shellcheck disable=SC1090 |
| 34 | + . "$INIT_ENV" |
| 35 | + __INIT_ENV_LOADED=1 |
| 36 | +fi |
| 37 | + |
| 38 | +# shellcheck disable=SC1091 |
| 39 | +. "$TOOLS/functestlib.sh" |
| 40 | +# shellcheck disable=SC1091 |
| 41 | +. "$TOOLS/lib_display.sh" |
| 42 | + |
| 43 | +TESTNAME="weston-flower" |
| 44 | +RES_FILE="./${TESTNAME}.res" |
| 45 | +RUN_LOG="./${TESTNAME}_run.log" |
| 46 | +ts="$(date +%Y%m%d-%H%M%S 2>/dev/null || printf '%s' 0)" |
| 47 | +STDOUT_LOG="./${TESTNAME}_stdout_${ts}.log" |
| 48 | + |
| 49 | +: >"$RES_FILE" |
| 50 | +: >"$RUN_LOG" |
| 51 | +: >"$STDOUT_LOG" |
| 52 | + |
| 53 | +# --------------------------------------------------------------------------- |
| 54 | +# Config |
| 55 | +# --------------------------------------------------------------------------- |
| 56 | +DURATION="${DURATION:-30s}" |
| 57 | +STOP_GRACE="${STOP_GRACE:-3s}" |
| 58 | +VALIDATE_WAYLAND_PROTO="${VALIDATE_WAYLAND_PROTO:-1}" |
| 59 | +VALIDATE_SCREENSHOT="${VALIDATE_SCREENSHOT:-0}" |
| 60 | + |
| 61 | +BUILD_FLAVOUR="base" |
| 62 | +if [ -f /usr/share/glvnd/egl_vendor.d/EGL_adreno.json ]; then |
| 63 | + BUILD_FLAVOUR="overlay" |
| 64 | +fi |
| 65 | + |
| 66 | +log_info "Weston log directory: $SCRIPT_DIR" |
| 67 | +log_info "--------------------------------------------------------------------------" |
| 68 | +log_info "------------------- Starting ${TESTNAME} Testcase --------------------------" |
| 69 | +log_info "Config: DURATION=${DURATION} VALIDATE_WAYLAND_PROTO=${VALIDATE_WAYLAND_PROTO} VALIDATE_SCREENSHOT=${VALIDATE_SCREENSHOT} BUILD_FLAVOUR=${BUILD_FLAVOUR}" |
| 70 | + |
| 71 | +if command -v detect_platform >/dev/null 2>&1; then |
| 72 | + detect_platform |
| 73 | +fi |
| 74 | + |
| 75 | +# --------------------------------------------------------------------------- |
| 76 | +# Display snapshot |
| 77 | +# --------------------------------------------------------------------------- |
| 78 | +if command -v display_debug_snapshot >/dev/null 2>&1; then |
| 79 | + display_debug_snapshot "pre-display-check" |
| 80 | +fi |
| 81 | + |
| 82 | +if command -v modetest >/dev/null 2>&1; then |
| 83 | + log_info "----- modetest -M msm -ac (capped at 200 lines) -----" |
| 84 | + modetest -M msm -ac 2>&1 | sed -n '1,200p' | while IFS= read -r l; do |
| 85 | + [ -n "$l" ] && log_info "[modetest] $l" |
| 86 | + done |
| 87 | + log_info "----- End modetest -M msm -ac -----" |
| 88 | +else |
| 89 | + log_warn "modetest not found in PATH skipping modetest snapshot." |
| 90 | +fi |
| 91 | + |
| 92 | +have_connector=0 |
| 93 | +if command -v display_connected_summary >/dev/null 2>&1; then |
| 94 | + sysfs_summary=$(display_connected_summary) |
| 95 | + if [ -n "$sysfs_summary" ] && [ "$sysfs_summary" != "none" ]; then |
| 96 | + have_connector=1 |
| 97 | + log_info "Connected display (sysfs): $sysfs_summary" |
| 98 | + fi |
| 99 | +fi |
| 100 | + |
| 101 | +if [ "$have_connector" -eq 0 ]; then |
| 102 | + log_warn "No connected DRM display found skipping ${TESTNAME}." |
| 103 | + echo "${TESTNAME} SKIP" >"$RES_FILE" |
| 104 | + exit 0 |
| 105 | +fi |
| 106 | + |
| 107 | +# --------------------------------------------------------------------------- |
| 108 | +# Wayland / Weston environment |
| 109 | +# --------------------------------------------------------------------------- |
| 110 | +if command -v wayland_debug_snapshot >/dev/null 2>&1; then |
| 111 | + wayland_debug_snapshot "${TESTNAME}: start" |
| 112 | +fi |
| 113 | + |
| 114 | +sock="" |
| 115 | + |
| 116 | +if command -v discover_wayland_socket_anywhere >/dev/null 2>&1; then |
| 117 | + sock=$(discover_wayland_socket_anywhere | head -n 1 || true) |
| 118 | +fi |
| 119 | + |
| 120 | +if [ -n "$sock" ] && command -v adopt_wayland_env_from_socket >/dev/null 2>&1; then |
| 121 | + log_info "Found existing Wayland socket: $sock" |
| 122 | + if ! adopt_wayland_env_from_socket "$sock"; then |
| 123 | + log_warn "Failed to adopt env from $sock" |
| 124 | + fi |
| 125 | +fi |
| 126 | + |
| 127 | +if [ -z "$sock" ] && command -v overlay_start_weston_drm >/dev/null 2>&1; then |
| 128 | + log_info "No usable Wayland socket trying overlay_start_weston_drm helper..." |
| 129 | + if command -v weston_force_primary_1080p60_if_not_60 >/dev/null 2>&1; then |
| 130 | + log_info "Pre-configuring primary output to ~60Hz before starting Weston best-effort" |
| 131 | + weston_force_primary_1080p60_if_not_60 || true |
| 132 | + fi |
| 133 | + if overlay_start_weston_drm; then |
| 134 | + if command -v discover_wayland_socket_anywhere >/dev/null 2>&1; then |
| 135 | + sock=$(discover_wayland_socket_anywhere | head -n 1 || true) |
| 136 | + fi |
| 137 | + if [ -n "$sock" ] && command -v adopt_wayland_env_from_socket >/dev/null 2>&1; then |
| 138 | + log_info "Overlay Weston created Wayland socket: $sock" |
| 139 | + if ! adopt_wayland_env_from_socket "$sock"; then |
| 140 | + log_warn "Failed to adopt env from $sock" |
| 141 | + fi |
| 142 | + else |
| 143 | + log_warn "overlay_start_weston_drm reported success but no Wayland socket was found." |
| 144 | + fi |
| 145 | + else |
| 146 | + log_warn "overlay_start_weston_drm returned non-zero private Weston may have failed to start." |
| 147 | + fi |
| 148 | +fi |
| 149 | + |
| 150 | +if [ -z "$sock" ]; then |
| 151 | + log_warn "No Wayland socket found after autodetection skipping ${TESTNAME}." |
| 152 | + echo "${TESTNAME} SKIP" >"$RES_FILE" |
| 153 | + exit 0 |
| 154 | +fi |
| 155 | + |
| 156 | +if command -v wayland_connection_ok >/dev/null 2>&1; then |
| 157 | + if ! wayland_connection_ok; then |
| 158 | + log_fail "Wayland connection test failed cannot run ${TESTNAME}." |
| 159 | + echo "${TESTNAME} SKIP" >"$RES_FILE" |
| 160 | + exit 0 |
| 161 | + fi |
| 162 | + log_info "Wayland connection test: OK" |
| 163 | +else |
| 164 | + log_warn "wayland_connection_ok helper not found continuing without explicit Wayland probe." |
| 165 | +fi |
| 166 | + |
| 167 | +# --------------------------------------------------------------------------- |
| 168 | +# Ensure primary output is ~60Hz best-effort |
| 169 | +# --------------------------------------------------------------------------- |
| 170 | +if command -v weston_force_primary_1080p60_if_not_60 >/dev/null 2>&1; then |
| 171 | + log_info "Ensuring primary output is ~60Hz best-effort" |
| 172 | + if weston_force_primary_1080p60_if_not_60; then |
| 173 | + log_info "Primary output is ~60Hz or was already ~60Hz." |
| 174 | + else |
| 175 | + log_warn "Unable to force ~60Hz continuing not a hard failure." |
| 176 | + fi |
| 177 | +else |
| 178 | + log_warn "weston_force_primary_1080p60_if_not_60 helper not found skipping ~60Hz enforcement." |
| 179 | +fi |
| 180 | + |
| 181 | +# --- Skip if CPU/software renderer is active --- |
| 182 | +if command -v display_is_cpu_renderer >/dev/null 2>&1; then |
| 183 | + if display_is_cpu_renderer auto; then |
| 184 | + log_skip "$TESTNAME SKIP: GPU HW acceleration not enabled CPU/software renderer detected" |
| 185 | + echo "${TESTNAME} SKIP" >"$RES_FILE" |
| 186 | + exit 0 |
| 187 | + fi |
| 188 | +else |
| 189 | + log_warn "display_is_cpu_renderer helper not found continuing without GPU accel gating." |
| 190 | +fi |
| 191 | + |
| 192 | +# --------------------------------------------------------------------------- |
| 193 | +# Binary |
| 194 | +# --------------------------------------------------------------------------- |
| 195 | +if ! check_dependencies weston-flower; then |
| 196 | + log_fail "Required binary weston-flower not found in PATH." |
| 197 | + echo "${TESTNAME} FAIL" >"$RES_FILE" |
| 198 | + exit 0 |
| 199 | +fi |
| 200 | + |
| 201 | +BIN=$(command -v weston-flower) |
| 202 | +log_info "Using weston-flower: $BIN" |
| 203 | + |
| 204 | +# --------------------------------------------------------------------------- |
| 205 | +# Optional screenshot delta begin |
| 206 | +# --------------------------------------------------------------------------- |
| 207 | +shot_begin_rc=2 |
| 208 | +if [ "$VALIDATE_SCREENSHOT" -ne 0 ]; then |
| 209 | + log_info "Screenshot delta validation enabled." |
| 210 | + if command -v display_screenshot_delta_begin >/dev/null 2>&1; then |
| 211 | + display_screenshot_delta_begin "$TESTNAME" "$SCRIPT_DIR" >>"$STDOUT_LOG" 2>&1 |
| 212 | + shot_begin_rc=$? |
| 213 | + if [ "$shot_begin_rc" -eq 2 ]; then |
| 214 | + log_warn "Screenshot delta requested, tool unavailable or unauthorized skipping screenshot validation." |
| 215 | + elif [ "$shot_begin_rc" -ne 0 ]; then |
| 216 | + log_warn "Screenshot delta requested, unable to capture before screenshot." |
| 217 | + fi |
| 218 | + else |
| 219 | + log_warn "display_screenshot_delta_begin helper not found skipping screenshot validation." |
| 220 | + shot_begin_rc=2 |
| 221 | + fi |
| 222 | +fi |
| 223 | + |
| 224 | +# --------------------------------------------------------------------------- |
| 225 | +# Run client with timeout |
| 226 | +# - If VALIDATE_WAYLAND_PROTO=1 capture WAYLAND_DEBUG into RUN_LOG |
| 227 | +# --------------------------------------------------------------------------- |
| 228 | +log_info "Launching ${TESTNAME} for ${DURATION} ..." |
| 229 | + |
| 230 | +start_ts=$(date +%s) |
| 231 | + |
| 232 | +rc=0 |
| 233 | +if [ "$VALIDATE_WAYLAND_PROTO" -ne 0 ]; then |
| 234 | + log_info "Wayland protocol validation enabled (WAYLAND_DEBUG=1)." |
| 235 | + WAYLAND_DEBUG=1 |
| 236 | + export WAYLAND_DEBUG |
| 237 | +else |
| 238 | + WAYLAND_DEBUG="" |
| 239 | + export WAYLAND_DEBUG |
| 240 | +fi |
| 241 | + |
| 242 | +if command -v run_with_timeout >/dev/null 2>&1; then |
| 243 | + if command -v stdbuf >/dev/null 2>&1; then |
| 244 | + if [ "$VALIDATE_WAYLAND_PROTO" -ne 0 ]; then |
| 245 | + run_with_timeout "$DURATION" stdbuf -oL -eL "$BIN" >>"$RUN_LOG" 2>&1 |
| 246 | + else |
| 247 | + run_with_timeout "$DURATION" stdbuf -oL -eL "$BIN" >>"$STDOUT_LOG" 2>&1 |
| 248 | + fi |
| 249 | + else |
| 250 | + log_warn "stdbuf not found running $BIN without output re-buffering." |
| 251 | + if [ "$VALIDATE_WAYLAND_PROTO" -ne 0 ]; then |
| 252 | + run_with_timeout "$DURATION" "$BIN" >>"$RUN_LOG" 2>&1 |
| 253 | + else |
| 254 | + run_with_timeout "$DURATION" "$BIN" >>"$STDOUT_LOG" 2>&1 |
| 255 | + fi |
| 256 | + fi |
| 257 | + rc=$? |
| 258 | +else |
| 259 | + log_warn "run_with_timeout not found using naive sleep+kill fallback." |
| 260 | + if [ "$VALIDATE_WAYLAND_PROTO" -ne 0 ]; then |
| 261 | + "$BIN" >>"$RUN_LOG" 2>&1 & |
| 262 | + else |
| 263 | + "$BIN" >>"$STDOUT_LOG" 2>&1 & |
| 264 | + fi |
| 265 | + cpid=$! |
| 266 | + dur_s=$(printf '%s\n' "$DURATION" | sed -n 's/^\([0-9][0-9]*\)s$/\1/p') |
| 267 | + [ -n "$dur_s" ] || dur_s=30 |
| 268 | + sleep "$dur_s" |
| 269 | + kill "$cpid" 2>/dev/null || true |
| 270 | + rc=143 |
| 271 | +fi |
| 272 | + |
| 273 | +end_ts=$(date +%s) |
| 274 | +elapsed=$((end_ts - start_ts)) |
| 275 | + |
| 276 | +log_info "Client finished: rc=${rc} elapsed=${elapsed}s" |
| 277 | + |
| 278 | +# --------------------------------------------------------------------------- |
| 279 | +# Validation |
| 280 | +# --------------------------------------------------------------------------- |
| 281 | +final="PASS" |
| 282 | + |
| 283 | +# Exit code: accept 0 and 143 as non-fatal here |
| 284 | +if [ "$rc" -ne 0 ] && [ "$rc" -ne 143 ]; then |
| 285 | + final="FAIL" |
| 286 | +fi |
| 287 | + |
| 288 | +# Duration sanity |
| 289 | +if [ "$elapsed" -le 1 ]; then |
| 290 | + log_fail "Client exited too quickly (elapsed=${elapsed}s) expected ~${DURATION} runtime." |
| 291 | + final="FAIL" |
| 292 | +fi |
| 293 | + |
| 294 | +# Wayland protocol validation |
| 295 | +if [ "$VALIDATE_WAYLAND_PROTO" -ne 0 ]; then |
| 296 | + if command -v display_wayland_proto_validate >/dev/null 2>&1; then |
| 297 | + if display_wayland_proto_validate "$RUN_LOG"; then |
| 298 | + log_info "Wayland protocol validation passed." |
| 299 | + else |
| 300 | + log_fail "Wayland protocol validation failed missing surface/commit evidence in WAYLAND_DEBUG" |
| 301 | + final="FAIL" |
| 302 | + fi |
| 303 | + else |
| 304 | + log_warn "display_wayland_proto_validate helper not found skipping protocol validation." |
| 305 | + fi |
| 306 | +fi |
| 307 | + |
| 308 | +# Screenshot delta end |
| 309 | +if [ "$VALIDATE_SCREENSHOT" -ne 0 ]; then |
| 310 | + if [ "$shot_begin_rc" -eq 0 ]; then |
| 311 | + if command -v display_screenshot_delta_end >/dev/null 2>&1; then |
| 312 | + display_screenshot_delta_end "$TESTNAME" >>"$STDOUT_LOG" 2>&1 |
| 313 | + src=$? |
| 314 | + if [ "$src" -eq 0 ]; then |
| 315 | + log_info "Screenshot delta validation passed." |
| 316 | + elif [ "$src" -eq 1 ]; then |
| 317 | + log_fail "Screenshot delta validation failed screenshots identical." |
| 318 | + final="FAIL" |
| 319 | + else |
| 320 | + log_warn "Screenshot delta validation skipped." |
| 321 | + fi |
| 322 | + else |
| 323 | + log_warn "display_screenshot_delta_end helper not found skipping screenshot validation." |
| 324 | + fi |
| 325 | + else |
| 326 | + log_warn "Screenshot delta validation skipped, before screenshot was not captured." |
| 327 | + fi |
| 328 | +fi |
| 329 | + |
| 330 | +log_info "Final decision for ${TESTNAME}: ${final}" |
| 331 | + |
| 332 | +# --------------------------------------------------------------------------- |
| 333 | +# Emit result & exit |
| 334 | +# --------------------------------------------------------------------------- |
| 335 | +echo "${TESTNAME} ${final}" >"$RES_FILE" |
| 336 | + |
| 337 | +if [ "$final" = "PASS" ]; then |
| 338 | + log_pass "${TESTNAME} : PASS" |
| 339 | + exit 0 |
| 340 | +fi |
| 341 | + |
| 342 | +log_fail "${TESTNAME} : FAIL" |
| 343 | +exit 0 |
0 commit comments