From 05da272cc754d4e579a2e382ef337ff5dbe3af3a Mon Sep 17 00:00:00 2001 From: Srikanth Muppandam Date: Mon, 1 Sep 2025 21:08:26 +0530 Subject: [PATCH] fix(fastrpc_test): robust binary + assets detection; default assets to /usr/bin/linux MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add resilient binary discovery: * prefer --bin-dir * else PATH via command -v * else fallbacks (/usr/bin/fastrpc_test, /opt/qcom/bin/fastrpc_test) - Resolve assets directory with clear priority: * --assets-dir / FASTRPC_ASSETS_DIR * (so /usr/bin → /usr/bin/linux by default) * SCRIPT_DIR * FHS-ish fallbacks (/usr/share|/usr/lib/fastrpc_test) - Prefer /linux as default to match install layout (/usr/bin/linux) - Buffering execution fallback: stdbuf → script → plain, with optional timeout - Improve logs (binary path/details, run dir, repeats, timeout, buffering) - Guarantee .res creation on all exit paths for CI/LAVA consumption Signed-off-by: Srikanth Muppandam --- .../Multimedia/CDSP/fastrpc_test/run.sh | 186 ++++++++++-------- 1 file changed, 108 insertions(+), 78 deletions(-) diff --git a/Runner/suites/Multimedia/CDSP/fastrpc_test/run.sh b/Runner/suites/Multimedia/CDSP/fastrpc_test/run.sh index ec0675a8..8f15a70b 100755 --- a/Runner/suites/Multimedia/CDSP/fastrpc_test/run.sh +++ b/Runner/suites/Multimedia/CDSP/fastrpc_test/run.sh @@ -19,6 +19,7 @@ if [ -z "$INIT_ENV" ]; then exit 1 fi +# Only source once (idempotent) if [ -z "$__INIT_ENV_LOADED" ]; then # shellcheck disable=SC1090 . "$INIT_ENV" @@ -45,20 +46,20 @@ Usage: $0 [OPTIONS] Options: --arch Architecture (only if explicitly provided) --bin-dir Directory containing 'fastrpc_test' binary - --assets-dir Directory that CONTAINS 'linux/' (run from here if present) - --repeat Number of test repetitions (default: 1) + --assets-dir Directory that CONTAINS 'linux/' (defaults to \$BINDIR, e.g. /usr/bin) + --repeat Number of repetitions (default: 1) --timeout Timeout for each run (no timeout if omitted) --verbose Extra logging for CI debugging --help Show this help Notes: -- If --bin-dir is omitted, 'fastrpc_test' must be on PATH. -- If --assets-dir is omitted or lacks 'linux/', we run from the binary's dir. +- If --bin-dir is omitted, 'fastrpc_test' must be on PATH or in known fallback paths. +- Default assets location prefers \$BINDIR/linux (so /usr/bin/linux in your layout). - If --arch is omitted, the -a flag is not passed at all. EOF } -# Parse arguments +# --------------------- Parse arguments ------------------------- while [ $# -gt 0 ]; do case "$1" in --arch) ARCH="$2"; shift 2 ;; @@ -68,7 +69,7 @@ while [ $# -gt 0 ]; do --timeout) TIMEOUT="$2"; shift 2 ;; --verbose) VERBOSE=1; shift ;; --help) usage; exit 0 ;; - *) echo "[ERROR] Unknown argument: $1" >&2; usage; exit 1 ;; + *) echo "[ERROR] Unknown argument: $1" >&2; usage; echo "$TESTNAME : FAIL" >"$RESULT_FILE"; exit 1 ;; esac done @@ -78,8 +79,17 @@ if [ -n "$TIMEOUT" ]; then case "$TIMEOUT" in *[!0-9]*|"") log_error "Invalid --timeout: $TIMEOUT"; echo "$TESTNAME : FAIL" >"$RESULT_FILE"; exit 1 ;; esac fi -test_path="$(find_test_case_by_name "$TESTNAME")" -cd "$test_path" || exit 1 +# Ensure we're in the testcase directory (repo convention) +test_path="$(find_test_case_by_name "$TESTNAME")" || { + log_error "Cannot locate test path for $TESTNAME" + echo "$TESTNAME : FAIL" >"$RESULT_FILE" + exit 1 +} +cd "$test_path" || { + log_error "cd to test path failed: $test_path" + echo "$TESTNAME : FAIL" >"$RESULT_FILE" + exit 1 +} log_info "--------------------------------------------------------------------------" log_info "-------------------Starting $TESTNAME Testcase----------------------------" @@ -87,39 +97,47 @@ log_info "-------------------Starting $TESTNAME Testcase------------------------ # Small debug helper log_debug() { [ "$VERBOSE" -eq 1 ] && log_info "[debug] $*"; } -# ---------- Locate binary ---------- +# -------------------- Binary detection (robust) ----------------- +FASTBIN="" if [ -n "$BIN_DIR" ]; then FASTBIN="$BIN_DIR/fastrpc_test" - if [ ! -x "$FASTBIN" ]; then - log_fail "fastrpc_test not executable at: $FASTBIN" - echo "$TESTNAME : FAIL" > "$RESULT_FILE" - exit 1 - fi +elif command -v fastrpc_test >/dev/null 2>&1; then + FASTBIN="$(command -v fastrpc_test)" +elif [ -x "/usr/bin/fastrpc_test" ]; then + FASTBIN="/usr/bin/fastrpc_test" +elif [ -x "/opt/qcom/bin/fastrpc_test" ]; then + FASTBIN="/opt/qcom/bin/fastrpc_test" else - if ! FASTBIN="$(command -v fastrpc_test 2>/dev/null)"; then - log_fail "'fastrpc_test' binary not found on PATH (or use --bin-dir)." - echo "$TESTNAME : FAIL" > "$RESULT_FILE" - exit 1 - fi + log_fail "'fastrpc_test' not found (try --bin-dir or ensure PATH includes /usr/bin)." + echo "$TESTNAME : FAIL" >"$RESULT_FILE" + exit 1 +fi + +if [ ! -x "$FASTBIN" ]; then + log_fail "Binary not executable: $FASTBIN" + echo "$TESTNAME : FAIL" >"$RESULT_FILE" + exit 1 fi -BINDIR="$(dirname "$FASTBIN")" -log_info "Binary: $FASTBIN" -# Extra binary info for debugging +BINDIR="$(dirname "$FASTBIN")" +log_info "Using binary: $FASTBIN" +log_debug "PATH=$PATH" log_info "Binary details:" +# shellcheck disable=SC2012 log_info " ls -l: $(ls -l "$FASTBIN" 2>/dev/null || echo 'N/A')" log_info " file : $(file "$FASTBIN" 2>/dev/null || echo 'N/A')" -# ---------- Optional arch argument ---------- -ARCH_OPT="" +# -------------------- Optional arch argument ------------------- +# Use positional params trick so we don't misquote "-a " +set -- # clear "$@" if [ -n "$ARCH" ]; then - ARCH_OPT="-a $ARCH" - log_info "Arch option provided: $ARCH" + set -- -a "$ARCH" + log_info "Arch option: -a $ARCH" else log_info "No --arch provided; running without -a" fi -# ---------- Buffering tool availability ---------- +# -------------------- Buffering tool availability --------------- HAVE_STDBUF=0; command -v stdbuf >/dev/null 2>&1 && HAVE_STDBUF=1 HAVE_SCRIPT=0; command -v script >/dev/null 2>&1 && HAVE_SCRIPT=1 HAVE_TIMEOUT=0; command -v timeout >/dev/null 2>&1 && HAVE_TIMEOUT=1 @@ -131,41 +149,47 @@ elif [ $HAVE_SCRIPT -eq 1 ]; then buf_label="script -q" fi -# ---------- Assets directory resolution ---------- +# ---------------- Assets directory resolution ------------------ +# Default must prefer $BINDIR/linux (e.g., /usr/bin/linux) +: "${FASTRPC_ASSETS_DIR:=}" RESOLVED_RUN_DIR="" -if [ -n "$ASSETS_DIR" ]; then - if [ -d "$ASSETS_DIR" ]; then - RESOLVED_RUN_DIR="$ASSETS_DIR" - if [ -d "$ASSETS_DIR/linux" ]; then - log_info "Using --assets-dir: $ASSETS_DIR (expects: $ASSETS_DIR/linux)" - else - log_debug "--assets-dir provided but no 'linux/' inside: $ASSETS_DIR" - fi - else - log_warn "--assets-dir not found: $ASSETS_DIR (falling back to binary dir)" - fi -fi -if [ -z "$RESOLVED_RUN_DIR" ]; then - if [ -d "$BINDIR/linux" ]; then - RESOLVED_RUN_DIR="$BINDIR" - elif [ -d "$SCRIPT_DIR/linux" ]; then - RESOLVED_RUN_DIR="$SCRIPT_DIR" - else - RESOLVED_RUN_DIR="$BINDIR" + +# Priority: explicit flags/env → alongside binary → script dir → FHS-ish fallbacks +CANDIDATES=" +${ASSETS_DIR} +${FASTRPC_ASSETS_DIR} +${BINDIR} +${SCRIPT_DIR} +${BINDIR%/bin}/share/fastrpc_test +/usr/share/fastrpc_test +/usr/lib/fastrpc_test +" + +for d in $CANDIDATES; do + [ -n "$d" ] || continue + if [ -d "$d/linux" ]; then + RESOLVED_RUN_DIR="$d" + break fi +done + +if [ -n "$RESOLVED_RUN_DIR" ]; then + log_info "Assets dir: $RESOLVED_RUN_DIR (found 'linux/')" +else + RESOLVED_RUN_DIR="$BINDIR" + log_warn "No 'linux/' assets found; continuing from $RESOLVED_RUN_DIR" fi -[ -d "$RESOLVED_RUN_DIR/linux" ] || log_debug "No 'linux/' under run dir: $RESOLVED_RUN_DIR" -# ---------- Logging root ---------- +# -------------------- Logging root ----------------------------- TS="$(date +%Y%m%d-%H%M%S)" LOG_ROOT="./logs_${TESTNAME}_${TS}" mkdir -p "$LOG_ROOT" || { log_error "Cannot create $LOG_ROOT"; echo "$TESTNAME : FAIL" >"$RESULT_FILE"; exit 1; } tmo_label="none"; [ -n "$TIMEOUT" ] && tmo_label="${TIMEOUT}s" log_info "Repeats: $REPEAT | Timeout: $tmo_label | Buffering: $buf_label" -log_debug "Run dir: $RESOLVED_RUN_DIR | PATH=$PATH" +log_debug "Run dir: $RESOLVED_RUN_DIR" -# ---------- Run loop ---------- +# -------------------- Run loop --------------------------------- PASS_COUNT=0 i=1 while [ "$i" -le "$REPEAT" ]; do @@ -176,33 +200,33 @@ while [ "$i" -le "$REPEAT" ]; do log_info "Running $iter_tag/$REPEAT | start: $iso_now | dir: $RESOLVED_RUN_DIR" - # Build command string for debug only - CMD="$FASTBIN -d 3 -U 1 -t linux $ARCH_OPT" - log_info "Executing: $CMD" - - if [ $HAVE_STDBUF -eq 1 ]; then - ( - cd "$RESOLVED_RUN_DIR" || exit 127 - run_with_timeout "$TIMEOUT" stdbuf -oL -eL "$FASTBIN" -d 3 -U 1 -t linux "$ARCH_OPT" - ) >"$iter_log" 2>&1 - rc=$? - elif [ $HAVE_SCRIPT -eq 1 ]; then - ( - cd "$RESOLVED_RUN_DIR" || exit 127 + # Base command (for logging only) + # shellcheck disable=SC2145 + log_info "Executing: $FASTBIN -d 3 -U 1 -t linux $*" + + rc=127 + ( + cd "$RESOLVED_RUN_DIR" || exit 127 + + if [ $HAVE_STDBUF -eq 1 ]; then + # Prefer line-buffered stdout/stderr when available + # run_with_timeout from functestlib.sh wraps timeout if TIMEOUT is set + run_with_timeout "$TIMEOUT" stdbuf -oL -eL "$FASTBIN" -d 3 -U 1 -t linux "$@" + + elif [ $HAVE_SCRIPT -eq 1 ]; then + # script(1) fallback to get unbuffered-ish output if [ -n "$TIMEOUT" ] && [ $HAVE_TIMEOUT -eq 1 ]; then - script -q -c "timeout $TIMEOUT $CMD" /dev/null + script -q -c "timeout $TIMEOUT $FASTBIN -d 3 -U 1 -t linux $*" /dev/null else - script -q -c "$CMD" /dev/null + script -q -c "$FASTBIN -d 3 -U 1 -t linux $*" /dev/null fi - ) >"$iter_log" 2>&1 - rc=$? - else - ( - cd "$RESOLVED_RUN_DIR" || exit 127 - run_with_timeout "$TIMEOUT" "$FASTBIN" -d 3 -U 1 -t linux "$ARCH_OPT" - ) >"$iter_log" 2>&1 - rc=$? - fi + + else + # Plain execution (still via run_with_timeout if available) + run_with_timeout "$TIMEOUT" "$FASTBIN" -d 3 -U 1 -t linux "$@" + fi + ) >"$iter_log" 2>&1 + rc=$? printf '%s\n' "$rc" >"$iter_rc" @@ -226,13 +250,19 @@ while [ "$i" -le "$REPEAT" ]; do i=$((i+1)) done -# ---------- Finalize ---------- +# -------------------- Finalize -------------------------------- if [ "$PASS_COUNT" -eq "$REPEAT" ]; then log_pass "$TESTNAME : Test Passed ($PASS_COUNT/$REPEAT)" echo "$TESTNAME : PASS" > "$RESULT_FILE" - exit 0 else log_fail "$TESTNAME : Test Failed ($PASS_COUNT/$REPEAT)" echo "$TESTNAME : FAIL" > "$RESULT_FILE" - exit 1 fi + +# Failsafe: ensure the .res file exists for CI/LAVA consumption +[ -f "$RESULT_FILE" ] || { + log_error "Missing result file ($RESULT_FILE) — creating FAIL" + echo "$TESTNAME : FAIL" >"$RESULT_FILE" +} + +exit 0