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
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19if test x$TESTLOOPS = x ; then
20	TESTLOOPS=50
21fi
22
23mkdir -p $TESTDIR $DBDIR1
24
25echo "Running slapadd to build slapd database..."
26. $CONFFILTER $BACKEND < $CONF > $CONF1
27$SLAPADD -f $CONF1 -l $LDIFORDERED -d -1 2> $SLAPADDLOG1
28RC=$?
29if test $RC != 0 ; then
30	echo "slapadd failed ($RC)!"
31	exit $RC
32fi
33
34echo "Starting slapd on TCP/IP port $PORT1..."
35$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
36PID=$!
37if test $WAIT != 0 ; then
38    echo PID $PID
39    read foo
40fi
41KILLPIDS="$PID"
42
43sleep 1
44
45echo "Using ldapsearch to check that slapd is running..."
46for i in 0 1 2 3 4 5; do
47	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
48		'objectclass=*' > /dev/null 2>&1
49	RC=$?
50	if test $RC = 0 ; then
51		break
52	fi
53	echo "Waiting 5 seconds for slapd to start..."
54	sleep 5
55done
56
57# fix test data to include back-monitor, if available
58# NOTE: copies do_* files from $DATADIR to $TESTDIR
59$MONITORDATA "$DATADIR" "$TESTDIR"
60
61echo "Using tester for concurrent server access..."
62$SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" -H $URI1 -D "$MANAGERDN" -w $PASSWD -l $TESTLOOPS
63RC=$?
64
65if test $RC != 0 ; then
66	echo "slapd-tester failed ($RC)!"
67	test $KILLSERVERS != no && kill -HUP $KILLPIDS
68	exit $RC
69fi 
70
71echo "Using ldapsearch to retrieve all the entries..."
72$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
73			'objectClass=*' > $SEARCHOUT 2>&1
74RC=$?
75
76test $KILLSERVERS != no && kill -HUP $KILLPIDS
77
78if test $RC != 0 ; then
79	echo "ldapsearch failed ($RC)!"
80	exit $RC
81fi
82
83echo "Filtering ldapsearch results..."
84$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
85echo "Filtering original ldif used to create database..."
86$LDIFFILTER < $LDIF > $LDIFFLT
87echo "Comparing filter output..."
88$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
89
90if test $? != 0 ; then
91	echo "comparison failed - database was not created correctly"
92	exit 1
93fi
94
95echo ">>>>> Test succeeded"
96
97test $KILLSERVERS != no && wait
98
99exit 0
100