0f1ca32e4a11fa839b736f8b4a0f5f01f4a03ab3
[metze/samba/wip.git] / source3 / script / tests / selftest.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4         echo "$0 <directory> <all | quick> [-t <smbtorture4>] [-s <shrdir>] " \
5              "[-c <custom conf>]"
6         exit 1
7 fi
8
9 ##
10 ## Setup the required args
11 ##
12 DIRECTORY=$1; shift;
13 SUBTESTS=$1; shift;
14
15 ##
16 ## Parse oprtional args
17 ##
18 while getopts s:c:t: f
19 do
20     case $f in
21         t)      SMBTORTURE4=$OPTARG;;
22         s)      ALT_SHRDIR_ARG=$OPTARG;;
23         c)      CUSTOM_CONF_ARG=$OPTARG;;
24     esac
25 done
26
27 echo "Running selftest with the following"
28 echo "Selftest Directory: $DIRECTORY"
29 echo "Subtests to Run: $SUBTESTS"
30 echo "smbtorture4 Path: $SMBTORTURE4"
31 echo "Alternative Share Dir: $ALT_SHRDIR_ARG"
32 echo "Custom Configuration: $CUSTOM_CONF_ARG"
33
34 if [ $CUSTOM_CONF_ARG ]; then
35     INCLUDE_CUSTOM_CONF="include = $CUSTOM_CONF_ARG"
36 fi
37
38 ##
39 ## create the test directory
40 ##
41 PREFIX=`echo $DIRECTORY | sed s+//+/+`
42 mkdir -p $PREFIX || exit $?
43 OLD_PWD=`pwd`
44 cd $PREFIX || exit $?
45 PREFIX_ABS=`pwd`
46 cd $OLD_PWD
47
48 if [ -z "$TORTURE_MAXTIME" ]; then
49     TORTURE_MAXTIME=300
50 fi
51 export TORTURE_MAXTIME
52
53 ##
54 ## setup the various environment variables we need
55 ##
56
57 WORKGROUP=SAMBA-TEST
58 SERVER=localhost2
59 SERVER_IP=127.0.0.2
60 USERNAME=`PATH=/usr/ucb:$PATH whoami`
61 USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'`
62 GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'`
63 PASSWORD=test
64
65 SRCDIR="`dirname $0`/../.."
66 BINDIR="`pwd`/bin"
67 SCRIPTDIR=$SRCDIR/script/tests
68 LIBDIR=$PREFIX_ABS/lib
69 PIDDIR=$PREFIX_ABS/pid
70 CONFFILE=$LIBDIR/client.conf
71 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
72 SERVERCONFFILE=$LIBDIR/server.conf
73 COMMONCONFFILE=$LIBDIR/common.conf
74 PRIVATEDIR=$PREFIX_ABS/private
75 LOCKDIR=$PREFIX_ABS/lockdir
76 LOGDIR=$PREFIX_ABS/logs
77 SOCKET_WRAPPER_DIR=$PREFIX/sw
78 CONFIGURATION="--configfile $CONFFILE"
79 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
80 NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd"
81 NSS_WRAPPER_GROUP="$PRIVATEDIR/group"
82 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd
83 WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged
84
85 export PREFIX PREFIX_ABS
86 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
87 export PATH SOCKET_WRAPPER_DIR DOMAIN
88 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
89 export SRCDIR SCRIPTDIR BINDIR
90 export USERNAME PASSWORD
91 export WORKGROUP SERVER SERVER_IP
92 export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
93 export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR
94
95 PATH=bin:$PATH
96 export PATH
97
98 if [ $SMBTORTURE4 ]; then
99     SAMBA4BINDIR=`dirname $SMBTORTURE4`
100 fi
101
102 SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared"
103
104 export SAMBA4SHAREDDIR
105 export SMBTORTURE4
106
107 if test x"$LD_LIBRARY_PATH" != x""; then
108         LD_LIBRARY_PATH="$BINDIR:$SAMBA4SHAREDDIR:$LD_LIBRARY_PATH"
109 else
110         LD_LIBRARY_PATH="$BINDIR:$SAMBA4SHAREDDIR"
111 fi
112 echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
113 export LD_LIBRARY_PATH
114
115 ##
116 ## verify that we were built with --enable-socket-wrapper
117 ##
118
119 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
120         echo "***"
121         echo "*** You must include --enable-socket-wrapper when compiling Samba"
122         echo "*** in order to execute 'make test'.  Exiting...."
123         echo "***"
124         exit 1
125 fi
126
127 if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then
128         echo "***"
129         echo "*** You must include --enable-nss-wrapper when compiling Samba"
130         echo "*** in order to execute 'make test'.  Exiting...."
131         echo "***"
132         exit 1
133 fi
134
135
136 ## 
137 ## create the test directory layout
138 ##
139 printf "%s" "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
140 /bin/rm -rf $PREFIX/*
141 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR
142 mkdir -p $SOCKET_WRAPPER_DIR
143 mkdir -p $WINBINDD_SOCKET_DIR
144 chmod 755 $WINBINDD_SOCKET_DIR
145
146 ##
147 ## Create an alternate shrdir if one was specified.
148 ##
149 if [ $ALT_SHRDIR_ARG ]; then
150     ALT_SHRDIR=`echo $ALT_SHRDIR_ARG | sed s+//+/+`
151     mkdir -p $ALT_SHRDIR || exit $?
152     OLD_PWD=`pwd`
153     cd $ALT_SHRDIR || exit $?
154     SHRDIR=`pwd`
155     cd $OLD_PWD
156     /bin/rm -rf $SHRDIR/*
157 else
158     SHRDIR=$PREFIX_ABS/tmp
159     mkdir -p $SHRDIR
160 fi
161 chmod 777 $SHRDIR
162
163 ##
164 ## Create the common config include file with the basic settings
165 ##
166
167 cat >$COMMONCONFFILE<<EOF
168         workgroup = $WORKGROUP
169
170         private dir = $PRIVATEDIR
171         pid directory = $PIDDIR
172         lock directory = $LOCKDIR
173         state directory = $LOCKDIR
174         cache directory = $LOCKDIR
175         log file = $LOGDIR/log.%m
176         log level = 0
177
178         name resolve order = bcast
179 EOF
180
181 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'
182
183 cat >$CONFFILE<<EOF
184 [global]
185         netbios name = TORTURE_6
186         interfaces = $TORTURE_INTERFACES
187         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
188         include = $COMMONCONFFILE
189
190         passdb backend = tdbsam
191 EOF
192
193 cat >$SAMBA4CONFFILE<<EOF
194 [global]
195         netbios name = TORTURE_6
196         interfaces = $TORTURE_INTERFACES
197         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
198         include = $COMMONCONFFILE
199         modules dir = $SRCDIR/bin/modules
200 EOF
201
202 cat >$SERVERCONFFILE<<EOF
203 [global]
204         netbios name = $SERVER
205         interfaces = $SERVER_IP/8
206         bind interfaces only = yes
207         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
208         include = $COMMONCONFFILE
209
210         passdb backend = tdbsam
211
212         domain master = yes
213         domain logons = yes
214         time server = yes
215
216         add user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
217         add machine script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
218         delete user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
219
220         kernel oplocks = no
221         kernel change notify = no
222
223         syslog = no
224         printing = bsd
225         printcap name = /dev/null
226
227         winbindd:socket dir = $WINBINDD_SOCKET_DIR
228         idmap uid = 100000-200000
229         idmap gid = 100000-200000
230
231 #       min receivefile size = 4000
232
233         read only = no
234         smbd:sharedelay = 100000
235         smbd:writetimeupdatedelay = 500000
236         map hidden = yes
237         map system = yes
238         create mask = 755
239         vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
240
241         #Include user defined custom parameters if set
242         $INCLUDE_CUSTOM_CONF
243
244 [tmp]
245         path = $SHRDIR
246 [hideunread]
247         copy = tmp
248         hide unreadable = yes
249 [hideunwrite]
250         copy = tmp
251         hide unwriteable files = yes
252 [print1]
253         copy = tmp
254         printable = yes
255         printing = test
256 [print2]
257         copy = print1
258 [print3]
259         copy = print1
260 [print4]
261         copy = print1
262 EOF
263
264 ##
265 ## create a test account
266 ##
267
268 cat >$NSS_WRAPPER_PASSWD<<EOF
269 nobody:x:65534:65533:nobody gecos:$PREFIX_ABS:/bin/false
270 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
271 EOF
272
273 cat >$NSS_WRAPPER_GROUP<<EOF
274 nobody:x:65533:
275 nogroup:x:65534:nobody
276 $USERNAME-group:x:$GROUPID:
277 EOF
278
279 MAKE_TEST_BINARY="bin/smbpasswd"
280 export MAKE_TEST_BINARY
281
282 (echo $PASSWORD; echo $PASSWORD) | \
283         bin/smbpasswd -c $CONFFILE -L -s -a $USERNAME >/dev/null || exit 1
284
285 echo "DONE";
286
287 MAKE_TEST_BINARY=""
288
289 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
290 export SERVER_TEST_FIFO
291 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
292 export NMBD_TEST_LOG
293 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
294 export WINBINDD_TEST_LOG
295 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
296 export SMBD_TEST_LOG
297
298 # start off with 0 failures
299 failed=0
300 export failed
301
302 . $SCRIPTDIR/test_functions.sh
303
304 SOCKET_WRAPPER_DEFAULT_IFACE=2
305 export SOCKET_WRAPPER_DEFAULT_IFACE
306 samba3_check_or_start
307
308
309 # ensure any one smbtorture call doesn't run too long
310 # and smbtorture will use 127.0.0.6 as source address by default
311 SOCKET_WRAPPER_DEFAULT_IFACE=6
312 export SOCKET_WRAPPER_DEFAULT_IFACE
313 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
314 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
315 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
316 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
317 export TORTURE4_OPTIONS
318
319 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
320         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
321 fi
322
323
324 ##
325 ## ready to go...now loop through the tests
326 ##
327
328 START=`date`
329 (
330  # give time for nbt server to register its names
331  echo "delaying for nbt name registration"
332  sleep 10
333  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
334  MAKE_TEST_BINARY="bin/nmblookup"
335  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
336  bin/nmblookup $CONFIGURATION __SAMBA__
337  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
338  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
339  bin/nmblookup $CONFIGURATION $SERVER
340  # make sure smbd is also up set
341  echo "wait for smbd"
342  MAKE_TEST_BINARY="bin/smbclient"
343  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
344  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
345  MAKE_TEST_BINARY=""
346
347  failed=0
348
349  . $SCRIPTDIR/tests_$SUBTESTS.sh
350  exit $failed
351 )
352 failed=$?
353
354 samba3_stop_sig_term
355
356 END=`date`
357 echo "START: $START ($0)";
358 echo "END:   $END ($0)";
359
360 # if there were any valgrind failures, show them
361 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
362 if [ "$count" != 0 ]; then
363     for f in $PREFIX/valgrind.log*; do
364         if [ -s $f ]; then
365             echo "VALGRIND FAILURE";
366             failed=`expr $failed + 1`
367             cat $f
368         fi
369     done
370 fi
371
372 sleep 2
373 samba3_stop_sig_kill
374
375 teststatus $0 $failed