Skip to content

Commit 2709798

Browse files
authored
Merge pull request #195 from vnarapar/DSP_fix
Minor fix for DSP test
2 parents a0cba29 + 1570f4d commit 2709798

File tree

2 files changed

+112
-14
lines changed

2 files changed

+112
-14
lines changed

Runner/suites/Multimedia/DSP_AudioPD/run.sh

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,23 @@ log_info "=== Test Initialization ==="
4242
log_info "Checking if dependency binary is available"
4343
check_dependencies adsprpcd
4444

45-
adsprpcd &
46-
PID=$!
45+
if is_process_running "adsprpcd"; then
46+
log_info "adsprpcd is running"
47+
PID=$(get_pid "adsprpcd")
48+
else
49+
log_info "adsprpcd is not running"
50+
log_info "Manually starting adsprpcd daemon"
51+
adsprpcd &
52+
PID=$!
53+
fi
54+
log_info "PID is $PID"
55+
sleep 5
4756

4857
if [ -z "$PID" ]; then
49-
echo "Failed to start the binary"
50-
exit 1
58+
log_info "Failed to start the binary"
59+
exit 1
5160
else
52-
echo "Binary is running successfully"
61+
log_info "Binary is running successfully"
5362
fi
5463

5564
check_stack_trace() {
@@ -60,20 +69,17 @@ check_stack_trace() {
6069
return 1
6170
fi
6271
}
72+
6373
# Print overall test result
6474
if check_stack_trace "$PID"; then
6575
log_pass "$TESTNAME : Test Passed"
6676
echo "$TESTNAME PASS" > "$res_file"
77+
kill_process "$PID"
6778
exit 0
6879
else
6980
log_fail "$TESTNAME : Test Failed"
7081
echo "$TESTNAME FAIL" > "$res_file"
82+
kill_process "$PID"
7183
exit 1
7284
fi
73-
74-
log_info "Kill the process"
75-
if kill -0 "$PID" 2>/dev/null; then
76-
kill -9 "$PID"
77-
wait "$PID"
78-
fi
79-
log_info "-------------------Completed $TESTNAME Testcase----------------------------"
85+
log_info "-------------------Completed $TESTNAME Testcase----------------------------"

Runner/utils/functestlib.sh

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ extract_tar_from_url() {
602602
log_info "Extracting $(basename "$tarfile")..."
603603
if tar -xvf "$tarfile"; then
604604
: > "$markfile" 2>/dev/null || true
605-
# Clear the minimal/offline sentinel only if it exists (SC2015-safe)
605+
# Clear the minimal/offline sentinel only if it exists (SC2015-safe)
606606
if [ -f "$skip_sentinel" ]; then
607607
rm -f "$skip_sentinel" 2>/dev/null || true
608608
fi
@@ -706,7 +706,7 @@ weston_stop() {
706706
log_info "Stopping Weston..."
707707
pkill -x weston
708708
for i in $(seq 1 10); do
709-
log_info "Waiting for Weston to stop with $i attempt "
709+
log_info "Waiting for Weston to stop with $i attempt "
710710
if ! weston_is_running; then
711711
log_info "Weston stopped successfully"
712712
return 0
@@ -3846,3 +3846,95 @@ ensure_network_online() {
38463846
unset net_script_path net_ifaces net_wifi net_ifc net_rc net_had_any_ip
38473847
return 1
38483848
}
3849+
3850+
kill_process() {
3851+
PID="$1"
3852+
KILL_TERM_GRACE="${KILL_TERM_GRACE:-5}"
3853+
KILL_KILL_GRACE="${KILL_KILL_GRACE:-5}"
3854+
SELF_PID="$$"
3855+
3856+
# Safety checks
3857+
if [ "$PID" -eq 1 ] || [ "$PID" -eq "$SELF_PID" ]; then
3858+
log_warn "Refusing to kill PID $PID (init or self)"
3859+
return 1
3860+
fi
3861+
3862+
# Check if process exists
3863+
if ! kill -0 "$PID" 2>/dev/null; then
3864+
log_info "Process $PID not running"
3865+
return 0
3866+
fi
3867+
3868+
log_info "Sending SIGTERM to PID $PID"
3869+
kill -TERM "$PID" 2>/dev/null
3870+
sleep "$KILL_TERM_GRACE"
3871+
3872+
if kill -0 "$PID" 2>/dev/null; then
3873+
log_info "Sending SIGKILL to PID $PID"
3874+
kill -KILL "$PID" 2>/dev/null
3875+
sleep "$KILL_KILL_GRACE"
3876+
fi
3877+
3878+
# Final check
3879+
if kill -0 "$PID" 2>/dev/null; then
3880+
log_warn "Failed to kill process $PID"
3881+
return 1
3882+
else
3883+
log_info "Process $PID terminated successfully"
3884+
return 0
3885+
fi
3886+
}
3887+
3888+
is_process_running() {
3889+
if [ -z "$1" ]; then
3890+
log_info "Usage: is_running <process_name_or_pid>"
3891+
return 1
3892+
fi
3893+
input="$1"
3894+
case "$input" in
3895+
''|*[!0-9]*)
3896+
# Non-numeric input: treat as process name
3897+
if ps -e | grep -w "$input" >/dev/null 2>&1 ||
3898+
ps -A | grep -w "$input" >/dev/null 2>&1; then
3899+
log_info "Process '$input' is running."
3900+
return 0
3901+
else
3902+
log_info "Process '$input' is not running."
3903+
return 1
3904+
fi
3905+
;;
3906+
*)
3907+
# Numeric input: treat as PID
3908+
if kill -0 "$input" 2>/dev/null; then
3909+
log_info "Process with PID $input is running."
3910+
return 0
3911+
else
3912+
log_info "Process with PID $input is not running."
3913+
return 1
3914+
fi
3915+
;;
3916+
esac
3917+
}
3918+
3919+
get_pid() {
3920+
if [ -z "$1" ]; then
3921+
log_info "Usage: get_pid <process_name>"
3922+
return 1
3923+
fi
3924+
3925+
process_name="$1"
3926+
3927+
# Try multiple ps variants for compatibility
3928+
pid=$(ps -e | awk -v name="$process_name" '$NF == name { print $1 }')
3929+
[ -z "$pid" ] && pid=$(ps -A | awk -v name="$process_name" '$NF == name { print $1 }')
3930+
[ -z "$pid" ] && pid=$(ps -aux | awk -v name="$process_name" '$11 == name { print $2 }')
3931+
[ -z "$pid" ] && pid=$(ps -ef | awk -v name="$process_name" '$NF == name { print $2 }')
3932+
3933+
if [ -n "$pid" ]; then
3934+
echo "$pid"
3935+
return 0
3936+
else
3937+
log_info "Process '$process_name' not found."
3938+
return 1
3939+
fi
3940+
}

0 commit comments

Comments
 (0)