r14865: - enforce timelimits for the tests
[samba.git] / source / script / tests / test_functions.sh
1
2 samba3_stop_sig_term() {
3         RET=0
4         kill -USR1 `cat $PIDDIR/timelimit.nmbd.pid` >/dev/null 2>&1 || \
5                 kill -ALRM `cat $PIDDIR/timelimit.nmbd.pid` || RET=$?
6
7         kill -USR1 `cat $PIDDIR/timelimit.smbd.pid` >/dev/null 2>&1 || \
8                 kill -ALRM `cat $PIDDIR/timelimit.smbd.pid` || RET=$?
9
10         return $RET;
11 }
12
13 samba3_stop_sig_kill() {
14         kill -ALRM `cat $PIDDIR/timelimit.nmbd.pid` >/dev/null 2>&1
15         kill -ALRM `cat $PIDDIR/timelimit.smbd.pid` >/dev/null 2>&1
16         return 0;
17 }
18
19 samba3_check_or_start() {
20         if [ -n "$SERVER_TEST_FIFO" ];then
21
22                 trap samba3_stop_sig_kill SIGINT SIGQUIT
23                 trap samba3_stop_sig_kill SIGTERM
24
25                 if [ -p "$SERVER_TEST_FIFO" ];then
26                         return 0;
27                 fi
28
29                 if [ -n "$SOCKET_WRAPPER_DIR" ];then
30                         if [ -d "$SOCKET_WRAPPER_DIR" ]; then
31                                 rm -f $SOCKET_WRAPPER_DIR/*
32                         else
33                                 mkdir -p $SOCKET_WRAPPER_DIR
34                         fi
35                 fi
36
37                 rm -f $SERVER_TEST_FIFO
38                 mkfifo $SERVER_TEST_FIFO
39
40                 rm -f $NMBD_TEST_LOG
41                 echo -n "STARTING NMBD..."
42                 ((
43                         if [ -z "$NMBD_MAXTIME" ]; then
44                             NMBD_MAXTIME=2700
45                         fi
46                         timelimit $NMBD_MAXTIME $NMBD_VALGRIND $SRCDIR/bin/nmbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $NMBD_TEST_LOG 2>&1 &
47                         TIMELIMIT_NMBD_PID=$!
48                         echo $TIMELIMIT_NMBD_PID > $PIDDIR/timelimit.nmbd.pid
49                         wait $TIMELIMIT_NMBD_PID
50                         ret=$?;
51                         rm -f $SERVER_TEST_FIFO
52                         if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then
53                                 rm -f $SOCKET_WRAPPER_DIR/*
54                         fi
55                         if [ x"$ret" = x"0" ];then
56                                 echo "nmbd exits with status $ret";
57                                 echo "nmbd exits with status $ret" >>$NMBD_TEST_LOG;
58                         elif [ x"$ret" = x"137" ];then
59                                 echo "nmbd got SIGXCPU and exits with status $ret!"
60                                 echo "nmbd got SIGXCPU and exits with status $ret!">>$NMBD_TEST_LOG;
61                         else
62                                 echo "nmbd failed with status $ret!"
63                                 echo "nmbd failed with status $ret!">>$NMBD_TEST_LOG;
64                         fi
65                         exit $ret;
66                 ) || exit $? &) 2>/dev/null || exit $?
67                 echo  "DONE"
68
69                 rm -f $SMBD_TEST_LOG
70                 echo -n "STARTING SMBD..."
71                 ((
72                         if [ -z "$SMBD_MAXTIME" ]; then
73                             SMBD_MAXTIME=2700
74                         fi
75                         timelimit $SMBD_MAXTIME $SMBD_VALGRIND $SRCDIR/bin/smbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $SMBD_TEST_LOG 2>&1 &
76                         TIMELIMIT_SMBD_PID=$!
77                         echo $TIMELIMIT_SMBD_PID > $PIDDIR/timelimit.smbd.pid
78                         wait $TIMELIMIT_SMBD_PID
79                         ret=$?;
80                         rm -f $SERVER_TEST_FIFO
81                         if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then
82                                 rm -f $SOCKET_WRAPPER_DIR/*
83                         fi
84                         if [ x"$ret" = x"0" ];then
85                                 echo "smbd exits with status $ret";
86                                 echo "smbd exits with status $ret" >>$SMBD_TEST_LOG;
87                         elif [ x"$ret" = x"137" ];then
88                                 echo "smbd got SIGXCPU and exits with status $ret!"
89                                 echo "smbd got SIGXCPU and exits with status $ret!">>$SMBD_TEST_LOG;
90                         else
91                                 echo "smbd failed with status $ret!"
92                                 echo "smbd failed with status $ret!">>$SMBD_TEST_LOG;
93                         fi
94                         exit $ret;
95                 ) || exit $? &) 2>/dev/null || exit $?
96                 echo  "DONE"
97         fi
98         return 0;
99 }
100
101 samba3_nmbd_test_log() {
102         if [ -n "$NMBD_TEST_LOG" ];then
103                 if [ -r "$NMBD_TEST_LOG" ];then
104                         return 0;
105                 fi
106         fi
107         return 1;
108 }
109
110 samba3_smbd_test_log() {
111         if [ -n "$SMBD_TEST_LOG" ];then
112                 if [ -r "$SMBD_TEST_LOG" ];then
113                         return 0;
114                 fi
115         fi
116         return 1;
117 }
118
119 samba3_check_only() {
120         if [ -n "$SERVER_TEST_FIFO" ];then
121                 if [ -p "$SERVER_TEST_FIFO" ];then
122                         return 0;
123                 fi
124                 return 1;
125         fi
126         return 0;
127 }
128
129 testit() {
130         if [ -z "$PREFIX" ]; then
131             PREFIX=test_prefix
132             mkdir -p $PREFIX
133         fi
134         name=$1
135         shift 1
136         SERVERS_ARE_UP="no"
137         TEST_LOG="$PREFIX/test_log.$$"
138         trap "rm -f $TEST_LOG" EXIT
139         cmdline="$*"
140
141         if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
142                 echo "--==--==--==--==--==--==--==--==--==--==--"
143                 echo "Running test $name (level 0 stdout)"
144                 echo "--==--==--==--==--==--==--==--==--==--==--"
145                 date
146                 echo "Testing $name"
147         else
148                 echo "Testing $name ($failed)"
149         fi
150
151         samba3_check_only && SERVERS_ARE_UP="yes"
152         if [ x"$SERVERS_ARE_UP" != x"yes" ];then
153                 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
154                         echo "SERVERS are down! Skipping: $cmdline"
155                         echo "=========================================="
156                         echo "TEST SKIPPED: $name (reason SERVERS are down)"
157                         echo "=========================================="
158                 else
159                         echo "TEST SKIPPED: $name (reason SERVERS are down)"
160                 fi
161                 return 1
162         fi
163         
164         if [ -z "$TORTURE_MAXTIME" ];then
165                 TORTURE_MAXTIME=300
166         fi
167         ( timelimit $TORTURE_MAXTIME $cmdline > $TEST_LOG 2>&1 )
168         status=$?
169         if [ x"$status" != x"0" ]; then
170                 echo "TEST OUTPUT:"
171                 cat $TEST_LOG;
172                 samba3_nmbd_test_log && echo "NMBD OUTPUT:";
173                 samba3_nmbd_test_log && cat $NMBD_TEST_LOG;
174                 samba3_smbd_test_log && echo "SMBD OUTPUT:";
175                 samba3_smbd_test_log && cat $SMBD_TEST_LOG;
176                 rm -f $TEST_LOG;
177                 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
178                         echo "=========================================="
179                         echo "TEST FAILED: $name (status $status)"
180                         echo "=========================================="
181                 else
182                         echo "TEST FAILED: $cmdline (status $status)"
183                 fi
184                 return 1;
185         fi
186         rm -f $TEST_LOG;
187         if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
188                 echo "ALL OK: $cmdline"
189                 echo "=========================================="
190                 echo "TEST PASSED: $name"
191                 echo "=========================================="
192         fi
193         return 0;
194 }
195
196 testok() {
197         name=`basename $1`
198         failed=$2
199
200         if [ x"$failed" = x"0" ];then
201                 :
202         else
203                 echo "$failed TESTS FAILED or SKIPPED ($name)";
204         fi
205         exit $failed
206 }
207
208 teststatus() {
209         name=`basename $1`
210         failed=$2
211
212         if [ x"$failed" = x"0" ];then
213                 echo "TEST STATUS: $failed";
214         else
215                 echo "TEST STATUS: $failed";
216         fi
217         exit $failed
218 }
219
220 if [ -z "$VALGRIND" ]; then
221     MALLOC_CHECK_=2
222     export MALLOC_CHECK_
223 fi
224