s3-printing: Fix vlp testprinter application.
[metze/samba/wip.git] / source3 / script / tests / selftest.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4         echo "$0 <directory> <all | quick> [-t <smbtorture4>] [-s <shrdir>] " \
5              "[-c <custom conf>]"
6         exit 1
7 fi
8
9 ##
10 ## Setup the required args
11 ##
12 DIRECTORY=$1; shift;
13 SUBTESTS=$1; shift;
14
15 ##
16 ## Parse oprtional args
17 ##
18 while getopts s:c:t: f
19 do
20     case $f in
21         t)      SMBTORTURE4=$OPTARG;;
22         s)      ALT_SHRDIR_ARG=$OPTARG;;
23         c)      CUSTOM_CONF_ARG=$OPTARG;;
24     esac
25 done
26
27 echo "Running selftest with the following"
28 echo "Selftest Directory: $DIRECTORY"
29 echo "Subtests to Run: $SUBTESTS"
30 echo "smbtorture4 Path: $SMBTORTURE4"
31 echo "Alternative Share Dir: $ALT_SHRDIR_ARG"
32 echo "Custom Configuration: $CUSTOM_CONF_ARG"
33
34 if [ $CUSTOM_CONF_ARG ]; then
35     INCLUDE_CUSTOM_CONF="include = $CUSTOM_CONF_ARG"
36 fi
37
38 ##
39 ## create the test directory
40 ##
41 PREFIX=`echo $DIRECTORY | sed s+//+/+`
42 mkdir -p $PREFIX || exit $?
43 OLD_PWD=`pwd`
44 cd $PREFIX || exit $?
45 PREFIX_ABS=`pwd`
46 cd $OLD_PWD
47
48 if [ -z "$TORTURE_MAXTIME" ]; then
49     TORTURE_MAXTIME=300
50 fi
51 export TORTURE_MAXTIME
52
53 ##
54 ## setup the various environment variables we need
55 ##
56
57 WORKGROUP=SAMBA-TEST
58 SERVER=localhost2
59 SERVER_IP=127.0.0.2
60 USERNAME=`PATH=/usr/ucb:$PATH whoami`
61 USERID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f1 | sed -e 's/uid=\([0-9]*\).*/\1/g'`
62 GROUPID=`PATH=/usr/ucb:$PATH id | cut -d ' ' -f2 | sed -e 's/gid=\([0-9]*\).*/\1/g'`
63 PASSWORD=test
64
65 SRCDIR="`dirname $0`/../.."
66 BINDIR="`pwd`/bin"
67 SCRIPTDIR=$SRCDIR/script/tests
68 LIBDIR=$PREFIX_ABS/lib
69 PIDDIR=$PREFIX_ABS/pid
70 CONFFILE=$LIBDIR/client.conf
71 SAMBA4CONFFILE=$LIBDIR/samba4client.conf
72 SERVERCONFFILE=$LIBDIR/server.conf
73 COMMONCONFFILE=$LIBDIR/common.conf
74 PRIVATEDIR=$PREFIX_ABS/private
75 LOCKDIR=$PREFIX_ABS/lockdir
76 LOGDIR=$PREFIX_ABS/logs
77 SOCKET_WRAPPER_DIR=$PREFIX/sw
78 CONFIGURATION="--configfile $CONFFILE"
79 SAMBA4CONFIGURATION="-s $SAMBA4CONFFILE"
80 NSS_WRAPPER_PASSWD="$PRIVATEDIR/passwd"
81 NSS_WRAPPER_GROUP="$PRIVATEDIR/group"
82 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbindd
83 WINBINDD_PRIV_PIPE_DIR=$LOCKDIR/winbindd_privileged
84
85 export PREFIX PREFIX_ABS
86 export CONFIGURATION CONFFILE SAMBA4CONFIGURATION SAMBA4CONFFILE
87 export PATH SOCKET_WRAPPER_DIR DOMAIN
88 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR SERVERCONFFILE
89 export SRCDIR SCRIPTDIR BINDIR
90 export USERNAME PASSWORD
91 export WORKGROUP SERVER SERVER_IP
92 export NSS_WRAPPER_PASSWD NSS_WRAPPER_GROUP
93 export WINBINDD_SOCKET_DIR WINBINDD_PRIV_PIPE_DIR
94
95 PATH=bin:$PATH
96 export PATH
97
98 if [ $SMBTORTURE4 ]; then
99     SAMBA4BINDIR=`dirname $SMBTORTURE4`
100 fi
101
102 SAMBA4SHAREDDIR="$SAMBA4BINDIR/shared"
103
104 export SAMBA4SHAREDDIR
105 export SMBTORTURE4
106
107 if [ -z "$LIB_PATH_VAR" ] ; then
108         echo "Warning: LIB_PATH_VAR not set. Using best guess LD_LIBRARY_PATH." >&2
109         LIB_PATH_VAR=LD_LIBRARY_PATH
110         export LIB_PATH_VAR
111 fi
112
113 eval $LIB_PATH_VAR=$BINDIR:$SAMBA4SHAREDDIR:\$$LIB_PATH_VAR
114 export $LIB_PATH_VAR
115
116 ##
117 ## verify that we were built with --enable-socket-wrapper
118 ##
119
120 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
121         echo "***"
122         echo "*** You must include --enable-socket-wrapper when compiling Samba"
123         echo "*** in order to execute 'make test'.  Exiting...."
124         echo "***"
125         exit 1
126 fi
127
128 if test "x`smbd -b | grep NSS_WRAPPER`" = "x"; then
129         echo "***"
130         echo "*** You must include --enable-nss-wrapper when compiling Samba"
131         echo "*** in order to execute 'make test'.  Exiting...."
132         echo "***"
133         exit 1
134 fi
135
136
137 ## 
138 ## create the test directory layout
139 ##
140 printf "%s" "CREATE TEST ENVIRONMENT IN '$PREFIX'"...
141 /bin/rm -rf $PREFIX/*
142 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR
143 mkdir -p $SOCKET_WRAPPER_DIR
144 mkdir -p $WINBINDD_SOCKET_DIR
145 chmod 755 $WINBINDD_SOCKET_DIR
146
147 ##
148 ## Create an alternate shrdir if one was specified.
149 ##
150 if [ $ALT_SHRDIR_ARG ]; then
151     ALT_SHRDIR=`echo $ALT_SHRDIR_ARG | sed s+//+/+`
152     mkdir -p $ALT_SHRDIR || exit $?
153     OLD_PWD=`pwd`
154     cd $ALT_SHRDIR || exit $?
155     SHRDIR=`pwd`
156     cd $OLD_PWD
157     /bin/rm -rf $SHRDIR/*
158 else
159     SHRDIR=$PREFIX_ABS/tmp
160     mkdir -p $SHRDIR
161 fi
162 chmod 777 $SHRDIR
163
164 ##
165 ## Create the common config include file with the basic settings
166 ##
167
168 cat >$COMMONCONFFILE<<EOF
169         workgroup = $WORKGROUP
170
171         private dir = $PRIVATEDIR
172         pid directory = $PIDDIR
173         lock directory = $LOCKDIR
174         log file = $LOGDIR/log.%m
175         log level = 0
176
177         name resolve order = bcast
178 EOF
179
180 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'
181
182 cat >$CONFFILE<<EOF
183 [global]
184         netbios name = TORTURE_6
185         interfaces = $TORTURE_INTERFACES
186         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
187         include = $COMMONCONFFILE
188
189         passdb backend = tdbsam
190 EOF
191
192 cat >$SAMBA4CONFFILE<<EOF
193 [global]
194         netbios name = TORTURE_6
195         interfaces = $TORTURE_INTERFACES
196         panic action = $SCRIPTDIR/gdb_backtrace %PID% %PROG%
197         include = $COMMONCONFFILE
198         modules dir = $SRCDIR/bin/modules
199 EOF
200
201 cat >$SERVERCONFFILE<<EOF
202 [global]
203         netbios name = $SERVER
204         interfaces = $SERVER_IP/8
205         bind interfaces only = yes
206         panic action = $SCRIPTDIR/gdb_backtrace %d %\$(MAKE_TEST_BINARY)
207         include = $COMMONCONFFILE
208
209         state directory = $LOCKDIR
210         cache directory = $LOCKDIR
211
212         passdb backend = tdbsam
213
214         domain master = yes
215         domain logons = yes
216         lanman auth = yes
217         time server = yes
218
219         add user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
220         add machine script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action add --name %u
221         delete user script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --path $NSS_WRAPPER_PASSWD --type passwd --action delete --name %u
222
223         kernel oplocks = no
224         kernel change notify = no
225
226         syslog = no
227         printing = bsd
228         printcap name = /dev/null
229
230         winbindd:socket dir = $WINBINDD_SOCKET_DIR
231         idmap uid = 100000-200000
232         idmap gid = 100000-200000
233
234 #       min receivefile size = 4000
235
236         read only = no
237         smbd:sharedelay = 100000
238         smbd:writetimeupdatedelay = 500000
239         map hidden = yes
240         map system = yes
241         create mask = 755
242         vfs objects = $BINDIR/xattr_tdb.so $BINDIR/streams_depot.so
243
244         #Include user defined custom parameters if set
245         $INCLUDE_CUSTOM_CONF
246
247 [tmp]
248         path = $SHRDIR
249 [hideunread]
250         copy = tmp
251         hide unreadable = yes
252 [hideunwrite]
253         copy = tmp
254         hide unwriteable files = yes
255 [print1]
256         copy = tmp
257         printable = yes
258         printing = vlp
259         print command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb print %p %s
260         lpq command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpq %p
261         lp rm command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lprm %p %j
262         lp pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lppause %p %j
263         lp resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb lpresume %p %j
264         queue pause command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queuepause %p
265         queue resume command = $BINDIR/vlp tdbfile=$LOCKDIR/vlp.tdb queueresume %p
266
267 [print2]
268         copy = print1
269 [print3]
270         copy = print1
271 [print4]
272         copy = print1
273 EOF
274
275 ##
276 ## create a test account
277 ##
278
279 cat >$NSS_WRAPPER_PASSWD<<EOF
280 root:x:65533:65532:root gecos:$PREFIX_ABS:/bin/false
281 nobody:x:65534:65533:nobody gecos:$PREFIX_ABS:/bin/false
282 $USERNAME:x:$USERID:$GROUPID:$USERNAME gecos:$PREFIX_ABS:/bin/false
283 EOF
284
285 cat >$NSS_WRAPPER_GROUP<<EOF
286 nobody:x:65533:
287 nogroup:x:65534:nobody
288 $USERNAME-group:x:$GROUPID:
289 EOF
290
291 MAKE_TEST_BINARY="bin/smbpasswd"
292 export MAKE_TEST_BINARY
293
294 (echo $PASSWORD; echo $PASSWORD) | \
295         bin/smbpasswd -c $SERVERCONFFILE -L -s -a $USERNAME >/dev/null || exit 1
296
297 echo "DONE";
298
299 MAKE_TEST_BINARY=""
300
301 SERVER_TEST_FIFO="$PREFIX/server_test.fifo"
302 export SERVER_TEST_FIFO
303 NMBD_TEST_LOG="$PREFIX/nmbd_test.log"
304 export NMBD_TEST_LOG
305 WINBINDD_TEST_LOG="$PREFIX/winbindd_test.log"
306 export WINBINDD_TEST_LOG
307 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
308 export SMBD_TEST_LOG
309
310 # start off with 0 failures
311 failed=0
312 export failed
313
314 . $SCRIPTDIR/test_functions.sh
315
316 SOCKET_WRAPPER_DEFAULT_IFACE=2
317 export SOCKET_WRAPPER_DEFAULT_IFACE
318 samba3_check_or_start
319
320
321 # ensure any one smbtorture call doesn't run too long
322 # and smbtorture will use 127.0.0.6 as source address by default
323 SOCKET_WRAPPER_DEFAULT_IFACE=6
324 export SOCKET_WRAPPER_DEFAULT_IFACE
325 TORTURE4_OPTIONS="$SAMBA4CONFIGURATION"
326 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --maximum-runtime=$TORTURE_MAXTIME"
327 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --target=samba3"
328 TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:localdir=$SHRDIR"
329 export TORTURE4_OPTIONS
330
331 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
332         TORTURE4_OPTIONS="$TORTURE4_OPTIONS --option=torture:progress=no"
333 fi
334
335
336 ##
337 ## ready to go...now loop through the tests
338 ##
339
340 START=`date`
341 (
342  # give time for nbt server to register its names
343  echo "delaying for nbt name registration"
344  sleep 10
345  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
346  MAKE_TEST_BINARY="bin/nmblookup"
347  bin/nmblookup $CONFIGURATION -U $SERVER_IP __SAMBA__
348  bin/nmblookup $CONFIGURATION __SAMBA__
349  bin/nmblookup $CONFIGURATION -U 127.255.255.255 __SAMBA__
350  bin/nmblookup $CONFIGURATION -U $SERVER_IP $SERVER
351  bin/nmblookup $CONFIGURATION $SERVER
352  # make sure smbd is also up set
353  echo "wait for smbd"
354  MAKE_TEST_BINARY="bin/smbclient"
355  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
356  bin/smbclient $CONFIGURATION -L $SERVER_IP -U% -p 139 | head -2
357  MAKE_TEST_BINARY=""
358
359  failed=0
360
361  . $SCRIPTDIR/tests_$SUBTESTS.sh
362  exit $failed
363 )
364 failed=$?
365
366 samba3_stop_sig_term
367
368 END=`date`
369 echo "START: $START ($0)";
370 echo "END:   $END ($0)";
371
372 # if there were any valgrind failures, show them
373 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
374 if [ "$count" != 0 ]; then
375     for f in $PREFIX/valgrind.log*; do
376         if [ -s $f ]; then
377             echo "VALGRIND FAILURE";
378             failed=`expr $failed + 1`
379             cat $f
380         fi
381     done
382 fi
383
384 sleep 2
385 samba3_stop_sig_kill
386
387 teststatus $0 $failed