aboutsummaryrefslogtreecommitdiff
path: root/tests/pkill.test
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-03-02 13:46:52 -0600
committerRob Landley <rob@landley.net>2016-03-02 13:46:52 -0600
commit7ae108f7c9d0845d8f7759ebeeb1b98a11ef8ceb (patch)
tree73ac1b6e488dcae8a2bb112037d4e65fec198c72 /tests/pkill.test
parent7ca5dc4232b9ac5ee5cd25c8b5b33a58904cd251 (diff)
downloadtoybox-7ae108f7c9d0845d8f7759ebeeb1b98a11ef8ceb.tar.gz
split pgrep/pkill tests.
Diffstat (limited to 'tests/pkill.test')
-rwxr-xr-xtests/pkill.test100
1 files changed, 100 insertions, 0 deletions
diff --git a/tests/pkill.test b/tests/pkill.test
new file mode 100755
index 00000000..e753d31f
--- /dev/null
+++ b/tests/pkill.test
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+# Copyright 2013 Divya Kothari <divya.s.kothari@gmail.com>
+# Copyright 2013 Robin Mittal <robinmittal.it@gmail.com>
+
+#cleaning 'yes' processes
+killall yes >/dev/null 2>&1
+
+[ -f testing.sh ] && . testing.sh
+
+#testing "name" "command" "result" "infile" "stdin"
+
+# Testcases for pkill command
+
+yes >/dev/null &
+sleep 1
+testing "pkill pattern" "pkill yes && sleep 1 && (pgrep yes || echo 'yes')" \
+ "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+yes print1 >/dev/null &
+yes print2 >/dev/null &
+sleep 1
+testing "pkill pattern (multiple)" "pkill yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+sleep 1
+testing "pkill -f pattern (one)" "pkill -f yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes print1 >/dev/null &
+sleep 1
+testing "pkill -f pattern args" "pkill -f \"yes print1\" && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+yes print1 >/dev/null &
+yes print2 >/dev/null &
+sleep 1
+testing "pkill -f pattern (multiple)" "pkill -f yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+sleep 1
+testing "pkill -s 0 -f pattern (regexp)" "pkill -s 0 -f ye* && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+proc1=$!
+yes >/dev/null &
+proc2=$!
+sleep 1
+testing "pkill -n pattern" "pkill -n yes && sleep 1 && pgrep yes" \
+ "$proc1\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+proc1=$!
+yes >/dev/null &
+proc2=$!
+sleep 1
+testing "pkill -o pattern" "pkill -o yes && sleep 1 && pgrep yes" \
+ "$proc2\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+sleep 1
+testing "pkill -s (blank) pattern" "pkill -s '' yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+sleep 1
+testing "pkill -s 0 pattern" "pkill -s 0 yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+proc=$!
+proc_p=`cat /proc/${proc}/stat | awk '{ print $4 }'`
+sleep 1
+testing "pkill -P parent_prodId pattern" "pkill -P $proc_p yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+
+yes >/dev/null &
+proc=$!
+proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
+sleep 1
+testing "pkill -9 pattern" "pkill -9 yes && sleep 1 &&
+ (pgrep yes || echo 'yes')" "yes\n" "" ""
+killall yes >/dev/null 2>&1
+