summaryrefslogtreecommitdiff
path: root/bin/pkill
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2015-02-12 20:57:57 +0000
committerEnji Cooper <ngie@FreeBSD.org>2015-02-12 20:57:57 +0000
commitb8b9865304fd1f88de35b7459c3b6f2315effe87 (patch)
treec4ef264f0dfd66609330e1bc003f55b9b0c62ab3 /bin/pkill
parente50def75bdeccc6095b18a7bbc5fae18374cfc6c (diff)
downloadsrc-test-b8b9865304fd1f88de35b7459c3b6f2315effe87.tar.gz
src-test-b8b9865304fd1f88de35b7459c3b6f2315effe87.zip
Refactor the tests
1. `id -u` -> 0 is now only checked once; the entire test script is now skipped if this assertion is violated 2. De-dent whitespace, based on 1. 3. Only setup the symlink for $sleep once at the top of the script, and tear it down once at the bottom of the script
Notes
Notes: svn path=/head/; revision=278633
Diffstat (limited to 'bin/pkill')
-rw-r--r--bin/pkill/tests/pgrep-j_test.sh107
1 files changed, 48 insertions, 59 deletions
diff --git a/bin/pkill/tests/pgrep-j_test.sh b/bin/pkill/tests/pgrep-j_test.sh
index f61e1748f1ac6..57c86a89ebb16 100644
--- a/bin/pkill/tests/pgrep-j_test.sh
+++ b/bin/pkill/tests/pgrep-j_test.sh
@@ -19,79 +19,68 @@ jail_name_to_jid()
base=pgrep_j_test
+if [ `id -u` -ne 0 ]; then
+ echo "1..0 # skip Test needs uid 0."
+ exit 0
+fi
+
echo "1..3"
+sleep=$(pwd)/sleep.txt
+ln -sf /bin/sleep $sleep
+
name="pgrep -j <jid>"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_1_1.pid $sleep 5 &
+jail -c path=/ name=${base}_1_1 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_1_1.pid $sleep 5 &
- jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_1_2.pid $sleep 5 &
+jail -c path=/ name=${base}_1_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_1_2.pid $sleep 5 &
- jid1=$(jail_name_to_jid ${base}_1_1)
- jid2=$(jail_name_to_jid ${base}_1_2)
- jid="${jid1},${jid2}"
- pid1="$(pgrep -f -x -j $jid "$sleep 5" | sort)"
- pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
- $(cat ${PWD}/${base}_1_2.pid) | sort)
- if [ "$pid1" = "$pid2" ]; then
- echo "ok 1 - $name"
- else
- echo "not ok 1 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
- fi
- [ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
- [ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
- rm -f $sleep
+jid1=$(jail_name_to_jid ${base}_1_1)
+jid2=$(jail_name_to_jid ${base}_1_2)
+jid="${jid1},${jid2}"
+pid1="$(pgrep -f -x -j $jid "$sleep 5" | sort)"
+pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_1_1.pid)" \
+ $(cat ${PWD}/${base}_1_2.pid) | sort)
+if [ "$pid1" = "$pid2" ]; then
+ echo "ok 1 - $name"
else
- echo "ok 1 - $name # skip Test needs uid 0."
+ echo "not ok 1 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
fi
+[ -f ${PWD}/${base}_1_1.pid ] && kill $(cat ${PWD}/${base}_1_1.pid)
+[ -f ${PWD}/${base}_1_2.pid ] && kill $(cat ${PWD}/${base}_1_2.pid)
name="pgrep -j any"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_2_1.pid $sleep 5 &
+jail -c path=/ name=${base}_2_1 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_2_1.pid $sleep 5 &
- jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_2_2.pid $sleep 5 &
+jail -c path=/ name=${base}_2_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_2_2.pid $sleep 5 &
- sleep 2
- pid1="$(pgrep -f -x -j any "$sleep 5" | sort)"
- pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
- $(cat ${PWD}/${base}_2_2.pid) | sort)
- if [ "$pid1" = "$pid2" ]; then
- echo "ok 2 - $name"
- else
- echo "not ok 2 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
- fi
- [ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
- [ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
- rm -f $sleep
+sleep 2
+pid1="$(pgrep -f -x -j any "$sleep 5" | sort)"
+pid2=$(printf "%s\n%s" "$(cat ${PWD}/${base}_2_1.pid)" \
+ $(cat ${PWD}/${base}_2_2.pid) | sort)
+if [ "$pid1" = "$pid2" ]; then
+ echo "ok 2 - $name"
else
- echo "ok 2 - $name # skip Test needs uid 0."
+ echo "not ok 2 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
fi
+[ -f ${PWD}/${base}_2_1.pid ] && kill $(cat ${PWD}/${base}_2_1.pid)
+[ -f ${PWD}/${base}_2_2.pid ] && kill $(cat ${PWD}/${base}_2_2.pid)
name="pgrep -j none"
-if [ `id -u` -eq 0 ]; then
- sleep=$(pwd)/sleep.txt
- ln -sf /bin/sleep $sleep
- daemon -p ${PWD}/${base}_3_1.pid $sleep 5 &
- jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
- command=daemon -p ${PWD}/${base}_3_2.pid $sleep 5 &
- sleep 2
- pid="$(pgrep -f -x -j none "$sleep 5")"
- if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
- echo "ok 3 - $name"
- else
- echo "not ok 3 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
- fi
- rm -f $sleep
- [ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid)
- [ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid)
+daemon -p ${PWD}/${base}_3_1.pid $sleep 5 &
+jail -c path=/ name=${base}_3_2 ip4.addr=127.0.0.1 \
+ command=daemon -p ${PWD}/${base}_3_2.pid $sleep 5 &
+sleep 2
+pid="$(pgrep -f -x -j none "$sleep 5")"
+if [ "$pid" = "$(cat ${PWD}/${base}_3_1.pid)" ]; then
+ echo "ok 3 - $name"
else
- echo "ok 3 - $name # skip Test needs uid 0."
+ echo "not ok 3 - $name # pgrep output: '$(echo $pid1)', pidfile output: '$(echo $pid2)'"
fi
+[ -f ${PWD}/${base}_3_1.pid ] && kill $(cat $PWD/${base}_3_1.pid)
+[ -f ${PWD}/${base}_3_2.pid ] && kill $(cat $PWD/${base}_3_2.pid)
+
+rm -f $sleep