master - tests: rename kill_tagged_processes
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=16e8006eb05a3fd18d1efeb58f79ffbb41ba61e2 Commit: 16e8006eb05a3fd18d1efeb58f79ffbb41ba61e2 Parent: c18e969e30a44ec392f40414e1f134ff70cecb38 Author: Zdenek Kabelac <[email protected]> AuthorDate: Thu Apr 30 18:42:31 2015 +0200 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Fri May 1 15:07:58 2015 +0200
tests: rename kill_tagged_processes
Better name for aux function.
First use normal -TERM, and only after a while use -KILL (leaving some time to correctly finish)
Print INFO about killed processes.
--- test/lib/aux.sh | 31 +++++++++++++++++++++++++------ test/shell/pvmove-abort-all.sh | 2 +- test/shell/pvmove-abort.sh | 2 +- test/shell/pvmove-restart.sh | 2 +- test/shell/pvmove-resume-1.sh | 2 +- test/shell/pvmove-resume-2.sh | 2 +- test/shell/pvmove-resume-multiseg.sh | 2 +- 7 files changed, 31 insertions(+), 12 deletions(-)
test/lib/aux.sh +25 -6
@@ -233,17 +233,36 @@ kill_sleep_kill_() { } print_procs_by_tag_() { - ps -o pid=,args= ehax 2>/dev/null | grep -weLVM_TEST_TAG=${1:-kill_me_$PREFIX} 2>/dev/null || true + (ps -o pid,args ehax | grep -we"LVM_TEST_TAG=${1:-kill_me_$PREFIX}") || true } count_processes_with_tag() { print_procs_by_tag_ | wc -l } -kill_listed_processes() { - while read pid b; do - test -z "$pid" || kill -9 $pid - done <<< $(print_procs_by_tag_ $@) +kill_tagged_processes() { + local pid + local pids + local wait + + # read uses all vars within pipe subshell + print_procs_by_tag_ "$@" | while read -r pid wait; do + if test -n "$pid" ; then + echo "Killing tagged process: $pid ${wait:0:120}..." + kill -TERM $pid 2>/dev/null || true + fi + pids="$pids $pid" + done + + # wait if process exited and eventually -KILL + wait=0 + for pid in $pids ; do + while ps $pid > /dev/null && test $wait -le 10; do + sleep .2 + wait=$(($wait + 1)) + done + test $wait -le 10 || kill -KILL $pid 2>/dev/null || true + done } teardown() {
@@ -252,7 +271,7 @@ teardown() { if test -f TESTNAME ; then - kill_listed_processes + kill_tagged_processes kill_sleep_kill_ LOCAL_LVMETAD ${LVM_VALGRIND_LVMETAD:-0}
test/shell/pvmove-abort-all.sh +1 -1
@@ -67,7 +67,7 @@ not grep "^\[pvmove" out lvremove -ff $vg $vg1 wait -aux kill_listed_processes +aux kill_tagged_processes done done
test/shell/pvmove-abort.sh +1 -1
@@ -58,7 +58,7 @@ pvmove --abort lvremove -ff $vg wait -aux kill_listed_processes +aux kill_tagged_processes done done
test/shell/pvmove-restart.sh +1 -1
@@ -90,7 +90,7 @@ pvmove --abort lvs -a -o+devices $vg lvremove -ff $vg -aux kill_listed_processes +aux kill_tagged_processes done # Restore delayed device back
test/shell/pvmove-resume-1.sh +1 -1
@@ -98,7 +98,7 @@ test_pvmove_resume() { i=$((i + 1)) done - aux kill_listed_processes + aux kill_tagged_processes lvremove -ff $vg $vg1 }
test/shell/pvmove-resume-2.sh +1 -1
@@ -80,7 +80,7 @@ test_pvmove_resume() { i=$((i + 1)) done - aux kill_listed_processes + aux kill_tagged_processes lvremove -ff $vg }
test/shell/pvmove-resume-multiseg.sh +1 -1
@@ -92,7 +92,7 @@ test_pvmove_resume() { i=$((i + 1)) done - aux kill_listed_processes + aux kill_tagged_processes lvremove -ff $vg }