Attempt to make the build farm run s4torture again
[ira/wip.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 WORKGROUP=SAMBA-TEST
31 SERVER=localhost2
32 SERVER_IP=127.0.0.2
33 USERNAME=`PATH=/usr/ucb:$PATH whoami`
34 USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'`
35 GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'`
36 PASSWORD=test
37
38 SRCDIR="`dirname $0`/../.."
39 BINDIR="`pwd`/bin"
40 SCRIPTDIR=$SRCDIR/script/tests
41 SHRDIR=$PREFIX_ABS/tmp
42 LIBDIR=$PREFIX_ABS/lib
43 PIDDIR=$PREFIX_ABS/pid
44 CONFFILE=$LIBDIR/client.conf
45 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
46 SERVERCONFFILE=$LIBDIR/server.conf
47 COMMONCONFFILE=$LIBDIR/common.conf
48 PRIVATEDIR=$PREFIX_ABS/private
49 LOCKDIR=$PREFIX_ABS/lockdir
50 LOGDIR=$PREFIX_ABS/logs
51 SOCKET_WRAPPER_DIR=$PREFIX/sw
52 CONFIGURATION="--configfile $CONFFILE"
53 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
54 NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd"
55 NSS_WRAPPER_GROUP="$PRIVATEDIR/group"
56 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd
57 WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged
58
59 export PREFIX PREFIX_ABS
60 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
61 export PATH SOCKET_WRAPPER_DIR DOMAIN
62 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
63 export SRCDIR SCRIPTDIR BINDIR
64 export USERNAME PASSWORD
65 export SMBTORTURE4
66 export WORKGROUP SERVER SERVER_IP
67 export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
68 export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR
69
70 PATH=bin:$PATH
71 export PATH
72
73 LD_LIBRARY_PATH="$LD_LIBRARY_PATH":"$BINDIR"
74 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
75 export LD_LIBRARY_PATH
76
77 ##
78 ## verify that we were built with --enable-socket-wrapper
79 ##
80
81 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
82         echo "***"
83         echo "*** You must include --enable-socket-wrapper when compiling Samba"
84         echo "*** in order to execute 'make test'.  Exiting...."
85         echo "***"
86         exit 1
87 fi
88
89 if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then
90         echo "***"
91         echo "*** You must include --enable-nss-wrapper when compiling Samba"
92         echo "*** in order to execute 'make test'.  Exiting...."
93         echo "***"
94         exit 1
95 fi
96
97
98 ## 
99 ## create the test directory layout
100 ##
101 echo -n "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
102 /bin/rm -rf $PREFIX/*
103 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR
104 mkdir -p $SOCKET_WRAPPER_DIR
105 mkdir -p $WINBINDD_SOCKET_DIR
106 chmod 755 $WINBINDD_SOCKET_DIR
107 mkdir -p $PREFIX_ABS/tmp
108 chmod 777 $PREFIX_ABS/tmp
109
110 ##
111 ## Create the common config include file with the basic settings
112 ##
113
114 cat >$COMMONCONFFILE<<EOF
115         workgroup = $WORKGROUP
116
117         private dir = $PRIVATEDIR
118         pid directory = $PIDDIR
119         lock directory = $LOCKDIR
120         log file = $LOGDIR/log.%m
121         log level = 0
122
123         name resolve order = bcast
124 EOF
125
126 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'
127
128 cat >$CONFFILE<<EOF
129 [global]
130         netbios name = TORTURE_6
131         interfaces = $TORTURE_INTERFACES
132         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
133         include = $COMMONCONFFILE
134
135         passdb backend = tdbsam
136 EOF
137
138 cat >$SAMBA4CONFFILE<<EOF
139 [global]
140         netbios name = TORTURE_6
141         interfaces = $TORTURE_INTERFACES
142         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
143         include = $COMMONCONFFILE
144 EOF
145
146 cat >$SERVERCONFFILE<<EOF
147 [global]
148         netbios name = $SERVER
149         interfaces = $SERVER_IP/8
150         bind interfaces only = yes
151         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
152         include = $COMMONCONFFILE
153
154         passdb backend = tdbsam
155
156         add user script = $PERL $SRCDIR/lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
157         add machine script = $PERL $SRCDIR/lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
158         delete user script = $PERL $SRCDIR/lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
159
160         kernel oplocks = no
161         kernel change notify = no
162
163         syslog = no
164         printing = bsd
165         printcap name = /dev/null
166
167         winbindd:socket dir = $WINBINDD_SOCKET_DIR
168         idmap uid = 100000-200000
169         idmap gid = 100000-200000
170
171 #       min receivefile size = 4000
172
173 [tmp]
174         path = $PREFIX_ABS/tmp
175         read only = no
176         smbd:sharedelay = 100000
177         map hidden = yes
178         map system = yes
179         create mask = 755
180 [hideunread]
181         copy = tmp
182         hide unreadable = yes
183 [hideunwrite]
184         copy = tmp
185         hide unwriteable files = yes
186 [print1]
187         copy = tmp
188         printable = yes
189         printing = test
190 [print2]
191         copy = print1
192 [print3]
193         copy = print1
194 [print4]
195         copy = print1
196 EOF
197
198 ##
199 ## create a test account
200 ##
201
202 cat >$NSS_WRAPPER_PASSWD<<EOF
203 nobody:x:65534:65533:nobody gecos:$PREFIX_ABS:/bin/false
204 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
205 EOF
206
207 cat >$NSS_WRAPPER_GROUP<<EOF
208 nobody:x:65533:
209 nogroup:x:65534:nobody
210 $USERNAME-group:x:$GROUPID:
211 EOF
212
213 (echo $PASSWORD; echo $PASSWORD) | \
214         smbpasswd -c $CONFFILE -L -s -a $USERNAME >/dev/null || exit 1
215
216 echo "DONE";
217
218 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
219 export SERVER_TEST_FIFO
220 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
221 export NMBD_TEST_LOG
222 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
223 export WINBINDD_TEST_LOG
224 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
225 export SMBD_TEST_LOG
226
227 MAKE_TEST_BINARY=""
228 export MAKE_TEST_BINARY
229
230 # start off with 0 failures
231 failed=0
232 export failed
233
234 . $SCRIPTDIR/test_functions.sh
235
236 SOCKET_WRAPPER_DEFAULT_IFACE=2
237 export SOCKET_WRAPPER_DEFAULT_IFACE
238 samba3_check_or_start
239
240 # ensure any one smbtorture call doesn't run too long
241 # and smbtorture will use 127.0.0.6 as source address by default
242 SOCKET_WRAPPER_DEFAULT_IFACE=6
243 export SOCKET_WRAPPER_DEFAULT_IFACE
244 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
245 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
246 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
247 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$PREFIX_ABS/tmp"
248 export TORTURE4_OPTIONS
249
250 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
251         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
252 fi
253
254
255 ##
256 ## ready to go...now loop through the tests
257 ##
258
259 START=`date`
260 (
261  # give time for nbt server to register its names
262  echo "delaying for nbt name registration"
263  sleep 10
264  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
265  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
266  bin/nmblookup $CONFIGURATION __SAMBA__
267  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
268  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
269  bin/nmblookup $CONFIGURATION $SERVER
270  # make sure smbd is also up set
271  echo "wait for smbd"
272  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
273  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
274
275  failed=0
276
277  . $SCRIPTDIR/tests_$TESTS.sh
278  exit $failed
279 )
280 failed=$?
281
282 samba3_stop_sig_term
283
284 END=`date`
285 echo "START: $START ($0)";
286 echo "END:   $END ($0)";
287
288 # if there were any valgrind failures, show them
289 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
290 if [ "$count" != 0 ]; then
291     for f in $PREFIX/valgrind.log*; do
292         if [ -s $f ]; then
293             echo "VALGRIND FAILURE";
294             failed=`expr $failed + 1`
295             cat $f
296         fi
297     done
298 fi
299
300 sleep 2
301 samba3_stop_sig_kill
302
303 teststatus $0 $failed