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 $MONITORDB = "no" ; then 
20	echo "Monitor backend not available, test skipped"
21	exit 0
22fi 
23
24mkdir -p $TESTDIR $DBDIR1
25
26echo "Starting slapd on TCP/IP port $PORT..."
27. $CONFFILTER $BACKEND $MONITORDB < $SCHEMACONF > $CONF1
28$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
29PID=$!
30if test $WAIT != 0 ; then
31    echo PID $PID
32    read foo
33fi
34KILLPIDS="$PID"
35
36sleep 1
37
38echo "Using ldapsearch to check that slapd is running..."
39for i in 0 1 2 3 4 5; do
40	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
41		'objectclass=*' > /dev/null 2>&1
42	RC=$?
43	if test $RC = 0 ; then
44		break
45	fi
46	echo "Waiting 5 seconds for slapd to start..."
47	sleep 5
48done
49
50echo "Using ldapsearch to read connection monitor entries..."
51$LDAPSEARCH -S "" -b "$CONNECTIONSMONITORDN" -h $LOCALHOST -p $PORT1 \
52	'objectclass=*' \
53	structuralObjectClass entryDN \
54	monitorConnectionProtocol monitorConnectionOpsReceived \
55	monitorConnectionOpsExecuting monitorConnectionOpsPending \
56	monitorConnectionOpsCompleted monitorConnectionGet \
57	monitorConnectionRead monitorConnectionWrite \
58	monitorConnectionMask monitorConnectionAuthzDN \
59	monitorConnectionListener monitorConnectionLocalAddress \
60	> $SEARCHOUT 2>&1
61RC=$?
62
63if test $RC != 0 ; then
64        echo "ldapsearch failed ($RC)!"
65	test $KILLSERVERS != no && kill -HUP $KILLPIDS
66        exit $RC
67fi
68
69# Compare results, ignoring possible difference of IPv4/IPv6 localhost address
70localrewrite='s/=127\.0\.0\.1:/=LOCAL:/; s/=\[::1\]:/=LOCAL:/'
71echo "Filtering ldapsearch results..."
72sed -e "$localrewrite" < $SEARCHOUT | $LDIFFILTER > $SEARCHFLT
73echo "Filtering expected data..."
74. $CONFFILTER < $MONITOROUT1 | sed -e "$localrewrite" | $LDIFFILTER > $LDIFFLT
75echo "Comparing filter output..."
76$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
77
78if test $? != 0 ; then
79        echo "comparison failed - connection monitor output is not correct"
80	test $KILLSERVERS != no && kill -HUP $KILLPIDS
81        exit 1
82fi
83
84echo "Using ldapsearch to read database monitor entries..."
85$LDAPSEARCH -S "" -b "$DATABASESMONITORDN" -h $LOCALHOST -p $PORT1 \
86	'objectclass=*' \
87	structuralObjectClass entryDN namingContexts readOnly \
88	monitorIsShadow monitorContext \
89	olmBDBEntryCache olmBDBDNCache olmBDBIDLCache \
90	> $SEARCHOUT 2>&1
91RC=$?
92
93if test $RC != 0 ; then
94        echo "ldapsearch failed ($RC)!"
95	test $KILLSERVERS != no && kill -HUP $KILLPIDS
96        exit $RC
97fi
98
99echo "Filtering ldapsearch results..."
100$LDIFFILTER -b monitor < $SEARCHOUT > $SEARCHFLT
101
102TMPMONITOROUT2=$MONITOROUT2
103case $BACKEND in
104bdb|hdb)
105	;;
106*)
107	TMPMONITOROUT2=$TESTDIR/monitor2.out
108	grep -v "olmBDB" $MONITOROUT2 > $TMPMONITOROUT2
109	;;
110esac
111
112echo "Comparing filter output..."
113$CMP $SEARCHFLT $TMPMONITOROUT2 > $CMPOUT
114
115if test $? != 0 ; then
116        echo "comparison failed - database monitor output is not correct"
117	test $KILLSERVERS != no && kill -HUP $KILLPIDS
118        exit 1
119fi
120
121echo "Using ldapsearch to read statistics monitor entries..."
122$LDAPSEARCH -S "" -b "$STATISTICSMONITORDN" -h $LOCALHOST -p $PORT1 \
123	'(|(cn=Entries)(cn=PDU)(cn=Referrals))' \
124	structuralObjectClass monitorCounter entryDN \
125	> $SEARCHOUT 2>&1
126RC=$?
127
128if test $RC != 0 ; then
129        echo "ldapsearch failed ($RC)!"
130	test $KILLSERVERS != no && kill -HUP $KILLPIDS
131        exit $RC
132fi
133
134echo "Filtering ldapsearch results..."
135$LDIFFILTER -b monitor < $SEARCHOUT > $SEARCHFLT
136
137echo "Comparing filter output..."
138$CMP $SEARCHFLT $MONITOROUT3 > $CMPOUT
139
140if test $? != 0 ; then
141        echo "comparison failed - statistics monitor output is not correct"
142	test $KILLSERVERS != no && kill -HUP $KILLPIDS
143        exit 1
144fi
145
146echo "Using ldapsearch to read operation monitor entries..."
147$LDAPSEARCH -S "" -b "$OPERATIONSMONITORDN" -h $LOCALHOST -p $PORT1 \
148	'objectclass=*' \
149	structuralObjectClass monitorOpInitiated monitorOpCompleted entryDN \
150	> $SEARCHOUT 2>&1
151RC=$?
152
153if test $RC != 0 ; then
154        echo "ldapsearch failed ($RC)!"
155	test $KILLSERVERS != no && kill -HUP $KILLPIDS
156        exit $RC
157fi
158
159echo "Filtering ldapsearch results..."
160$LDIFFILTER -b monitor < $SEARCHOUT > $SEARCHFLT
161
162echo "Comparing filter output..."
163$CMP $SEARCHFLT $MONITOROUT4 > $CMPOUT
164
165if test $? != 0 ; then
166        echo "comparison failed - operations monitor output is not correct"
167	test $KILLSERVERS != no && kill -HUP $KILLPIDS
168        exit 1
169fi
170
171test $KILLSERVERS != no && kill -HUP $KILLPIDS
172
173echo ">>>>> Test succeeded"
174
175test $KILLSERVERS != no && wait
176
177exit 0
178
179