1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2011 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 $MONITORDB < $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 $TIMING > $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 $LOCALHOST -p $PORT1 \
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 "$MONITORDB" "$DATADIR" "$TESTDIR"
60
61echo "Using tester for concurrent server access..."
62time $SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD -l $TESTLOOPS
63#$SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" -h $LOCALHOST -p $PORT1 -D "$MANAGERDN" -w $PASSWD -l $TESTLOOPS
64RC=$?
65
66if test $RC != 0 ; then
67	echo "slapd-tester failed ($RC)!"
68	test $KILLSERVERS != no && kill -HUP $KILLPIDS
69	exit $RC
70fi 
71
72echo "Using ldapsearch to retrieve all the entries..."
73$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
74			'objectClass=*' > $SEARCHOUT 2>&1
75RC=$?
76
77test $KILLSERVERS != no && kill -HUP $KILLPIDS
78
79if test $RC != 0 ; then
80	echo "ldapsearch failed ($RC)!"
81	exit $RC
82fi
83
84echo "Filtering ldapsearch results..."
85$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
86echo "Filtering original ldif used to create database..."
87$LDIFFILTER < $LDIF > $LDIFFLT
88echo "Comparing filter output..."
89$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
90
91if test $? != 0 ; then
92	echo "comparison failed - database was not created correctly"
93	exit 1
94fi
95
96echo ">>>>> Test succeeded"
97
98test $KILLSERVERS != no && wait
99
100exit 0
101