b102bf20fee51de8e20ec779a0af619e0350dd80
[samba.git] / source / 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=$DOMAIN
7 PASSWORD=penguin
8 SRCDIR=`pwd`
9 ROOT=$USER
10 if test -z "$ROOT"; then
11     ROOT=$LOGNAME
12 fi
13 if test -z "$ROOT"; then
14     ROOT=`whoami`
15 fi
16
17 if [ $# -lt 1 ]
18 then
19         echo "$0 PREFIX"
20         exit
21 fi
22
23
24 PREFIX=$1
25 PREFIX=`echo $PREFIX | sed s+//+/+`
26 export PREFIX
27
28 # allow selection of the test lists
29 TESTS=$2
30
31 if [ $TESTS = "all" ]; then
32     TLS_ENABLED="yes"
33 else
34     TLS_ENABLED="no"
35 fi
36
37 mkdir -p $PREFIX || exit $?
38 OLD_PWD=`pwd`
39 cd $PREFIX || exit $?
40 PREFIX_ABS=`pwd`
41 export PREFIX_ABS
42 cd $OLD_PWD
43
44 TMPDIR=$PREFIX_ABS/tmp
45 LIBDIR=$PREFIX_ABS/lib
46 PIDDIR=$PREFIX_ABS/pid
47 CONFFILE=$LIBDIR/smb.conf
48 PRIVATEDIR=$PREFIX_ABS/private
49 NCALRPCDIR=$PREFIX_ABS/ncalrpc
50 LOCKDIR=$PREFIX_ABS/lockdir
51 TLSDIR=$PRIVATEDIR/tls
52 CONFIGURATION="--configfile=$CONFFILE"
53 export CONFIGURATION
54 export CONFFILE
55
56 SMBD_TEST_FIFO="$PREFIX/smbd_test.fifo"
57 export SMBD_TEST_FIFO
58 SMBD_TEST_LOG="$PREFIX/smbd_test.log"
59 export SMBD_TEST_LOG
60
61 DO_SOCKET_WRAPPER=$3
62 if [ x"$DO_SOCKET_WRAPPER" = x"SOCKET_WRAPPER" ];then
63         SOCKET_WRAPPER_DIR="$PREFIX/sw"
64         export SOCKET_WRAPPER_DIR
65         echo "SOCKET_WRAPPER_DIR=$SOCKET_WRAPPER_DIR"
66 fi
67
68 # start off with 0 failures
69 failed=0
70 export failed
71
72 incdir=`dirname $0`
73 . $incdir/test_functions.sh
74
75 PATH=bin:$PATH
76 export PATH
77
78 rm -rf $PREFIX/*
79 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $NCALRPCDIR $LOCKDIR $TMPDIR $TLSDIR
80
81 cat >$CONFFILE<<EOF
82 [global]
83         netbios name = LOCALHOST
84         workgroup = $DOMAIN
85         realm = $REALM
86         private dir = $PRIVATEDIR
87         pid directory = $PIDDIR
88         ncalrpc dir = $NCALRPCDIR
89         lock dir = $LOCKDIR
90         setup directory = $SRCDIR/setup
91         js include = $SRCDIR/scripting/libjs
92         name resolve order = bcast
93         interfaces = lo*
94         tls enabled = $TLS_ENABLED
95         panic action = $SRCDIR/script/gdb_backtrace %PID% %PROG%
96         wins support = yes
97         domain master = yes
98         domain logons = yes
99
100 [tmp]
101         path = $TMPDIR
102         read only = no
103         ntvfs handler = posix
104         posix:sharedelay = 100000
105         posix:eadb = $LOCKDIR/eadb.tdb
106
107 [cifs]
108         read only = no
109         ntvfs handler = cifs
110         cifs:server = localhost
111         cifs:user = $USERNAME
112         cifs:password = $PASSWORD
113         cifs:domain = $DOMAIN
114         cifs:share = tmp
115 EOF
116
117 ./setup/provision $CONFIGURATION --quiet --domain $DOMAIN --realm $REALM \
118     --adminpass $PASSWORD --root=$ROOT || exit 1
119
120 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
121         CONFIGURATION="$CONFIGURATION --option=\"torture:progress=no\""
122 fi
123
124 smbd_check_or_start
125
126 # ensure any one smbtorture call doesn't run too long
127 TORTURE_OPTIONS="--maximum-runtime=300 $CONFIGURATION"
128 export TORTURE_OPTIONS
129
130
131 START=`date`
132 (
133  # give time for nbt server to register its names
134  echo delaying for nbt name registration
135  sleep 4
136  bin/nmblookup -U localhost localhost 
137
138  failed=0
139
140  . script/tests/tests_$TESTS.sh
141  exit $failed
142 ) 9>$SMBD_TEST_FIFO
143 failed=$?
144
145 kill `cat $PIDDIR/smbd.pid`
146
147 END=`date`
148 echo "START: $START ($0)";
149 echo "END:   $END ($0)";
150
151 # if there were any valgrind failures, show them
152 count=`find $PREFIX -name 'valgrind.log*' | wc -l`
153 if [ "$count" != 0 ]; then
154     for f in $PREFIX/valgrind.log*; do
155         if [ -s $f ]; then
156             echo "VALGRIND FAILURE";
157             failed=`expr $failed + 1`
158             cat $f
159         fi
160     done
161 fi
162
163 teststatus $0 $failed