Add more tests.
[pwmd.git] / tests / common.sh
blob5f9be23359f08bfdc93d56942e790b48f63d4e4f
1 on_exit() {
2 if [ $PID ]; then
3 kill $PID
4 fi
6 if [ -f "gpg-agent.env" ]; then
7 local pid="`awk -F: '{print $2}' < gpg-agent.env`"
8 kill $pid 2>/dev/null
9 unset pid
10 rm -f gpg-agent.env
13 rm -f config
16 wait_for_socket() {
17 local pid="$1"
18 local socket="$2"
20 until [ -e $socket ]; do
21 echo "waiting for socket '$socket' ..."
22 if [ $pid != 0 ]; then
23 kill -0 $PID || break;
25 sleep 1
26 done
28 unset pid
29 unset socket
32 launch_pwmd () {
33 $PWMD --homedir $WDIR -n $@ > /dev/null &
34 PID=$!
35 wait_for_socket $PID socket
38 set -e
40 PWMD="../src/pwmd"
41 WDIR="`/bin/pwd`"
42 PID=
43 trap on_exit EXIT
45 eval `gpg-agent --homedir $WDIR --sh --daemon --write-env-file \
46 $WDIR/gpg-agent.env`
47 wait_for_socket 0 "S.gpg-agent"