From 78aa8f181469b24f7ad836c2b7b8629c33f9f6b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 May 2004 10:06:45 +0000 Subject: r444: - added the beginnings of a ldb test suite and benchmark - updated the test slapd config to use bdb and indexing (This used to be commit 7ad0858c060ee212a33434dc4be75e7a0cd1a0e3) --- source4/lib/ldb/Makefile.ldb | 5 +- source4/lib/ldb/include/includes.h | 2 + source4/lib/ldb/tests/init_slapd.sh | 2 +- source4/lib/ldb/tests/slapd.conf | 12 +- source4/lib/ldb/tests/start_slapd.sh | 3 +- source4/lib/ldb/tests/test-index.ldif | 3 +- source4/lib/ldb/tests/test.ldif | 3 + source4/lib/ldb/tools/ldbtest.c | 247 ++++++++++++++++++++++++++++++++++ 8 files changed, 266 insertions(+), 11 deletions(-) create mode 100644 source4/lib/ldb/tools/ldbtest.c (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/Makefile.ldb b/source4/lib/ldb/Makefile.ldb index ba8c040f9c..dfd429ecc8 100644 --- a/source4/lib/ldb/Makefile.ldb +++ b/source4/lib/ldb/Makefile.ldb @@ -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) diff --git a/source4/lib/ldb/include/includes.h b/source4/lib/ldb/include/includes.h index 485d7157b8..7ee6876f48 100644 --- a/source4/lib/ldb/include/includes.h +++ b/source4/lib/ldb/include/includes.h @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include "ldb.h" #include "ldb_parse.h" diff --git a/source4/lib/ldb/tests/init_slapd.sh b/source4/lib/ldb/tests/init_slapd.sh index 94dca71791..67eecb031c 100755 --- a/source4/lib/ldb/tests/init_slapd.sh +++ b/source4/lib/ldb/tests/init_slapd.sh @@ -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 diff --git a/source4/lib/ldb/tests/slapd.conf b/source4/lib/ldb/tests/slapd.conf index cb71eb3963..10d15b541c 100644 --- a/source4/lib/ldb/tests/slapd.conf +++ b/source4/lib/ldb/tests/slapd.conf @@ -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 diff --git a/source4/lib/ldb/tests/start_slapd.sh b/source4/lib/ldb/tests/start_slapd.sh index d000eec9a4..d03a0fca32 100755 --- a/source4/lib/ldb/tests/start_slapd.sh +++ b/source4/lib/ldb/tests/start_slapd.sh @@ -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`" $* - diff --git a/source4/lib/ldb/tests/test-index.ldif b/source4/lib/ldb/tests/test-index.ldif index fe9c79d1a2..0f1268c44f 100644 --- a/source4/lib/ldb/tests/test-index.ldif +++ b/source4/lib/ldb/tests/test-index.ldif @@ -1,4 +1,3 @@ dn: @INDEXLIST -@IDXATTR: drink -@IDXATTR: title +@IDXATTR: uid @IDXATTR: objectclass diff --git a/source4/lib/ldb/tests/test.ldif b/source4/lib/ldb/tests/test.ldif index 72d52a25f8..2d7e1f95de 100644 --- a/source4/lib/ldb/tests/test.ldif +++ b/source4/lib/ldb/tests/test.ldif @@ -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/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c new file mode 100644 index 0000000000..b7d1d22db8 --- /dev/null +++ b/source4/lib/ldb/tools/ldbtest.c @@ -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= 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 \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; +} -- cgit