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