Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 108 additions & 78 deletions Runner/suites/Multimedia/CDSP/fastrpc_test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -45,20 +46,20 @@ Usage: $0 [OPTIONS]
Options:
--arch <name> Architecture (only if explicitly provided)
--bin-dir <path> Directory containing 'fastrpc_test' binary
--assets-dir <path> Directory that CONTAINS 'linux/' (run from here if present)
--repeat <N> Number of test repetitions (default: 1)
--assets-dir <path> Directory that CONTAINS 'linux/' (defaults to \$BINDIR, e.g. /usr/bin)
--repeat <N> Number of repetitions (default: 1)
--timeout <sec> 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 ;;
Expand All @@ -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

Expand All @@ -78,48 +79,65 @@ 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----------------------------"

# 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 <arch>"
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
Expand All @@ -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
Expand All @@ -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"

Expand All @@ -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
Loading