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