Add thread mutex deadlock checker script to tests/.
[pwmd.git] / tests / mutexcheck.sh
blob875e730f5fa6c666a712d704833a9d08c1f78225
1 #!/bin/bash
3 # A thread mutex deadlock checker. Note that your systems sleep(1) program
4 # should be able to accept floating point time arguments.
6 # Try running as: mutexcheck.sh 200 0.0 35 0.5
8 if [ $# -ne 4 ]; then
9 echo "Usage: $0 total_clients delay burst_clients burst_delay"
10 exit 1
13 TOTAL=$1
14 DELAY=$2
15 BCLIENTS=$3
16 BDELAY=$4
17 COUNT=0
19 source common.sh
20 source import-common.sh
22 do_import list
24 cat > config << EOF
25 [global]
26 log_level=9
27 #enable_logging=true
28 [list]
29 passphrase_file=`pwd`/list.key
30 EOF
32 launch_pwmd list
34 while [ $COUNT -lt $TOTAL ]; do
36 n=$BCLIENTS
37 while [ $n -gt 0 ]; do
39 sleep $BDELAY; echo -ne 'LIST' | \
40 pwmc $PWMC_ARGS --quiet list > /dev/null;
41 } &
43 n=$(($n - 1));
44 done;
45 } &
47 COUNT=$(($COUNT + $BCLIENTS));
48 echo "Forked $COUNT total clients.";
49 sleep $DELAY;
50 done
52 kill $PWMD_PID
54 while true; do
55 kill -n 0 $PWMD_PID 2>/dev/null
56 if [ $? -eq 0 ]; then
57 echo "Pwmd is still running. Press Ctrl-C to interrupt."
58 sleep 1
59 else
60 break
62 done
64 on_exit