diff options
author | pst <pst@FreeBSD.org> | 1996-02-27 01:59:15 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1996-02-27 01:59:15 +0000 |
commit | c2306789fe98946429af7462a2fd453454034a79 (patch) | |
tree | e6563df097216e3af35d87ac698b2ea9eb3f5f75 /lib/libc/db/test | |
parent | 5476eae499a3e1c3530620c0ebc3a69ffb2f25ba (diff) | |
download | FreeBSD-src-c2306789fe98946429af7462a2fd453454034a79.zip FreeBSD-src-c2306789fe98946429af7462a2fd453454034a79.tar.gz |
Import updated Berkeley DB into CSRG branch
Diffstat (limited to 'lib/libc/db/test')
-rw-r--r-- | lib/libc/db/test/Makefile | 24 | ||||
-rw-r--r-- | lib/libc/db/test/README | 41 | ||||
-rw-r--r-- | lib/libc/db/test/dbtest.c | 209 | ||||
-rw-r--r-- | lib/libc/db/test/run.test | 38 |
4 files changed, 215 insertions, 97 deletions
diff --git a/lib/libc/db/test/Makefile b/lib/libc/db/test/Makefile index c816432..a5dd08a 100644 --- a/lib/libc/db/test/Makefile +++ b/lib/libc/db/test/Makefile @@ -1,17 +1,23 @@ -# @(#)Makefile 8.9 (Berkeley) 2/21/94 +# @(#)Makefile 8.15 (Berkeley) 7/28/94 PROG= dbtest OBJS= dbtest.o strerror.o -# Add -DSTATISTICS to CFLAGS to get btree statistical use info. -# Note, the db library has to be compiled for statistics as well. -CFLAGS= -D__DBINTERFACE_PRIVATE -DDEBUG -O ${INC} +# Uncomment the STAT line get hash and btree statistical use info. This +# also forces ld to load the btree debug functions for use by gdb, which +# is useful. The db library has to be compiled with -DSTATISTICS as well. +INC= -I${PORTDIR}/include -I${PORTDIR} +OORG= -g +#STAT= -DSTATISTICS +CFLAGS= -D__DBINTERFACE_PRIVATE -DDEBUG ${STAT} ${OORG} ${INC} -dbtest: ${OBJS} ${LIB} - ${CC} -o $@ ${OBJS} ${LIB} +dbtest: ${OBJS} ${PORTDIR}/libdb.a + ${CC} -o $@ ${OBJS} ${PORTDIR}/libdb.a -strerror.o: ../PORT/clib/strerror.c - ${CC} -c ../PORT/clib/strerror.c +strerror.o: ${PORTDIR}/clib/strerror.c + ${CC} -c ${PORTDIR}/clib/strerror.c clean: - rm -f gmon.out ${OBJS} ${PROG} t1 t2 t3 + rm -f dbtest.core gmon.out ${OBJS} ${PROG} t1 t2 t3 + +${OBJS}: Makefile diff --git a/lib/libc/db/test/README b/lib/libc/db/test/README index 8631c77..0c0cd13 100644 --- a/lib/libc/db/test/README +++ b/lib/libc/db/test/README @@ -1,17 +1,25 @@ -# @(#)README 8.2 (Berkeley) 2/21/94 +# @(#)README 8.8 (Berkeley) 7/31/94 To build this portably, try something like: - make INC="-I../PORT/MACH/ -I../PORT/MACH/include" LIB=../PORT/MACH/libdb.a + make PORTDIR="../PORT/MACH" where MACH is the machine, i.e. "sunos.4.1.1". To run the tests, enter "sh run.test". If your system dictionary isn't in /usr/share/dict/words, edit run.test to reflect the correct place. +Fairly large files (the command files) are built in this directory during +the test runs, and even larger files (the database files) are created in +"/var/tmp". If the latter directory doesn't exist, set the environmental +variable TMPDIR to a directory where the files can be built. + =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -The script file consists of lines with a initial character which is -the "command" for that line. Legal characters are as follows: +The script file consists of lines with an initial character which is +the command for that line, or an initial character indicating a key +or data entry for a previous command. + +Legal command characters are as follows: c: compare a record + must be followed by [kK][dD]; the data value in the database @@ -20,17 +28,24 @@ c: compare a record e: echo a string + writes out the rest of the line into the output file; if the last character is not a carriage-return, a newline is appended. +f: set the flags for the next command + + no value zero's the flags g: do a get command + must be followed by [kK] + writes out the retrieved data DBT. +o [r]: dump [reverse] + + dump the database out, if 'r' is set, in reverse order. p: do a put command + must be followed by [kK][dD] r: do a del command - + must be followed by [kK] + + must be followed by [kK] unless R_CURSOR flag set. +S: sync the database s: do a seq command + + must be followed by [kK] if R_CURSOR flag set. + writes out the retrieved data DBT. -f: set the flags for the next command - + no value zero's the flags + +Legal key/data characters are as follows: + D [file]: data file + set the current data value to the contents of the file d [data]: @@ -39,17 +54,21 @@ K [file]: key file + set the current key value to the contents of the file k [data]: + set the current key value to the contents of the line. -o [r]: dump [reverse] - + dump the database out, if 'r' is set, in reverse order. + +Blank lines, lines with leading white space, and lines with leading +hash marks (#) are ignored. Options to dbtest are as follows: + -d: Set the DB_LOCK flag. -f: Use the file argument as the database file. -i: Use the rest of the argument to set elements in the info structure. If the type is btree, then "-i cachesize=10240" will set BTREEINFO.cachesize to 10240. -o: The rest of the argument is the output file instead of using stdout. + -s: Don't delete the database file before opening it, i.e. + use the database file from a previous run. -Dbtest requires two arguments, the type of access "hash", "recno" or -"btree", and the script name. +Dbtest requires two arguments, the type of access "hash", "recno" +or "btree", and the script name or "-" to indicate stdin. diff --git a/lib/libc/db/test/dbtest.c b/lib/libc/db/test/dbtest.c index b8f97dc..4341b4c 100644 --- a/lib/libc/db/test/dbtest.c +++ b/lib/libc/db/test/dbtest.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1992, 1993 + * Copyright (c) 1992, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,12 +33,12 @@ #ifndef lint static char copyright[] = -"@(#) Copyright (c) 1992, 1993\n\ +"@(#) Copyright (c) 1992, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; #endif /* not lint */ #include <sys/param.h> @@ -65,6 +65,8 @@ void get __P((DB *, DBT *)); void getdata __P((DB *, DBT *, DBT *)); void put __P((DB *, DBT *, DBT *)); void rem __P((DB *, DBT *)); +char *sflags __P((int)); +void synk __P((DB *)); void *rfile __P((char *, size_t *)); void seq __P((DB *, DBT *)); u_int setflags __P((char *)); @@ -72,13 +74,14 @@ void *setinfo __P((DBTYPE, char *)); void usage __P((void)); void *xmalloc __P((char *, size_t)); -DBTYPE type; -void *infop; -u_long lineno; -u_int flags; -int ofd = STDOUT_FILENO; +DBTYPE type; /* Database type. */ +void *infop; /* Iflags. */ +u_long lineno; /* Current line in test script. */ +u_int flags; /* Current DB flags. */ +int ofd = STDOUT_FILENO; /* Standard output fd. */ DB *XXdbp; /* Global for gdb. */ +int XXlineno; /* Fast breakpoint for gdb. */ int main(argc, argv) @@ -91,14 +94,15 @@ main(argc, argv) DB *dbp; DBT data, key, keydata; size_t len; - int ch, oflags; - char *fname, *infoarg, *p, buf[8 * 1024]; + int ch, oflags, sflag; + char *fname, *infoarg, *p, *t, buf[8 * 1024]; infoarg = NULL; fname = NULL; oflags = O_CREAT | O_RDWR; - while ((ch = getopt(argc, argv, "f:i:lo:")) != EOF) - switch(ch) { + sflag = 0; + while ((ch = getopt(argc, argv, "f:i:lo:s")) != EOF) + switch (ch) { case 'f': fname = optarg; break; @@ -113,6 +117,9 @@ main(argc, argv) O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) err("%s: %s", optarg, strerror(errno)); break; + case 's': + sflag = 1; + break; case '?': default: usage(); @@ -127,8 +134,8 @@ main(argc, argv) type = dbtype(*argv++); /* Open the descriptor file. */ - if (freopen(*argv, "r", stdin) == NULL) - err("%s: %s", *argv, strerror(errno)); + if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) + err("%s: %s", *argv, strerror(errno)); /* Set up the db structure as necessary. */ if (infoarg == NULL) @@ -139,7 +146,10 @@ main(argc, argv) if (*p != '\0') infop = setinfo(type, p); - /* Open the DB. */ + /* + * Open the DB. Delete any preexisting copy, you almost never + * want it around, and it often screws up tests. + */ if (fname == NULL) { p = getenv("TMPDIR"); if (p == NULL) @@ -147,7 +157,9 @@ main(argc, argv) (void)sprintf(buf, "%s/__dbtest", p); fname = buf; (void)unlink(buf); - } + } else if (!sflag) + (void)unlink(fname); + if ((dbp = dbopen(fname, oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) err("dbopen: %s", strerror(errno)); @@ -156,8 +168,16 @@ main(argc, argv) state = COMMAND; for (lineno = 1; (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { - len = strlen(buf); - switch(*p) { + /* Delete the newline, displaying the key/data is easier. */ + if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) + *t = '\0'; + if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') + continue; + + /* Convenient gdb break point. */ + if (XXlineno == lineno) + XXlineno = 1; + switch (*p) { case 'c': /* compare */ if (state != COMMAND) err("line %lu: not expecting command", lineno); @@ -170,7 +190,8 @@ main(argc, argv) /* Don't display the newline, if CR at EOL. */ if (p[len - 2] == '\r') --len; - if (write(ofd, p + 1, len - 1) != len - 1) + if (write(ofd, p + 1, len - 1) != len - 1 || + write(ofd, "\n", 1) != 1) err("write: %s", strerror(errno)); break; case 'g': /* get */ @@ -188,8 +209,19 @@ main(argc, argv) case 'r': /* remove */ if (state != COMMAND) err("line %lu: not expecting command", lineno); - state = KEY; - command = REMOVE; + if (flags == R_CURSOR) { + rem(dbp, &key); + state = COMMAND; + } else { + state = KEY; + command = REMOVE; + } + break; + case 'S': /* sync */ + if (state != COMMAND) + err("line %lu: not expecting command", lineno); + synk(dbp); + state = COMMAND; break; case 's': /* seq */ if (state != COMMAND) @@ -213,7 +245,7 @@ main(argc, argv) err("line %lu: not expecting data", lineno); data.data = xmalloc(p + 1, len - 1); data.size = len - 1; -ldata: switch(command) { +ldata: switch (command) { case COMPARE: compare(&keydata, &data); break; @@ -249,7 +281,7 @@ ldata: switch(command) { key.data = xmalloc(p + 1, len - 1); key.size = len - 1; } -lkey: switch(command) { +lkey: switch (command) { case COMPARE: getdata(dbp, &key, &keydata); state = DATA; @@ -265,13 +297,13 @@ lkey: switch(command) { break; case REMOVE: rem(dbp, &key); - if (type != DB_RECNO) + if ((type != DB_RECNO) && (flags != R_CURSOR)) free(key.data); state = COMMAND; break; case SEQ: seq(dbp, &key); - if (type != DB_RECNO) + if ((type != DB_RECNO) && (flags != R_CURSOR)) free(key.data); state = COMMAND; break; @@ -285,11 +317,15 @@ lkey: switch(command) { break; default: err("line %lu: %s: unknown command character", - p, lineno); + lineno, p); } } #ifdef STATISTICS - if (type == DB_BTREE) + /* + * -l must be used (DB_LOCK must be set) for this to be + * used, otherwise a page will be locked and it will fail. + */ + if (type == DB_BTREE && oflags & DB_LOCK) __bt_stat(dbp); #endif if (dbp->close(dbp)) @@ -299,7 +335,6 @@ lkey: switch(command) { } #define NOOVERWRITE "put failed, would overwrite key\n" -#define NOSUCHKEY "get failed, no such key\n" void compare(db1, db2) @@ -328,17 +363,23 @@ get(dbp, kp) { DBT data; - switch(dbp->get(dbp, kp, &data, flags)) { + switch (dbp->get(dbp, kp, &data, flags)) { case 0: (void)write(ofd, data.data, data.size); + if (ofd == STDOUT_FILENO) + (void)write(ofd, "\n", 1); break; case -1: err("line %lu: get: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: - (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); - (void)fprintf(stderr, "%d: %.*s: %s\n", - lineno, kp->size, kp->data, NOSUCHKEY); +#define NOSUCHKEY "get failed, no such key\n" + if (ofd != STDOUT_FILENO) + (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); + else + (void)fprintf(stderr, "%d: %.*s: %s", + lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); +#undef NOSUCHKEY break; } } @@ -348,14 +389,14 @@ getdata(dbp, kp, dp) DB *dbp; DBT *kp, *dp; { - switch(dbp->get(dbp, kp, dp, flags)) { + switch (dbp->get(dbp, kp, dp, flags)) { case 0: return; case -1: err("line %lu: getdata: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: - err("line %lu: get failed, no such key", lineno); + err("line %lu: getdata failed, no such key", lineno); /* NOTREACHED */ } } @@ -365,7 +406,7 @@ put(dbp, kp, dp) DB *dbp; DBT *kp, *dp; { - switch(dbp->put(dbp, kp, dp, flags)) { + switch (dbp->put(dbp, kp, dp, flags)) { case 0: break; case -1: @@ -382,34 +423,67 @@ rem(dbp, kp) DB *dbp; DBT *kp; { - switch(dbp->del(dbp, kp, flags)) { + switch (dbp->del(dbp, kp, flags)) { case 0: break; case -1: - err("line %lu: get: %s", lineno, strerror(errno)); + err("line %lu: rem: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: - (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); +#define NOSUCHKEY "rem failed, no such key\n" + if (ofd != STDOUT_FILENO) + (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); + else if (flags != R_CURSOR) + (void)fprintf(stderr, "%d: %.*s: %s", + lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); + else + (void)fprintf(stderr, + "%d: rem of cursor failed\n", lineno); +#undef NOSUCHKEY break; } } void +synk(dbp) + DB *dbp; +{ + switch (dbp->sync(dbp, flags)) { + case 0: + break; + case -1: + err("line %lu: synk: %s", lineno, strerror(errno)); + /* NOTREACHED */ + } +} + +void seq(dbp, kp) DB *dbp; DBT *kp; { DBT data; - switch(dbp->seq(dbp, kp, &data, flags)) { + switch (dbp->seq(dbp, kp, &data, flags)) { case 0: (void)write(ofd, data.data, data.size); + if (ofd == STDOUT_FILENO) + (void)write(ofd, "\n", 1); break; case -1: err("line %lu: seq: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: - (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); +#define NOSUCHKEY "seq failed, no such key\n" + if (ofd != STDOUT_FILENO) + (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); + else if (flags == R_CURSOR) + (void)fprintf(stderr, "%d: %.*s: %s", + lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); + else + (void)fprintf(stderr, + "%d: seq (%s) failed\n", lineno, sflags(flags)); +#undef NOSUCHKEY break; } } @@ -430,9 +504,11 @@ dump(dbp, rev) nflags = R_NEXT; } for (;; flags = nflags) - switch(dbp->seq(dbp, &key, &data, flags)) { + switch (dbp->seq(dbp, &key, &data, flags)) { case 0: (void)write(ofd, data.data, data.size); + if (ofd == STDOUT_FILENO) + (void)write(ofd, "\n", 1); break; case 1: goto done; @@ -451,31 +527,42 @@ setflags(s) char *p, *index(); for (; isspace(*s); ++s); - if (*s == '\n') + if (*s == '\n' || *s == '\0') return (0); if ((p = index(s, '\n')) != NULL) *p = '\0'; - if (!strcmp(s, "R_CURSOR")) - return (R_CURSOR); - if (!strcmp(s, "R_FIRST")) - return (R_FIRST); - if (!strcmp(s, "R_IAFTER")) - return (R_IAFTER); - if (!strcmp(s, "R_IBEFORE")) - return (R_IBEFORE); - if (!strcmp(s, "R_LAST")) - return (R_LAST); - if (!strcmp(s, "R_NEXT")) - return (R_NEXT); - if (!strcmp(s, "R_NOOVERWRITE")) - return (R_NOOVERWRITE); - if (!strcmp(s, "R_PREV")) - return (R_PREV); - if (!strcmp(s, "R_SETCURSOR")) - return (R_SETCURSOR); + if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); + if (!strcmp(s, "R_FIRST")) return (R_FIRST); + if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); + if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); + if (!strcmp(s, "R_LAST")) return (R_LAST); + if (!strcmp(s, "R_NEXT")) return (R_NEXT); + if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); + if (!strcmp(s, "R_PREV")) return (R_PREV); + if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); + err("line %lu: %s: unknown flag", lineno, s); /* NOTREACHED */ } + +char * +sflags(flags) + int flags; +{ + switch (flags) { + case R_CURSOR: return ("R_CURSOR"); + case R_FIRST: return ("R_FIRST"); + case R_IAFTER: return ("R_IAFTER"); + case R_IBEFORE: return ("R_IBEFORE"); + case R_LAST: return ("R_LAST"); + case R_NEXT: return ("R_NEXT"); + case R_NOOVERWRITE: return ("R_NOOVERWRITE"); + case R_PREV: return ("R_PREV"); + case R_SETCURSOR: return ("R_SETCURSOR"); + } + + return ("UNKNOWN!"); +} DBTYPE dbtype(s) @@ -507,7 +594,7 @@ setinfo(type, s) if (!isdigit(*eq)) err("%s: structure set statement must be a number", s); - switch(type) { + switch (type) { case DB_BTREE: if (!strcmp("flags", s)) { ib.flags = atoi(eq); diff --git a/lib/libc/db/test/run.test b/lib/libc/db/test/run.test index 5eeaf74..52b74c3 100644 --- a/lib/libc/db/test/run.test +++ b/lib/libc/db/test/run.test @@ -1,19 +1,26 @@ #!/bin/sh - # -# @(#)run.test 8.7 (Berkeley) 9/16/93 +# @(#)run.test 8.10 (Berkeley) 7/26/94 # # db regression tests main() { -DICT=/usr/share/dict/words -#DICT=/usr/dict/words -PROG=./dbtest -TMP1=t1 -TMP2=t2 -TMP3=t3 + PROG=./dbtest + TMP1=t1 + TMP2=t2 + TMP3=t3 + if [ -f /usr/share/dict/words ]; then + DICT=/usr/share/dict/words + elif [ -f /usr/dict/words ]; then + DICT=/usr/dict/words + else + echo 'run.test: no dictionary' + exit 1 + fi + if [ $# -eq 0 ]; then for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do test$t @@ -345,7 +352,7 @@ test7() for (i = 1; i <= 120; ++i) printf("%05d: input key %d: %s\n", i, i, $0); printf("%05d: input key %d: %s\n", 120, 120, $0); - printf("get failed, no such key\n"); + printf("seq failed, no such key\n"); printf("%05d: input key %d: %s\n", 1, 1, $0); printf("%05d: input key %d: %s\n", 2, 2, $0); exit; @@ -364,10 +371,10 @@ test7() for (i = 1; i <= 120; ++i) printf("s\n"); printf("fR_CURSOR\ns\nk120\n"); - printf("r\nk120\n"); + printf("r\n"); printf("fR_NEXT\ns\n"); printf("fR_CURSOR\ns\nk1\n"); - printf("r\nk1\n"); + printf("r\n"); printf("fR_FIRST\ns\n"); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 @@ -392,13 +399,11 @@ test8() if (i % 8 == 0) { printf("c\nkkey2\nD/bin/csh\n"); printf("c\nkkey1\nD/bin/sh\n"); - printf("e\t%d of 10 (comparison)\r\n", i); + printf("e\t%d of 10 (comparison)\n", i); } else - printf("e\t%d of 10 \r\n", i); + printf("e\t%d of 10 \n", i); printf("r\nkkey1\nr\nkkey2\n"); } - printf("e\n"); - printf("eend of test8 run\n"); }' > $TMP1 $PROG btree $TMP1 # $PROG hash $TMP1 @@ -459,7 +464,7 @@ test10() printf("p\nk%d\nd%s\n", ++i, $0); } END { - printf("fR_CURSOR\nr\nk1\n"); + printf("fR_CURSOR\nr\n"); printf("eR_CURSOR SHOULD HAVE FAILED\n"); }' > $TMP2 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 @@ -573,7 +578,8 @@ test13() echo g echo k$i done > $TMP2 - $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 + $PROG -s \ + -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 if (cmp -s $TMP1 $TMP3) ; then : else echo "test13: $type/$order get failed" |