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