summaryrefslogtreecommitdiff
path: root/regress/lib/libc
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-05-07 09:02:24 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-05-07 09:02:24 +0000
commit30981883e827aa69632bca87e2764ef1ab152fa8 (patch)
treee1095f47308154adb4c7d01f0b14a4f737d2da8e /regress/lib/libc
parent6a0d2fe1f44c1b101f0a8a97b06b5e847918cf81 (diff)
db release 1.85
Diffstat (limited to 'regress/lib/libc')
-rw-r--r--regress/lib/libc/db/README36
-rw-r--r--regress/lib/libc/db/dbtest.c213
-rw-r--r--regress/lib/libc/db/run.test35
3 files changed, 196 insertions, 88 deletions
diff --git a/regress/lib/libc/db/README b/regress/lib/libc/db/README
index 3b290b09d81..fddf5c3d5a0 100644
--- a/regress/lib/libc/db/README
+++ b/regress/lib/libc/db/README
@@ -1,5 +1,5 @@
-# $NetBSD: README,v 1.4 1995/04/20 22:39:18 cgd Exp $
-# @(#)README 8.4 (Berkeley) 6/20/94
+# $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $
+# @(#)README 8.8 (Berkeley) 7/31/94
To run the tests, enter "make regress".
@@ -9,8 +9,11 @@ the test runs, and even larger files (the database files) are created in
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
@@ -19,17 +22,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]:
@@ -38,17 +48,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/regress/lib/libc/db/dbtest.c b/regress/lib/libc/db/dbtest.c
index 1fcf09af97f..65587a6fcb2 100644
--- a/regress/lib/libc/db/dbtest.c
+++ b/regress/lib/libc/db/dbtest.c
@@ -1,7 +1,7 @@
-/* $NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $ */
+/* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */
/*-
- * 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
@@ -35,15 +35,15 @@
#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
#if 0
-static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94";
+static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94";
#else
-static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $";
+static char rcsid[] = "$NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $";
#endif
#endif /* not lint */
@@ -71,6 +71,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 *));
@@ -78,13 +80,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)
@@ -97,14 +100,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;
@@ -119,6 +123,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();
@@ -133,8 +140,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)
@@ -145,7 +152,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)
@@ -153,7 +163,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));
@@ -162,8 +174,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);
@@ -176,7 +196,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 */
@@ -194,8 +215,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)
@@ -219,7 +251,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;
@@ -255,7 +287,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;
@@ -271,13 +303,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;
@@ -291,11 +323,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))
@@ -305,7 +341,6 @@ lkey: switch(command) {
}
#define NOOVERWRITE "put failed, would overwrite key\n"
-#define NOSUCHKEY "get failed, no such key\n"
void
compare(db1, db2)
@@ -334,17 +369,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;
}
}
@@ -354,14 +395,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 */
}
}
@@ -371,7 +412,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:
@@ -388,34 +429,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;
}
}
@@ -436,9 +510,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;
@@ -457,31 +533,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)
@@ -513,7 +600,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/regress/lib/libc/db/run.test b/regress/lib/libc/db/run.test
index 4073310a311..acbd3f49e17 100644
--- a/regress/lib/libc/db/run.test
+++ b/regress/lib/libc/db/run.test
@@ -1,19 +1,27 @@
#!/bin/sh -
-# $NetBSD: run.test,v 1.7 1995/04/20 22:39:27 cgd Exp $
#
-# @(#)run.test 8.8 (Berkeley) 6/16/94
+# $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $
+# @(#)run.test 8.10 (Berkeley) 7/26/94
#
# db regression tests
main()
{
-DICT=/usr/share/dict/web2
-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 +353,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 +372,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
@@ -397,8 +405,6 @@ test8()
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 +465,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 +579,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"