[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[sfrench/samba-autobuild/.git] / source3 / 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 INT QUIT
23                 trap samba3_stop_sig_kill TERM
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 test x"$NMBD_MAXTIME" = x; then
44                             NMBD_MAXTIME=2700
45                         fi
46                         MAKE_TEST_BINARY=$BINDIR/nmbd
47                         export MAKE_TEST_BINARY
48                         timelimit $NMBD_MAXTIME $NMBD_VALGRIND $BINDIR/nmbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $NMBD_TEST_LOG 2>&1 &
49                         TIMELIMIT_NMBD_PID=$!
50                         MAKE_TEST_BINARY=
51                         echo $TIMELIMIT_NMBD_PID > $PIDDIR/timelimit.nmbd.pid
52                         wait $TIMELIMIT_NMBD_PID
53                         ret=$?;
54                         rm -f $SERVER_TEST_FIFO
55                         if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then
56                                 rm -f $SOCKET_WRAPPER_DIR/*
57                         fi
58                         if [ x"$ret" = x"0" ];then
59                                 echo "nmbd exits with status $ret";
60                                 echo "nmbd exits with status $ret" >>$NMBD_TEST_LOG;
61                         elif [ x"$ret" = x"137" ];then
62                                 echo "nmbd got SIGXCPU and exits with status $ret!"
63                                 echo "nmbd got SIGXCPU and exits with status $ret!">>$NMBD_TEST_LOG;
64                         else
65                                 echo "nmbd failed with status $ret!"
66                                 echo "nmbd failed with status $ret!">>$NMBD_TEST_LOG;
67                         fi
68                         exit $ret;
69                 ) || exit $? &) 2>/dev/null || exit $?
70                 echo  "DONE"
71
72                 rm -f $SMBD_TEST_LOG
73                 echo -n "STARTING SMBD..."
74                 ((
75                         if test x"$SMBD_MAXTIME" = x; then
76                             SMBD_MAXTIME=2700
77                         fi
78                         MAKE_TEST_BINARY=$BINDIR/smbd
79                         export MAKE_TEST_BINARY
80                         timelimit $SMBD_MAXTIME $SMBD_VALGRIND $BINDIR/smbd -F -S --no-process-group -d0 -s $SERVERCONFFILE > $SMBD_TEST_LOG 2>&1 &
81                         TIMELIMIT_SMBD_PID=$!
82                         MAKE_TEST_BINARY=
83                         echo $TIMELIMIT_SMBD_PID > $PIDDIR/timelimit.smbd.pid
84                         wait $TIMELIMIT_SMBD_PID
85                         ret=$?;
86                         rm -f $SERVER_TEST_FIFO
87                         if [ -n "$SOCKET_WRAPPER_DIR" -a -d "$SOCKET_WRAPPER_DIR" ]; then
88                                 rm -f $SOCKET_WRAPPER_DIR/*
89                         fi
90                         if [ x"$ret" = x"0" ];then
91                                 echo "smbd exits with status $ret";
92                                 echo "smbd exits with status $ret" >>$SMBD_TEST_LOG;
93                         elif [ x"$ret" = x"137" ];then
94                                 echo "smbd got SIGXCPU and exits with status $ret!"
95                                 echo "smbd got SIGXCPU and exits with status $ret!">>$SMBD_TEST_LOG;
96                         else
97                                 echo "smbd failed with status $ret!"
98                                 echo "smbd failed with status $ret!">>$SMBD_TEST_LOG;
99                         fi
100                         exit $ret;
101                 ) || exit $? &) 2>/dev/null || exit $?
102                 echo  "DONE"
103         fi
104         return 0;
105 }
106
107 samba3_nmbd_test_log() {
108         if [ -n "$NMBD_TEST_LOG" ];then
109                 if [ -r "$NMBD_TEST_LOG" ];then
110                         return 0;
111                 fi
112         fi
113         return 1;
114 }
115
116 samba3_smbd_test_log() {
117         if [ -n "$SMBD_TEST_LOG" ];then
118                 if [ -r "$SMBD_TEST_LOG" ];then
119                         return 0;
120                 fi
121         fi
122         return 1;
123 }
124
125 samba3_check_only() {
126         if [ -n "$SERVER_TEST_FIFO" ];then
127                 if [ -p "$SERVER_TEST_FIFO" ];then
128                         return 0;
129                 fi
130                 return 1;
131         fi
132         return 0;
133 }
134
135 testit() {
136         if [ -z "$PREFIX" ]; then
137             PREFIX=test_prefix
138             mkdir -p $PREFIX
139         fi
140         name=$1
141         shift 1
142         binary=$1
143         cmdline="$*"
144
145         SERVERS_ARE_UP="no"
146
147         shname=`echo $name | \
148         sed -e 's%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g'`
149
150         UNIQUE_PID=`/bin/sh -c 'echo $$'`
151         TEST_LOG="$PREFIX/test_log.${UNIQUE_PID}"
152         TEST_PCAP="$PREFIX/test_${shname}_${UNIQUE_PID}.pcap"
153         trap "rm -f $TEST_LOG $TEST_PCAP" EXIT
154
155         if [ -z "$nmbd_log_size" ]; then
156                 nmbd_log_size=`wc -l < $NMBD_TEST_LOG`;
157         fi
158         if [ -z "$smbd_log_size" ]; then
159                 smbd_log_size=`wc -l < $SMBD_TEST_LOG`;
160         fi
161
162         if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
163                 echo "--==--==--==--==--==--==--==--==--==--==--"
164                 echo "Running test $name (level 0 stdout)"
165                 echo "--==--==--==--==--==--==--==--==--==--==--"
166                 date
167                 echo "Testing $name"
168         else
169                 echo "Testing $name ($failed)"
170         fi
171
172         samba3_check_only && SERVERS_ARE_UP="yes"
173         if [ x"$SERVERS_ARE_UP" != x"yes" ];then
174                 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
175                         echo "SERVERS are down! Skipping: $cmdline"
176                         echo "=========================================="
177                         echo "TEST SKIPPED: $name (reason SERVERS are down)"
178                         echo "=========================================="
179                 else
180                         echo "TEST SKIPPED: $name (reason SERVERS are down)"
181                 fi
182                 return 1
183         fi
184
185         if [ x"$MAKE_TEST_ENABLE_PCAP" = x"yes" ];then
186                 SOCKET_WRAPPER_PCAP_FILE=$TEST_PCAP
187                 export SOCKET_WRAPPER_PCAP_FILE
188         fi
189
190         MAKE_TEST_BINARY=$binary
191         export MAKE_TEST_BINARY
192         ( $cmdline > $TEST_LOG 2>&1 )
193         status=$?
194         MAKE_TEST_BINARY=
195         # show any additional output from smbd that has happened in this test
196         samba3_nmbd_test_log && {
197                 new_log_size=`wc -l < $NMBD_TEST_LOG`;
198                 test "$new_log_size" = "$nmbd_log_size" || {
199                         echo "NMBD OUTPUT:";
200                         incr_log_size=`expr $new_log_size - $nmbd_log_size`;
201                         tail -$incr_log_size $NMBD_TEST_LOG;
202                         nmbd_log_size=$new_log_size;
203                 }
204         }
205         samba3_smbd_test_log && {
206                 new_log_size=`wc -l < $SMBD_TEST_LOG`;
207                 test "$new_log_size" = "$smbd_log_size" || {
208                         echo "SMBD OUTPUT:";
209                         incr_log_size=`expr $new_log_size - $smbd_log_size`;
210                         tail -$incr_log_size $SMBD_TEST_LOG;
211                         smbd_log_size=$new_log_size;
212                 }
213         }
214
215         if [ x"$status" != x"0" ]; then
216                 echo "TEST OUTPUT:"
217                 cat $TEST_LOG;
218                 rm -f $TEST_LOG;
219                 if [ x"$MAKE_TEST_ENABLE_PCAP" = x"yes" ];then
220                         echo "TEST PCAP: $TEST_PCAP"
221                 fi
222                 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
223                         echo "=========================================="
224                         echo "TEST FAILED: $name (status $status)"
225                         echo "=========================================="
226                 else
227                         echo "TEST FAILED: $cmdline (status $status)"
228                 fi
229                 trap "" EXIT
230                 return 1;
231         fi
232         rm -f $TEST_LOG;
233         if [ x"$MAKE_TEST_KEEP_PCAP" = x"yes" ];then
234                 echo "TEST PCAP: $TEST_PCAP"
235         else
236                 rm -f $TEST_PCAP;
237         fi
238         if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
239                 echo "ALL OK: $cmdline"
240                 echo "=========================================="
241                 echo "TEST PASSED: $name"
242                 echo "=========================================="
243         fi
244         trap "" EXIT
245         return 0;
246 }
247
248 testok() {
249         name=`basename $1`
250         failed=$2
251
252         if [ x"$failed" = x"0" ];then
253                 :
254         else
255                 echo "$failed TESTS FAILED or SKIPPED ($name)";
256         fi
257         exit $failed
258 }
259
260 teststatus() {
261         name=`basename $1`
262         failed=$2
263
264         if [ x"$failed" = x"0" ];then
265                 echo "TEST STATUS: $failed";
266         else
267                 echo "TEST STATUS: $failed";
268         fi
269         exit $failed
270 }
271
272 if [ -z "$VALGRIND" ]; then
273     MALLOC_CHECK_=2
274     export MALLOC_CHECK_
275 fi
276