Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions case-lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,29 @@ check_alsa_tool_process()
esac
}

kill_process()
{
local pid="$1"

[[ -n "$pid" ]] || {
dloge "kill_process: missing pid"
return 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would die here because this looks like a serious enough bug.

}

kill -0 "$pid" 2>/dev/null || return 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-0 looks a bit mysterious and it could fail for other reasons. ps is more direct and more obvious:

Suggested change
kill -0 "$pid" 2>/dev/null || return 0
ps -p "$pid" >/dev/null || return 0

https://stackoverflow.com/questions/3043978/how-to-check-if-a-process-id-pid-exists

BTW there is still a race: the process could still exit right after this check.


kill -15 "$pid" 2>/dev/null || true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discarding stderr is almost always a bad idea. What unwanted message does this discard?

Suggested change
kill -15 "$pid" 2>/dev/null || true
kill -TERM "$pid" || true

sleep 1

kill -0 "$pid" 2>/dev/null || return 0

kill -9 "$pid" 2>/dev/null || true

kill -0 "$pid" 2>/dev/null && return 1

return 0
}

aplay_opts()
{
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then
Expand Down
10 changes: 6 additions & 4 deletions test-case/check-runtime-pm-double-active.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ do
dlogi "runtime status: $result"
if [[ $result == active ]]; then
# stop playback or capture device - check status again
dlogc "kill process: kill -9 $pid"
kill -9 $pid && wait $pid 2>/dev/null
dlogc "kill process: $pid"
kill_process "$pid" || true
wait "$pid" 2>/dev/null || true
dlogi "$cmd killed"

# check runtime pm status with maxmium timeout value, it will exit if dsp is not suspended
Expand All @@ -125,8 +126,9 @@ do
else
dloge "$cmd process for pcm $pcm runtime status is not active as expected"
# stop playback or capture device otherwise no one will stop this $cmd.
dlogc "kill process: kill -9 $pid"
kill -9 $pid && wait $pid 2>/dev/null
dlogc "kill process: $pid"
kill_process "$pid" || true
wait "$pid" 2>/dev/null || true
func_lib_lsof_error_dump $snd
exit 1
fi
Expand Down
10 changes: 6 additions & 4 deletions test-case/check-runtime-pm-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ do
dlogi "runtime status: $result"
if [[ $result == active ]]; then
# stop playback or capture device - check status again
dlogc "kill process: kill -9 $pid"
kill -9 $pid && wait $pid 2>/dev/null
dlogc "kill process: $pid"
kill_process "$pid" || true
wait "$pid" 2>/dev/null || true
dlogi "$cmd killed"
func_check_dsp_status ${OPT_VAL['d']}
result=`sof-dump-status.py --dsp_status 0`
Expand All @@ -123,8 +124,9 @@ do
else
dloge "$cmd process for pcm $pcm runtime status is not active as expected"
# stop playback or capture device otherwise no one will stop this $cmd.
dlogc "kill process: kill -9 $pid"
kill -9 $pid && wait $pid 2>/dev/null
dlogc "kill process: $pid"
kill_process "$pid" || true
wait "$pid" 2>/dev/null || true
func_lib_lsof_error_dump $snd
exit 1
fi
Expand Down
6 changes: 3 additions & 3 deletions test-case/check-signal-stop-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func_stop_start_pipeline()
# check aplay/arecord process state
sof-process-state.sh "$pid" >/dev/null || {
dloge "$cmd($pid) process is in an abnormal status"
kill -9 "$pid"
kill_process "$pid" || true
exit 1
}
dlogi "Stop/start count: $i"
Expand Down Expand Up @@ -116,8 +116,8 @@ do
func_stop_start_pipeline

# kill aplay/arecord process
dlogc "kill process: kill -9 $pid"
kill -9 "$pid"
dlogc "kill process: $pid"
kill_process "$pid" || true
done

sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"
Expand Down
2 changes: 1 addition & 1 deletion test-case/check-suspend-resume-with-audio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ do
exit 1
}
dlogi "Killing $cmd_args"
kill -9 $process_id || true
kill_process "$process_id" || true
done

2 changes: 1 addition & 1 deletion test-case/check-userspace-paplay.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ for round in $(seq 1 $round_cnt); do
else
dlogi "paplay runs successfully"
# kill all paplay process
kill -9 $pid
kill_process "$pid" || true
sleep 0.5
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion test-case/check-userspace-parecord.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ for round in $(seq 1 $round_cnt); do
else
dlogi "parecord runs successfully"
# kill all parecord processes
kill -9 $pid
kill_process "$pid" || true
sleep 0.5
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion test-case/check-volume-levels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ main () {
# Stop sine playback and do cleanup
nap
dlogi "The test procedure is now complete. Killing the aplay process $aplayPID."
kill $aplayPID
kill_process "$aplayPID" || true

# Measure, delete unnecessary wav files if passed
if measure_levels; then
Expand Down
8 changes: 5 additions & 3 deletions test-case/check-xrun-injection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ func_xrun_injection()
# check aplay/arecord process state
sof-process-state.sh "$pid" >/dev/null || {
dloge "aplay/arecord process is in an abnormal status"
kill -9 "$pid" && wait "$pid" 2>/dev/null
kill_process "$pid" || true
wait "$pid" 2>/dev/null || true
exit 1
}
dlogi "XRUN injection: $i"
Expand Down Expand Up @@ -119,8 +120,9 @@ do
dlogc "echo 1 > $xrun_injection"
func_xrun_injection
# kill aplay/arecord process
dlogc "kill process: kill -9 $pid"
kill -9 $pid && wait $pid 2>/dev/null
dlogc "kill process: $pid"
kill_process "$pid" || true
wait "$pid" 2>/dev/null || true
done

sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"
Expand Down
12 changes: 7 additions & 5 deletions test-case/multiple-pipeline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ func_error_exit()
{
dloge "$*"

pgrep -a aplay && pkill -9 aplay
pgrep -a arecord && pkill -9 arecord
pgrep -a aplay &&
while read -r pid; do kill_process "$pid" || true; done < <(pgrep -x aplay)
pgrep -a arecord &&
while read -r pid; do kill_process "$pid" || true; done < <(pgrep -x arecord)

exit 1
}
Expand Down Expand Up @@ -208,9 +210,9 @@ do
dlogi "checking pipeline status again"
ps_checks

dlogc 'pkill -9 aplay arecord'
pkill -9 arecord || true
pkill -9 aplay || true
dlogc 'kill_process all aplay/arecord pids'
while read -r pid; do kill_process "$pid" || true; done < <(pgrep -x arecord)
while read -r pid; do kill_process "$pid" || true; done < <(pgrep -x aplay)
sleep 1 # try not to pollute the next iteration

if pgrep arecord || pgrep aplay; then
Expand Down
12 changes: 8 additions & 4 deletions test-case/simultaneous-playback-capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ logger_disabled || func_lib_start_log_collect
func_error_exit()
{
dloge "$*"
kill -9 "$aplay_pid" && wait "$aplay_pid" 2>/dev/null
kill -9 "$arecord_pid" && wait "$arecord_pid" 2>/dev/null
kill_process "$aplay_pid" || true
wait "$aplay_pid" 2>/dev/null || true
kill_process "$arecord_pid" || true
wait "$arecord_pid" 2>/dev/null || true
exit 1
}

Expand Down Expand Up @@ -113,8 +115,10 @@ do

# kill all live processes, successful end of test
dlogc "killing all pipelines"
kill -9 $aplay_pid && wait $aplay_pid 2>/dev/null
kill -9 $arecord_pid && wait $arecord_pid 2>/dev/null
kill_process "$aplay_pid" || true
wait "$aplay_pid" 2>/dev/null || true
kill_process "$arecord_pid" || true
wait "$arecord_pid" 2>/dev/null || true

done
# check kernel log for each iteration to catch issues
Expand Down
2 changes: 1 addition & 1 deletion test-case/test-jack-detection-playback-capture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ testing_one_pcm()
die "Plug $headphone_jack_name jack failed."
}

kill -9 $pid_playback > /dev/null 2>&1
kill_process "$pid_playback" > /dev/null 2>&1 || true
wait $pid_playback 2>/dev/null || true
ps -p "$pid_playback" > /dev/null && {
dloge "Failed to kill playback process."
Expand Down
Loading