]> git.sur5r.net Git - openldap/blob - tests/scripts/test012-glue
Save a malloc
[openldap] / tests / scripts / test012-glue
1 #! /bin/sh
2 # $OpenLDAP$
3
4 SRCDIR="."
5 if test $# -ge 1 ; then
6         SRCDIR=$1; shift
7 fi
8 BACKEND=bdb
9 if test $# -ge 1 ; then
10         BACKEND=$1; shift
11 fi
12 MONITORDB=no
13 if test $# -ge 1 ; then
14         MONITORDB=$1; shift
15 fi
16 WAIT=0
17 if test $# -ge 1 ; then
18         WAIT=1; shift
19 fi
20
21 echo "running defines.sh"
22 . $SRCDIR/scripts/defines.sh
23
24 echo "Cleaning up in $DBDIR..."
25
26 mkdir $DBDIR/C_db1 $DBDIR/C_db2 $DBDIR/C_db3
27
28 rm -f $DBDIR/[!C]* $DBDIR/C_db?/*
29
30 echo "Running slapadd to build glued slapd databases..."
31 . $CONFFILTER $BACKEND $MONITORDB < $GLUECONF > $DBCONF
32 $SLAPADD -d $LVL -f $DBCONF -l $LDIFORDERED > $DBDIR/slapadd.log 2>&1
33 RC=$?
34 if test $RC != 0 ; then
35         echo "slapadd failed ($RC)!"
36         exit $RC
37 fi
38
39 echo "Starting slapd on TCP/IP port $PORT..."
40 $SLAPD -f $DBCONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46
47 echo "Using ldapsearch to retrieve all the entries..."
48 cd test-db
49 for i in 0 1 2 3 4 5; do
50         ../$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT > ../$SEARCHOUT 2>&1
51         RC=$?
52         if test $RC = 1 ; then
53                 echo "Waiting 5 seconds for slapd to start..."
54                 sleep 5
55         fi
56 done
57 cd ..
58
59 kill -HUP $PID
60 echo "Sleeping for 5 seconds to let slapd exit..."
61 sleep 5
62
63 if test $RC != 0 ; then
64         echo "ldapsearch failed ($RC)!"
65         exit $RC
66 fi
67
68 echo "Filtering ldapsearch results..."
69 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
70 echo "Filtering original ldif used to create database..."
71 . $LDIFFILTER < $LDIFGLUED > $LDIFFLT
72 echo "Comparing filter output..."
73 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
74
75 if test $? != 0 ; then
76         echo "comparison failed - database was not created correctly"
77         echo $SEARCHFLT $LDIFFLT
78         $DIFF $SEARCHFLT $LDIFFLT
79         exit 1
80 fi
81
82 echo "OK...  Cleaning up in $DBDIR..."
83
84 rm -f $DBDIR/C_db?/*
85
86 echo "Starting slapd on TCP/IP port $PORT..."
87 $SLAPD -f $DBCONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
88 PID=$!
89 if test $WAIT != 0 ; then
90     echo PID $PID
91     read foo
92 fi
93
94 echo "Using ldapsearch to check that slapd is running..."
95 for i in 0 1 2 3 4 5; do
96         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT \
97                 'objectclass=*' > /dev/null 2>&1
98         RC=$?
99         if test $RC = 1 ; then
100                 echo "Waiting 5 seconds for slapd to start..."
101                 sleep 5
102         fi
103 done
104
105 echo "Using ldapadd to populate the glued database..."
106 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT -w $PASSWD < \
107         $LDIFORDERED > $TESTOUT 2>&1
108 RC=$?
109 if test $RC != 0 ; then
110         echo "ldapadd failed ($RC)!"
111         kill -HUP $PID
112         exit $RC
113 fi
114
115 echo "Using ldapsearch to read all the entries..."
116 $LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT \
117         'objectclass=*' > $SEARCHOUT 2>&1
118 RC=$?
119
120 kill -HUP $PID
121
122 if test $RC != 0 ; then
123         echo "ldapsearch failed ($RC)!"
124         exit $RC
125 fi
126
127 echo "Filtering ldapsearch results..."
128 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
129 echo "Filtering original ldif used to create database..."
130 . $LDIFFILTER < $LDIFGLUED > $LDIFFLT
131 echo "Comparing filter output..."
132 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
133
134 if test $? != 0 ; then
135         echo "comparison failed - database was not created correctly"
136         exit 1
137 fi
138
139 echo ">>>>> Test succeeded"
140
141
142 exit 0