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