From ba11e7d0c049ec3f5eca4d040d6e14dfa09e2e78 Mon Sep 17 00:00:00 2001 From: Srikanth Muppandam Date: Wed, 25 Feb 2026 00:06:17 +0530 Subject: [PATCH 1/2] Multimedia: DSP_AudioPD: validate both adsprpcd instances and reduce log duplication - Iterate all adsprpcd PIDs for wait-state validation - Avoid repeated running/PIDs log lines (CI readability) Signed-off-by: Srikanth Muppandam --- Runner/suites/Multimedia/DSP_AudioPD/run.sh | 108 ++++++++++++++++---- 1 file changed, 86 insertions(+), 22 deletions(-) diff --git a/Runner/suites/Multimedia/DSP_AudioPD/run.sh b/Runner/suites/Multimedia/DSP_AudioPD/run.sh index 264061dc..0bd52766 100755 --- a/Runner/suites/Multimedia/DSP_AudioPD/run.sh +++ b/Runner/suites/Multimedia/DSP_AudioPD/run.sh @@ -67,6 +67,7 @@ fi STARTED_BY_TEST=0 PID="" +PIDS="" check_adsprpcd_wait_state() { pid="$1" @@ -112,9 +113,17 @@ check_adsprpcd_wait_state() { } if is_process_running "adsprpcd"; then - log_info "adsprpcd is running" - PID=$(get_one_pid_by_name "adsprpcd" 2>/dev/null || true) - PID=$(sanitize_pid "$PID") + # is_process_running already prints instances/cmdline (for CI debug) + PIDS=$(get_one_pid_by_name "adsprpcd" all 2>/dev/null || true) + + # Pick a primary PID for legacy logging (first valid numeric PID) + for p in $PIDS; do + p_clean=$(sanitize_pid "$p") + if [ -n "$p_clean" ]; then + PID="$p_clean" + break + fi + done else log_info "adsprpcd is not running" log_info "Manually starting adsprpcd daemon" @@ -130,47 +139,102 @@ else PID=$(get_one_pid_by_name "adsprpcd" 2>/dev/null || true) PID=$(sanitize_pid "$PID") fi + + # After start, gather all adsprpcd PIDs (if helper supports it) + PIDS=$(get_one_pid_by_name "adsprpcd" all 2>/dev/null || true) +fi + +# Fallback if helper returned nothing +if [ -z "$PIDS" ] && [ -n "$PID" ]; then + PIDS="$PID" fi log_info "PID is $PID" -if [ -z "$PID" ] || ! wait_pid_alive "$PID" 10; then - log_fail "Failed to start adsprpcd or PID did not become alive" +# Build an "alive" PID list (avoid false failures if a PID disappears) +PIDS_ALIVE="" +alive_count=0 +dead_seen=0 +for p in $PIDS; do + p_clean=$(sanitize_pid "$p") + if [ -z "$p_clean" ]; then + continue + fi + + if wait_pid_alive "$p_clean" 10; then + alive_count=$((alive_count + 1)) + if [ -z "$PIDS_ALIVE" ]; then + PIDS_ALIVE="$p_clean" + else + PIDS_ALIVE="$PIDS_ALIVE $p_clean" + fi + else + dead_seen=1 + log_warn "adsprpcd PID $p_clean did not become alive" + fi +done + +# Only print alive list if something was dropped (avoids duplicate info in normal case) +if [ "$dead_seen" -eq 1 ]; then + log_info "Alive adsprpcd PIDs: $PIDS_ALIVE" +fi + +if [ "$alive_count" -le 0 ]; then + log_fail "Failed to start adsprpcd or no alive PID found" echo "$TESTNAME FAIL" >"$res_file" # Kill only if we started it and PID is valid if [ "$STARTED_BY_TEST" -eq 1 ]; then - PID_CLEAN=$(sanitize_pid "$PID") - if [ -n "$PID_CLEAN" ]; then - kill_process "$PID_CLEAN" || true - fi + for p in $PIDS; do + p_clean=$(sanitize_pid "$p") + if [ -n "$p_clean" ]; then + kill_process "$p_clean" || true + fi + done fi exit 0 fi -# Evaluate -check_adsprpcd_wait_state "$PID" -rc=$? +# Evaluate all alive PIDs +fail_seen=0 +skip_seen=0 + +for p in $PIDS_ALIVE; do + check_adsprpcd_wait_state "$p" + rc=$? -if [ "$rc" -eq 0 ]; then - log_pass "$TESTNAME : Test Passed" - echo "$TESTNAME PASS" >"$res_file" -elif [ "$rc" -eq 2 ]; then + if [ "$rc" -eq 2 ]; then + skip_seen=1 + break + fi + if [ "$rc" -ne 0 ]; then + fail_seen=1 + fi +done + +if [ "$skip_seen" -eq 1 ]; then # SKIP already written by the function : else - log_fail "$TESTNAME : Test Failed" - echo "$TESTNAME FAIL" >"$res_file" + if [ "$fail_seen" -eq 0 ]; then + log_pass "$TESTNAME : Test Passed" + echo "$TESTNAME PASS" >"$res_file" + else + log_fail "$TESTNAME : Test Failed" + echo "$TESTNAME FAIL" >"$res_file" + fi fi log_info "-------------------Completed $TESTNAME Testcase----------------------------" # Kill only if we started it if [ "$STARTED_BY_TEST" -eq 1 ]; then - PID_CLEAN=$(sanitize_pid "$PID") - if [ -n "$PID_CLEAN" ]; then - kill_process "$PID_CLEAN" || true - fi + for p in $PIDS; do + p_clean=$(sanitize_pid "$p") + if [ -n "$p_clean" ]; then + kill_process "$p_clean" || true + fi + done fi exit 0 From d2403eb4bd8cbb5759f9a4ef1d326044852fa920 Mon Sep 17 00:00:00 2001 From: Srikanth Muppandam Date: Wed, 25 Feb 2026 00:06:32 +0530 Subject: [PATCH 2/2] utils: functestlib: make adsprpcd PID detection robust for multi-instance setups - Return all matching PIDs when requested - Log per-PID cmdline to help CI debugging Signed-off-by: Srikanth Muppandam --- Runner/utils/functestlib.sh | 159 +++++++++++++++++++++--------------- 1 file changed, 95 insertions(+), 64 deletions(-) diff --git a/Runner/utils/functestlib.sh b/Runner/utils/functestlib.sh index 58eba107..cbcd7177 100755 --- a/Runner/utils/functestlib.sh +++ b/Runner/utils/functestlib.sh @@ -4343,34 +4343,68 @@ sanitize_pid() { | awk '{print $1; exit}' } -# Get a single PID (first match) for a given process name. -# Prefer pgrep, then get_pid, then a ps fallback. -get_one_pid_by_name() { +get_pids_by_name() { name="$1" - [ -z "$name" ] && return 1 - - pid="" - - # Prefer pgrep - if command -v pgrep >/dev/null 2>&1; then - pid=$(pgrep -x "$name" 2>/dev/null | awk 'NR==1{print; exit}') - pid=$(sanitize_pid "$pid") - [ -n "$pid" ] && { printf '%s\n' "$pid"; return 0; } + + if [ -z "$name" ]; then + return 1 fi - - # Fallback to get_pid (should already return first PID after your update) - if command -v get_pid >/dev/null 2>&1; then - pid=$(get_pid "$name" 2>/dev/null) - pid=$(sanitize_pid "$pid") - [ -n "$pid" ] && { printf '%s\n' "$pid"; return 0; } + + # Print one PID per line (sanitized), for all processes whose basename matches $name + ps -ef 2>/dev/null | awk -v n="$name" ' + NR==1 { next } + { + cmd=$8 + sub(".*/", "", cmd) + if (cmd == n) { print $2 } + }' | while IFS= read -r p; do + p_clean=$(sanitize_pid "$p") + if [ -n "$p_clean" ]; then + printf '%s\n' "$p_clean" + fi + done +} + +# Backward-compatible wrapper: +# get_one_pid_by_name -> first PID +# get_one_pid_by_name all -> all PIDs (newline-separated) +get_one_pid_by_name() { + name="$1" + mode="${2:-}" + + pids="" + first_pid="" + + for d in /proc/[0-9]*; do + [ -r "$d/comm" ] || continue + comm=$(tr -d '\r\n' <"$d/comm" 2>/dev/null) + [ "$comm" = "$name" ] || continue + + pid=${d#/proc/} + case "$pid" in + ''|*[!0-9]*) + continue + ;; + esac + + if [ -z "$first_pid" ] || [ "$pid" -lt "$first_pid" ]; then + first_pid="$pid" + fi + + if [ -z "$pids" ]; then + pids="$pid" + else + pids="$pids $pid" + fi + done + + [ -n "$pids" ] || return 1 + + if [ "$mode" = "all" ]; then + printf '%s\n' "$pids" + else + printf '%s\n' "$first_pid" fi - - # Final fallback: ps - pid=$(ps -e 2>/dev/null | awk -v n="$name" '$NF==n {print $1; exit}') - pid=$(sanitize_pid "$pid") - [ -n "$pid" ] && { printf '%s\n' "$pid"; return 0; } - - return 1 } # Wait until PID is alive (kill -0 succeeds) or timeout seconds elapse. @@ -4441,52 +4475,49 @@ kill_process() { } is_process_running() { - if [ -z "$1" ]; then - log_info "Usage: is_running " - return 1 - fi + name="$1" - input="$1" - case "$input" in - ''|*[!0-9]*) - # Non-numeric input: treat as process name - found=0 + pids=$(get_one_pid_by_name "$name" all 2>/dev/null) || { + log_info "Process '$name' is not running." + return 1 + } - # Prefer pgrep if available (ShellCheck-friendly, efficient) - if command -v pgrep >/dev/null 2>&1; then - if pgrep -x "$input" >/dev/null 2>&1; then - found=1 - fi - else - # POSIX fallback: avoid 'ps | grep' to silence SC2009 - # Match as a separate word to mimic 'grep -w' - if ps -e 2>/dev/null | awk -v name="$input" ' - $0 ~ ("(^|[[:space:]])" name "([[:space:]]|$)") { exit 0 } - END { exit 1 } - '; then - found=1 - fi - fi + log_info "Process '$name' is running." - if [ "$found" -eq 1 ]; then - log_info "Process '$input' is running." + # Only add extra debug if multiple instances exist + case "$pids" in + *" "*) + log_info "Process '$name' instances: $pids" + ;; + *) return 0 - else - log_info "Process '$input' is not running." - return 1 + ;; + esac + + for pid in $pids; do + case "$pid" in + ''|*[!0-9]*) + continue + ;; + esac + + cmd="" + if [ -r "/proc/$pid/cmdline" ]; then + cmd=$(tr '\000' ' ' <"/proc/$pid/cmdline" 2>/dev/null) fi - ;; - *) - # Numeric input: treat as PID - if kill -0 "$input" 2>/dev/null; then - log_info "Process with PID $input is running." - return 0 + + if [ -n "$cmd" ]; then + log_info "Process '$name' PID $pid cmdline: $cmd" else - log_info "Process with PID $input is not running." - return 1 + comm="" + if [ -r "/proc/$pid/comm" ]; then + comm=$(tr -d '\r\n' <"/proc/$pid/comm" 2>/dev/null) + fi + log_info "Process '$name' PID $pid comm: ${comm:-unknown}" fi - ;; - esac + done + + return 0 } get_pid() {