diff options
author | Karel Zak | 2014-04-28 12:01:37 +0200 |
---|---|---|
committer | Karel Zak | 2014-04-28 12:01:37 +0200 |
commit | 7a1c980c68db5a6f85478c5a0ca21d25c67287e9 (patch) | |
tree | cf5e7f4b437e9d046fa71ea5e458b9618759f37b /tests/ts/kill | |
parent | Merge branch 'kill-tests-v4' of git://github.com/kerolasa/lelux-utiliteetit (diff) | |
download | kernel-qcow2-util-linux-7a1c980c68db5a6f85478c5a0ca21d25c67287e9.tar.gz kernel-qcow2-util-linux-7a1c980c68db5a6f85478c5a0ca21d25c67287e9.tar.xz kernel-qcow2-util-linux-7a1c980c68db5a6f85478c5a0ca21d25c67287e9.zip |
tests: add kill_functions.sh to avoid duplicate code
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'tests/ts/kill')
-rwxr-xr-x | tests/ts/kill/all_processes | 20 | ||||
-rw-r--r-- | tests/ts/kill/kill_functions.sh | 22 | ||||
-rwxr-xr-x | tests/ts/kill/name_to_number | 23 | ||||
-rwxr-xr-x | tests/ts/kill/options | 22 | ||||
-rwxr-xr-x | tests/ts/kill/print_pid | 21 |
5 files changed, 43 insertions, 65 deletions
diff --git a/tests/ts/kill/all_processes b/tests/ts/kill/all_processes index 8d6238152..af863d56a 100755 --- a/tests/ts/kill/all_processes +++ b/tests/ts/kill/all_processes @@ -23,6 +23,8 @@ ts_skip_nonroot ts_check_test_command "$TS_CMD_KILL" ts_check_test_command "$TS_HELPER_SIGRECEIVE" +. "$TS_SELF/kill_functions.sh" + HELPER_SYMLINK="$TS_CWD/$(mktemp -u XXXXXXXXXXXXXXX)" ln -s "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK" trap "rm -f $HELPER_SYMLINK" 0 @@ -30,21 +32,9 @@ trap "rm -f $HELPER_SYMLINK" 0 "$HELPER_SYMLINK" -s "$TS_TESTUSER" >> "$TS_OUTPUT" 2>&1 & TEST_PID=$! -# test_sigreceive needs time to start up -for i in 0.01 0.1 1 1 1 1; do - awk 'BEGIN { retval=1 } - $1 ~ /^SigCgt/ { - lbyte = strtonum("0x" substr($2, 16, 16)) - if (and(lbyte, 1)) { - retval=0 - } - } END { - exit retval - }' /proc/$TEST_PID/status && - up=1 && - break - sleep $i -done +check_test_sigreceive $TEST_PID +[ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT" + echo "test 1" >> "$TS_OUTPUT" "$TS_CMD_KILL" ${HELPER_SYMLINK##*/} >> "$TS_OUTPUT" 2>&1 if [ $? -ne 1 ]; then diff --git a/tests/ts/kill/kill_functions.sh b/tests/ts/kill/kill_functions.sh new file mode 100644 index 000000000..043b4cb4f --- /dev/null +++ b/tests/ts/kill/kill_functions.sh @@ -0,0 +1,22 @@ + +# The test_sigreceive is ready when signal process mask contains SIGHUP +function check_test_sigreceive { + local rc=0 + local pid=$1 + + for i in 0.01 0.1 1 1 1 1; do + awk 'BEGIN { retval=1 } + /^SigCgt/ { + lbyte = strtonum("0x" substr($2, 16, 16)) + if (and(lbyte, 1)) { + retval=0 + } + } END { + exit retval + }' /proc/$pid/status && + rc=1 && + break + sleep $i + done + return $rc +} diff --git a/tests/ts/kill/name_to_number b/tests/ts/kill/name_to_number index a6a70fc58..a57ed852e 100755 --- a/tests/ts/kill/name_to_number +++ b/tests/ts/kill/name_to_number @@ -21,6 +21,8 @@ ts_init "$*" ts_check_test_command "$TS_CMD_KILL" ts_check_test_command "$TS_HELPER_SIGRECEIVE" +. "$TS_SELF/kill_functions.sh" + all_ok=true HELPER_SYMLINK="$TS_OUTDIR/$(mktemp -u XXXXXXXXXXXXXXX)" ln -s "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK" @@ -39,25 +41,12 @@ for SIG in $($TS_CMD_KILL -L); do if [ "x$SIG" = "xRTMAX" ]; then SIG="$SIG-0" fi + "$HELPER_SYMLINK" >> "$TS_OUTPUT" 2>&1 & TEST_PID=$! - # test_sigreceive needs time to start up - up=0 - for i in 0.01 0.1 1 1 1 1; do - awk 'BEGIN { retval=1 } - $1 ~ /^SigCgt/ { - lbyte = strtonum("0x" substr($2, 16, 16)) - if (and(lbyte, 1)) { - retval=0 - } - } END { - exit retval - }' /proc/$TEST_PID/status && - up=1 && - break - sleep $i - done - test $up = 0 && echo "$SIG sigreceive ${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT" + check_test_sigreceive $TEST_PID + [ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT" + "$TS_CMD_KILL" -$SIG ${HELPER_SYMLINK##*/} >> "$TS_OUTPUT" 2>&1 wait $TEST_PID if [ $? -ne $EXPECTED ]; then diff --git a/tests/ts/kill/options b/tests/ts/kill/options index 33a9b9b85..413037c21 100755 --- a/tests/ts/kill/options +++ b/tests/ts/kill/options @@ -21,6 +21,8 @@ ts_init "$*" ts_check_test_command "$TS_CMD_KILL" ts_check_test_command "$TS_HELPER_SIGRECEIVE" +. "$TS_SELF/kill_functions.sh" + all_ok=true HELPER_SYMLINK="$TS_OUTDIR/$(mktemp -u XXXXXXXXXXXXXXX)" @@ -31,23 +33,9 @@ try_option() { "$HELPER_SYMLINK" >> "$TS_OUTPUT" 2>&1 & TEST_PID=$! - # test_sigreceive needs time to start up - up=0 - for i in 0.01 0.1 1 1 1 1; do - awk 'BEGIN { retval=1 } - $1 ~ /^SigCgt/ { - lbyte = strtonum("0x" substr($2, 16, 16)) - if (and(lbyte, 1)) { - retval=0 - } - } END { - exit retval - }' /proc/$TEST_PID/status && - up=1 && - break - sleep $i - done - test $up = 1 || echo "$@ sigreceive helper did not start" >> "$TS_OUTPUT" + check_test_sigreceive $TEST_PID + [ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT" + "$TS_CMD_KILL" "$@" $TEST_PID >> "$TS_OUTPUT" 2>&1 if [ $? -ne 0 ]; then echo "kill $@ did not work" >> "$TS_OUTPUT" diff --git a/tests/ts/kill/print_pid b/tests/ts/kill/print_pid index 46bbb13aa..4da8b4509 100755 --- a/tests/ts/kill/print_pid +++ b/tests/ts/kill/print_pid @@ -21,6 +21,8 @@ ts_init "$*" ts_check_test_command "$TS_CMD_KILL" ts_check_test_command "$TS_HELPER_SIGRECEIVE" +. "$TS_SELF/kill_functions.sh" + all_ok=true HELPER_SYMLINK="$TS_OUTDIR/$(mktemp -u XXXXXXXXXXXXXXX)" @@ -29,22 +31,9 @@ trap "rm -f $HELPER_SYMLINK" 0 "$HELPER_SYMLINK" >> "$TS_OUTPUT" 2>&1 & TEST_PID=$! -# test_sigreceive needs time to start up -up=0 -for i in 0.01 0.1 1 1 1 1; do - awk 'BEGIN { retval=1 } - $1 ~ /^SigCgt/ { - lbyte = strtonum("0x" substr($2, 16, 16)) - if (and(lbyte, 1)) { - retval=0 - } - } END { - exit retval - }' /proc/$TEST_PID/status && - up=1 && - break - sleep $i -done +check_test_sigreceive $TEST_PID +[ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT" + KILL_PID=$("$TS_CMD_KILL" -p ${HELPER_SYMLINK##*/} 2>> "$TS_OUTPUT" 2>&1) if [ $? -ne 0 ]; then echo "kill -p did not work" >> "$TS_OUTPUT" |