Add regression tests for pkill/pgrep.

MFC after:	3 days
This commit is contained in:
Pawel Jakub Dawidek 2005-03-20 12:38:08 +00:00
parent d0cf19a161
commit 1897c44125
25 changed files with 803 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -F <pidfile>"
pidfile=`mktemp /tmp/$base.XXXXXX` || exit 1
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
echo $chpid > $pidfile
pid=`pgrep -f -F $pidfile $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $chpid
rm -f $pidfile
rm -f $sleep

View File

@ -0,0 +1,38 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -G <gid>"
rgid=`id -gr`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -G $rgid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill $chpid
rm -f $sleep
name="pgrep -G <group>"
rgid=`id -grn`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -G $rgid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $chpid
rm -f $sleep

View File

@ -0,0 +1,22 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -P <ppid>"
ppid=$$
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -P $ppid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $chpid
rm -f $sleep

View File

@ -0,0 +1,20 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -S"
pid=`pgrep -Sx g_event`
if [ "$pid" = "2" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
pid=`pgrep -x g_event`
if [ "$pid" != "2" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi

View File

@ -0,0 +1,38 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -U <uid>"
ruid=`id -ur`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -U $ruid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill $chpid
rm -f $sleep
name="pgrep -U <user>"
ruid=`id -urn`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -U $ruid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $chpid
rm -f $sleep

View File

@ -0,0 +1,37 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -g <pgrp>"
pgrp=`ps -o tpgid -p $$ | tail -1`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -g $pgrp $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill $chpid
rm -f $sleep
name="pgrep -g 0"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -g 0 $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $chpid
rm -f $sleep

View File

@ -0,0 +1,24 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -i"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
usleep="${sleep}XXX"
touch $usleep
lsleep="${sleep}xxx"
ln -sf /bin/sleep $usleep
$usleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -i $lsleep`
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $chpid
rm -f $sleep $usleep

View File

@ -0,0 +1,45 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -j <jid>"
if [ `id -u` -eq 0 ]; then
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
jail / temp 127.0.0.1 $sleep 5 &
sleep 0.3
chpid=$!
jid=`jls | egrep '127\.0\.0\.1.*temp.*\/' | awk '{print $1}'`
pid=`pgrep -f -j $jid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill $chpid
rm -f $sleep
else
echo "ok 1 - $name # skip Test needs uid 0."
fi
name="pgrep -j 0"
if [ `id -u` -eq 0 ]; then
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
jail / temp 127.0.0.1 $sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -j 0 $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $chpid
rm -f $sleep
else
echo "ok 2 - $name # skip Test needs uid 0."
fi

View File

@ -0,0 +1,20 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -l"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pid=$!
if [ "$pid $sleep 5" = "`pgrep -f -l $sleep`" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $pid
rm -f $sleep

View File

@ -0,0 +1,24 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -n"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
oldpid=$!
$sleep 5 &
sleep 0.3
newpid=$!
pid=`pgrep -f -n $sleep`
if [ "$pid" = "$newpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $oldpid
kill $newpid
rm -f $sleep

View File

@ -0,0 +1,24 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -o"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
oldpid=$!
$sleep 5 &
sleep 0.3
newpid=$!
pid=`pgrep -f -o $sleep`
if [ "$pid" = "$oldpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $oldpid
kill $newpid
rm -f $sleep

View File

@ -0,0 +1,37 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -s <sid>"
sid=`ps -o tsid -p $$ | tail -1`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -s $sid $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
kill $chpid
rm -f $sleep
name="pgrep -s 0"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -s 0 $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $chpid
rm -f $sleep

View File

@ -0,0 +1,25 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pgrep -t <tty>"
tty=`ps -o tty -p $$ | tail -1`
if [ "$tty" = "??" ]; then
tty="-"
fi
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
chpid=$!
pid=`pgrep -f -t $tty $sleep`
if [ "$pid" = "$chpid" ]; then
echo "ok - $name"
else
echo "not ok - $name"
fi
kill $chpid
rm -f $sleep

View File

@ -0,0 +1,25 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pgrep -v"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pid=$!
if [ -z "`pgrep -f -v $sleep | egrep '^'"$pid"'$'`" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
if [ ! -z "`pgrep -f -v -x x | egrep '^'"$pid"'$'`" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
kill $pid
rm -f $sleep

View File

@ -0,0 +1,36 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..4"
name="pgrep -x"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pid=$!
if [ ! -z "`pgrep -x sleep | egrep '^'"$pid"'$'`" ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
if [ -z "`pgrep -x slee | egrep '^'"$pid"'$'`" ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
name="pgrep -x -f"
if [ ! -z "`pgrep -x -f ''"$sleep"' 5' | egrep '^'"$pid"'$'`" ]; then
echo "ok 3 - $name"
else
echo "not ok 3 - $name"
fi
if [ -z "`pgrep -x -f ''"$sleep"' ' | egrep '^'"$pid"'$'`" ]; then
echo "ok 4 - $name"
else
echo "not ok 4 - $name"
fi
kill $pid
rm -f $sleep

View File

@ -0,0 +1,27 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pkill -F <pidfile>"
pidfile=`mktemp /tmp/$base.XXXXXX` || exit 1
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
echo $! > $pidfile
pkill -f -F $pidfile $sleep
ec=$?
case $ec in
0)
echo "ok - $name"
;;
*)
echo "not ok - $name"
;;
esac
rm -f $pidfile
rm -f $sleep

View File

@ -0,0 +1,42 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pkill -G <gid>"
rgid=`id -gr`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -G $rgid $sleep
ec=$?
case $ec in
0)
echo "ok 1 - $name"
;;
*)
echo "not ok 1 - $name"
;;
esac
rm -f $sleep
name="pkill -G <group>"
rgid=`id -grn`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -G $rgid $sleep
ec=$?
case $ec in
0)
echo "ok 2 - $name"
;;
*)
echo "not ok 2 - $name"
;;
esac
rm -f $sleep

View File

@ -0,0 +1,25 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pkill -P <ppid>"
ppid=$$
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -P $ppid $sleep
ec=$?
case $ec in
0)
echo "ok - $name"
;;
*)
echo "not ok - $name"
;;
esac
rm -f $sleep

View File

@ -0,0 +1,42 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pkill -U <uid>"
ruid=`id -ur`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -U $ruid $sleep
ec=$?
case $ec in
0)
echo "ok 1 - $name"
;;
*)
echo "not ok 1 - $name"
;;
esac
rm -f $sleep
name="pkill -U <user>"
ruid=`id -urn`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -U $ruid $sleep
ec=$?
case $ec in
0)
echo "ok 2 - $name"
;;
*)
echo "not ok 2 - $name"
;;
esac
rm -f $sleep

View File

@ -0,0 +1,41 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pkill -g <pgrp>"
pgrp=`ps -o tpgid -p $$ | tail -1`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -g $pgrp $sleep
ec=$?
case $ec in
0)
echo "ok 1 - $name"
;;
*)
echo "not ok 1 - $name"
;;
esac
rm -f $sleep
name="pkill -g 0"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -g 0 $sleep
ec=$?
case $ec in
0)
echo "ok 2 - $name"
;;
*)
echo "not ok 2 - $name"
;;
esac
rm -f $sleep

View File

@ -0,0 +1,26 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pkill -i"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
usleep="${sleep}XXX"
touch $usleep
lsleep="${sleep}xxx"
ln -sf /bin/sleep $usleep
$usleep 5 &
sleep 0.3
pkill -f -i $lsleep
ec=$?
case $ec in
0)
echo "ok - $name"
;;
*)
echo "not ok - $name"
;;
esac
rm -f $sleep $usleep

View File

@ -0,0 +1,49 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pkill -j <jid>"
if [ `id -u` -eq 0 ]; then
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
jail / temp 127.0.0.1 $sleep 5 &
sleep 0.3
jid=`jls | egrep '127\.0\.0\.1.*temp.*\/' | awk '{print $1}'`
pkill -f -j $jid $sleep
ec=$?
case $ec in
0)
echo "ok 1 - $name"
;;
*)
echo "not ok 1 - $name"
;;
esac
rm -f $sleep
else
echo "ok 1 - $name # skip Test needs uid 0."
fi
name="pkill -j 0"
if [ `id -u` -eq 0 ]; then
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
jail / temp 127.0.0.1 $sleep 5 &
sleep 0.3
pkill -f -j 0 $sleep
ec=$?
case $ec in
0)
echo "ok 2 - $name"
;;
*)
echo "not ok 2 - $name"
;;
esac
rm -f $sleep
else
echo "ok 1 - $name # skip Test needs uid 0."
fi

View File

@ -0,0 +1,41 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..2"
name="pkill -s <sid>"
sid=`ps -o tsid -p $$ | tail -1`
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -s $sid $sleep
ec=$?
case $ec in
0)
echo "ok 1 - $name"
;;
*)
echo "not ok 1 - $name"
;;
esac
rm -f $sleep
name="pkill -s 0"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -s 0 $sleep
ec=$?
case $ec in
0)
echo "ok 2 - $name"
;;
*)
echo "not ok 2 - $name"
;;
esac
rm -f $sleep

View File

@ -0,0 +1,27 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..1"
name="pkill -t <tty>"
tty=`ps -o tty -p $$ | tail -1`
if [ "$tty" = "??" ]; then
tty="-"
fi
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -f -t $tty $sleep
ec=$?
case $ec in
0)
echo "ok - $name"
;;
*)
echo "not ok - $name"
;;
esac
rm -f $sleep

View File

@ -0,0 +1,44 @@
#!/bin/sh
# $FreeBSD$
base=`basename $0`
echo "1..4"
name="pkill -x"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -x slee -P $$
if [ $? -ne 0 ]; then
echo "ok 1 - $name"
else
echo "not ok 1 - $name"
fi
pkill -x sleep -P $$
if [ $? -eq 0 ]; then
echo "ok 2 - $name"
else
echo "not ok 2 - $name"
fi
rm -f $sleep
name="pkill -x -f"
sleep=`mktemp /tmp/$base.XXXXXX` || exit 1
ln -sf /bin/sleep $sleep
$sleep 5 &
sleep 0.3
pkill -x -f "$sleep " -P $$
if [ $? -ne 0 ]; then
echo "ok 3 - $name"
else
echo "not ok 3 - $name"
fi
pkill -x -f "$sleep 5" -P $$
if [ $? -eq 0 ]; then
echo "ok 4 - $name"
else
echo "not ok 4 - $name"
fi
rm -f $sleep