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