r8671: use much shorter names for the selftest directory and socket wrapper
[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=$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
96 [tmp]
97         path = $TMPDIR
98         read only = no
99         ntvfs handler = posix
100         posix:sharedelay = 100000
101         posix:eadb = $LOCKDIR/eadb.tdb
102
103 [cifs]
104         read only = no
105         ntvfs handler = cifs
106         cifs:server = localhost
107         cifs:user = $USERNAME
108         cifs:password = $PASSWORD
109         cifs:domain = $DOMAIN
110         cifs:share = tmp
111 EOF
112
113 ./setup/provision $CONFIGURATION --quiet --domain $DOMAIN --realm $REALM \
114     --adminpass $PASSWORD --root=$ROOT || exit 1
115
116 if [ x"$RUN_FROM_BUILD_FARM" = x"yes" ];then
117         CONFIGURATION="$CONFIGURATION --option=\"torture:progress=no\""
118 fi
119
120 smbd_check_or_start
121
122 # ensure any one smbtorture call doesn't run too long
123 TORTURE_OPTIONS="--maximum-runtime=300 $CONFIGURATION"
124 export TORTURE_OPTIONS
125
126
127 START=`date`
128 (
129  # give time for nbt server to register its names
130  echo delaying for nbt name registration
131  sleep 4
132  bin/nmblookup -U localhost localhost 
133
134  failed=0
135
136  . script/tests/tests_$TESTS.sh
137  exit $failed
138 ) 9>$SMBD_TEST_FIFO
139 failed=$?
140
141 kill `cat $PIDDIR/smbd.pid`
142
143 END=`date`
144 echo "START: $START ($0)";
145 echo "END:   $END ($0)";
146
147 teststatus $0 $failed