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