xref: /aosp_15_r20/external/toybox/tests/pidof.test (revision cf5a6c84e2b8763fc1a7db14496fd4742913b199)
1#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7#
8# pidof (unlike killall) doesn't match argv[1] unless you supply -x.
9#
10
11mkfifo fifo
12echo -e "#!$(which sh)\nread i < fifo" > pidof-$$.test
13chmod a+x pidof-$$.test
14cp pidof-$$.test toybox.pidof-$$.test.script
15(./pidof-$$.test & echo $! > pid.txt)
16pid=$(cat pid.txt)
17testcmd "short argv[1]" "pidof-$$.test" "" "" ""
18testcmd "short argv[1] -x" "-x pidof-$$.test" "$pid\n" "" ""
19kill $pid
20
21(./toybox.pidof-$$.test.script & echo $! > pid.txt)
22pid=$(cat pid.txt)
23testcmd "long argv[1]" "toybox.pidof-$$.test.script" "" "" ""
24testcmd "long argv[1] -x" "-x toybox.pidof-$$.test.script" "$pid\n" "" ""
25kill $pid
26
27rm -f toybox.pidof-$$.test.script pidof-$$.test pid.txt fifo
28
29# pidof (unlike killall) will match itself.
30testcmd "pidof pidof" "pidof > /dev/null && echo found" "found\n" "" ""
31