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