autotest: Refactor reap_spdk_processes()
This is done in order to speed up entire lookup and be more robust with matching target processes. This implementation also tries to detect processes executed outside of the local repo workspace - this is most relevant for the CI where lingering processes may come from different jenkins workspaces (i.e. executed by different jobs). Signed-off-by: Michal Berger <michal.berger@intel.com> Change-Id: Id4f62302701f064ad00906497379e16ff8c04993 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16356 Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
37b5d87b19
commit
15e31017dd
@ -1544,51 +1544,40 @@ function pap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_proc_paths() {
|
function get_proc_paths() {
|
||||||
local procs proc
|
case "$(uname -s)" in
|
||||||
if [[ $(uname -s) == Linux ]]; then
|
Linux) # ps -e -opid,exe <- not supported under {centos7,rocky8}'s procps-ng
|
||||||
for proc in /proc/[0-9]*; do
|
local pid
|
||||||
[[ -e $proc/exe ]] || continue
|
for pid in /proc/[0-9]*; do
|
||||||
procs[${proc##*/}]=$(readlink -f "$proc/exe")
|
[[ -e $pid/exe ]] || continue
|
||||||
done
|
echo "${pid##*/} $(readlink -f "$pid/exe")"
|
||||||
elif [[ $(uname -s) == FreeBSD ]]; then
|
|
||||||
while read -r proc _ _ path; do
|
|
||||||
[[ -e $path ]] || continue
|
|
||||||
procs[proc]=$path
|
|
||||||
done < <(procstat -ab)
|
|
||||||
fi
|
|
||||||
|
|
||||||
for proc in "${!procs[@]}"; do
|
|
||||||
echo "$proc" "${procs[proc]}"
|
|
||||||
done
|
done
|
||||||
|
;;
|
||||||
|
FreeeBSD) procstat -ab | awk '{print $1, $4}' ;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
is_exec_file() { [[ -f $1 && $(file "$1") =~ ELF.+executable ]]; }
|
exec_files() { file "$@" | awk -F: '/ELF.+executable/{print $1}'; }
|
||||||
|
|
||||||
function reap_spdk_processes() {
|
function reap_spdk_processes() {
|
||||||
local bins bin
|
local bins test_bins procs
|
||||||
local misc_bins
|
local spdk_procs spdk_pids
|
||||||
|
|
||||||
while read -r bin; do
|
mapfile -t test_bins < <(find "$rootdir"/test/{app,env,event} -type f)
|
||||||
is_exec_file "$bin" && misc_bins+=("$bin")
|
mapfile -t bins < <(
|
||||||
done < <(find "$rootdir"/test/{app,env,event} -type f)
|
exec_files "${test_bins[@]}"
|
||||||
|
readlink -f "$SPDK_BIN_DIR/"* "$SPDK_EXAMPLE_DIR/"*
|
||||||
|
)
|
||||||
|
|
||||||
mapfile -t bins < <(readlink -f "$SPDK_BIN_DIR/"* "$SPDK_EXAMPLE_DIR/"* "${misc_bins[@]}")
|
mapfile -t spdk_procs < <(get_proc_paths | grep -E "$(
|
||||||
|
IFS="|"
|
||||||
|
echo "${bins[*]#$rootdir/}"
|
||||||
|
)" || true)
|
||||||
|
((${#spdk_procs[@]} > 0)) || return 0
|
||||||
|
|
||||||
local spdk_pid spdk_pids path
|
printf '%s is still up, killing\n' "${spdk_procs[@]}" >&2
|
||||||
while read -r spdk_pid path; do
|
mapfile -t spdk_pids < <(printf '%s\n' "${spdk_procs[@]}" | awk '{print $1}')
|
||||||
if [[ ${bins[*]/$path/} != "${bins[*]}" ]]; then
|
|
||||||
echo "$path is still up ($spdk_pid), killing"
|
|
||||||
spdk_pids[spdk_pid]=$path
|
|
||||||
fi
|
|
||||||
done < <(get_proc_paths)
|
|
||||||
|
|
||||||
((${#spdk_pids[@]} > 0)) || return 0
|
|
||||||
|
|
||||||
kill -SIGTERM "${!spdk_pids[@]}" 2> /dev/null || :
|
|
||||||
# Wait a bit and then use the stick
|
|
||||||
sleep 2
|
|
||||||
kill -SIGKILL "${!spdk_pids[@]}" 2> /dev/null || :
|
|
||||||
|
|
||||||
|
kill -SIGKILL "${spdk_pids[@]}" 2> /dev/null || :
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user