r17934: allow srcdir != builddir for 'make test'
[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 SERVERCONFFILE=$LIBDIR/server.conf
43 COMMONCONFFILE=$LIBDIR/common.conf
44 PRIVATEDIR=$PREFIX_ABS/private
45 LOCKDIR=$PREFIX_ABS/lockdir
46 LOGDIR=$PREFIX_ABS/logs
47 SOCKET_WRAPPER_DIR=$PREFIX/sw
48 CONFIGURATION="-s $CONFFILE"
49
50 export PREFIX PREFIX_ABS CONFIGURATION CONFFILE PATH SOCKET_WRAPPER_DIR DOMAIN
51 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
52 export SRCDIR SCRIPTDIR BINDIR
53 export USERNAME PASSWORD
54 export SMBTORTURE4
55 export SERVER SERVER_IP
56
57 PATH=bin:$PATH
58 export PATH
59
60 ##
61 ## verify that we were built with --enable-socket-wrapper
62 ##
63
64 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
65         echo "***"
66         echo "*** You must include --enable-socket-wrapper when compiling Samba"
67         echo "*** in order to execute 'make test'.  Exiting...."
68         echo "***"
69         exit 1
70 fi
71
72 ## 
73 ## create the test directory layout
74 ##
75 echo -n "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
76 /bin/rm -rf $PREFIX/*
77 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR $SOCKET_WRAPPER_DIR
78 mkdir -p $PREFIX_ABS/tmp
79 chmod 777 $PREFIX_ABS/tmp
80
81 ##
82 ## Create the common config include file with the basic settings
83 ##
84
85 cat >$COMMONCONFFILE<<EOF
86         workgroup = SAMBA-TEST
87
88         private dir = $PRIVATEDIR
89         pid directory = $PIDDIR
90         lock directory = $LOCKDIR
91         log file = $LOGDIR/log.%m
92         log level = 0
93
94         passdb backend = tdbsam
95
96         name resolve order = bcast
97
98         panic action = $SCRIPTDIR/gdb_backtrace %d
99 EOF
100
101 cat >$CONFFILE<<EOF
102 [global]
103         netbios name = TORTURE26
104         interfaces = 127.0.0.26/8
105         include = $COMMONCONFFILE
106 EOF
107
108 cat >$SERVERCONFFILE<<EOF
109 [global]
110         netbios name = $SERVER
111         interfaces = $SERVER_IP/8
112         bind interfaces only = yes
113         include = $COMMONCONFFILE
114
115         ; Necessary to add the build farm hacks
116         add user script = /bin/false
117         add machine script = /bin/false
118
119         kernel oplocks = no
120
121         printing = bsd
122         printcap name = /dev/null
123
124 [tmp]
125         path = $PREFIX_ABS/tmp
126         read only = no
127         smbd:sharedelay = 100000
128 [hideunread]
129         copy = tmp
130         hide unreadable = yes
131 [hideunwrite]
132         copy = tmp
133         hide unwriteable files = yes
134 EOF
135
136
137 ##
138 ## create a test account
139 ##
140
141 (echo $PASSWORD; echo $PASSWORD) | \
142         smbpasswd -c $CONFFILE -L -s -a $USERNAME >/dev/null || exit 1
143
144 echo "DONE";
145
146 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
147         CONFIGURATION="$CONFIGURATION --option=\"torture:progress=no\""
148 fi
149
150 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
151 export SERVER_TEST_FIFO
152 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
153 export NMBD_TEST_LOG
154 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
155 export SMBD_TEST_LOG
156
157 # start off with 0 failures
158 failed=0
159 export failed
160
161 . $SCRIPTDIR/test_functions.sh
162
163 SOCKET_WRAPPER_DEFAULT_IFACE=2
164 export SOCKET_WRAPPER_DEFAULT_IFACE
165 samba3_check_or_start
166
167 # ensure any one smbtorture call doesn't run too long
168 # and smbtorture will use 127.0.0.26 as source address by default
169 SOCKET_WRAPPER_DEFAULT_IFACE=26
170 export SOCKET_WRAPPER_DEFAULT_IFACE
171 TORTURE4_INTERFACES='127.0.0.26/8,127.0.0.27/8,127.0.0.28/8,127.0.0.29/8,127.0.0.30/8,127.0.0.31/8'
172 TORTURE4_OPTIONS="--maximum-runtime=$TORTURE_MAXTIME --option=interfaces=$TORTURE4_INTERFACES $CONFIGURATION"
173 export TORTURE4_OPTIONS
174
175 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
176         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
177 fi
178
179 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=target:samba3=yes"
180
181 ##
182 ## ready to go...now loop through the tests
183 ##
184
185 START=`date`
186 (
187  # give time for nbt server to register its names
188  echo "delaying for nbt name registration"
189  sleep 4
190  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
191  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
192  bin/nmblookup $CONFIGURATION __SAMBA__
193  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
194  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
195  bin/nmblookup $CONFIGURATION $SERVER
196  # make sure smbd is also up set
197  echo "wait for smbd"
198  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
199  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
200
201  failed=0
202
203  . $SCRIPTDIR/tests_$TESTS.sh
204  exit $failed
205 )
206 failed=$?
207
208 samba3_stop_sig_term
209
210 END=`date`
211 echo "START: $START ($0)";
212 echo "END:   $END ($0)";
213
214 # if there were any valgrind failures, show them
215 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
216 if [ "$count" != 0 ]; then
217     for f in $PREFIX/valgrind.log*; do
218         if [ -s $f ]; then
219             echo "VALGRIND FAILURE";
220             failed=`expr $failed + 1`
221             cat $f
222         fi
223     done
224 fi
225
226 sleep 2
227 samba3_stop_sig_kill
228
229 teststatus $0 $failed