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