r444: - added the beginnings of a ldb test suite and benchmark
authorAndrew Tridgell <tridge@samba.org>
Sun, 2 May 2004 10:06:45 +0000 (10:06 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:51:42 +0000 (12:51 -0500)
 - updated the test slapd config to use bdb and indexing

source/lib/ldb/Makefile.ldb
source/lib/ldb/include/includes.h
source/lib/ldb/tests/init_slapd.sh
source/lib/ldb/tests/slapd.conf
source/lib/ldb/tests/start_slapd.sh
source/lib/ldb/tests/test-index.ldif
source/lib/ldb/tests/test.ldif
source/lib/ldb/tools/ldbtest.c [new file with mode: 0644]

index ba8c040f9ccab79f78b975cc6965a5aef84a2584..dfd429ecc8147704218e6b952586274c58cff578 100644 (file)
@@ -11,7 +11,7 @@ endif
 
 TDBDIR=../tdb
 
-CFLAGS=-Wall -g -Iinclude -I. -I.. -DSTANDALONE=1 -DUSE_MMAP=1 $(LDAP_FLAGS)
+CFLAGS=-Wall -O3 -Iinclude -I. -I.. -DSTANDALONE=1 -DUSE_MMAP=1 $(LDAP_FLAGS)
 LIB_FLAGS=-Llib -lldb $(LDAP_LIBS)
 
 TDB_OBJ=$(TDBDIR)/tdb.o $(TDBDIR)/spinlock.o
@@ -59,6 +59,9 @@ bin/ldbmodify: tools/ldbmodify.o $(LIBS)
 bin/ldbedit: tools/ldbedit.o $(LIBS)
        $(CC) -o bin/ldbedit tools/ldbedit.o $(LIB_FLAGS)
 
+bin/ldbtest: tools/ldbtest.o $(LIBS)
+       $(CC) -o bin/ldbtest tools/ldbtest.o $(LIB_FLAGS)
+
 clean:
        rm -f */*.o *~ */*~ $(BINS) $(LDB_LIB)
 
index 485d7157b867501d8ecd31094855c8caa2162861..7ee6876f485f5532013283c156a4c5fef3dbce43 100644 (file)
@@ -15,6 +15,8 @@
 #include <signal.h>
 #include <unistd.h>
 #include <fnmatch.h>
+#include <sys/time.h>
+#include <time.h>
 #include "ldb.h"
 #include "ldb_parse.h"
 
index 94dca7179187840b7620652a5859543279487cb0..67eecb031c784e0e7dc7361e6dd59fae2c80948b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-export PATH=/home/tridge/samba/openldap/prefix/sbin:/home/tridge/samba/openldap/prefix/bin:/home/tridge/samba/openldap/prefix/libexec:$PATH
+export PATH=/usr/sbin:$PATH
 
 rm -rf tests/tmp/db
 mkdir -p tests/tmp/db
index cb71eb3963af61a54d2e74d244384a86510cb66a..10d15b541ce3d9a312eccdc61e24581bc97f4f17 100644 (file)
@@ -14,12 +14,14 @@ access to * by * write
 
 allow update_anon bind_anon_dn
 
+modulepath     /usr/lib/ldap
+moduleload     back_bdb
+
 defaultsearchbase "o=University of Michigan,c=US"
 
-database        ldbm
+backend                bdb
+database        bdb
 suffix         "o=University of Michigan,c=US"
 directory      tests/tmp/db
-
-index  objectClass     eq
-index  drink   eq
-index  title   eq
+index           objectClass eq
+index           uid eq
index d000eec9a4bed40bf2b0e8a9cff6cad5c4d3dde3..d03a0fca3238bf6dad8c2ff8b29f05508e536e61 100755 (executable)
@@ -1,8 +1,7 @@
 #!/bin/sh
 
-export PATH=/home/tridge/samba/openldap/prefix/sbin:/home/tridge/samba/openldap/prefix/bin:/home/tridge/samba/openldap/prefix/libexec:$PATH
+export PATH=/usr/sbin:$PATH
 
 mkdir -p tests/tmp/db
 
 slapd -f tests/slapd.conf -h "`tests/ldapi_url.sh`" $*
-
index fe9c79d1a2d51f44472bbba435e5a82832199c55..0f1268c44f15e7024dc046bf31a9c8c5a40c0c9e 100644 (file)
@@ -1,4 +1,3 @@
 dn: @INDEXLIST
-@IDXATTR: drink
-@IDXATTR: title
+@IDXATTR: uid
 @IDXATTR: objectclass
index 72d52a25f860aa71cd58060a3666ec03ba2f7297..2d7e1f95de8f1fa7c5c656e79844c910e59f0130 100644 (file)
@@ -414,3 +414,6 @@ pager: +1 313 555 2844
 facsimiletelephonenumber: +1 313 555 9700
 telephonenumber: +1 313 555 5331
 
+dn: ou=Ldb Test,ou=People,o=University of Michigan,c=US
+objectclass: organizationalUnit
+ou: Ldb Test
diff --git a/source/lib/ldb/tools/ldbtest.c b/source/lib/ldb/tools/ldbtest.c
new file mode 100644 (file)
index 0000000..b7d1d22
--- /dev/null
@@ -0,0 +1,247 @@
+/* 
+   ldb database library
+
+   Copyright (C) Andrew Tridgell  2004
+
+     ** NOTE! The following LGPL license applies to the ldb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+/*
+ *  Name: ldb
+ *
+ *  Component: ldbtest
+ *
+ *  Description: utility to test ldb
+ *
+ *  Author: Andrew Tridgell
+ */
+
+#include "includes.h"
+
+static struct timeval tp1,tp2;
+
+static void start_timer()
+{
+       gettimeofday(&tp1,NULL);
+}
+
+static double end_timer()
+{
+       gettimeofday(&tp2,NULL);
+       return((tp2.tv_sec - tp1.tv_sec) + 
+              (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
+}
+
+static void add_records(struct ldb_context *ldb,
+                       const char *basedn,
+                       int count)
+{
+       struct ldb_message msg;
+       int i;
+
+       for (i=0;i<count;i++) {
+               struct ldb_message_element el[6];
+               struct ldb_val vals[6][1];
+               char *name;
+               
+               asprintf(&name, "Test%d", i);
+
+               asprintf(&msg.dn, "cn=%s,%s", name, basedn);
+               msg.num_elements = 6;
+               msg.elements = el;
+
+               el[0].flags = 0;
+               el[0].name = "cn";
+               el[0].num_values = 1;
+               el[0].values = vals[0];
+               vals[0][0].data = name;
+               vals[0][0].length = strlen(name);
+
+               el[1].flags = 0;
+               el[1].name = "title";
+               el[1].num_values = 1;
+               el[1].values = vals[1];
+               asprintf((char **)&vals[1][0].data, "The title of %s", name);
+               vals[1][0].length = strlen(vals[1][0].data);
+
+               el[2].flags = 0;
+               el[2].name = "uid";
+               el[2].num_values = 1;
+               el[2].values = vals[2];
+               vals[2][0].data = ldb_casefold(name);
+               vals[2][0].length = strlen(vals[2][0].data);
+
+               el[3].flags = 0;
+               el[3].name = "mail";
+               el[3].num_values = 1;
+               el[3].values = vals[3];
+               asprintf((char **)&vals[3][0].data, "%s@example.com", name);
+               vals[3][0].length = strlen(vals[3][0].data);
+
+               el[4].flags = 0;
+               el[4].name = "objectClass";
+               el[4].num_values = 1;
+               el[4].values = vals[4];
+               vals[4][0].data = "OpenLDAPperson";
+               vals[4][0].length = strlen(vals[4][0].data);
+
+               el[5].flags = 0;
+               el[5].name = "sn";
+               el[5].num_values = 1;
+               el[5].values = vals[5];
+               vals[5][0].data = name;
+               vals[5][0].length = strlen(vals[5][0].data);
+
+               if (ldb_add(ldb, &msg) != 0) {
+                       printf("Add of %s failed - %s\n", name, ldb_errstring(ldb));
+                       exit(1);
+               }
+
+               printf("adding uid %s\r", name);
+               fflush(stdout);
+
+               free(name);
+               free(msg.dn);
+               free(vals[1][0].data);
+               free(vals[2][0].data);
+               free(vals[3][0].data);
+       }
+
+       printf("\n");
+}
+
+static void search_uid(struct ldb_context *ldb, int nrecords, int nsearches)
+{
+       int i;
+
+       for (i=0;i<nsearches;i++) {
+               int uid = (i * 700 + 17) % (nrecords * 2);
+               char *expr;
+               struct ldb_message **res;
+               int ret;
+
+               asprintf(&expr, "(uid=TEST%d)", uid);
+               ret = ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res);
+
+               if (uid < nrecords && ret != 1) {
+                       printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb));
+                       exit(1);
+               }
+
+               if (uid >= nrecords && ret > 0) {
+                       printf("Found %s !? - %d\n", expr, ret);
+                       exit(1);
+               }
+
+               if (ret > 0) {
+                       ldb_search_free(ldb, res);
+               }
+
+               printf("testing uid %d/%d - %d  \r", i, uid, ret);
+               fflush(stdout);
+
+               free(expr);
+       }
+
+       printf("\n");
+}
+
+static void start_test(struct ldb_context *ldb, int nrecords, int nsearches)
+{
+       printf("Adding %d records\n", nrecords);
+
+       add_records(ldb, "ou=Ldb Test,ou=People,o=University of Michigan,c=US", 
+                       nrecords);
+
+       printf("Starting search on uid\n");
+
+       start_timer();
+
+       search_uid(ldb, nrecords, nsearches);
+
+       printf("uid search took %.2f seconds\n", end_timer());
+}
+
+
+static void usage(void)
+{
+       printf("Usage: ldbtest <options>\n");
+       printf("Options:\n");
+       printf("  -H ldb_url       choose the database (or $LDB_URL)\n");
+       printf("  -r nrecords      database size to use\n");
+       printf("  -s nsearches     number of searches to do\n");
+       printf("\n");
+       printf("tests ldb API\n\n");
+       exit(1);
+}
+
+ int main(int argc, char * const argv[])
+{
+       struct ldb_context *ldb;
+       const char *ldb_url;
+       int opt;
+       int nrecords = 5000;
+       int nsearches = 2000;
+
+       ldb_url = getenv("LDB_URL");
+
+       while ((opt = getopt(argc, argv, "hH:r:s:")) != EOF) {
+               switch (opt) {
+               case 'H':
+                       ldb_url = optarg;
+                       break;
+
+               case 'r':
+                       nrecords = atoi(optarg);
+                       break;
+
+               case 's':
+                       nsearches = atoi(optarg);
+                       break;
+
+               case 'h':
+               default:
+                       usage();
+                       break;
+               }
+       }
+
+       if (!ldb_url) {
+               fprintf(stderr, "You must specify a ldb URL\n\n");
+               usage();
+       }
+
+       argc -= optind;
+       argv += optind;
+
+       ldb = ldb_connect(ldb_url, 0, NULL);
+
+       if (!ldb) {
+               perror("ldb_connect");
+               exit(1);
+       }
+
+       srandom(1);
+
+       start_test(ldb, nrecords, nsearches);
+
+       ldb_close(ldb);
+
+       return 0;
+}