Initial import
[samba] / source / script / tests / runtests.sh
1 #!/bin/sh
2
3 if [ "x$1" = "x" ]; then
4         echo "$0 <directory>"
5         exit 1
6 fi
7
8 if [ $# = 2 ]; then
9         testnum=$2
10 fi
11
12 ##
13 ## create the test directory
14 ##
15 PREFIX=`echo $1 | sed s+//+/+`
16 mkdir -p $PREFIX || exit $?
17 OLD_PWD=`pwd`
18 cd $PREFIX || exit $?
19 export PREFIX_ABS=`pwd`
20 cd $OLD_PWD
21
22 ##
23 ## setup the various environment variables we need
24 ##
25
26 USERNAME=`whoami`
27 PASSWORD=test
28
29 SRCDIR=`pwd`
30 SCRIPTDIR=$SRCDIR/script/tests
31 SHRDIR=$PREFIX_ABS/tmp
32 LIBDIR=$PREFIX_ABS/lib
33 PIDDIR=$PREFIX_ABS/pid
34 CONFFILE=$LIBDIR/smb.conf
35 PRIVATEDIR=$PREFIX_ABS/private
36 LOCKDIR=$PREFIX_ABS/lockdir
37 LOGDIR=$PREFIX_ABS/logs
38 SOCKET_WRAPPER_DIR=$PREFIX_ABS/sockwrap
39 CONFIGURATION="-s $CONFFILE"
40 PATH=`pwd`/bin:$PATH
41
42 export PREFIX_ABS CONFIGURATION CONFFILE PATH SOCKET_WRAPPER_DIR DOMAIN
43 export PRIVATEDIR LIBDIR PIDDIR LOCKDIR LOGDIR
44 export SRCDIR SCRIPTDIR
45 export USERNAME PASSWORD
46
47
48 ##
49 ## verify that we were built with --enable-socket-wrapper
50 ##
51
52 if test "x`smbd -b | grep SOCKET_WRAPPER`" = "x"; then
53         echo "***"
54         echo "*** You must include --enable-socket-wrapper when compiling Samba"
55         echo "*** in order to execute 'make test'.  Exiting...."
56         echo "***"
57         exit 1
58 fi
59
60 ## 
61 ## create the test directory layout
62 ##
63
64 /bin/rm -rf $PREFIX/*
65 mkdir -p $PRIVATEDIR $LIBDIR $PIDDIR $LOCKDIR $LOGDIR $SOCKET_WRAPPER_DIR
66
67 ##
68 ## Create the common config include file with the basic settings
69 ##
70
71 cat >$LIBDIR/common.conf<<EOF
72         netbios name = LOCALHOST
73         workgroup = SAMBA-TEST
74
75         private dir = $PRIVATEDIR
76         pid directory = $PIDDIR
77         lock directory = $LOCKDIR
78         log file = $LOGDIR/log.%m
79         log level = 0
80
81         passdb backend = tdbsam
82
83         interfaces = lo
84         bind interfaces only = yes
85
86         panic action = $SCRIPTDIR/gdb_backtrace %d
87 EOF
88
89 cat >$LIBDIR/smb.conf<<EOF
90 [global]
91         include = $LIBDIR/common.conf
92 EOF
93
94
95 ##
96 ## create a test account
97 ##
98
99 (echo $PASSWORD; echo $PASSWORD) | smbpasswd -c $LIBDIR/smb.conf -L -s -a $USERNAME
100
101
102 ##
103 ## ready to go...now loop through the tests
104 ##
105
106 if [ -f $SCRIPTDIR/t_$testnum.sh ]; then
107         testfile=$SCRIPTDIR/t_$testnum.sh
108         echo ">>>>>> Starting test driver `basename $testfile` <<<<<"
109         sh $testfile
110         if [ $? = 0 ]; then
111                 echo ">>>>> test ok <<<<<"
112         else
113                 echo ">>>>> test failed <<<<<"
114         fi
115
116         exit 0
117 fi
118
119 for testfile in `ls $SCRIPTDIR/t_*sh | sort`; do
120         echo " "
121         echo ">>>>>> Starting test driver `basename $testfile` <<<<<"
122         sh $testfile
123         if [ $? = 0 ]; then
124                 echo ">>>>> test ok <<<<<"
125         else
126                 echo ">>>>> test failed <<<<<"
127         fi
128 done
129