]> git.sur5r.net Git - openldap/blob - tests/run.in
afa6e792775d543084f8685585f5a2eb270ee266
[openldap] / tests / run.in
1 #!/bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2011 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
15
16 USAGE="$0 [-b <backend>] [-c] [-k] [-l #] [-p] [-s {ro|rp}] [-u] [-w] <script>"
17
18 # configure generated
19 SRCDIR="@srcdir@"
20 TOPSRCDIR="@top_srcdir@"
21 LN_S="@LN_S@"
22 EGREP_CMD="@EGREP@"
23
24 export SRCDIR TOPSRCDIR LN_S EGREP_CMD
25
26 # backends known to ./run -b <backend> (used to deduce $BACKENDTYPE)
27 AC_bdb=@BUILD_BDB@
28 AC_hdb=@BUILD_HDB@
29 AC_ldif=yes
30 AC_mdb=@BUILD_MDB@
31 AC_null=@BUILD_NULL@
32
33 # other backends
34 AC_ldap=ldap@BUILD_LDAP@
35 AC_meta=meta@BUILD_META@
36 AC_monitor=@BUILD_MONITOR@
37 AC_relay=relay@BUILD_RELAY@
38 AC_sql=sql@BUILD_SQL@
39
40 # overlays
41 AC_accesslog=accesslog@BUILD_ACCESSLOG@
42 AC_dds=dds@BUILD_DDS@
43 AC_dynlist=dynlist@BUILD_DYNLIST@
44 AC_memberof=memberof@BUILD_MEMBEROF@
45 AC_pcache=pcache@BUILD_PROXYCACHE@
46 AC_ppolicy=ppolicy@BUILD_PPOLICY@
47 AC_refint=refint@BUILD_REFINT@
48 AC_retcode=retcode@BUILD_RETCODE@
49 AC_translucent=translucent@BUILD_TRANSLUCENT@
50 AC_unique=unique@BUILD_UNIQUE@
51 AC_rwm=rwm@BUILD_RWM@
52 AC_syncprov=syncprov@BUILD_SYNCPROV@
53 AC_valsort=valsort@BUILD_VALSORT@
54
55 # misc
56 AC_WITH_SASL=@WITH_SASL@
57 AC_WITH_TLS=@WITH_TLS@
58 AC_WITH_MODULES_ENABLED=@WITH_MODULES_ENABLED@
59 AC_ACI_ENABLED=aci@WITH_ACI_ENABLED@
60 AC_THREADS=threads@BUILD_THREAD@
61 AC_LIBS_DYNAMIC=lib@BUILD_LIBS_DYNAMIC@
62
63 # sanitize
64 if test "${AC_ldap}" = "ldapmod" && test "${AC_LIBS_DYNAMIC}" = "static" ; then
65         AC_ldap="ldapno"
66 fi
67 if test "${AC_meta}" = "metamod" && test "${AC_LIBS_DYNAMIC}" = "static" ; then
68         AC_meta="metano"
69 fi
70
71 export AC_bdb AC_hdb AC_ldap AC_mdb AC_meta AC_monitor AC_null AC_relay AC_sql \
72         AC_accesslog AC_dds AC_dynlist AC_memberof AC_pcache AC_ppolicy \
73         AC_refint AC_retcode AC_rwm AC_unique AC_syncprov AC_translucent \
74         AC_valsort \
75         AC_WITH_SASL AC_WITH_TLS AC_WITH_MODULES_ENABLED AC_ACI_ENABLED \
76         AC_THREADS AC_LIBS_DYNAMIC
77
78 if test ! -x ../servers/slapd/slapd ; then
79         echo "Could not locate slapd(8)"
80         exit 1
81 fi
82
83 BACKEND=
84 CLEAN=no
85 WAIT=0
86 KILLSERVERS=yes
87 PRESERVE=${PRESERVE-no}
88 SYNCMODE=${SYNCMODE-rp}
89 USERDATA=no
90 LOOP=1
91 COUNTER=1
92
93 while test $# -gt 0 ; do
94         case "$1" in
95                 -b | -backend)
96                         BACKEND="$2"
97                         shift; shift ;;
98
99                 -c | -clean)
100                         CLEAN=yes
101                         shift ;;
102
103                 -k | -kill)
104                         KILLSERVERS=no
105                         shift ;;
106                 -l | -loop)
107                         NUM="`echo $2 | sed 's/[0-9]//g'`"
108                         if [ -z "$NUM" ]; then
109                                 LOOP=$2
110                         else
111                                 echo "Loop variable not an int: $2"
112                                 echo "$USAGE"; exit 1
113                         fi
114                         shift ;
115                         shift ;;
116
117                 -p | -preserve)
118                         PRESERVE=yes
119                         shift ;;
120
121                 -s | -syncmode)
122                         case "$2" in
123                                 ro | rp)
124                                         SYNCMODE="$2"
125                                         ;;
126                                 *)
127                                         echo "unknown sync mode $2"
128                                         echo "$USAGE"; exit 1
129                                         ;;
130                         esac
131                         shift; shift ;;
132
133                 -u | -userdata)
134                         USERDATA=yes
135                         shift ;;
136
137                 -w | -wait)
138                         WAIT=1
139                         shift ;;
140
141                 -)
142                         shift
143                         break ;;
144
145                 -*)
146                         echo "$USAGE"; exit 1
147                         ;;
148
149                 *)
150                         break ;;
151         esac
152 done
153
154 if test -z "$BACKEND" ; then
155         for b in bdb hdb mdb ; do
156                 if eval "test \"\$AC_$b\" != no" ; then
157                         BACKEND=$b
158                         break
159                 fi
160         done
161         if test -z "$BACKEND" ; then
162                 echo "No suitable default database backend configured" >&2
163                 exit 1
164         fi
165 fi
166 BACKENDTYPE=`eval 'echo $AC_'$BACKEND`
167 if test "x$BACKENDTYPE" = "x" ; then
168         BACKENDTYPE="unknown"
169 fi
170 export BACKEND BACKENDTYPE WAIT KILLSERVERS PRESERVE SYNCMODE USERDATA
171
172 if test $# = 0 ; then
173         echo "$USAGE"; exit 1
174 fi
175
176 # need defines.sh for the definitions of the directories
177 . $SRCDIR/scripts/defines.sh
178
179 SCRIPTDIR="${SRCDIR}/scripts"
180 SCRIPTNAME="$1"
181 shift
182
183 if test -x "${SCRIPTDIR}/${SCRIPTNAME}" ; then
184         SCRIPT="${SCRIPTDIR}/${SCRIPTNAME}"
185 elif test -x "`echo ${SCRIPTDIR}/test*-${SCRIPTNAME}`"; then
186         SCRIPT="`echo ${SCRIPTDIR}/test*-${SCRIPTNAME}`"
187 elif test -x "`echo ${SCRIPTDIR}/${SCRIPTNAME}-*`"; then
188         SCRIPT="`echo ${SCRIPTDIR}/${SCRIPTNAME}-*`"
189 else
190         echo "run: ${SCRIPTNAME} not found (or not executable)"
191         exit 1;
192 fi
193
194 if test ! -r ${DATADIR}/test.ldif ; then
195         ${LN_S} ${SRCDIR}/data ${DATADIR}
196 fi
197 if test ! -r ${SCHEMADIR}/core.schema ; then
198         ${LN_S} ${TOPSRCDIR}/servers/slapd/schema ${SCHEMADIR}
199 fi
200
201 if test -d ${TESTDIR} ; then
202         if test $PRESERVE = no ; then
203                 echo "Cleaning up test run directory leftover from previous run."
204                 /bin/rm -rf ${TESTDIR}
205         elif test $PRESERVE = yes ; then
206                 echo "Cleaning up only database directories leftover from previous run."
207                 /bin/rm -rf ${TESTDIR}/db.*
208         fi
209 fi
210 if test $BACKEND = ndb ; then
211         mysql --user root <<EOF
212         drop database if exists db_1;
213         drop database if exists db_2;
214         drop database if exists db_3;
215         drop database if exists db_4;
216         drop database if exists db_5;
217         drop database if exists db_6;
218 EOF
219 fi
220 mkdir -p ${TESTDIR}
221
222 if test $USERDATA = yes ; then
223         if test ! -d userdata ; then
224                 echo "User data directory (userdata) does not exist."
225                 exit 1
226         fi
227         cp -R userdata/* ${TESTDIR}
228 fi
229
230 # disable LDAP initialization
231 LDAPNOINIT=true; export LDAPNOINIT
232
233 echo "Running ${SCRIPT} for ${BACKEND}..."
234 while [ $COUNTER -le $LOOP ]; do
235         if [ $LOOP -gt 1 ]; then
236                 echo "Running $COUNTER of $LOOP iterations"
237         fi
238         $SCRIPT $*
239         RC=$?
240
241         if test $CLEAN = yes ; then
242                 echo "Cleaning up test run directory from this run."
243                 /bin/rm -rf ${TESTDIR}
244                 echo "Cleaning up symlinks."
245                 /bin/rm -f ${DATADIR} ${SCHEMADIR}
246         fi
247
248         if [ $RC -ne 0 ]; then
249                 exit $RC
250         else
251                 COUNTER=`expr $COUNTER + 1`
252                 if [ $COUNTER -le $LOOP ]; then
253                         echo "Cleaning up test run directory from this run."
254                         /bin/rm -rf ${TESTDIR}
255                 fi
256         fi
257 done
258 exit $RC