Revert "Add thread mutex deadlock checker script to tests/."
[pwmd.git] / tests / common.sh
blob2e11a0754919cb30550274d7dde727ce7a5c45b8
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 test_success() {
39 echo "All tests in $0 succeeded."
42 begin_test() {
43 echo ""
44 echo "Starting test $0 ..."
45 echo ""
48 set -e
50 PWMD="../src/pwmd"
51 WDIR="`/bin/pwd`"
52 PWMC_ARGS="--url $WDIR/socket --no-status"
53 PID=
54 trap on_exit EXIT
56 eval `gpg-agent --homedir $WDIR --sh --daemon --write-env-file \
57 $WDIR/gpg-agent.env`
58 wait_for_socket 0 "S.gpg-agent"