79440b9207b2188cd02bbd893e7b78497fdb7d63
[garming/samba-autobuild/.git] / source4 / script / tests / selftest.sh
1 #!/bin/sh
2 # Bootstrap Samba and run a number of tests against it.
3
4 DOMAIN=SAMBADOMAIN
5 USERNAME=administrator
6 REALM=SAMBA.EXAMPLE.COM
7 PASSWORD=penguin
8 SRCDIR=`pwd`
9 ROOT=$USER
10 SERVER=localhost
11 NETBIOSNAME=localtest
12 if test -z "$ROOT"; then
13     ROOT=$LOGNAME
14 fi
15 if test -z "$ROOT"; then
16     ROOT=`whoami`
17 fi
18
19 if [ $# -lt 1 ]
20 then
21         echo "$0 PREFIX"
22         exit
23 fi
24
25 if [ -z "$TORTURE_MAXTIME" ]; then
26     TORTURE_MAXTIME=300
27 fi
28
29
30 PREFIX=$1
31 PREFIX=`echo $PREFIX | sed s+//+/+`
32 export PREFIX
33
34 # allow selection of the test lists
35 TESTS=$2
36
37 if [ $TESTS = "all" ]; then
38     TLS_ENABLED="yes"
39 else
40     TLS_ENABLED="no"
41 fi
42
43 mkdir -p $PREFIX || exit $?
44 OLD_PWD=`pwd`
45 cd $PREFIX || exit $?
46 PREFIX_ABS=`pwd`
47 export PREFIX_ABS
48 cd $OLD_PWD
49
50 TEST_DATA_PREFIX=$PREFIX_ABS
51 export TEST_DATA_PREFIX
52
53 LD_LIBRARY_PATH=$OLD_PWD/bin:$LD_LIBRARY_PATH
54 export LD_LIBRARY_PATH
55
56 TMPDIR=$PREFIX_ABS/tmp
57 LIBDIR=$PREFIX_ABS/lib
58 ETCDIR=$PREFIX_ABS/etc
59 PIDDIR=$PREFIX_ABS/pid
60 CONFFILE=$ETCDIR/smb.conf
61 KRB5_CONFIG=$ETCDIR/krb5.conf
62 PRIVATEDIR=$PREFIX_ABS/private
63 NCALRPCDIR=$PREFIX_ABS/ncalrpc
64 LOCKDIR=$PREFIX_ABS/lockdir
65 TLSDIR=$PRIVATEDIR/tls
66 WINBINDD_SOCKET_DIR=$PREFIX_ABS/winbind_socket
67 CONFIGURATION="--configfile=$CONFFILE"
68 export CONFIGURATION
69 export CONFFILE
70
71 SMBD_TEST_FIFO="$PREFIX/smbd_test.fifo"
72 export SMBD_TEST_FIFO
73 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
74 export SMBD_TEST_LOG
75
76 DO_SOCKET_WRAPPER=$3
77 if [ x"$DO_SOCKET_WRAPPER" = x"SOCKET_WRAPPER" ];then
78         SOCKET_WRAPPER_DIR="$PREFIX/sw"
79         export SOCKET_WRAPPER_DIR
80         echo "SOCKET_WRAPPER_DIR=$SOCKET_WRAPPER_DIR"
81 fi
82
83 # start off with 0 failures
84 failed=0
85 export failed
86
87 incdir=`dirname $0`
88 . $incdir/test_functions.sh
89
90 PATH=bin:$PATH
91 export PATH
92
93 rm -rf $PREFIX/*
94 mkdir -p $PRIVATEDIR $ETCDIR $LIBDIR $PIDDIR $NCALRPCDIR $LOCKDIR $TMPDIR $TLSDIR
95
96 cat >$PRIVATEDIR/wins_config.ldif<<EOF
97 dn: name=TORTURE_26,CN=PARTNERS
98 objectClass: wreplPartner
99 name: TORTURE_26
100 address: 127.0.0.26
101 pullInterval: 0
102 pushChangeCount: 0
103 type: 0x3
104 EOF
105
106 cat >$CONFFILE<<EOF
107 [global]
108         netbios name = $NETBIOSNAME
109         netbios aliases = $SERVER
110         workgroup = $DOMAIN
111         realm = $REALM
112         private dir = $PRIVATEDIR
113         pid directory = $PIDDIR
114         ncalrpc dir = $NCALRPCDIR
115         lock dir = $LOCKDIR
116         setup directory = $SRCDIR/setup
117         js include = $SRCDIR/scripting/libjs
118         winbindd socket directory = $WINBINDD_SOCKET_DIR
119         name resolve order = bcast
120         interfaces = 127.0.0.1/8
121         tls enabled = $TLS_ENABLED
122         panic action = $SRCDIR/script/gdb_backtrace %PID% %PROG%
123         wins support = yes
124         server role = pdc
125         max xmit = 32K
126
127 [tmp]
128         path = $TMPDIR
129         read only = no
130         ntvfs handler = posix
131         posix:sharedelay = 100000
132         posix:eadb = $LOCKDIR/eadb.tdb
133
134 [cifs]
135         read only = no
136         ntvfs handler = cifs
137         cifs:server = $SERVER
138         cifs:user = $USERNAME
139         cifs:password = $PASSWORD
140         cifs:domain = $DOMAIN
141         cifs:share = tmp
142 EOF
143
144 cat >$KRB5_CONFIG<<EOF
145 [libdefaults]
146  default_realm = SAMBA.EXAMPLE.COM
147  dns_lookup_realm = false
148  dns_lookup_kdc = false
149  ticket_lifetime = 24h
150  forwardable = yes
151
152 [realms]
153  SAMBA.EXAMPLE.COM = {
154   kdc = 127.0.0.1
155   admin_server = 127.0.0.1
156   default_domain = samba.example.com
157  }
158 [domain_realm]
159  .samba.example.com = SAMBA.EXAMPLE.COM
160 EOF
161
162 export KRB5_CONFIG
163
164 echo -n "PROVISIONING..."
165
166 ./setup/provision $CONFIGURATION --host-name=$NETBIOSNAME --host-ip=127.0.0.1 \
167     --quiet --domain $DOMAIN --realm $REALM \
168     --adminpass $PASSWORD --root=$ROOT || exit 1
169
170 ./bin/ldbadd -H $PRIVATEDIR/wins_config.ldb < $PRIVATEDIR/wins_config.ldif >/dev/null || exit 1
171
172 echo "DONE"
173
174 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
175         CONFIGURATION="$CONFIGURATION --option=torture:progress=no"
176 fi
177
178 SOCKET_WRAPPER_DEFAULT_IFACE=1
179 export SOCKET_WRAPPER_DEFAULT_IFACE
180 smbd_check_or_start
181
182 # ensure any one smbtorture call doesn't run too long
183 SOCKET_WRAPPER_DEFAULT_IFACE=26
184 export SOCKET_WRAPPER_DEFAULT_IFACE
185 TORTURE_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'
186 TORTURE_OPTIONS="--maximum-runtime=$TORTURE_MAXTIME --option=interfaces=$TORTURE_INTERFACES $CONFIGURATION"
187 export TORTURE_OPTIONS
188
189 TORTURE_OPTIONS="$TORTURE_OPTIONS --option=target:samba4=yes"
190
191 START=`date`
192 (
193  # give time for nbt server to register its names
194  echo delaying for nbt name registration
195  sleep 4
196  # This will return quickly when things are up, but be slow if we need to wait for (eg) SSL init 
197  bin/nmblookup $CONFIGURATION $SERVER
198  bin/nmblookup $CONFIGURATION -U $SERVER $SERVER
199  bin/nmblookup $CONFIGURATION $SERVER
200  bin/nmblookup $CONFIGURATION -U $SERVER $NETBIOSNAME
201  bin/nmblookup $CONFIGURATION $NETBIOSNAME
202  bin/nmblookup $CONFIGURATION -U $SERVER $NETBIOSNAME
203
204  failed=0
205
206  . script/tests/tests_$TESTS.sh
207  exit $failed
208 ) 9>$SMBD_TEST_FIFO
209 failed=$?
210
211 kill `cat $PIDDIR/smbd.pid`
212
213 END=`date`
214 echo "START: $START ($0)";
215 echo "END:   $END ($0)";
216
217 # if there were any valgrind failures, show them
218 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
219 if [ "$count" != 0 ]; then
220     for f in $PREFIX/valgrind.log*; do
221         if [ -s $f ]; then
222             echo "VALGRIND FAILURE";
223             failed=`expr $failed + 1`
224             cat $f
225         fi
226     done
227 fi
228
229 teststatus $0 $failed