xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/variant/tests/run (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#!/bin/sh
2*e670fd5cSchristos## $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos##
16*e670fd5cSchristos## ACKNOWLEDGEMENTS:
17*e670fd5cSchristos## This module was written in 2016 by Ondřej Kuzník for Symas Corp.
18*e670fd5cSchristos
19*e670fd5cSchristosUSAGE="$0 [-b <backend>] [-c] [-k] [-l #] [-p] [-s {ro|rp}] [-u] [-w] <script>"
20*e670fd5cSchristos
21*e670fd5cSchristosTOPSRCDIR="${SRCDIR-$LDAP_SRC}"
22*e670fd5cSchristosSRCDIR="${TOPSRCDIR}/tests"
23*e670fd5cSchristoseval `grep EGREP_CMD= ${LDAP_BUILD}/tests/run`
24*e670fd5cSchristoseval `$EGREP_CMD -e '^LN_S=' ${LDAP_BUILD}/tests/run`
25*e670fd5cSchristos
26*e670fd5cSchristosexport SRCDIR TOPSRCDIR LN_S EGREP_CMD
27*e670fd5cSchristos
28*e670fd5cSchristos. "${SRCDIR}/scripts/defines.sh"
29*e670fd5cSchristos
30*e670fd5cSchristosBACKEND=
31*e670fd5cSchristosCLEAN=no
32*e670fd5cSchristosWAIT=0
33*e670fd5cSchristosKILLSERVERS=yes
34*e670fd5cSchristosPRESERVE=${PRESERVE-no}
35*e670fd5cSchristosSYNCMODE=${SYNCMODE-rp}
36*e670fd5cSchristosUSERDATA=no
37*e670fd5cSchristosLOOP=1
38*e670fd5cSchristosCOUNTER=1
39*e670fd5cSchristos
40*e670fd5cSchristoswhile test $# -gt 0 ; do
41*e670fd5cSchristos	case "$1" in
42*e670fd5cSchristos		-b | -backend)
43*e670fd5cSchristos			BACKEND="$2"
44*e670fd5cSchristos			shift; shift ;;
45*e670fd5cSchristos
46*e670fd5cSchristos		-c | -clean)
47*e670fd5cSchristos			CLEAN=yes
48*e670fd5cSchristos			shift ;;
49*e670fd5cSchristos
50*e670fd5cSchristos		-k | -kill)
51*e670fd5cSchristos			KILLSERVERS=no
52*e670fd5cSchristos			shift ;;
53*e670fd5cSchristos		-l | -loop)
54*e670fd5cSchristos			NUM="`echo $2 | sed 's/[0-9]//g'`"
55*e670fd5cSchristos			if [ -z "$NUM" ]; then
56*e670fd5cSchristos				LOOP=$2
57*e670fd5cSchristos			else
58*e670fd5cSchristos				echo "Loop variable not an int: $2"
59*e670fd5cSchristos				echo "$USAGE"; exit 1
60*e670fd5cSchristos			fi
61*e670fd5cSchristos			shift ;
62*e670fd5cSchristos			shift ;;
63*e670fd5cSchristos
64*e670fd5cSchristos		-p | -preserve)
65*e670fd5cSchristos			PRESERVE=yes
66*e670fd5cSchristos			shift ;;
67*e670fd5cSchristos
68*e670fd5cSchristos		-s | -syncmode)
69*e670fd5cSchristos			case "$2" in
70*e670fd5cSchristos				ro | rp)
71*e670fd5cSchristos					SYNCMODE="$2"
72*e670fd5cSchristos					;;
73*e670fd5cSchristos				*)
74*e670fd5cSchristos					echo "unknown sync mode $2"
75*e670fd5cSchristos					echo "$USAGE"; exit 1
76*e670fd5cSchristos					;;
77*e670fd5cSchristos			esac
78*e670fd5cSchristos			shift; shift ;;
79*e670fd5cSchristos
80*e670fd5cSchristos		-u | -userdata)
81*e670fd5cSchristos			USERDATA=yes
82*e670fd5cSchristos			shift ;;
83*e670fd5cSchristos
84*e670fd5cSchristos		-w | -wait)
85*e670fd5cSchristos			WAIT=1
86*e670fd5cSchristos			shift ;;
87*e670fd5cSchristos
88*e670fd5cSchristos		-)
89*e670fd5cSchristos			shift
90*e670fd5cSchristos			break ;;
91*e670fd5cSchristos
92*e670fd5cSchristos		-*)
93*e670fd5cSchristos			echo "$USAGE"; exit 1
94*e670fd5cSchristos			;;
95*e670fd5cSchristos
96*e670fd5cSchristos		*)
97*e670fd5cSchristos			break ;;
98*e670fd5cSchristos	esac
99*e670fd5cSchristosdone
100*e670fd5cSchristos
101*e670fd5cSchristoseval `$EGREP_CMD -e '^AC' ${LDAP_BUILD}/tests/run`
102*e670fd5cSchristosexport `$EGREP_CMD -e '^AC' ${LDAP_BUILD}/tests/run | sed 's/=.*//'`
103*e670fd5cSchristos
104*e670fd5cSchristosif test -z "$BACKEND" ; then
105*e670fd5cSchristos	for b in mdb ; do
106*e670fd5cSchristos		if eval "test \"\$AC_$b\" != no" ; then
107*e670fd5cSchristos			BACKEND=$b
108*e670fd5cSchristos			break
109*e670fd5cSchristos		fi
110*e670fd5cSchristos	done
111*e670fd5cSchristos	if test -z "$BACKEND" ; then
112*e670fd5cSchristos		echo "No suitable default database backend configured" >&2
113*e670fd5cSchristos		exit 1
114*e670fd5cSchristos	fi
115*e670fd5cSchristosfi
116*e670fd5cSchristos
117*e670fd5cSchristosBACKENDTYPE=`eval 'echo $AC_'$BACKEND`
118*e670fd5cSchristosif test "x$BACKENDTYPE" = "x" ; then
119*e670fd5cSchristos	BACKENDTYPE="unknown"
120*e670fd5cSchristosfi
121*e670fd5cSchristos
122*e670fd5cSchristos# Backend features.  indexdb: indexing and unchecked limit.
123*e670fd5cSchristos# maindb: main storage backend.  Currently index,limits,mode,paged results.
124*e670fd5cSchristosINDEXDB=noindexdb MAINDB=nomaindb
125*e670fd5cSchristoscase $BACKEND in
126*e670fd5cSchristos	mdb) INDEXDB=indexdb MAINDB=maindb ;;
127*e670fd5cSchristos	ndb) INDEXDB=indexdb ;;
128*e670fd5cSchristosesac
129*e670fd5cSchristos
130*e670fd5cSchristosexport	BACKEND BACKENDTYPE INDEXDB MAINDB \
131*e670fd5cSchristos	WAIT KILLSERVERS PRESERVE SYNCMODE USERDATA \
132*e670fd5cSchristos	SRCDIR
133*e670fd5cSchristos
134*e670fd5cSchristosif test $# = 0 ; then
135*e670fd5cSchristos	echo "$USAGE"; exit 1
136*e670fd5cSchristosfi
137*e670fd5cSchristos
138*e670fd5cSchristos# need defines.sh for the definitions of the directories
139*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
140*e670fd5cSchristos
141*e670fd5cSchristosSCRIPTDIR="${TOPDIR}/tests/scripts"
142*e670fd5cSchristos
143*e670fd5cSchristosexport SCRIPTDIR
144*e670fd5cSchristos
145*e670fd5cSchristosSCRIPTNAME="$1"
146*e670fd5cSchristosshift
147*e670fd5cSchristos
148*e670fd5cSchristosif test -x "${SCRIPTDIR}/${SCRIPTNAME}" ; then
149*e670fd5cSchristos	SCRIPT="${SCRIPTDIR}/${SCRIPTNAME}"
150*e670fd5cSchristoselif test -x "`echo ${SCRIPTDIR}/test*-${SCRIPTNAME}`"; then
151*e670fd5cSchristos	SCRIPT="`echo ${SCRIPTDIR}/test*-${SCRIPTNAME}`"
152*e670fd5cSchristoselif test -x "`echo ${SCRIPTDIR}/${SCRIPTNAME}-*`"; then
153*e670fd5cSchristos	SCRIPT="`echo ${SCRIPTDIR}/${SCRIPTNAME}-*`"
154*e670fd5cSchristoselse
155*e670fd5cSchristos	echo "run: ${SCRIPTNAME} not found (or not executable)"
156*e670fd5cSchristos	exit 1;
157*e670fd5cSchristosfi
158*e670fd5cSchristos
159*e670fd5cSchristosif test ! -r ${DATADIR}/test.ldif ; then
160*e670fd5cSchristos	${LN_S} ${SRCDIR}/data ${DATADIR}
161*e670fd5cSchristosfi
162*e670fd5cSchristosif test ! -r ${SCHEMADIR}/core.schema ; then
163*e670fd5cSchristos	${LN_S} ${TOPSRCDIR}/servers/slapd/schema ${SCHEMADIR}
164*e670fd5cSchristosfi
165*e670fd5cSchristosif test ! -r ./data; then
166*e670fd5cSchristos	${LN_S} ${TOPDIR}/tests/data ./
167*e670fd5cSchristosfi
168*e670fd5cSchristos
169*e670fd5cSchristosif test -d ${TESTDIR} ; then
170*e670fd5cSchristos	if test $PRESERVE = no ; then
171*e670fd5cSchristos		echo "Cleaning up test run directory leftover from previous run."
172*e670fd5cSchristos		/bin/rm -rf ${TESTDIR}
173*e670fd5cSchristos	elif test $PRESERVE = yes ; then
174*e670fd5cSchristos		echo "Cleaning up only database directories leftover from previous run."
175*e670fd5cSchristos		/bin/rm -rf ${TESTDIR}/db.*
176*e670fd5cSchristos	fi
177*e670fd5cSchristosfi
178*e670fd5cSchristosif test $BACKEND = ndb ; then
179*e670fd5cSchristos	mysql --user root <<EOF
180*e670fd5cSchristos	drop database if exists db_1;
181*e670fd5cSchristos	drop database if exists db_2;
182*e670fd5cSchristos	drop database if exists db_3;
183*e670fd5cSchristos	drop database if exists db_4;
184*e670fd5cSchristos	drop database if exists db_5;
185*e670fd5cSchristos	drop database if exists db_6;
186*e670fd5cSchristosEOF
187*e670fd5cSchristosfi
188*e670fd5cSchristosmkdir -p ${TESTDIR}
189*e670fd5cSchristos
190*e670fd5cSchristosif test $USERDATA = yes ; then
191*e670fd5cSchristos	if test ! -d userdata ; then
192*e670fd5cSchristos		echo "User data directory (userdata) does not exist."
193*e670fd5cSchristos		exit 1
194*e670fd5cSchristos	fi
195*e670fd5cSchristos	cp -R userdata/* ${TESTDIR}
196*e670fd5cSchristosfi
197*e670fd5cSchristos
198*e670fd5cSchristos# disable LDAP initialization
199*e670fd5cSchristosLDAPNOINIT=true; export LDAPNOINIT
200*e670fd5cSchristos
201*e670fd5cSchristosecho "Running ${SCRIPT} for ${BACKEND}..."
202*e670fd5cSchristoswhile [ $COUNTER -le $LOOP ]; do
203*e670fd5cSchristos	if [ $LOOP -gt 1 ]; then
204*e670fd5cSchristos		echo "Running $COUNTER of $LOOP iterations"
205*e670fd5cSchristos	fi
206*e670fd5cSchristos	$SCRIPT $*
207*e670fd5cSchristos	RC=$?
208*e670fd5cSchristos
209*e670fd5cSchristos	if test $CLEAN = yes ; then
210*e670fd5cSchristos		echo "Cleaning up test run directory from this run."
211*e670fd5cSchristos		/bin/rm -rf ${TESTDIR}
212*e670fd5cSchristos		echo "Cleaning up symlinks."
213*e670fd5cSchristos		/bin/rm -f ${DATADIR} ${SCHEMADIR}
214*e670fd5cSchristos	fi
215*e670fd5cSchristos
216*e670fd5cSchristos	if [ $RC -ne 0 ]; then
217*e670fd5cSchristos		if [ $LOOP -gt 1 ]; then
218*e670fd5cSchristos			echo "Failed after $COUNTER of $LOOP iterations"
219*e670fd5cSchristos		fi
220*e670fd5cSchristos		exit $RC
221*e670fd5cSchristos	else
222*e670fd5cSchristos		COUNTER=`expr $COUNTER + 1`
223*e670fd5cSchristos		if [ $COUNTER -le $LOOP ]; then
224*e670fd5cSchristos			echo "Cleaning up test run directory from this run."
225*e670fd5cSchristos			/bin/rm -rf ${TESTDIR}
226*e670fd5cSchristos		fi
227*e670fd5cSchristos	fi
228*e670fd5cSchristosdone
229*e670fd5cSchristosexit $RC
230