summaryrefslogtreecommitdiffstats
path: root/tests/ts/kill
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ts/kill')
-rwxr-xr-xtests/ts/kill/all_processes66
-rw-r--r--tests/ts/kill/kill_functions.sh29
-rwxr-xr-xtests/ts/kill/name_to_number72
-rwxr-xr-xtests/ts/kill/options68
-rwxr-xr-xtests/ts/kill/print_pid63
-rwxr-xr-xtests/ts/kill/queue58
6 files changed, 356 insertions, 0 deletions
diff --git a/tests/ts/kill/all_processes b/tests/ts/kill/all_processes
new file mode 100755
index 0000000..b228077
--- /dev/null
+++ b/tests/ts/kill/all_processes
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="all_processes"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+ts_skip_nonroot
+
+# make sure we do not use shell built-in command
+if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
+ TS_CMD_KILL="$(which kill)"
+fi
+
+ts_check_test_command "$TS_CMD_KILL"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+. "$TS_SELF/kill_functions.sh"
+
+HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/alXXXXXXXXXXXXX")"
+ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
+
+"$HELPER_SYMLINK" -s "$TS_TESTUSER" >> $TS_OUTPUT 2>> $TS_ERRLOG &
+TEST_PID=$!
+
+check_test_sigreceive $TEST_PID
+[ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT"
+
+
+ts_log_both "test 1"
+"$TS_CMD_KILL" ${HELPER_SYMLINK##*/} >> $TS_OUTPUT 2>> $TS_ERRLOG
+if [ $? -ne 1 ]; then
+ echo "kill did not return 1" >> "$TS_OUTPUT"
+fi
+
+ts_log_both "test 2"
+"$TS_CMD_KILL" -a ${HELPER_SYMLINK##*/} >> $TS_OUTPUT 2>> $TS_ERRLOG
+if [ $? -ne 0 ]; then
+ echo "kill did not return 0" >> "$TS_OUTPUT"
+fi
+wait $TEST_PID
+
+ts_log_both "test 3"
+"$TS_CMD_KILL" -a -p ${HELPER_SYMLINK##*/} >> $TS_OUTPUT 2>> $TS_ERRLOG
+if [ $? -ne 1 ]; then
+ echo "kill -a -p did not return 1" >> "$TS_OUTPUT"
+fi
+
+sed -i "s/${HELPER_SYMLINK##*/}/${TS_HELPER_SIGRECEIVE##*/}/" $TS_OUTPUT $TS_ERRLOG
+
+rm -f "$HELPER_SYMLINK"
+
+ts_finalize
diff --git a/tests/ts/kill/kill_functions.sh b/tests/ts/kill/kill_functions.sh
new file mode 100644
index 0000000..4ace3d9
--- /dev/null
+++ b/tests/ts/kill/kill_functions.sh
@@ -0,0 +1,29 @@
+# kill tests, or command, will not when /proc is missing.
+test -d /proc || ts_skip "/proc not available"
+
+# 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
+ if [ ! -f /proc/$pid/status ]; then
+ # The /proc exists, but not status file. Because the
+ # process already started it is unlikely the file would
+ # appear after any amount of waiting. Try to sleep for
+ # moment and hopefully test_sigreceive is ready to be
+ # killed.
+ echo "kill_functions.sh: /proc/$pid/status: No such file or directory"
+ sleep 2
+ rc=1
+ break
+ fi
+ sigmask=$((16#$( awk '/SigCgt/ { print $2}' /proc/$pid/status) ))
+ if [ $(( $sigmask & 1 )) == 1 ]; then
+ rc=1
+ break
+ fi
+ sleep $i
+ done
+ return $rc
+}
diff --git a/tests/ts/kill/name_to_number b/tests/ts/kill/name_to_number
new file mode 100755
index 0000000..8a7f4be
--- /dev/null
+++ b/tests/ts/kill/name_to_number
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="name_to_number"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+# make sure we do not use shell built-in command
+if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
+ TS_CMD_KILL="$(which kill)"
+fi
+
+ts_check_test_command "$TS_CMD_KILL"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+. "$TS_SELF/kill_functions.sh"
+
+all_ok=true
+
+HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/naXXXXXXXXXXXXX")"
+ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
+
+for SIG in $($TS_CMD_KILL -L); do
+ if [ "x${SIG//[0-9]/}" = "x" ]; then
+ EXPECTED=$SIG
+ continue
+ fi
+ if [ "$TS_ENABLE_ASAN" == "yes" ] && [ "x$SIG" = "xSEGV" ]; then
+ continue
+ fi
+ if [ "x$SIG" = "xSTOP" ] || [ "x$SIG" = "xKILL" ]; then
+ continue
+ fi
+ if [ "x$SIG" = "xRTMIN" ]; then
+ SIG="$SIG+0"
+ fi
+ if [ "x$SIG" = "xRTMAX" ]; then
+ SIG="$SIG-0"
+ fi
+
+ "$HELPER_SYMLINK" >> $TS_OUTPUT 2>> $TS_ERRLOG &
+ TEST_PID=$!
+ 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>> $TS_ERRLOG
+ wait $TEST_PID
+ if [ $? -ne $EXPECTED ]; then
+ echo "$SIG returned $? while $EXPECTED was expected" >> "$TS_OUTPUT"
+ all_ok=false
+ fi
+done
+
+if $all_ok; then
+ echo 'all ok' >> "$TS_OUTPUT"
+fi
+rm -f "$HELPER_SYMLINK"
+
+ts_finalize
diff --git a/tests/ts/kill/options b/tests/ts/kill/options
new file mode 100755
index 0000000..10653a5
--- /dev/null
+++ b/tests/ts/kill/options
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="options"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+# make sure we do not use shell built-in command
+if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
+ TS_CMD_KILL="$(which kill)"
+fi
+
+ts_check_test_command "$TS_CMD_KILL"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+. "$TS_SELF/kill_functions.sh"
+
+all_ok=true
+
+HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/opXXXXXXXXXXXXX")"
+ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
+
+try_option()
+{
+ "$HELPER_SYMLINK" >> $TS_OUTPUT 2>> $TS_ERRLOG &
+ TEST_PID=$!
+ check_test_sigreceive $TEST_PID
+ [ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT"
+
+ "$TS_CMD_KILL" "$@" $TEST_PID >> $TS_OUTPUT 2>> $TS_ERRLOG
+ if [ $? -ne 0 ]; then
+ echo "kill $@ did not work" >> "$TS_OUTPUT"
+ all_ok=false
+ fi
+ wait $TEST_PID
+ if [ $? -ne 1 ]; then
+ echo "wait $TEST_PID for $@ did not work" >> "$TS_OUTPUT"
+ all_ok=false
+ fi
+}
+
+try_option -s 1
+try_option --signal 1
+try_option --signal HUP
+try_option --signal SIGHUP
+try_option -1
+try_option -HUP
+try_option -SIGHUP
+
+if $all_ok; then
+ echo 'all ok' >> "$TS_OUTPUT"
+fi
+rm -f "$HELPER_SYMLINK"
+
+ts_finalize
diff --git a/tests/ts/kill/print_pid b/tests/ts/kill/print_pid
new file mode 100755
index 0000000..6e2db37
--- /dev/null
+++ b/tests/ts/kill/print_pid
@@ -0,0 +1,63 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="print_pid"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+# make sure we do not use shell built-in command
+if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
+ TS_CMD_KILL="$(which kill)"
+fi
+
+ts_check_test_command "$TS_CMD_KILL"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+. "$TS_SELF/kill_functions.sh"
+
+all_ok=true
+
+HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/prXXXXXXXXXXXXX")"
+ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
+
+"$HELPER_SYMLINK" >> $TS_OUTPUT 2>> $TS_ERRLOG &
+TEST_PID=$!
+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>> $TS_ERRLOG)
+if [ $? -ne 0 ]; then
+ echo "kill -p did not work" >> "$TS_OUTPUT"
+ all_ok=false
+fi
+if [ "x$TEST_PID" != "x$KILL_PID" ]; then
+ echo "jobs -p $TEST_PID != kill -p $KILL_PID" >> "$TS_OUTPUT"
+ all_ok=false
+fi
+
+"$TS_CMD_KILL" -1 $TEST_PID
+wait $TEST_PID
+if [ $? -ne 1 ]; then
+ echo "wait $TEST_PID returned ${?}" >> "$TS_OUTPUT"
+ all_ok=false
+fi
+
+if $all_ok; then
+ echo 'all ok' >> "$TS_OUTPUT"
+fi
+rm -f "$HELPER_SYMLINK"
+
+ts_finalize
diff --git a/tests/ts/kill/queue b/tests/ts/kill/queue
new file mode 100755
index 0000000..6c9e9ef
--- /dev/null
+++ b/tests/ts/kill/queue
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="queue"
+
+. "$TS_TOPDIR/functions.sh"
+ts_init "$*"
+
+# make sure we do not use shell built-in command
+if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
+ TS_CMD_KILL="$(which kill)"
+fi
+
+ts_check_test_command "$TS_CMD_KILL"
+ts_check_test_command "$TS_HELPER_SIGRECEIVE"
+
+. "$TS_SELF/kill_functions.sh"
+
+all_ok=true
+
+HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/quXXXXXXXXXXXXX")"
+ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
+
+"$HELPER_SYMLINK" >> $TS_OUTPUT 2>> $TS_ERRLOG &
+TEST_PID=$!
+check_test_sigreceive $TEST_PID
+[ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT"
+
+"$TS_CMD_KILL" -1 --queue 42 $TEST_PID >> $TS_OUTPUT 2>> $TS_ERRLOG
+if [ $? -ne 0 ]; then
+ echo "kill --queue 42 failed" >> "$TS_OUTPUT"
+ all_ok=false
+fi
+wait $TEST_PID
+if [ $? -ne 42 ]; then
+ echo "wait $TEST_PID returned $? instead of 42" >> "$TS_OUTPUT"
+ all_ok=false
+fi
+
+if $all_ok; then
+ echo 'all ok' >> "$TS_OUTPUT"
+fi
+
+rm -f "$HELPER_SYMLINK"
+
+ts_finalize