xref: /freebsd/bin/pkill/tests/pgrep-f_test.sh (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1#!/bin/sh
2
3: ${ARG_MAX:=524288}
4base=$(dirname $(realpath "$0"))
5
6echo "1..2"
7
8waitfor() {
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
23sentinel="findme=test-$$"
24sentinelsz=$(printf "${sentinel}" | wc -c | tr -d '[[:space:]]')
25name="pgrep -f"
26spin="${base}/spin_helper"
27flagfile="pgrep_f_short.flag"
28
29${spin} --short ${flagfile} ${sentinel} &
30chpid=$!
31if ! waitfor ${flagfile}; then
32	echo "not ok - $name"
33else
34	pid=$(pgrep -f ${sentinel})
35	if [ "$pid" = "$chpid" ]; then
36		echo "ok - $name"
37	else
38		echo "not ok - $name"
39	fi
40fi
41kill $chpid
42
43name="pgrep -f long args"
44flagfile="pgrep_f_long.flag"
45${spin} --long ${flagfile} ${sentinel} &
46chpid=$!
47if ! waitfor ${flagfile}; then
48	echo "not ok - $name"
49else
50	pid=$(pgrep -f ${sentinel})
51	if [ "$pid" = "$chpid" ]; then
52		echo "ok - $name"
53	else
54		echo "not ok - $name"
55	fi
56fi
57kill $chpid
58