r20150: better memory handling for some functions, make sure we don't
[jra/samba/.git] / source3 / script / tests / selftest.sh
1 #!/bin/sh
2
3 if [ $# != 3 ]; then
4         echo "$0 <directory> <all | quick> <smbtorture4>"
5         exit 1
6 fi
7
8 SMBTORTURE4=$3
9 TESTS=$2
10
11 ##
12 ## create the test directory
13 ##
14 PREFIX=`echo $1 | sed s+//+/+`
15 mkdir -p $PREFIX || exit $?
16 OLD_PWD=`pwd`
17 cd $PREFIX || exit $?
18 PREFIX_ABS=`pwd`
19 cd $OLD_PWD
20
21 if [ -z "$TORTURE_MAXTIME" ]; then
22     TORTURE_MAXTIME=300
23 fi
24 export TORTURE_MAXTIME
25
26 ##
27 ## setup the various environment variables we need
28 ##
29
30 SERVER=localhost2
31 SERVER_IP=127.0.0.2
32 USERNAME=`PATH=/usr/ucb:$PATH whoami`
33 PASSWORD=test
34
35 SRCDIR="`dirname $0`/../.."
36 BINDIR="`pwd`/bin"
37 SCRIPTDIR=$SRCDIR/script/tests
38 SHRDIR=$PREFIX_ABS/tmp
39 LIBDIR=$PREFIX_ABS/lib
40 PIDDIR=$PREFIX_ABS/pid
41 CONFFILE=$LIBDIR/client.conf
42 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
43 SERVERCONFFILE=$LIBDIR/server.conf
44 COMMONCONFFILE=$LIBDIR/common.conf
45 PRIVATEDIR=$PREFIX_ABS/private
46 LOCKDIR=$PREFIX_ABS/lockdir
47 LOGDIR=$PREFIX_ABS/logs
48 SOCKET_WRAPPER_DIR=$PREFIX/sw
49 CONFIGURATION="-s $CONFFILE"
50 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
51
52 export PREFIX PREFIX_ABS
53 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
54 export PATH SOCKET_WRAPPER_DIR DOMAIN
55 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
56 export SRCDIR SCRIPTDIR BINDIR
57 export USERNAME PASSWORD
58 export SMBTORTURE4
59 export SERVER SERVER_IP
60
61 PATH=bin:$PATH
62 export PATH
63
64 ##
65 ## verify that we were built with --enable-socket-wrapper
66 ##
67
68 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
69         echo "***"
70         echo "*** You must include --enable-socket-wrapper when compiling Samba"
71         echo "*** in order to execute 'make test'.  Exiting...."
72         echo "***"
73         exit 1
74 fi
75
76 ## 
77 ## create the test directory layout
78 ##
79 echo -n "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
80 /bin/rm -rf $PREFIX/*
81 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR $SOCKET_WRAPPER_DIR
82 mkdir -p $PREFIX_ABS/tmp
83 chmod 777 $PREFIX_ABS/tmp
84
85 ##
86 ## Create the common config include file with the basic settings
87 ##
88
89 cat >$COMMONCONFFILE<<EOF
90         workgroup = SAMBA-TEST
91
92         private dir = $PRIVATEDIR
93         pid directory = $PIDDIR
94         lock directory = $LOCKDIR
95         log file = $LOGDIR/log.%m
96         log level = 0
97
98         name resolve order = bcast
99 EOF
100
101 TORTURE_INTERFACES='127.0.0.6/8,127.0.0.7/8,127.0.0.8/8,127.0.0.9/8,127.0.0.10/8,127.0.0.11/8'
102
103 cat >$CONFFILE<<EOF
104 [global]
105         netbios name = TORTURE_6
106         interfaces = $TORTURE_INTERFACES
107         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
108         include = $COMMONCONFFILE
109
110         passdb backend = tdbsam
111 EOF
112
113 cat >$SAMBA4CONFFILE<<EOF
114 [global]
115         netbios name = TORTURE_6
116         interfaces = $TORTURE_INTERFACES
117         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
118         include = $COMMONCONFFILE
119 EOF
120
121 cat >$SERVERCONFFILE<<EOF
122 [global]
123         netbios name = $SERVER
124         interfaces = $SERVER_IP/8
125         bind interfaces only = yes
126         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
127         include = $COMMONCONFFILE
128
129         passdb backend = tdbsam
130
131         ; Necessary to add the build farm hacks
132         add user script = /bin/false
133         add machine script = /bin/false
134
135         kernel oplocks = no
136
137         syslog = no
138         printing = bsd
139         printcap name = /dev/null
140
141 [tmp]
142         path = $PREFIX_ABS/tmp
143         read only = no
144         smbd:sharedelay = 100000
145 [hideunread]
146         copy = tmp
147         hide unreadable = yes
148 [hideunwrite]
149         copy = tmp
150         hide unwriteable files = yes
151 [print1]
152         copy = tmp
153         printable = yes
154         printing = test
155 [print2]
156         copy = print1
157 [print3]
158         copy = print1
159 [print4]
160         copy = print1
161 EOF
162
163 ##
164 ## create a test account
165 ##
166
167 (echo $PASSWORD; echo $PASSWORD) | \
168         smbpasswd -c $CONFFILE -L -s -a $USERNAME >/dev/null || exit 1
169
170 echo "DONE";
171
172 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
173 export SERVER_TEST_FIFO
174 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
175 export NMBD_TEST_LOG
176 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
177 export SMBD_TEST_LOG
178
179 MAKE_TEST_BINARY=""
180 export MAKE_TEST_BINARY
181
182 # start off with 0 failures
183 failed=0
184 export failed
185
186 . $SCRIPTDIR/test_functions.sh
187
188 SOCKET_WRAPPER_DEFAULT_IFACE=2
189 export SOCKET_WRAPPER_DEFAULT_IFACE
190 samba3_check_or_start
191
192 # ensure any one smbtorture call doesn't run too long
193 # and smbtorture will use 127.0.0.6 as source address by default
194 SOCKET_WRAPPER_DEFAULT_IFACE=6
195 export SOCKET_WRAPPER_DEFAULT_IFACE
196 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
197 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
198 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
199 export TORTURE4_OPTIONS
200
201 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
202         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
203 fi
204
205
206 ##
207 ## ready to go...now loop through the tests
208 ##
209
210 START=`date`
211 (
212  # give time for nbt server to register its names
213  echo "delaying for nbt name registration"
214  sleep 4
215  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
216  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
217  bin/nmblookup $CONFIGURATION __SAMBA__
218  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
219  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
220  bin/nmblookup $CONFIGURATION $SERVER
221  # make sure smbd is also up set
222  echo "wait for smbd"
223  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
224  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
225
226  failed=0
227
228  . $SCRIPTDIR/tests_$TESTS.sh
229  exit $failed
230 )
231 failed=$?
232
233 samba3_stop_sig_term
234
235 END=`date`
236 echo "START: $START ($0)";
237 echo "END:   $END ($0)";
238
239 # if there were any valgrind failures, show them
240 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
241 if [ "$count" != 0 ]; then
242     for f in $PREFIX/valgrind.log*; do
243         if [ -s $f ]; then
244             echo "VALGRIND FAILURE";
245             failed=`expr $failed + 1`
246             cat $f
247         fi
248     done
249 fi
250
251 sleep 2
252 samba3_stop_sig_kill
253
254 teststatus $0 $failed