]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - bin/pkill/tests/pgrep-f_test.sh
sys: add conf/std.debug, generic debugging options
[FreeBSD/FreeBSD.git] / bin / pkill / tests / pgrep-f_test.sh
1 #!/bin/sh
2
3 : ${ARG_MAX:=524288}
4 base=$(dirname $(realpath "$0"))
5
6 echo "1..2"
7
8 waitfor() {
9         flagfile=$1
10
11         iter=0
12
13         while [ ! -f ${flagfile} ] && [ ${iter} -lt 50 ]; do
14                 sleep 0.10
15                 iter=$((iter + 1))
16         done
17
18         if [ ! -f ${flagfile} ]; then
19                 return 1
20         fi
21 }
22
23 sentinel="findme=test-$$"
24 sentinelsz=$(printf "${sentinel}" | wc -c | tr -d '[[:space:]]')
25 name="pgrep -f"
26 spin="${base}/spin_helper"
27 flagfile="pgrep_f_short.flag"
28
29 ${spin} --short ${flagfile} ${sentinel} &
30 chpid=$!
31 if ! waitfor ${flagfile}; then
32         echo "not ok - $name"
33 else
34         pid=$(pgrep -f ${sentinel})
35         if [ "$pid" = "$chpid" ]; then
36                 echo "ok - $name"
37         else
38                 echo "not ok - $name"
39         fi
40 fi
41 kill $chpid
42
43 name="pgrep -f long args"
44 flagfile="pgrep_f_long.flag"
45 ${spin} --long ${flagfile} ${sentinel} &
46 chpid=$!
47 if ! waitfor ${flagfile}; then
48         echo "not ok - $name"
49 else
50         pid=$(pgrep -f ${sentinel})
51         if [ "$pid" = "$chpid" ]; then
52                 echo "ok - $name"
53         else
54                 echo "not ok - $name"
55         fi
56 fi
57 kill $chpid