r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[kai/samba-autobuild/.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 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=`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 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         ; Necessary to add the build farm hacks
115         add user script = /bin/false
116         add machine script = /bin/false
117
118         kernel oplocks = no
119
120 [tmp]
121         path = $PREFIX_ABS/tmp
122         read only = no
123         smbd:sharedelay = 100000
124 [hideunread]
125         copy = tmp
126         hide unreadable = yes
127 [hideunwrite]
128         copy = tmp
129         hide unwriteable files = yes
130 EOF
131
132
133 ##
134 ## create a test account
135 ##
136
137 (echo $PASSWORD; echo $PASSWORD) | \
138         smbpasswd -c $CONFFILE -L -s -a $USERNAME >/dev/null || exit 1
139
140 echo "DONE";
141
142 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
143         CONFIGURATION="$CONFIGURATION --option=\"torture:progress=no\""
144 fi
145
146 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
147 export SERVER_TEST_FIFO
148 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
149 export NMBD_TEST_LOG
150 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
151 export SMBD_TEST_LOG
152
153 # start off with 0 failures
154 failed=0
155 export failed
156
157 . $SCRIPTDIR/test_functions.sh
158
159 SOCKET_WRAPPER_DEFAULT_IFACE=2
160 export SOCKET_WRAPPER_DEFAULT_IFACE
161 samba3_check_or_start
162
163 # ensure any one smbtorture call doesn't run too long
164 # and smbtorture will use 127.0.0.26 as source address by default
165 SOCKET_WRAPPER_DEFAULT_IFACE=26
166 export SOCKET_WRAPPER_DEFAULT_IFACE
167 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'
168 TORTURE4_OPTIONS="--maximum-runtime=$TORTURE_MAXTIME --option=interfaces=$TORTURE4_INTERFACES $CONFIGURATION"
169 export TORTURE4_OPTIONS
170
171 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
172         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
173 fi
174
175 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=target:samba3=yes"
176
177 ##
178 ## ready to go...now loop through the tests
179 ##
180
181 START=`date`
182 (
183  # give time for nbt server to register its names
184  echo "delaying for nbt name registration"
185  sleep 4
186  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
187  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
188  bin/nmblookup $CONFIGURATION __SAMBA__
189  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
190  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
191  bin/nmblookup $CONFIGURATION $SERVER
192  # make sure smbd is also up set
193  echo "wait for smbd"
194  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
195  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
196
197  failed=0
198
199  . $SCRIPTDIR/tests_$TESTS.sh
200  exit $failed
201 )
202 failed=$?
203
204 samba3_stop_sig_term
205
206 END=`date`
207 echo "START: $START ($0)";
208 echo "END:   $END ($0)";
209
210 # if there were any valgrind failures, show them
211 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
212 if [ "$count" != 0 ]; then
213     for f in $PREFIX/valgrind.log*; do
214         if [ -s $f ]; then
215             echo "VALGRIND FAILURE";
216             failed=`expr $failed + 1`
217             cat $f
218         fi
219     done
220 fi
221
222 sleep 2
223 samba3_stop_sig_kill
224
225 teststatus $0 $failed