|
1 | 1 | #!/bin/sh |
| 2 | +# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. |
2 | 3 | # SPDX-License-Identifier: BSD-3-Clause-Clear |
3 | | -# Description: Script to test the 'weston-simple-egl' Wayland client for 30 seconds and log the result. |
| 4 | +# 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) |
4 | 8 |
|
5 | | -# Robustly find and source init_env |
| 9 | +# ---------- Source init_env and functestlib ---------- |
6 | 10 | SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
7 | 11 | INIT_ENV="" |
8 | 12 | SEARCH="$SCRIPT_DIR" |
9 | 13 | while [ "$SEARCH" != "/" ]; do |
10 | | - if [ -f "$SEARCH/init_env" ]; then |
11 | | - INIT_ENV="$SEARCH/init_env" |
12 | | - break |
13 | | - fi |
14 | | - SEARCH=$(dirname "$SEARCH") |
| 14 | + if [ -f "$SEARCH/init_env" ]; then INIT_ENV="$SEARCH/init_env"; break; fi |
| 15 | + SEARCH=$(dirname "$SEARCH") |
15 | 16 | done |
16 | | - |
17 | 17 | if [ -z "$INIT_ENV" ]; then |
18 | | - echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
19 | | - exit 1 |
| 18 | + echo "[ERROR] Could not find init_env (starting at $SCRIPT_DIR)" >&2 |
| 19 | + exit 1 |
20 | 20 | fi |
21 | | - |
22 | | -# Only source if not already loaded (idempotent) |
23 | 21 | if [ -z "$__INIT_ENV_LOADED" ]; then |
24 | | - # shellcheck disable=SC1090 |
25 | | - . "$INIT_ENV" |
| 22 | + # shellcheck disable=SC1090 |
| 23 | + . "$INIT_ENV" |
26 | 24 | fi |
27 | | - |
28 | | -# Always source functestlib.sh, using $TOOLS exported by init_env |
29 | 25 | # shellcheck disable=SC1090,SC1091 |
30 | 26 | . "$TOOLS/functestlib.sh" |
31 | 27 |
|
32 | 28 | TESTNAME="weston-simple-egl" |
| 29 | +# Tunables (env override) |
| 30 | +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) |
| 33 | +FPS_TOL_PCT="${FPS_TOL_PCT:-10}" # +/- tolerance % |
| 34 | +REQUIRE_FPS="${REQUIRE_FPS:-0}" # 1=require FPS lines & threshold; 0=best effort |
33 | 35 |
|
34 | | -test_path=$(find_test_case_by_name "$TESTNAME") |
| 36 | +test_path="$(find_test_case_by_name "$TESTNAME" 2>/dev/null || echo "$SCRIPT_DIR")" |
35 | 37 | cd "$test_path" || exit 1 |
36 | 38 | RES_FILE="./$TESTNAME.res" |
37 | 39 | LOG_FILE="./${TESTNAME}_run.log" |
38 | 40 | rm -f "$RES_FILE" "$LOG_FILE" |
39 | 41 |
|
40 | 42 | log_info "--------------------------------------------------------------------------" |
41 | 43 | log_info "------------------- Starting $TESTNAME Testcase --------------------------" |
| 44 | +# FIX #1: Use ASCII '+/-' and keep it in a normal string |
| 45 | +log_info "Config: DURATION=$DURATION STOP_GRACE=$STOP_GRACE EXPECT_FPS=${EXPECT_FPS}+/-${FPS_TOL_PCT}% REQUIRE_FPS=$REQUIRE_FPS" |
| 46 | + |
| 47 | +# Dependencies |
| 48 | +check_dependencies weston-simple-egl || { |
| 49 | + log_fail "$TESTNAME : weston-simple-egl binary not found in PATH" |
| 50 | + echo "$TESTNAME SKIP" > "$RES_FILE" |
| 51 | + exit 0 |
| 52 | +} |
| 53 | +BIN="$(command -v weston-simple-egl 2>/dev/null || true)" |
| 54 | +log_info "Using weston-simple-egl: ${BIN:-<none>}" |
| 55 | + |
| 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 |
42 | 62 |
|
43 | | -# Only start if not already running |
44 | | -if ! weston_is_running; then |
| 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 |
| 68 | +fi |
| 69 | + |
| 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 |
45 | 75 | log_info "Weston not running. Attempting to start..." |
46 | 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 |
47 | 88 | fi |
48 | 89 |
|
49 | | -if check_dependencies weston-simple-egl; then |
50 | | - log_fail "$TESTNAME : weston-simple-egl binary not found" |
51 | | - echo "$TESTNAME SKIP" > "$RES_FILE" |
52 | | - exit 1 |
| 90 | +if [ -z "$sock" ]; then |
| 91 | + log_fail "$TESTNAME : FAIL (no Wayland socket found after attempting to start Weston)" |
| 92 | + echo "$TESTNAME FAIL" > "$RES_FILE" |
| 93 | + exit 1 |
| 94 | +fi |
| 95 | + |
| 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" |
| 103 | + |
| 104 | +if wayland_connection_ok; then |
| 105 | + log_info "Wayland connection test: OK (wayland-info/env)" |
| 106 | +else |
| 107 | + log_fail "$TESTNAME : FAIL (Wayland connection test failed)" |
| 108 | + print_path_meta "$XDG_RUNTIME_DIR" | sed 's/^/[DBG] /' |
| 109 | + stat "$XDG_RUNTIME_DIR" 2>/dev/null | sed 's/^/[DBG] /' || true |
| 110 | + echo "$TESTNAME FAIL" > "$RES_FILE" |
| 111 | + exit 1 |
53 | 112 | fi |
54 | 113 |
|
55 | | -XDG_RUNTIME_DIR="/dev/socket/weston" |
56 | | -WAYLAND_DISPLAY="wayland-1" |
57 | | -export XDG_RUNTIME_DIR WAYLAND_DISPLAY |
58 | | - |
59 | | -mkdir -p "$XDG_RUNTIME_DIR" |
60 | | -chmod 0700 "$XDG_RUNTIME_DIR" |
61 | | -log_info "Running weston-simple-egl for 30 seconds..." |
62 | | -script -q -c "weston-simple-egl" "$LOG_FILE" 2>/dev/null & |
63 | | -EGL_PID=$! |
64 | | -sleep 30 |
65 | | -kill "$EGL_PID" 2>/dev/null |
66 | | -wait "$EGL_PID" 2>/dev/null |
67 | | - |
68 | | -count=$(grep -i -o "5 seconds" "$LOG_FILE" | wc -l) |
69 | | -if [ "$count" -ge 5 ]; then |
70 | | - log_pass "$TESTNAME : Test Passed" |
| 114 | +# Try to enable FPS prints if supported by the client build (best effort). |
| 115 | +export SIMPLE_EGL_FPS=1 |
| 116 | +export WESTON_SIMPLE_EGL_FPS=1 |
| 117 | + |
| 118 | +# Run the client for DURATION with a stopwatch for CI logs. |
| 119 | +log_info "Running weston-simple-egl for $DURATION ..." |
| 120 | +start_ts="$(date +%s 2>/dev/null || echo 0)" |
| 121 | +if command -v run_with_timeout >/dev/null 2>&1; then |
| 122 | + run_with_timeout "$DURATION" weston-simple-egl >"$LOG_FILE" 2>&1 |
| 123 | + rc=$? |
| 124 | +else |
| 125 | + if command -v timeout >/dev/null 2>&1; then |
| 126 | + timeout "$DURATION" weston-simple-egl >"$LOG_FILE" 2>&1 |
| 127 | + rc=$? |
| 128 | + else |
| 129 | + # Last resort: background and sleep. |
| 130 | + sh -c 'weston-simple-egl' >"$LOG_FILE" 2>&1 & |
| 131 | + pid=$! |
| 132 | + # DURATION like "30s" → "30" |
| 133 | + dur_s="$(printf '%s' "$DURATION" | sed -n 's/^\([0-9][0-9]*\)s$/\1/p')" |
| 134 | + [ -z "$dur_s" ] && dur_s="$DURATION" |
| 135 | + sleep "$dur_s" |
| 136 | + kill "$pid" 2>/dev/null || true |
| 137 | + wait "$pid" 2>/dev/null || true |
| 138 | + rc=143 |
| 139 | + fi |
| 140 | +fi |
| 141 | +end_ts="$(date +%s 2>/dev/null || echo 0)" |
| 142 | +elapsed=$(( end_ts - start_ts )) |
| 143 | +[ "$elapsed" -lt 0 ] && elapsed=0 |
| 144 | + |
| 145 | +# FPS parsing (best effort) |
| 146 | +fps="-" |
| 147 | +fps_line="$(grep -E '([Ff][Pp][Ss]|frames per second|^fps:)' "$LOG_FILE" 2>/dev/null | tail -n 1)" |
| 148 | +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 | + }')" |
| 153 | + [ -z "$fps" ] && fps="-" |
| 154 | +fi |
| 155 | + |
| 156 | +# CI debugging summary |
| 157 | +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. |
| 159 | +dur_s="$(printf '%s' "$DURATION" | sed -n 's/^\([0-9][0-9]*\)s$/\1/p')" |
| 160 | +[ -z "$dur_s" ] && dur_s="$DURATION" |
| 161 | +min_ok=$(( dur_s - 1 )) |
| 162 | +[ "$min_ok" -lt 0 ] && min_ok=0 |
| 163 | + |
| 164 | +final="PASS" |
| 165 | + |
| 166 | +if [ "$elapsed" -lt "$min_ok" ]; then |
| 167 | + final="FAIL" |
| 168 | + log_fail "$TESTNAME : FAIL (exited after ${elapsed}s; expected ~${dur_s}s) — rc=$rc" |
| 169 | +fi |
| 170 | + |
| 171 | +# Optional FPS gate |
| 172 | +if [ "$final" = "PASS" ] && [ "$REQUIRE_FPS" -eq 1 ]; then |
| 173 | + if [ "$fps" = "-" ]; then |
| 174 | + final="FAIL" |
| 175 | + log_fail "$TESTNAME : FAIL (no FPS lines found but REQUIRE_FPS=1)" |
| 176 | + else |
| 177 | + # Integer-only tolerance check (portable) |
| 178 | + lo=$(( (EXPECT_FPS * (100 - FPS_TOL_PCT)) / 100 )) |
| 179 | + hi=$(( (EXPECT_FPS * (100 + FPS_TOL_PCT)) / 100 )) |
| 180 | + fps_int="$(printf '%s' "$fps" | cut -d. -f1)" |
| 181 | + if [ "$fps_int" -lt "$lo" ] || [ "$fps_int" -gt "$hi" ]; then |
| 182 | + final="FAIL" |
| 183 | + log_fail "$TESTNAME : FAIL (fps=$fps outside ${lo}-${hi})" |
| 184 | + fi |
| 185 | + fi |
| 186 | +fi |
| 187 | + |
| 188 | +case "$final" in |
| 189 | + PASS) |
| 190 | + log_pass "$TESTNAME : PASS" |
71 | 191 | echo "$TESTNAME PASS" > "$RES_FILE" |
72 | 192 | exit 0 |
73 | | -else |
74 | | - log_fail "$TESTNAME : Test Failed" |
| 193 | + ;; |
| 194 | + *) |
75 | 195 | echo "$TESTNAME FAIL" > "$RES_FILE" |
76 | 196 | exit 1 |
77 | | -fi |
78 | | - |
79 | | -log_info "------------------- Completed $TESTNAME Testcase ------------------------" |
80 | | -exit 0 |
| 197 | + ;; |
| 198 | +esac |
0 commit comments