xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/lloadd/test002-load (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
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
23if test x$TESTCHILDREN = x ; then
24    TESTCHILDREN=20
25fi
26
27if test x$MAXRETRIES = x ; then
28    MAXRETRIES=5
29fi
30
31mkdir -p $TESTDIR $DBDIR1 $DBDIR2
32
33$SLAPPASSWD -g -n >$CONFIGPWF
34echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
35
36echo "Running slapadd to build slapd database..."
37. $CONFFILTER $BACKEND < $CONF > $CONF2
38$SLAPADD -f $CONF2 -l $LDIFORDERED
39RC=$?
40if test $RC != 0 ; then
41    echo "slapadd failed ($RC)!"
42    exit $RC
43fi
44
45echo "Starting a slapd on TCP/IP port $PORT2..."
46$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
47PID=$!
48if test $WAIT != 0 ; then
49    echo PID $PID
50    read foo
51fi
52PID2="$PID"
53KILLPIDS="$PID"
54
55for i in 0 1 2 3 4 5; do
56    $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
57        '(objectclass=*)' > /dev/null 2>&1
58    RC=$?
59    if test $RC = 0 ; then
60        break
61    fi
62    echo "Waiting $SLEEP1 seconds for slapd to start..."
63    sleep $SLEEP1
64done
65if test $RC != 0 ; then
66    echo "ldapsearch failed ($RC)!"
67    test $KILLSERVERS != no && kill -HUP $KILLPIDS
68    exit $RC
69fi
70
71echo "Running slapadd to build slapd database..."
72. $CONFFILTER $BACKEND < $CONFTWO > $CONF3
73$SLAPADD -f $CONF3 -l $LDIFORDERED
74RC=$?
75if test $RC != 0 ; then
76    echo "slapadd failed ($RC)!"
77    exit $RC
78fi
79
80echo "Running slapindex to index slapd database..."
81$SLAPINDEX -f $CONF3
82RC=$?
83if test $RC != 0 ; then
84    echo "warning: slapindex failed ($RC)"
85    echo "  assuming no indexing support"
86fi
87
88echo "Starting second slapd on TCP/IP port $PORT3..."
89$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
90PID=$!
91if test $WAIT != 0 ; then
92    echo PID $PID
93    read foo
94fi
95PID2="$PID"
96KILLPIDS="$KILLPIDS $PID"
97
98sleep $SLEEP0
99
100echo "Testing slapd searching..."
101for i in 0 1 2 3 4 5; do
102    $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
103        '(objectclass=*)' > /dev/null 2>&1
104    RC=$?
105    if test $RC = 0 ; then
106        break
107    fi
108    echo "Waiting $SLEEP1 seconds for slapd to start..."
109    sleep $SLEEP1
110done
111if test $RC != 0 ; then
112    echo "ldapsearch failed ($RC)!"
113    test $KILLSERVERS != no && kill -HUP $KILLPIDS
114    exit $RC
115fi
116
117echo "Starting lloadd on TCP/IP port $PORT1..."
118. $CONFFILTER $BACKEND < $LLOADDCONF > $CONF1.lloadd
119if test $AC_lloadd = lloaddyes; then
120    $LLOADD -f $CONF1.lloadd -h $URI1 -d $LVL > $LOG1 2>&1 &
121else
122    . $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
123    # FIXME: this won't work on Windows, but lloadd doesn't support Windows yet
124    $SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 &
125fi
126PID=$!
127if test $WAIT != 0 ; then
128    echo PID $PID
129    read foo
130fi
131KILLPIDS="$KILLPIDS $PID"
132
133echo "Testing slapd searching..."
134for i in 0 1 2 3 4 5; do
135    $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
136        '(objectclass=*)' > /dev/null 2>&1
137    RC=$?
138    if test $RC = 0 ; then
139        break
140    fi
141    echo "Waiting $SLEEP1 seconds for lloadd to start..."
142    sleep $SLEEP1
143done
144
145if test $RC != 0 ; then
146    echo "ldapsearch failed ($RC)!"
147    test $KILLSERVERS != no && kill -HUP $KILLPIDS
148    exit $RC
149fi
150
151# fix test data to include back-monitor, if available
152# NOTE: copies do_* files from $DATADIR to $TESTDIR
153$MONITORDATA "$DATADIR" "$TESTDIR"
154
155
156echo "Using tester for concurrent server access ($TESTCHILDREN x $TESTLOOPS ops)..."
157$SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" \
158    -H $URI1 -D "$MANAGERDN" -w $PASSWD \
159    -t 1 -l $TESTLOOPS -r $MAXRETRIES -j $TESTCHILDREN \
160    -i '*INVALID_CREDENTIALS,*BUSY,UNWILLING_TO_PERFORM'
161RC=$?
162
163test $KILLSERVERS != no && kill -HUP $KILLPIDS
164
165if test $RC != 0 ; then
166    echo "slapd-tester failed ($RC)!"
167    exit $RC
168fi
169
170echo ">>>>> Test succeeded"
171
172test $KILLSERVERS != no && wait
173
174exit 0
175