android_external_toybox/tests/pidof.test
Rob Landley c8400d7f82 Fix same spurious test failures that were affecting killall,
and silence "killed" messages from the shell by forking in a subshell.
2019-10-11 15:40:08 -05:00

30 lines
879 B
Bash

#!/bin/bash
[ -f testing.sh ] && . testing.sh
#testing "name" "command" "result" "infile" "stdin"
#
# pidof (unlike killall) doesn't match argv[1] unless you supply -x.
#
echo -e "#!$(which sh)\nread i < /proc/self/fd/1" > pidof-$$.test
chmod a+x pidof-$$.test
cp pidof-$$.test toybox.pidof-$$.test.script
(./pidof-$$.test & echo $! > pid.txt)
pid=$(cat pid.txt)
testcmd "short argv[1]" "pidof-$$.test" "" "" ""
testcmd "short argv[1] -x" "-x pidof-$$.test" "$pid\n" "" ""
kill $pid
(./toybox.pidof-$$.test.script & echo $! > pid.txt)
pid=$(cat pid.txt)
testcmd "long argv[1]" "toybox.pidof-$$.test.script" "" "" ""
testcmd "long argv[1] -x" "-x toybox.pidof-$$.test.script" "$pid\n" "" ""
kill $pid
rm -f toybox.pidof-$$.test.script pidof-$$.test pid.txt
# pidof (unlike killall) will match itself.
testcmd "pidof pidof" "pidof > /dev/null && echo found" "found\n" "" ""