Skip to content

Commit f4ad536

Browse files
committed
test-case: Implement one common method for kill process
Implement one common method for kill process in lib.sh Replace all kill -9 with kill_process() function in tests. Method kill_process() try kill -15 first and as a last resort do kill -9. Signed-off-by: Szymon Richert <szymon1.richert@intel.com>
1 parent 17253b3 commit f4ad536

12 files changed

+63
-28
lines changed

case-lib/lib.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,29 @@ check_alsa_tool_process()
945945
esac
946946
}
947947

948+
kill_process()
949+
{
950+
local pid="$1"
951+
952+
[[ -n "$pid" ]] || {
953+
dloge "kill_process: missing pid"
954+
return 1
955+
}
956+
957+
kill -0 "$pid" 2>/dev/null || return 0
958+
959+
kill -15 "$pid" 2>/dev/null || true
960+
sleep 1
961+
962+
kill -0 "$pid" 2>/dev/null || return 0
963+
964+
kill -9 "$pid" 2>/dev/null || true
965+
966+
kill -0 "$pid" 2>/dev/null && return 1
967+
968+
return 0
969+
}
970+
948971
aplay_opts()
949972
{
950973
if [[ "$SOF_ALSA_TOOL" = "tinyalsa" ]]; then

test-case/check-runtime-pm-double-active.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ do
113113
dlogi "runtime status: $result"
114114
if [[ $result == active ]]; then
115115
# stop playback or capture device - check status again
116-
dlogc "kill process: kill -9 $pid"
117-
kill -9 $pid && wait $pid 2>/dev/null
116+
dlogc "kill process: $pid"
117+
kill_process "$pid" || true
118+
wait "$pid" 2>/dev/null || true
118119
dlogi "$cmd killed"
119120

120121
# check runtime pm status with maxmium timeout value, it will exit if dsp is not suspended
@@ -125,8 +126,9 @@ do
125126
else
126127
dloge "$cmd process for pcm $pcm runtime status is not active as expected"
127128
# stop playback or capture device otherwise no one will stop this $cmd.
128-
dlogc "kill process: kill -9 $pid"
129-
kill -9 $pid && wait $pid 2>/dev/null
129+
dlogc "kill process: $pid"
130+
kill_process "$pid" || true
131+
wait "$pid" 2>/dev/null || true
130132
func_lib_lsof_error_dump $snd
131133
exit 1
132134
fi

test-case/check-runtime-pm-status.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ do
109109
dlogi "runtime status: $result"
110110
if [[ $result == active ]]; then
111111
# stop playback or capture device - check status again
112-
dlogc "kill process: kill -9 $pid"
113-
kill -9 $pid && wait $pid 2>/dev/null
112+
dlogc "kill process: $pid"
113+
kill_process "$pid" || true
114+
wait "$pid" 2>/dev/null || true
114115
dlogi "$cmd killed"
115116
func_check_dsp_status ${OPT_VAL['d']}
116117
result=`sof-dump-status.py --dsp_status 0`
@@ -123,8 +124,9 @@ do
123124
else
124125
dloge "$cmd process for pcm $pcm runtime status is not active as expected"
125126
# stop playback or capture device otherwise no one will stop this $cmd.
126-
dlogc "kill process: kill -9 $pid"
127-
kill -9 $pid && wait $pid 2>/dev/null
127+
dlogc "kill process: $pid"
128+
kill_process "$pid" || true
129+
wait "$pid" 2>/dev/null || true
128130
func_lib_lsof_error_dump $snd
129131
exit 1
130132
fi

test-case/check-signal-stop-start.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func_stop_start_pipeline()
7070
# check aplay/arecord process state
7171
sof-process-state.sh "$pid" >/dev/null || {
7272
dloge "$cmd($pid) process is in an abnormal status"
73-
kill -9 "$pid"
73+
kill_process "$pid" || true
7474
exit 1
7575
}
7676
dlogi "Stop/start count: $i"
@@ -116,8 +116,8 @@ do
116116
func_stop_start_pipeline
117117

118118
# kill aplay/arecord process
119-
dlogc "kill process: kill -9 $pid"
120-
kill -9 "$pid"
119+
dlogc "kill process: $pid"
120+
kill_process "$pid" || true
121121
done
122122

123123
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"

test-case/check-suspend-resume-with-audio.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,6 @@ do
137137
exit 1
138138
}
139139
dlogi "Killing $cmd_args"
140-
kill -9 $process_id || true
140+
kill_process "$process_id" || true
141141
done
142142

test-case/check-userspace-paplay.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ for round in $(seq 1 $round_cnt); do
108108
else
109109
dlogi "paplay runs successfully"
110110
# kill all paplay process
111-
kill -9 $pid
111+
kill_process "$pid" || true
112112
sleep 0.5
113113
fi
114114
fi

test-case/check-userspace-parecord.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ for round in $(seq 1 $round_cnt); do
115115
else
116116
dlogi "parecord runs successfully"
117117
# kill all parecord processes
118-
kill -9 $pid
118+
kill_process "$pid" || true
119119
sleep 0.5
120120
fi
121121
fi

test-case/check-volume-levels.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ main () {
8383
# Stop sine playback and do cleanup
8484
nap
8585
dlogi "The test procedure is now complete. Killing the aplay process $aplayPID."
86-
kill $aplayPID
86+
kill_process "$aplayPID" || true
8787

8888
# Measure, delete unnecessary wav files if passed
8989
if measure_levels; then

test-case/check-xrun-injection.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ func_xrun_injection()
7272
# check aplay/arecord process state
7373
sof-process-state.sh "$pid" >/dev/null || {
7474
dloge "aplay/arecord process is in an abnormal status"
75-
kill -9 "$pid" && wait "$pid" 2>/dev/null
75+
kill_process "$pid" || true
76+
wait "$pid" 2>/dev/null || true
7677
exit 1
7778
}
7879
dlogi "XRUN injection: $i"
@@ -119,8 +120,9 @@ do
119120
dlogc "echo 1 > $xrun_injection"
120121
func_xrun_injection
121122
# kill aplay/arecord process
122-
dlogc "kill process: kill -9 $pid"
123-
kill -9 $pid && wait $pid 2>/dev/null
123+
dlogc "kill process: $pid"
124+
kill_process "$pid" || true
125+
wait "$pid" 2>/dev/null || true
124126
done
125127

126128
sof-kernel-log-check.sh "$KERNEL_CHECKPOINT"

test-case/multiple-pipeline.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ func_error_exit()
127127
{
128128
dloge "$*"
129129

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

133135
exit 1
134136
}
@@ -208,9 +210,9 @@ do
208210
dlogi "checking pipeline status again"
209211
ps_checks
210212

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

216218
if pgrep arecord || pgrep aplay; then

0 commit comments

Comments
 (0)