Skip to content

Commit 51e033b

Browse files
authored
Merge pull request qualcomm-linux#149 from smuppand/fastrpc-test
fastrpc_test: robust binary/assets discovery (default /usr/bin/linux), buffering fallback, and guaranteed .res
2 parents 26509ba + 05da272 commit 51e033b

File tree

1 file changed

+108
-78
lines changed
  • Runner/suites/Multimedia/CDSP/fastrpc_test

1 file changed

+108
-78
lines changed

Runner/suites/Multimedia/CDSP/fastrpc_test/run.sh

Lines changed: 108 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if [ -z "$INIT_ENV" ]; then
1919
exit 1
2020
fi
2121

22+
# Only source once (idempotent)
2223
if [ -z "$__INIT_ENV_LOADED" ]; then
2324
# shellcheck disable=SC1090
2425
. "$INIT_ENV"
@@ -45,20 +46,20 @@ Usage: $0 [OPTIONS]
4546
Options:
4647
--arch <name> Architecture (only if explicitly provided)
4748
--bin-dir <path> Directory containing 'fastrpc_test' binary
48-
--assets-dir <path> Directory that CONTAINS 'linux/' (run from here if present)
49-
--repeat <N> Number of test repetitions (default: 1)
49+
--assets-dir <path> Directory that CONTAINS 'linux/' (defaults to \$BINDIR, e.g. /usr/bin)
50+
--repeat <N> Number of repetitions (default: 1)
5051
--timeout <sec> Timeout for each run (no timeout if omitted)
5152
--verbose Extra logging for CI debugging
5253
--help Show this help
5354
5455
Notes:
55-
- If --bin-dir is omitted, 'fastrpc_test' must be on PATH.
56-
- If --assets-dir is omitted or lacks 'linux/', we run from the binary's dir.
56+
- If --bin-dir is omitted, 'fastrpc_test' must be on PATH or in known fallback paths.
57+
- Default assets location prefers \$BINDIR/linux (so /usr/bin/linux in your layout).
5758
- If --arch is omitted, the -a flag is not passed at all.
5859
EOF
5960
}
6061

61-
# Parse arguments
62+
# --------------------- Parse arguments -------------------------
6263
while [ $# -gt 0 ]; do
6364
case "$1" in
6465
--arch) ARCH="$2"; shift 2 ;;
@@ -68,7 +69,7 @@ while [ $# -gt 0 ]; do
6869
--timeout) TIMEOUT="$2"; shift 2 ;;
6970
--verbose) VERBOSE=1; shift ;;
7071
--help) usage; exit 0 ;;
71-
*) echo "[ERROR] Unknown argument: $1" >&2; usage; exit 1 ;;
72+
*) echo "[ERROR] Unknown argument: $1" >&2; usage; echo "$TESTNAME : FAIL" >"$RESULT_FILE"; exit 1 ;;
7273
esac
7374
done
7475

@@ -78,48 +79,65 @@ if [ -n "$TIMEOUT" ]; then
7879
case "$TIMEOUT" in *[!0-9]*|"") log_error "Invalid --timeout: $TIMEOUT"; echo "$TESTNAME : FAIL" >"$RESULT_FILE"; exit 1 ;; esac
7980
fi
8081

81-
test_path="$(find_test_case_by_name "$TESTNAME")"
82-
cd "$test_path" || exit 1
82+
# Ensure we're in the testcase directory (repo convention)
83+
test_path="$(find_test_case_by_name "$TESTNAME")" || {
84+
log_error "Cannot locate test path for $TESTNAME"
85+
echo "$TESTNAME : FAIL" >"$RESULT_FILE"
86+
exit 1
87+
}
88+
cd "$test_path" || {
89+
log_error "cd to test path failed: $test_path"
90+
echo "$TESTNAME : FAIL" >"$RESULT_FILE"
91+
exit 1
92+
}
8393

8494
log_info "--------------------------------------------------------------------------"
8595
log_info "-------------------Starting $TESTNAME Testcase----------------------------"
8696

8797
# Small debug helper
8898
log_debug() { [ "$VERBOSE" -eq 1 ] && log_info "[debug] $*"; }
8999

90-
# ---------- Locate binary ----------
100+
# -------------------- Binary detection (robust) -----------------
101+
FASTBIN=""
91102
if [ -n "$BIN_DIR" ]; then
92103
FASTBIN="$BIN_DIR/fastrpc_test"
93-
if [ ! -x "$FASTBIN" ]; then
94-
log_fail "fastrpc_test not executable at: $FASTBIN"
95-
echo "$TESTNAME : FAIL" > "$RESULT_FILE"
96-
exit 1
97-
fi
104+
elif command -v fastrpc_test >/dev/null 2>&1; then
105+
FASTBIN="$(command -v fastrpc_test)"
106+
elif [ -x "/usr/bin/fastrpc_test" ]; then
107+
FASTBIN="/usr/bin/fastrpc_test"
108+
elif [ -x "/opt/qcom/bin/fastrpc_test" ]; then
109+
FASTBIN="/opt/qcom/bin/fastrpc_test"
98110
else
99-
if ! FASTBIN="$(command -v fastrpc_test 2>/dev/null)"; then
100-
log_fail "'fastrpc_test' binary not found on PATH (or use --bin-dir)."
101-
echo "$TESTNAME : FAIL" > "$RESULT_FILE"
102-
exit 1
103-
fi
111+
log_fail "'fastrpc_test' not found (try --bin-dir or ensure PATH includes /usr/bin)."
112+
echo "$TESTNAME : FAIL" >"$RESULT_FILE"
113+
exit 1
114+
fi
115+
116+
if [ ! -x "$FASTBIN" ]; then
117+
log_fail "Binary not executable: $FASTBIN"
118+
echo "$TESTNAME : FAIL" >"$RESULT_FILE"
119+
exit 1
104120
fi
105-
BINDIR="$(dirname "$FASTBIN")"
106-
log_info "Binary: $FASTBIN"
107121

108-
# Extra binary info for debugging
122+
BINDIR="$(dirname "$FASTBIN")"
123+
log_info "Using binary: $FASTBIN"
124+
log_debug "PATH=$PATH"
109125
log_info "Binary details:"
126+
# shellcheck disable=SC2012
110127
log_info " ls -l: $(ls -l "$FASTBIN" 2>/dev/null || echo 'N/A')"
111128
log_info " file : $(file "$FASTBIN" 2>/dev/null || echo 'N/A')"
112129

113-
# ---------- Optional arch argument ----------
114-
ARCH_OPT=""
130+
# -------------------- Optional arch argument -------------------
131+
# Use positional params trick so we don't misquote "-a <arch>"
132+
set -- # clear "$@"
115133
if [ -n "$ARCH" ]; then
116-
ARCH_OPT="-a $ARCH"
117-
log_info "Arch option provided: $ARCH"
134+
set -- -a "$ARCH"
135+
log_info "Arch option: -a $ARCH"
118136
else
119137
log_info "No --arch provided; running without -a"
120138
fi
121139

122-
# ---------- Buffering tool availability ----------
140+
# -------------------- Buffering tool availability ---------------
123141
HAVE_STDBUF=0; command -v stdbuf >/dev/null 2>&1 && HAVE_STDBUF=1
124142
HAVE_SCRIPT=0; command -v script >/dev/null 2>&1 && HAVE_SCRIPT=1
125143
HAVE_TIMEOUT=0; command -v timeout >/dev/null 2>&1 && HAVE_TIMEOUT=1
@@ -131,41 +149,47 @@ elif [ $HAVE_SCRIPT -eq 1 ]; then
131149
buf_label="script -q"
132150
fi
133151

134-
# ---------- Assets directory resolution ----------
152+
# ---------------- Assets directory resolution ------------------
153+
# Default must prefer $BINDIR/linux (e.g., /usr/bin/linux)
154+
: "${FASTRPC_ASSETS_DIR:=}"
135155
RESOLVED_RUN_DIR=""
136-
if [ -n "$ASSETS_DIR" ]; then
137-
if [ -d "$ASSETS_DIR" ]; then
138-
RESOLVED_RUN_DIR="$ASSETS_DIR"
139-
if [ -d "$ASSETS_DIR/linux" ]; then
140-
log_info "Using --assets-dir: $ASSETS_DIR (expects: $ASSETS_DIR/linux)"
141-
else
142-
log_debug "--assets-dir provided but no 'linux/' inside: $ASSETS_DIR"
143-
fi
144-
else
145-
log_warn "--assets-dir not found: $ASSETS_DIR (falling back to binary dir)"
146-
fi
147-
fi
148-
if [ -z "$RESOLVED_RUN_DIR" ]; then
149-
if [ -d "$BINDIR/linux" ]; then
150-
RESOLVED_RUN_DIR="$BINDIR"
151-
elif [ -d "$SCRIPT_DIR/linux" ]; then
152-
RESOLVED_RUN_DIR="$SCRIPT_DIR"
153-
else
154-
RESOLVED_RUN_DIR="$BINDIR"
156+
157+
# Priority: explicit flags/env → alongside binary → script dir → FHS-ish fallbacks
158+
CANDIDATES="
159+
${ASSETS_DIR}
160+
${FASTRPC_ASSETS_DIR}
161+
${BINDIR}
162+
${SCRIPT_DIR}
163+
${BINDIR%/bin}/share/fastrpc_test
164+
/usr/share/fastrpc_test
165+
/usr/lib/fastrpc_test
166+
"
167+
168+
for d in $CANDIDATES; do
169+
[ -n "$d" ] || continue
170+
if [ -d "$d/linux" ]; then
171+
RESOLVED_RUN_DIR="$d"
172+
break
155173
fi
174+
done
175+
176+
if [ -n "$RESOLVED_RUN_DIR" ]; then
177+
log_info "Assets dir: $RESOLVED_RUN_DIR (found 'linux/')"
178+
else
179+
RESOLVED_RUN_DIR="$BINDIR"
180+
log_warn "No 'linux/' assets found; continuing from $RESOLVED_RUN_DIR"
156181
fi
157-
[ -d "$RESOLVED_RUN_DIR/linux" ] || log_debug "No 'linux/' under run dir: $RESOLVED_RUN_DIR"
158182

159-
# ---------- Logging root ----------
183+
# -------------------- Logging root -----------------------------
160184
TS="$(date +%Y%m%d-%H%M%S)"
161185
LOG_ROOT="./logs_${TESTNAME}_${TS}"
162186
mkdir -p "$LOG_ROOT" || { log_error "Cannot create $LOG_ROOT"; echo "$TESTNAME : FAIL" >"$RESULT_FILE"; exit 1; }
163187

164188
tmo_label="none"; [ -n "$TIMEOUT" ] && tmo_label="${TIMEOUT}s"
165189
log_info "Repeats: $REPEAT | Timeout: $tmo_label | Buffering: $buf_label"
166-
log_debug "Run dir: $RESOLVED_RUN_DIR | PATH=$PATH"
190+
log_debug "Run dir: $RESOLVED_RUN_DIR"
167191

168-
# ---------- Run loop ----------
192+
# -------------------- Run loop ---------------------------------
169193
PASS_COUNT=0
170194
i=1
171195
while [ "$i" -le "$REPEAT" ]; do
@@ -176,33 +200,33 @@ while [ "$i" -le "$REPEAT" ]; do
176200

177201
log_info "Running $iter_tag/$REPEAT | start: $iso_now | dir: $RESOLVED_RUN_DIR"
178202

179-
# Build command string for debug only
180-
CMD="$FASTBIN -d 3 -U 1 -t linux $ARCH_OPT"
181-
log_info "Executing: $CMD"
182-
183-
if [ $HAVE_STDBUF -eq 1 ]; then
184-
(
185-
cd "$RESOLVED_RUN_DIR" || exit 127
186-
run_with_timeout "$TIMEOUT" stdbuf -oL -eL "$FASTBIN" -d 3 -U 1 -t linux "$ARCH_OPT"
187-
) >"$iter_log" 2>&1
188-
rc=$?
189-
elif [ $HAVE_SCRIPT -eq 1 ]; then
190-
(
191-
cd "$RESOLVED_RUN_DIR" || exit 127
203+
# Base command (for logging only)
204+
# shellcheck disable=SC2145
205+
log_info "Executing: $FASTBIN -d 3 -U 1 -t linux $*"
206+
207+
rc=127
208+
(
209+
cd "$RESOLVED_RUN_DIR" || exit 127
210+
211+
if [ $HAVE_STDBUF -eq 1 ]; then
212+
# Prefer line-buffered stdout/stderr when available
213+
# run_with_timeout from functestlib.sh wraps timeout if TIMEOUT is set
214+
run_with_timeout "$TIMEOUT" stdbuf -oL -eL "$FASTBIN" -d 3 -U 1 -t linux "$@"
215+
216+
elif [ $HAVE_SCRIPT -eq 1 ]; then
217+
# script(1) fallback to get unbuffered-ish output
192218
if [ -n "$TIMEOUT" ] && [ $HAVE_TIMEOUT -eq 1 ]; then
193-
script -q -c "timeout $TIMEOUT $CMD" /dev/null
219+
script -q -c "timeout $TIMEOUT $FASTBIN -d 3 -U 1 -t linux $*" /dev/null
194220
else
195-
script -q -c "$CMD" /dev/null
221+
script -q -c "$FASTBIN -d 3 -U 1 -t linux $*" /dev/null
196222
fi
197-
) >"$iter_log" 2>&1
198-
rc=$?
199-
else
200-
(
201-
cd "$RESOLVED_RUN_DIR" || exit 127
202-
run_with_timeout "$TIMEOUT" "$FASTBIN" -d 3 -U 1 -t linux "$ARCH_OPT"
203-
) >"$iter_log" 2>&1
204-
rc=$?
205-
fi
223+
224+
else
225+
# Plain execution (still via run_with_timeout if available)
226+
run_with_timeout "$TIMEOUT" "$FASTBIN" -d 3 -U 1 -t linux "$@"
227+
fi
228+
) >"$iter_log" 2>&1
229+
rc=$?
206230

207231
printf '%s\n' "$rc" >"$iter_rc"
208232

@@ -226,13 +250,19 @@ while [ "$i" -le "$REPEAT" ]; do
226250
i=$((i+1))
227251
done
228252

229-
# ---------- Finalize ----------
253+
# -------------------- Finalize --------------------------------
230254
if [ "$PASS_COUNT" -eq "$REPEAT" ]; then
231255
log_pass "$TESTNAME : Test Passed ($PASS_COUNT/$REPEAT)"
232256
echo "$TESTNAME : PASS" > "$RESULT_FILE"
233-
exit 0
234257
else
235258
log_fail "$TESTNAME : Test Failed ($PASS_COUNT/$REPEAT)"
236259
echo "$TESTNAME : FAIL" > "$RESULT_FILE"
237-
exit 1
238260
fi
261+
262+
# Failsafe: ensure the .res file exists for CI/LAVA consumption
263+
[ -f "$RESULT_FILE" ] || {
264+
log_error "Missing result file ($RESULT_FILE) — creating FAIL"
265+
echo "$TESTNAME : FAIL" >"$RESULT_FILE"
266+
}
267+
268+
exit 0

0 commit comments

Comments
 (0)