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