aboutsummaryrefslogtreecommitdiff
path: root/tests/pgrep.test
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-09-20 13:09:14 -0500
committerRob Landley <rob@landley.net>2014-09-20 13:09:14 -0500
commit387edf547eb09b27ca6d49772eb048d729f09cf4 (patch)
tree59d482f33735690cab6d90723393afa1e2c8dce5 /tests/pgrep.test
parentd3df423a6cde0c6282658ff628574771d3824d71 (diff)
downloadtoybox-387edf547eb09b27ca6d49772eb048d729f09cf4.tar.gz
Move testsuite out of scripts/test into its own top level tests directory, and make ctrl-c kill "make test" more reliably.
Diffstat (limited to 'tests/pgrep.test')
-rw-r--r--tests/pgrep.test122
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/pgrep.test b/tests/pgrep.test
new file mode 100644
index 00000000..36df573a
--- /dev/null
+++ b/tests/pgrep.test
@@ -0,0 +1,122 @@
+#!/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"
+
+# Starting processes to test pgrep command
+yes >/dev/null &
+proc=$!
+echo "# Process created with id: $proc"
+sleep 1
+session_id=0
+proc_parent=`cat /proc/${proc}/stat | awk '{ print $4 }'`
+echo "# Parent Process id of $proc is $proc_parent"
+
+# Testcases for pgrep command
+testing "pgrep pattern" "pgrep yes" "$proc\n" "" ""
+testing "pgrep wildCardPattern" "pgrep ^y.*s$" "$proc\n" "" ""
+testing "pgrep -l pattern" "pgrep -l yes" "$proc yes\n" "" ""
+testing "pgrep -f pattern" "pgrep -f yes" "$proc\n" "" ""
+testing "pgrep -n pattern" "pgrep -n yes" "$proc\n" "" ""
+testing "pgrep -o pattern" "pgrep -o yes" "$proc\n" "" ""
+testing "pgrep -s" "pgrep -s $session_id yes" "$proc\n" "" ""
+testing "pgrep -P" "pgrep -P $proc_parent yes" "$proc\n" "" ""
+
+#Clean-up
+killall yes >/dev/null 2>&1
+
+# 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
+