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