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