b9c11b8f50bf1ea57f8cbaf6e64a68d9cd5d57e4
[abartlet/samba.git/.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 if [ ! "x$USER" = "x" ]; then
61     USERNAME=$USER
62 else
63     if [ ! "x$LOGNAME" = "x" ]; then
64         USERNAME=$LOGNAME
65     else
66         USERNAME=`PATH=/usr/ucb:$PATH whoami || id -un`
67     fi
68 fi
69 USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'`
70 GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'`
71 PASSWORD=test
72
73 SRCDIR="`dirname $0`/../.."
74 BINDIR="`pwd`/bin"
75 SCRIPTDIR=$SRCDIR/script/tests
76 LIBDIR=$PREFIX_ABS/lib
77 PIDDIR=$PREFIX_ABS/pid
78 CONFFILE=$LIBDIR/client.conf
79 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
80 SERVERCONFFILE=$LIBDIR/server.conf
81 COMMONCONFFILE=$LIBDIR/common.conf
82 PRIVATEDIR=$PREFIX_ABS/private
83 NCALRPCDIR=$PREFIX_ABS/ncalrpc
84 LOCKDIR=$PREFIX_ABS/lockdir
85 LOGDIR=$PREFIX_ABS/logs
86 SOCKET_WRAPPER_DIR=$PREFIX_ABS/sw
87 CONFIGURATION="--configfile $CONFFILE"
88 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
89 NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd"
90 NSS_WRAPPER_GROUP="$PRIVATEDIR/group"
91 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd
92 WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged
93 TEST_DIRECTORY=$DIRECTORY
94
95 export PREFIX PREFIX_ABS
96 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
97 export PATH SOCKET_WRAPPER_DIR DOMAIN
98 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
99 export SRCDIR SCRIPTDIR BINDIR
100 export USERNAME PASSWORD
101 export WORKGROUP SERVER SERVER_IP
102 export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
103 export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR
104 export TEST_DIRECTORY
105
106 PATH=bin:$PATH
107 export PATH
108
109 if [ $SMBTORTURE4 ]; then
110     SAMBA4BINDIR=`dirname $SMBTORTURE4`
111 fi
112
113 SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared"
114
115 export SAMBA4SHAREDDIR
116 export SMBTORTURE4
117
118 if [ -z "$LIB_PATH_VAR" ] ; then
119         echo "Warning: LIB_PATH_VAR not set. Using best guess LD_LIBRARY_PATH." >&2
120         LIB_PATH_VAR=LD_LIBRARY_PATH
121         export LIB_PATH_VAR
122 fi
123
124 eval $LIB_PATH_VAR=$BINDIR:$SAMBA4SHAREDDIR:\$$LIB_PATH_VAR
125 export $LIB_PATH_VAR
126
127 ##
128 ## verify that we were built with --enable-socket-wrapper
129 ##
130
131 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
132         echo "***"
133         echo "*** You must include --enable-socket-wrapper when compiling Samba"
134         echo "*** in order to execute 'make test'.  Exiting...."
135         echo "***"
136         exit 1
137 fi
138
139 if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then
140         echo "***"
141         echo "*** You must include --enable-nss-wrapper when compiling Samba"
142         echo "*** in order to execute 'make test'.  Exiting...."
143         echo "***"
144         exit 1
145 fi
146
147
148 ## 
149 ## create the test directory layout
150 ##
151 printf "%s" "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
152 /bin/rm -rf $PREFIX/*
153 mkdir -p $PRIVATEDIR $NCALRPCDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR
154 mkdir -p $SOCKET_WRAPPER_DIR
155 mkdir -p $WINBINDD_SOCKET_DIR
156 chmod 755 $WINBINDD_SOCKET_DIR
157
158 ##
159 ## Create an alternate shrdir if one was specified.
160 ##
161 if [ $ALT_SHRDIR_ARG ]; then
162     ALT_SHRDIR=`echo $ALT_SHRDIR_ARG | sed s+//+/+`
163     mkdir -p $ALT_SHRDIR || exit $?
164     OLD_PWD=`pwd`
165     cd $ALT_SHRDIR || exit $?
166     SHRDIR=`pwd`
167     cd $OLD_PWD
168     /bin/rm -rf $SHRDIR/*
169 else
170     SHRDIR=$PREFIX_ABS/tmp
171     mkdir -p $SHRDIR
172 fi
173 chmod 777 $SHRDIR
174
175 ##
176 ## Create the common config include file with the basic settings
177 ##
178
179 cat >$COMMONCONFFILE<<EOF
180         workgroup = $WORKGROUP
181
182         private dir = $PRIVATEDIR
183         pid directory = $PIDDIR
184         lock directory = $LOCKDIR
185         log file = $LOGDIR/log.%m
186         log level = 0
187
188         name resolve order = bcast
189 EOF
190
191 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'
192
193 cat >$CONFFILE<<EOF
194 [global]
195         netbios name = TORTURE_6
196         interfaces = $TORTURE_INTERFACES
197         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
198         include = $COMMONCONFFILE
199
200         passdb backend = tdbsam
201 EOF
202
203 cat >$SAMBA4CONFFILE<<EOF
204 [global]
205         netbios name = TORTURE_6
206         interfaces = $TORTURE_INTERFACES
207         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
208         include = $COMMONCONFFILE
209         modules dir = $SRCDIR/bin/modules
210         ncalrpc dir = $NCALRPCDIR
211 EOF
212
213 cat >$SERVERCONFFILE<<EOF
214 [global]
215         netbios name = $SERVER
216         interfaces = $SERVER_IP/8
217         bind interfaces only = yes
218         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
219         include = $COMMONCONFFILE
220
221         state directory = $LOCKDIR
222         cache directory = $LOCKDIR
223
224         passdb backend = tdbsam
225
226         domain master = yes
227         domain logons = yes
228         lanman auth = yes
229         time server = yes
230
231         add user script =               $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
232         add group script =              $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action add --name %g
233         add user to group script =      $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type member --action add --name %g --member %u --passwd_path $NSS_WRAPPER_PASSWD
234         add machine script =            $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
235         delete user script =            $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --passwd_path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
236         delete group script =           $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action delete --name %g
237         delete user from group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type member --action delete --name %g --member %u --passwd_path $NSS_WRAPPER_PASSWD
238
239         kernel oplocks = no
240         kernel change notify = no
241
242         syslog = no
243         printing = bsd
244         printcap name = /dev/null
245
246         winbindd:socket dir = $WINBINDD_SOCKET_DIR
247         idmap uid = 100000-200000
248         idmap gid = 100000-200000
249         winbind enum users = yes
250         winbind enum groups = yes
251
252 #       min receivefile size = 4000
253
254         read only = no
255         smbd:sharedelay = 100000
256 #       smbd:writetimeupdatedelay = 500000
257         map hidden = no
258         map system = no
259         map readonly = no
260         store dos attributes = yes
261         create mask = 755
262         store create time = yes
263         vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
264
265         #Include user defined custom parameters if set
266         $INCLUDE_CUSTOM_CONF
267
268 [tmp]
269         path = $SHRDIR
270 [hideunread]
271         copy = tmp
272         hide unreadable = yes
273 [tmpcase]
274         copy = tmp
275         case sensitive = yes
276 [hideunwrite]
277         copy = tmp
278         hide unwriteable files = yes
279 [print1]
280         copy = tmp
281         printable = yes
282         printing = vlp
283         print command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb print %p %s
284         lpq command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpq %p
285         lp rm command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lprm %p %j
286         lp pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lppause %p %j
287         lp resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpresume %p %j
288         queue pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queuepause %p
289         queue resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queueresume %p
290
291 [print2]
292         copy = print1
293 [print3]
294         copy = print1
295 [print4]
296         copy = print1
297 EOF
298
299 ##
300 ## create a test account
301 ##
302
303 cat >$NSS_WRAPPER_PASSWD<<EOF
304 root:x:65533:65532:root gecos:$PREFIX_ABS:/bin/false
305 nobody:x:65534:65533:nobody gecos:$PREFIX_ABS:/bin/false
306 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
307 EOF
308
309 cat >$NSS_WRAPPER_GROUP<<EOF
310 nobody:x:65533:
311 nogroup:x:65534:nobody
312 root:x:65532:
313 $USERNAME-group:x:$GROUPID:
314 EOF
315
316 MAKE_TEST_BINARY="bin/smbpasswd"
317 export MAKE_TEST_BINARY
318
319 (echo $PASSWORD; echo $PASSWORD) | \
320         bin/smbpasswd -c $SERVERCONFFILE -L -s -a $USERNAME >/dev/null || exit 1
321
322 echo "DONE";
323
324 MAKE_TEST_BINARY=""
325
326 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
327 export SERVER_TEST_FIFO
328 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
329 export NMBD_TEST_LOG
330 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
331 export WINBINDD_TEST_LOG
332 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
333 export SMBD_TEST_LOG
334
335 # start off with 0 failures
336 failed=0
337 export failed
338
339 . $SCRIPTDIR/test_functions.sh
340
341 SOCKET_WRAPPER_DEFAULT_IFACE=2
342 export SOCKET_WRAPPER_DEFAULT_IFACE
343 samba3_check_or_start
344
345
346 # ensure any one smbtorture call doesn't run too long
347 # and smbtorture will use 127.0.0.6 as source address by default
348 SOCKET_WRAPPER_DEFAULT_IFACE=6
349 export SOCKET_WRAPPER_DEFAULT_IFACE
350 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
351 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
352 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
353 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
354 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:winbindd_netbios_name=$SERVER"
355 export TORTURE4_OPTIONS
356
357 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
358         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
359 fi
360
361
362 ##
363 ## ready to go...now loop through the tests
364 ##
365
366 START=`date`
367 (
368  # give time for nbt server to register its names
369  echo "delaying for nbt name registration"
370  sleep 10
371  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
372  MAKE_TEST_BINARY="bin/nmblookup"
373  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
374  bin/nmblookup $CONFIGURATION __SAMBA__
375  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
376  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
377  bin/nmblookup $CONFIGURATION $SERVER
378  # make sure smbd is also up set
379  echo "wait for smbd"
380  MAKE_TEST_BINARY="bin/smbclient"
381  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
382  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
383  MAKE_TEST_BINARY=""
384
385  failed=0
386
387  . $SCRIPTDIR/tests_$SUBTESTS.sh
388  exit $failed
389 )
390 failed=$?
391
392 samba3_stop_sig_term
393
394 END=`date`
395 echo "START: $START ($0)";
396 echo "END:   $END ($0)";
397
398 # if there were any valgrind failures, show them
399 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
400 if [ "$count" != 0 ]; then
401     for f in $PREFIX/valgrind.log*; do
402         if [ -s $f ]; then
403             echo "VALGRIND FAILURE";
404             failed=`expr $failed + 1`
405             cat $f
406         fi
407     done
408 fi
409
410 sleep 2
411 samba3_stop_sig_kill
412
413 teststatus $0 $failed