diff options
Diffstat (limited to 'recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog')
-rwxr-xr-x | recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog b/recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog new file mode 100755 index 0000000..2010e3c --- /dev/null +++ b/recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog | |||
@@ -0,0 +1,93 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # This script is used to test watchdog functionality. | ||
4 | |||
5 | WAITTIME=10 | ||
6 | WDPID=0 | ||
7 | |||
8 | WATCHDOG=`which watchdog` | ||
9 | if [ "x$WATCHDOG" != "x" ]; then | ||
10 | echo "PASS: watchdog found" | ||
11 | else | ||
12 | echo "FAIL: watchdog not found" | ||
13 | exit 1 | ||
14 | fi | ||
15 | |||
16 | WATCHDOG_CONF=/etc/watchdog.conf | ||
17 | if [ -f $WATCHDOG_CONF ]; then | ||
18 | echo "PASS: watchdog config file found" | ||
19 | sed -i '23,23 s/#//' $WATCHDOG_CONF | ||
20 | else | ||
21 | echo "FAIL: watchdog config file not found" | ||
22 | exit 1 | ||
23 | fi | ||
24 | |||
25 | # kill any previous instance of watchdog (pkill may be used as well) | ||
26 | for wpid in `ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` ; do | ||
27 | kill -KILL $wpid | ||
28 | done | ||
29 | |||
30 | # wait until all processes are gone | ||
31 | for wt in `seq 1 $WAITTIME ` ; do | ||
32 | sleep 1 | ||
33 | wd_running=`ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` | ||
34 | |||
35 | if [ -z $wd_running ] ; then | ||
36 | break | ||
37 | fi | ||
38 | done | ||
39 | |||
40 | if [ $wt -ge $WAITTIME ] ; then | ||
41 | echo "FAIL: Failed to stop the watchdog daemon" | ||
42 | exit 1 | ||
43 | fi | ||
44 | |||
45 | # start a fresh watchdog | ||
46 | $WATCHDOG -v /dev/watchdog | ||
47 | |||
48 | # wait up to $WAITTIME seconds for the process to start | ||
49 | for wt in `seq 1 $WAITTIME ` ; do | ||
50 | sleep 1 | ||
51 | wd_running=`ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` | ||
52 | if [ ! -z $wd_running ] ; then | ||
53 | WDPID=$wd_running | ||
54 | echo "PASS: Watchdog daemon started successfully [$WDPID]" | ||
55 | break | ||
56 | fi | ||
57 | |||
58 | echo $wt | ||
59 | done | ||
60 | |||
61 | if [ $wt -ge $WAITTIME ] ; then | ||
62 | echo "FAIL: Failed to start watchdog daemon" | ||
63 | exit 1 | ||
64 | fi | ||
65 | |||
66 | logmsg_test() | ||
67 | { | ||
68 | WDCOUNTER1=`cat /var/log/messages | grep watchdog | grep $WDPID | wc -l` | ||
69 | sleep 5 | ||
70 | WDCOUNTER2=`cat /var/log/messages | grep watchdog | grep $WDPID | wc -l` | ||
71 | |||
72 | if [ $WDCOUNTER2 -gt $WDCOUNTER1 ] ; then | ||
73 | return 0 | ||
74 | fi | ||
75 | |||
76 | return 1 | ||
77 | } | ||
78 | |||
79 | exit_code=1 | ||
80 | |||
81 | # test is performed 2 times because logrotate may step in during those 5sec | ||
82 | if logmsg_test || logmsg_test ; then | ||
83 | echo "PASS: Watchdog is alive" | ||
84 | kill -KILL $WDPID > /dev/null 2>&1 | ||
85 | exit_code=0 | ||
86 | else | ||
87 | echo "FAIL: Watchdog is not working" | ||
88 | kill -KILL $WDPID > /dev/null 2>&1 | ||
89 | exit_code=1 | ||
90 | fi | ||
91 | |||
92 | kill -KILL $WDPID > /dev/null 2>&1 | ||
93 | exit $exit_code | ||