Skip to content

Commit 1605411

Browse files
authored
Merge pull request #302 from smuppand/remoteproc
fix(remoteproc): make SSR optional across remoteproc tests to avoid wedge and harden CLI parsing
2 parents bfff3e0 + 6afc03e commit 1605411

4 files changed

Lines changed: 441 additions & 166 deletions

File tree

Runner/suites/Kernel/Baseport/adsp_remoteproc/run.sh

Lines changed: 137 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/sh
22
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
3-
# SPDX-License-Identifier: BSD-3-Clause# Robustly find and source init_env
3+
# SPDX-License-Identifier: BSD-3-Clause
4+
5+
# Robustly find and source init_env
46
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
7+
58
INIT_ENV=""
69
SEARCH="$SCRIPT_DIR"
710
while [ "$SEARCH" != "/" ]; do
@@ -22,6 +25,7 @@ if [ -z "$__INIT_ENV_LOADED" ]; then
2225
# shellcheck disable=SC1090
2326
. "$INIT_ENV"
2427
fi
28+
2529
# Always source functestlib.sh, using $TOOLS exported by init_env
2630
# shellcheck disable=SC1090,SC1091
2731
. "$TOOLS/functestlib.sh"
@@ -44,7 +48,80 @@ POLL_I="${POLL_I:-1}" # state poll interval (s)
4448
PRE_STOP_DELAY="${PRE_STOP_DELAY:-30}" # FIXED delay before stopping ADSP (seconds)
4549
FATAL_ON_UNSUSPENDED="${FATAL_ON_UNSUSPENDED:-0}" # 1 = abort if audio not suspended/unsupported after delay
4650

51+
# --- CLI ----------------------------------------------------------------------
52+
# Default: do NOT do SSR (stop/start). Enable explicitly with --ssr
53+
DO_SSR=0
54+
55+
usage() {
56+
echo "Usage: $0 [--ssr] [--pre-stop-delay SEC] [--fatal-on-unsuspended] [--stop-to SEC] [--start-to SEC] [--poll-i SEC]" >&2
57+
echo " --ssr Perform ADSP stop/start (SSR). Default: OFF" >&2
58+
echo " --pre-stop-delay SEC Delay before stop when --ssr is used (default: $PRE_STOP_DELAY)" >&2
59+
echo " --fatal-on-unsuspended Abort if audio not suspended/unsupported after delay (only meaningful with --ssr)" >&2
60+
echo " --stop-to SEC Stop timeout (default: $STOP_TO)" >&2
61+
echo " --start-to SEC Start timeout (default: $START_TO)" >&2
62+
echo " --poll-i SEC Poll interval (default: $POLL_I)" >&2
63+
}
64+
65+
while [ $# -gt 0 ]; do
66+
case "$1" in
67+
--ssr)
68+
DO_SSR=1
69+
shift
70+
;;
71+
--pre-stop-delay)
72+
if [ $# -lt 2 ]; then
73+
log_fail "Missing value for --pre-stop-delay"
74+
usage
75+
exit 2
76+
fi
77+
PRE_STOP_DELAY="$2"
78+
shift 2
79+
;;
80+
--fatal-on-unsuspended)
81+
FATAL_ON_UNSUSPENDED=1
82+
shift
83+
;;
84+
--stop-to)
85+
if [ $# -lt 2 ]; then
86+
log_fail "Missing value for --stop-to"
87+
usage
88+
exit 2
89+
fi
90+
STOP_TO="$2"
91+
shift 2
92+
;;
93+
--start-to)
94+
if [ $# -lt 2 ]; then
95+
log_fail "Missing value for --start-to"
96+
usage
97+
exit 2
98+
fi
99+
START_TO="$2"
100+
shift 2
101+
;;
102+
--poll-i)
103+
if [ $# -lt 2 ]; then
104+
log_fail "Missing value for --poll-i"
105+
usage
106+
exit 2
107+
fi
108+
POLL_I="$2"
109+
shift 2
110+
;;
111+
-h|--help)
112+
usage
113+
exit 0
114+
;;
115+
*)
116+
log_warn "Unknown argument: $1"
117+
usage
118+
exit 2
119+
;;
120+
esac
121+
done
122+
47123
log_info "Tunables: STOP_TO=$STOP_TO START_TO=$START_TO POLL_I=$POLL_I PRE_STOP_DELAY=$PRE_STOP_DELAY FATAL_ON_UNSUSPENDED=$FATAL_ON_UNSUSPENDED"
124+
log_info "SSR control: DO_SSR=$DO_SSR (0=no stop/start, 1=do stop/start)"
48125

49126
# --- Audio readiness snapshot (no hardcoding, no long wait) -------------------
50127
# Discovers a bound snd*/snd-soc* driver, logs module once, collects nodes to check.
@@ -58,7 +135,6 @@ discover_audio_stack_and_snapshot() {
58135

59136
platform_drv=""
60137
platform_mod=""
61-
62138
for drvdir in "$DRIVERS_BASE"/snd-* "$DRIVERS_BASE"/snd-soc-*; do
63139
[ -d "$drvdir" ] || continue
64140
[ -L "$drvdir/sound" ] || continue
@@ -91,17 +167,16 @@ discover_audio_stack_and_snapshot() {
91167
fi
92168

93169
log_info "Using bound audio driver: $platform_drv${platform_mod:+ (module: $platform_mod)}"
94-
95170
TARGET_PATH="$DRIVERS_BASE/$platform_drv/sound"
96171

97172
# 1) Platform sound root + immediate children (collect runtime_status files)
98173
if [ -d "$TARGET_PATH" ]; then
99174
_rt_nodes_list="$(mktemp)"
100175
find "$TARGET_PATH" -maxdepth 2 -type f -path "*/power/runtime_status" \
101-
-exec printf '%s\n' {} \; 2>/dev/null > "$_rt_nodes_list"
176+
-exec printf '%s\n' {} \; 2>/dev/null >"$_rt_nodes_list"
102177
while IFS= read -r f; do
103178
[ -n "$f" ] && CHECK_NODES="$CHECK_NODES $f"
104-
done < "$_rt_nodes_list"
179+
done <"$_rt_nodes_list"
105180
rm -f "$_rt_nodes_list"
106181
fi
107182

@@ -196,69 +271,72 @@ while IFS='|' read -r rpath rstate rfirm rname; do
196271
log_fail "$inst_id: boot check FAIL (state=$rstate)"
197272
boot_res="FAIL"
198273
inst_fail=$((inst_fail + 1))
199-
RESULT_LINES="$RESULT_LINES
200-
$inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
274+
RESULT_LINES="$RESULT_LINES $inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
201275
continue
202276
fi
203277

204-
# ---- Fixed pre-stop delay (always wait PRE_STOP_DELAY seconds) -----------
205-
log_info "$inst_id: waiting ${PRE_STOP_DELAY}s before remoteproc stop (fixed delay)"
206-
[ "$PRE_STOP_DELAY" -gt 0 ] && sleep "$PRE_STOP_DELAY"
207-
208-
# Optional gating: after the fixed delay, ensure PM is OK before stopping
209-
if [ "$FATAL_ON_UNSUSPENDED" -eq 1 ]; then
210-
if [ "$(audio_pm_snapshot_ok)" -ne 1 ]; then
211-
log_fail "Audio not in suspended/unsupported state after ${PRE_STOP_DELAY}s (FATAL_ON_UNSUSPENDED=1); aborting before stop"
212-
log_info "Writing to file $RES_FILE"
213-
echo "$TESTNAME FAIL" >"$RES_FILE"
214-
exit 1
278+
if [ "$DO_SSR" -eq 1 ]; then
279+
# ---- Fixed pre-stop delay (always wait PRE_STOP_DELAY seconds) -----------
280+
log_info "$inst_id: waiting ${PRE_STOP_DELAY}s before remoteproc stop (fixed delay)"
281+
[ "$PRE_STOP_DELAY" -gt 0 ] && sleep "$PRE_STOP_DELAY"
282+
283+
# Optional gating: after the fixed delay, ensure PM is OK before stopping
284+
if [ "$FATAL_ON_UNSUSPENDED" -eq 1 ]; then
285+
if [ "$(audio_pm_snapshot_ok)" -ne 1 ]; then
286+
log_fail "Audio not in suspended/unsupported state after ${PRE_STOP_DELAY}s (FATAL_ON_UNSUSPENDED=1); aborting before stop"
287+
log_info "Writing to file $RES_FILE"
288+
echo "$TESTNAME FAIL" >"$RES_FILE"
289+
exit 1
290+
fi
215291
fi
216-
fi
217292

218-
# Helpful dmesg snapshots
219-
dmesg | tail -n 100 > "$test_path/dmesg_before_stop.log"
220-
dump_rproc_logs "$rpath" before-stop
221-
222-
# ---- Stop ADSP -----------------------------------------------------------
223-
t0="$(date +%s)"
224-
log_info "$inst_id: stopping"
225-
if stop_remoteproc "$rpath" && wait_remoteproc_state "$rpath" offline "$STOP_TO" "$POLL_I"; then
226-
t1="$(date +%s)"
227-
log_pass "$inst_id: stop PASS ($((t1 - t0))s)"
228-
stop_res="PASS"
229-
else
230-
dump_rproc_logs "$rpath" after-stop-fail
231-
log_fail "$inst_id: stop FAIL"
232-
stop_res="FAIL"
233-
inst_fail=$((inst_fail + 1))
234-
RESULT_LINES="$RESULT_LINES
235-
$inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
236-
continue
237-
fi
293+
# Helpful dmesg snapshots
294+
dmesg | tail -n 100 >"$test_path/dmesg_before_stop.log"
295+
dump_rproc_logs "$rpath" before-stop
296+
297+
# ---- Stop ADSP -----------------------------------------------------------
298+
t0="$(date +%s)"
299+
log_info "$inst_id: stopping"
300+
if stop_remoteproc "$rpath" && wait_remoteproc_state "$rpath" offline "$STOP_TO" "$POLL_I"; then
301+
t1="$(date +%s)"
302+
log_pass "$inst_id: stop PASS ($((t1 - t0))s)"
303+
stop_res="PASS"
304+
else
305+
dump_rproc_logs "$rpath" after-stop-fail
306+
log_fail "$inst_id: stop FAIL"
307+
stop_res="FAIL"
308+
inst_fail=$((inst_fail + 1))
309+
RESULT_LINES="$RESULT_LINES $inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
310+
continue
311+
fi
312+
313+
dump_rproc_logs "$rpath" after-stop
314+
dump_rproc_logs "$rpath" before-start
238315

239-
dump_rproc_logs "$rpath" after-stop
240-
dump_rproc_logs "$rpath" before-start
316+
# ---- Start ADSP ----------------------------------------------------------
317+
t2="$(date +%s)"
318+
log_info "$inst_id: starting"
319+
if start_remoteproc "$rpath" && wait_remoteproc_state "$rpath" running "$START_TO" "$POLL_I"; then
320+
t3="$(date +%s)"
321+
log_pass "$inst_id: start PASS ($((t3 - t2))s)"
322+
start_res="PASS"
323+
else
324+
dump_rproc_logs "$rpath" after-start-fail
325+
log_fail "$inst_id: start FAIL"
326+
start_res="FAIL"
327+
inst_fail=$((inst_fail + 1))
328+
RESULT_LINES="$RESULT_LINES $inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
329+
continue
330+
fi
241331

242-
# ---- Start ADSP ----------------------------------------------------------
243-
t2="$(date +%s)"
244-
log_info "$inst_id: starting"
245-
if start_remoteproc "$rpath" && wait_remoteproc_state "$rpath" running "$START_TO" "$POLL_I"; then
246-
t3="$(date +%s)"
247-
log_pass "$inst_id: start PASS ($((t3 - t2))s)"
248-
start_res="PASS"
332+
dump_rproc_logs "$rpath" after-start
333+
dmesg | tail -n 100 >"$test_path/dmesg_after_restart.log"
249334
else
250-
dump_rproc_logs "$rpath" after-start-fail
251-
log_fail "$inst_id: start FAIL"
252-
start_res="FAIL"
253-
inst_fail=$((inst_fail + 1))
254-
RESULT_LINES="$RESULT_LINES
255-
$inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
256-
continue
335+
log_info "$inst_id: SSR disabled (--ssr not set). Skipping stop/start."
336+
stop_res="SKIPPED"
337+
start_res="SKIPPED"
257338
fi
258339

259-
dump_rproc_logs "$rpath" after-start
260-
dmesg | tail -n 100 > "$test_path/dmesg_after_restart.log"
261-
262340
# ---- Optional RPMsg sanity ping -----------------------------------------
263341
if CTRL_DEV="$(find_rpmsg_ctrl_for "$FW")"; then
264342
log_info "$inst_id: RPMsg ctrl dev: $CTRL_DEV"
@@ -274,8 +352,7 @@ while IFS='|' read -r rpath rstate rfirm rname; do
274352
log_info "$inst_id: no RPMsg channel, skipping ping"
275353
fi
276354

277-
RESULT_LINES="$RESULT_LINES
278-
$inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
355+
RESULT_LINES="$RESULT_LINES $inst_id: boot=$boot_res, stop=$stop_res, start=$start_res, ping=$ping_res"
279356
done <<__RPROC_LIST__
280357
$entries
281358
__RPROC_LIST__

0 commit comments

Comments
 (0)