summaryrefslogtreecommitdiffstats
path: root/recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-test/ddt-runner/files/scripts/t1042rdb/watchdog')
-rwxr-xr-xrecipes-test/ddt-runner/files/scripts/t1042rdb/watchdog93
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
5WAITTIME=10
6WDPID=0
7
8WATCHDOG=`which watchdog`
9if [ "x$WATCHDOG" != "x" ]; then
10 echo "PASS: watchdog found"
11else
12 echo "FAIL: watchdog not found"
13 exit 1
14fi
15
16WATCHDOG_CONF=/etc/watchdog.conf
17if [ -f $WATCHDOG_CONF ]; then
18 echo "PASS: watchdog config file found"
19 sed -i '23,23 s/#//' $WATCHDOG_CONF
20else
21 echo "FAIL: watchdog config file not found"
22 exit 1
23fi
24
25# kill any previous instance of watchdog (pkill may be used as well)
26for wpid in `ps ax | grep $WATCHDOG | grep -v grep | awk -e '{print $1}'` ; do
27 kill -KILL $wpid
28done
29
30# wait until all processes are gone
31for 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
38done
39
40if [ $wt -ge $WAITTIME ] ; then
41 echo "FAIL: Failed to stop the watchdog daemon"
42 exit 1
43fi
44
45# start a fresh watchdog
46$WATCHDOG -v /dev/watchdog
47
48# wait up to $WAITTIME seconds for the process to start
49for 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
59done
60
61if [ $wt -ge $WAITTIME ] ; then
62 echo "FAIL: Failed to start watchdog daemon"
63 exit 1
64fi
65
66logmsg_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
79exit_code=1
80
81# test is performed 2 times because logrotate may step in during those 5sec
82if logmsg_test || logmsg_test ; then
83 echo "PASS: Watchdog is alive"
84 kill -KILL $WDPID > /dev/null 2>&1
85 exit_code=0
86else
87 echo "FAIL: Watchdog is not working"
88 kill -KILL $WDPID > /dev/null 2>&1
89 exit_code=1
90fi
91
92kill -KILL $WDPID > /dev/null 2>&1
93exit $exit_code