diff options
author | deraadt <> | 1996-05-07 09:02:23 +0000 |
---|---|---|
committer | deraadt <> | 1996-05-07 09:02:23 +0000 |
commit | b08ebc2003288b99b5bff2ea3afc425782eb3c08 (patch) | |
tree | 1a581e7edb42e14132c27491391f3f8bd151913b /src/regress/lib | |
parent | 42a36c73710670af2dd4f549d9c927cd17ed45bc (diff) | |
download | openbsd-b08ebc2003288b99b5bff2ea3afc425782eb3c08.tar.gz openbsd-b08ebc2003288b99b5bff2ea3afc425782eb3c08.tar.bz2 openbsd-b08ebc2003288b99b5bff2ea3afc425782eb3c08.zip |
db release 1.85
Diffstat (limited to 'src/regress/lib')
-rw-r--r-- | src/regress/lib/libc/db/README | 36 | ||||
-rw-r--r-- | src/regress/lib/libc/db/dbtest.c | 213 | ||||
-rw-r--r-- | src/regress/lib/libc/db/run.test | 35 |
3 files changed, 196 insertions, 88 deletions
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README index 3b290b09d8..fddf5c3d5a 100644 --- a/src/regress/lib/libc/db/README +++ b/src/regress/lib/libc/db/README | |||
@@ -1,5 +1,5 @@ | |||
1 | # $NetBSD: README,v 1.4 1995/04/20 22:39:18 cgd Exp $ | 1 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ |
2 | # @(#)README 8.4 (Berkeley) 6/20/94 | 2 | # @(#)README 8.8 (Berkeley) 7/31/94 |
3 | 3 | ||
4 | To run the tests, enter "make regress". | 4 | To run the tests, enter "make regress". |
5 | 5 | ||
@@ -9,8 +9,11 @@ the test runs, and even larger files (the database files) are created in | |||
9 | variable TMPDIR to a directory where the files can be built. | 9 | variable TMPDIR to a directory where the files can be built. |
10 | 10 | ||
11 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | 11 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
12 | The script file consists of lines with a initial character which is | 12 | The script file consists of lines with an initial character which is |
13 | the "command" for that line. Legal characters are as follows: | 13 | the command for that line, or an initial character indicating a key |
14 | or data entry for a previous command. | ||
15 | |||
16 | Legal command characters are as follows: | ||
14 | 17 | ||
15 | c: compare a record | 18 | c: compare a record |
16 | + must be followed by [kK][dD]; the data value in the database | 19 | + must be followed by [kK][dD]; the data value in the database |
@@ -19,17 +22,24 @@ c: compare a record | |||
19 | e: echo a string | 22 | e: echo a string |
20 | + writes out the rest of the line into the output file; if the | 23 | + writes out the rest of the line into the output file; if the |
21 | last character is not a carriage-return, a newline is appended. | 24 | last character is not a carriage-return, a newline is appended. |
25 | f: set the flags for the next command | ||
26 | + no value zero's the flags | ||
22 | g: do a get command | 27 | g: do a get command |
23 | + must be followed by [kK] | 28 | + must be followed by [kK] |
24 | + writes out the retrieved data DBT. | 29 | + writes out the retrieved data DBT. |
30 | o [r]: dump [reverse] | ||
31 | + dump the database out, if 'r' is set, in reverse order. | ||
25 | p: do a put command | 32 | p: do a put command |
26 | + must be followed by [kK][dD] | 33 | + must be followed by [kK][dD] |
27 | r: do a del command | 34 | r: do a del command |
28 | + must be followed by [kK] | 35 | + must be followed by [kK] unless R_CURSOR flag set. |
36 | S: sync the database | ||
29 | s: do a seq command | 37 | s: do a seq command |
38 | + must be followed by [kK] if R_CURSOR flag set. | ||
30 | + writes out the retrieved data DBT. | 39 | + writes out the retrieved data DBT. |
31 | f: set the flags for the next command | 40 | |
32 | + no value zero's the flags | 41 | Legal key/data characters are as follows: |
42 | |||
33 | D [file]: data file | 43 | D [file]: data file |
34 | + set the current data value to the contents of the file | 44 | + set the current data value to the contents of the file |
35 | d [data]: | 45 | d [data]: |
@@ -38,17 +48,21 @@ K [file]: key file | |||
38 | + set the current key value to the contents of the file | 48 | + set the current key value to the contents of the file |
39 | k [data]: | 49 | k [data]: |
40 | + set the current key value to the contents of the line. | 50 | + set the current key value to the contents of the line. |
41 | o [r]: dump [reverse] | 51 | |
42 | + dump the database out, if 'r' is set, in reverse order. | 52 | Blank lines, lines with leading white space, and lines with leading |
53 | hash marks (#) are ignored. | ||
43 | 54 | ||
44 | Options to dbtest are as follows: | 55 | Options to dbtest are as follows: |
45 | 56 | ||
57 | -d: Set the DB_LOCK flag. | ||
46 | -f: Use the file argument as the database file. | 58 | -f: Use the file argument as the database file. |
47 | -i: Use the rest of the argument to set elements in the info | 59 | -i: Use the rest of the argument to set elements in the info |
48 | structure. If the type is btree, then "-i cachesize=10240" | 60 | structure. If the type is btree, then "-i cachesize=10240" |
49 | will set BTREEINFO.cachesize to 10240. | 61 | will set BTREEINFO.cachesize to 10240. |
50 | -o: The rest of the argument is the output file instead of | 62 | -o: The rest of the argument is the output file instead of |
51 | using stdout. | 63 | using stdout. |
64 | -s: Don't delete the database file before opening it, i.e. | ||
65 | use the database file from a previous run. | ||
52 | 66 | ||
53 | Dbtest requires two arguments, the type of access "hash", "recno" or | 67 | Dbtest requires two arguments, the type of access "hash", "recno" |
54 | "btree", and the script name. | 68 | or "btree", and the script name or "-" to indicate stdin. |
diff --git a/src/regress/lib/libc/db/dbtest.c b/src/regress/lib/libc/db/dbtest.c index 1fcf09af97..65587a6fcb 100644 --- a/src/regress/lib/libc/db/dbtest.c +++ b/src/regress/lib/libc/db/dbtest.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* $NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $ */ | 1 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ |
2 | 2 | ||
3 | /*- | 3 | /*- |
4 | * Copyright (c) 1992, 1993 | 4 | * Copyright (c) 1992, 1993, 1994 |
5 | * The Regents of the University of California. All rights reserved. | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
@@ -35,15 +35,15 @@ | |||
35 | 35 | ||
36 | #ifndef lint | 36 | #ifndef lint |
37 | static char copyright[] = | 37 | static char copyright[] = |
38 | "@(#) Copyright (c) 1992, 1993\n\ | 38 | "@(#) Copyright (c) 1992, 1993, 1994\n\ |
39 | The Regents of the University of California. All rights reserved.\n"; | 39 | The Regents of the University of California. All rights reserved.\n"; |
40 | #endif /* not lint */ | 40 | #endif /* not lint */ |
41 | 41 | ||
42 | #ifndef lint | 42 | #ifndef lint |
43 | #if 0 | 43 | #if 0 |
44 | static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94"; | 44 | static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; |
45 | #else | 45 | #else |
46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.7 1995/04/20 22:39:22 cgd Exp $"; | 46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $"; |
47 | #endif | 47 | #endif |
48 | #endif /* not lint */ | 48 | #endif /* not lint */ |
49 | 49 | ||
@@ -71,6 +71,8 @@ void get __P((DB *, DBT *)); | |||
71 | void getdata __P((DB *, DBT *, DBT *)); | 71 | void getdata __P((DB *, DBT *, DBT *)); |
72 | void put __P((DB *, DBT *, DBT *)); | 72 | void put __P((DB *, DBT *, DBT *)); |
73 | void rem __P((DB *, DBT *)); | 73 | void rem __P((DB *, DBT *)); |
74 | char *sflags __P((int)); | ||
75 | void synk __P((DB *)); | ||
74 | void *rfile __P((char *, size_t *)); | 76 | void *rfile __P((char *, size_t *)); |
75 | void seq __P((DB *, DBT *)); | 77 | void seq __P((DB *, DBT *)); |
76 | u_int setflags __P((char *)); | 78 | u_int setflags __P((char *)); |
@@ -78,13 +80,14 @@ void *setinfo __P((DBTYPE, char *)); | |||
78 | void usage __P((void)); | 80 | void usage __P((void)); |
79 | void *xmalloc __P((char *, size_t)); | 81 | void *xmalloc __P((char *, size_t)); |
80 | 82 | ||
81 | DBTYPE type; | 83 | DBTYPE type; /* Database type. */ |
82 | void *infop; | 84 | void *infop; /* Iflags. */ |
83 | u_long lineno; | 85 | u_long lineno; /* Current line in test script. */ |
84 | u_int flags; | 86 | u_int flags; /* Current DB flags. */ |
85 | int ofd = STDOUT_FILENO; | 87 | int ofd = STDOUT_FILENO; /* Standard output fd. */ |
86 | 88 | ||
87 | DB *XXdbp; /* Global for gdb. */ | 89 | DB *XXdbp; /* Global for gdb. */ |
90 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
88 | 91 | ||
89 | int | 92 | int |
90 | main(argc, argv) | 93 | main(argc, argv) |
@@ -97,14 +100,15 @@ main(argc, argv) | |||
97 | DB *dbp; | 100 | DB *dbp; |
98 | DBT data, key, keydata; | 101 | DBT data, key, keydata; |
99 | size_t len; | 102 | size_t len; |
100 | int ch, oflags; | 103 | int ch, oflags, sflag; |
101 | char *fname, *infoarg, *p, buf[8 * 1024]; | 104 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; |
102 | 105 | ||
103 | infoarg = NULL; | 106 | infoarg = NULL; |
104 | fname = NULL; | 107 | fname = NULL; |
105 | oflags = O_CREAT | O_RDWR; | 108 | oflags = O_CREAT | O_RDWR; |
106 | while ((ch = getopt(argc, argv, "f:i:lo:")) != EOF) | 109 | sflag = 0; |
107 | switch(ch) { | 110 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != EOF) |
111 | switch (ch) { | ||
108 | case 'f': | 112 | case 'f': |
109 | fname = optarg; | 113 | fname = optarg; |
110 | break; | 114 | break; |
@@ -119,6 +123,9 @@ main(argc, argv) | |||
119 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 123 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
120 | err("%s: %s", optarg, strerror(errno)); | 124 | err("%s: %s", optarg, strerror(errno)); |
121 | break; | 125 | break; |
126 | case 's': | ||
127 | sflag = 1; | ||
128 | break; | ||
122 | case '?': | 129 | case '?': |
123 | default: | 130 | default: |
124 | usage(); | 131 | usage(); |
@@ -133,8 +140,8 @@ main(argc, argv) | |||
133 | type = dbtype(*argv++); | 140 | type = dbtype(*argv++); |
134 | 141 | ||
135 | /* Open the descriptor file. */ | 142 | /* Open the descriptor file. */ |
136 | if (freopen(*argv, "r", stdin) == NULL) | 143 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) |
137 | err("%s: %s", *argv, strerror(errno)); | 144 | err("%s: %s", *argv, strerror(errno)); |
138 | 145 | ||
139 | /* Set up the db structure as necessary. */ | 146 | /* Set up the db structure as necessary. */ |
140 | if (infoarg == NULL) | 147 | if (infoarg == NULL) |
@@ -145,7 +152,10 @@ main(argc, argv) | |||
145 | if (*p != '\0') | 152 | if (*p != '\0') |
146 | infop = setinfo(type, p); | 153 | infop = setinfo(type, p); |
147 | 154 | ||
148 | /* Open the DB. */ | 155 | /* |
156 | * Open the DB. Delete any preexisting copy, you almost never | ||
157 | * want it around, and it often screws up tests. | ||
158 | */ | ||
149 | if (fname == NULL) { | 159 | if (fname == NULL) { |
150 | p = getenv("TMPDIR"); | 160 | p = getenv("TMPDIR"); |
151 | if (p == NULL) | 161 | if (p == NULL) |
@@ -153,7 +163,9 @@ main(argc, argv) | |||
153 | (void)sprintf(buf, "%s/__dbtest", p); | 163 | (void)sprintf(buf, "%s/__dbtest", p); |
154 | fname = buf; | 164 | fname = buf; |
155 | (void)unlink(buf); | 165 | (void)unlink(buf); |
156 | } | 166 | } else if (!sflag) |
167 | (void)unlink(fname); | ||
168 | |||
157 | if ((dbp = dbopen(fname, | 169 | if ((dbp = dbopen(fname, |
158 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | 170 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) |
159 | err("dbopen: %s", strerror(errno)); | 171 | err("dbopen: %s", strerror(errno)); |
@@ -162,8 +174,16 @@ main(argc, argv) | |||
162 | state = COMMAND; | 174 | state = COMMAND; |
163 | for (lineno = 1; | 175 | for (lineno = 1; |
164 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | 176 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { |
165 | len = strlen(buf); | 177 | /* Delete the newline, displaying the key/data is easier. */ |
166 | switch(*p) { | 178 | if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) |
179 | *t = '\0'; | ||
180 | if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') | ||
181 | continue; | ||
182 | |||
183 | /* Convenient gdb break point. */ | ||
184 | if (XXlineno == lineno) | ||
185 | XXlineno = 1; | ||
186 | switch (*p) { | ||
167 | case 'c': /* compare */ | 187 | case 'c': /* compare */ |
168 | if (state != COMMAND) | 188 | if (state != COMMAND) |
169 | err("line %lu: not expecting command", lineno); | 189 | err("line %lu: not expecting command", lineno); |
@@ -176,7 +196,8 @@ main(argc, argv) | |||
176 | /* Don't display the newline, if CR at EOL. */ | 196 | /* Don't display the newline, if CR at EOL. */ |
177 | if (p[len - 2] == '\r') | 197 | if (p[len - 2] == '\r') |
178 | --len; | 198 | --len; |
179 | if (write(ofd, p + 1, len - 1) != len - 1) | 199 | if (write(ofd, p + 1, len - 1) != len - 1 || |
200 | write(ofd, "\n", 1) != 1) | ||
180 | err("write: %s", strerror(errno)); | 201 | err("write: %s", strerror(errno)); |
181 | break; | 202 | break; |
182 | case 'g': /* get */ | 203 | case 'g': /* get */ |
@@ -194,8 +215,19 @@ main(argc, argv) | |||
194 | case 'r': /* remove */ | 215 | case 'r': /* remove */ |
195 | if (state != COMMAND) | 216 | if (state != COMMAND) |
196 | err("line %lu: not expecting command", lineno); | 217 | err("line %lu: not expecting command", lineno); |
197 | state = KEY; | 218 | if (flags == R_CURSOR) { |
198 | command = REMOVE; | 219 | rem(dbp, &key); |
220 | state = COMMAND; | ||
221 | } else { | ||
222 | state = KEY; | ||
223 | command = REMOVE; | ||
224 | } | ||
225 | break; | ||
226 | case 'S': /* sync */ | ||
227 | if (state != COMMAND) | ||
228 | err("line %lu: not expecting command", lineno); | ||
229 | synk(dbp); | ||
230 | state = COMMAND; | ||
199 | break; | 231 | break; |
200 | case 's': /* seq */ | 232 | case 's': /* seq */ |
201 | if (state != COMMAND) | 233 | if (state != COMMAND) |
@@ -219,7 +251,7 @@ main(argc, argv) | |||
219 | err("line %lu: not expecting data", lineno); | 251 | err("line %lu: not expecting data", lineno); |
220 | data.data = xmalloc(p + 1, len - 1); | 252 | data.data = xmalloc(p + 1, len - 1); |
221 | data.size = len - 1; | 253 | data.size = len - 1; |
222 | ldata: switch(command) { | 254 | ldata: switch (command) { |
223 | case COMPARE: | 255 | case COMPARE: |
224 | compare(&keydata, &data); | 256 | compare(&keydata, &data); |
225 | break; | 257 | break; |
@@ -255,7 +287,7 @@ ldata: switch(command) { | |||
255 | key.data = xmalloc(p + 1, len - 1); | 287 | key.data = xmalloc(p + 1, len - 1); |
256 | key.size = len - 1; | 288 | key.size = len - 1; |
257 | } | 289 | } |
258 | lkey: switch(command) { | 290 | lkey: switch (command) { |
259 | case COMPARE: | 291 | case COMPARE: |
260 | getdata(dbp, &key, &keydata); | 292 | getdata(dbp, &key, &keydata); |
261 | state = DATA; | 293 | state = DATA; |
@@ -271,13 +303,13 @@ lkey: switch(command) { | |||
271 | break; | 303 | break; |
272 | case REMOVE: | 304 | case REMOVE: |
273 | rem(dbp, &key); | 305 | rem(dbp, &key); |
274 | if (type != DB_RECNO) | 306 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
275 | free(key.data); | 307 | free(key.data); |
276 | state = COMMAND; | 308 | state = COMMAND; |
277 | break; | 309 | break; |
278 | case SEQ: | 310 | case SEQ: |
279 | seq(dbp, &key); | 311 | seq(dbp, &key); |
280 | if (type != DB_RECNO) | 312 | if ((type != DB_RECNO) && (flags != R_CURSOR)) |
281 | free(key.data); | 313 | free(key.data); |
282 | state = COMMAND; | 314 | state = COMMAND; |
283 | break; | 315 | break; |
@@ -291,11 +323,15 @@ lkey: switch(command) { | |||
291 | break; | 323 | break; |
292 | default: | 324 | default: |
293 | err("line %lu: %s: unknown command character", | 325 | err("line %lu: %s: unknown command character", |
294 | p, lineno); | 326 | lineno, p); |
295 | } | 327 | } |
296 | } | 328 | } |
297 | #ifdef STATISTICS | 329 | #ifdef STATISTICS |
298 | if (type == DB_BTREE) | 330 | /* |
331 | * -l must be used (DB_LOCK must be set) for this to be | ||
332 | * used, otherwise a page will be locked and it will fail. | ||
333 | */ | ||
334 | if (type == DB_BTREE && oflags & DB_LOCK) | ||
299 | __bt_stat(dbp); | 335 | __bt_stat(dbp); |
300 | #endif | 336 | #endif |
301 | if (dbp->close(dbp)) | 337 | if (dbp->close(dbp)) |
@@ -305,7 +341,6 @@ lkey: switch(command) { | |||
305 | } | 341 | } |
306 | 342 | ||
307 | #define NOOVERWRITE "put failed, would overwrite key\n" | 343 | #define NOOVERWRITE "put failed, would overwrite key\n" |
308 | #define NOSUCHKEY "get failed, no such key\n" | ||
309 | 344 | ||
310 | void | 345 | void |
311 | compare(db1, db2) | 346 | compare(db1, db2) |
@@ -334,17 +369,23 @@ get(dbp, kp) | |||
334 | { | 369 | { |
335 | DBT data; | 370 | DBT data; |
336 | 371 | ||
337 | switch(dbp->get(dbp, kp, &data, flags)) { | 372 | switch (dbp->get(dbp, kp, &data, flags)) { |
338 | case 0: | 373 | case 0: |
339 | (void)write(ofd, data.data, data.size); | 374 | (void)write(ofd, data.data, data.size); |
375 | if (ofd == STDOUT_FILENO) | ||
376 | (void)write(ofd, "\n", 1); | ||
340 | break; | 377 | break; |
341 | case -1: | 378 | case -1: |
342 | err("line %lu: get: %s", lineno, strerror(errno)); | 379 | err("line %lu: get: %s", lineno, strerror(errno)); |
343 | /* NOTREACHED */ | 380 | /* NOTREACHED */ |
344 | case 1: | 381 | case 1: |
345 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 382 | #define NOSUCHKEY "get failed, no such key\n" |
346 | (void)fprintf(stderr, "%d: %.*s: %s\n", | 383 | if (ofd != STDOUT_FILENO) |
347 | lineno, kp->size, kp->data, NOSUCHKEY); | 384 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); |
385 | else | ||
386 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
387 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
388 | #undef NOSUCHKEY | ||
348 | break; | 389 | break; |
349 | } | 390 | } |
350 | } | 391 | } |
@@ -354,14 +395,14 @@ getdata(dbp, kp, dp) | |||
354 | DB *dbp; | 395 | DB *dbp; |
355 | DBT *kp, *dp; | 396 | DBT *kp, *dp; |
356 | { | 397 | { |
357 | switch(dbp->get(dbp, kp, dp, flags)) { | 398 | switch (dbp->get(dbp, kp, dp, flags)) { |
358 | case 0: | 399 | case 0: |
359 | return; | 400 | return; |
360 | case -1: | 401 | case -1: |
361 | err("line %lu: getdata: %s", lineno, strerror(errno)); | 402 | err("line %lu: getdata: %s", lineno, strerror(errno)); |
362 | /* NOTREACHED */ | 403 | /* NOTREACHED */ |
363 | case 1: | 404 | case 1: |
364 | err("line %lu: get failed, no such key", lineno); | 405 | err("line %lu: getdata failed, no such key", lineno); |
365 | /* NOTREACHED */ | 406 | /* NOTREACHED */ |
366 | } | 407 | } |
367 | } | 408 | } |
@@ -371,7 +412,7 @@ put(dbp, kp, dp) | |||
371 | DB *dbp; | 412 | DB *dbp; |
372 | DBT *kp, *dp; | 413 | DBT *kp, *dp; |
373 | { | 414 | { |
374 | switch(dbp->put(dbp, kp, dp, flags)) { | 415 | switch (dbp->put(dbp, kp, dp, flags)) { |
375 | case 0: | 416 | case 0: |
376 | break; | 417 | break; |
377 | case -1: | 418 | case -1: |
@@ -388,34 +429,67 @@ rem(dbp, kp) | |||
388 | DB *dbp; | 429 | DB *dbp; |
389 | DBT *kp; | 430 | DBT *kp; |
390 | { | 431 | { |
391 | switch(dbp->del(dbp, kp, flags)) { | 432 | switch (dbp->del(dbp, kp, flags)) { |
392 | case 0: | 433 | case 0: |
393 | break; | 434 | break; |
394 | case -1: | 435 | case -1: |
395 | err("line %lu: get: %s", lineno, strerror(errno)); | 436 | err("line %lu: rem: %s", lineno, strerror(errno)); |
396 | /* NOTREACHED */ | 437 | /* NOTREACHED */ |
397 | case 1: | 438 | case 1: |
398 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 439 | #define NOSUCHKEY "rem failed, no such key\n" |
440 | if (ofd != STDOUT_FILENO) | ||
441 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
442 | else if (flags != R_CURSOR) | ||
443 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
444 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
445 | else | ||
446 | (void)fprintf(stderr, | ||
447 | "%d: rem of cursor failed\n", lineno); | ||
448 | #undef NOSUCHKEY | ||
399 | break; | 449 | break; |
400 | } | 450 | } |
401 | } | 451 | } |
402 | 452 | ||
403 | void | 453 | void |
454 | synk(dbp) | ||
455 | DB *dbp; | ||
456 | { | ||
457 | switch (dbp->sync(dbp, flags)) { | ||
458 | case 0: | ||
459 | break; | ||
460 | case -1: | ||
461 | err("line %lu: synk: %s", lineno, strerror(errno)); | ||
462 | /* NOTREACHED */ | ||
463 | } | ||
464 | } | ||
465 | |||
466 | void | ||
404 | seq(dbp, kp) | 467 | seq(dbp, kp) |
405 | DB *dbp; | 468 | DB *dbp; |
406 | DBT *kp; | 469 | DBT *kp; |
407 | { | 470 | { |
408 | DBT data; | 471 | DBT data; |
409 | 472 | ||
410 | switch(dbp->seq(dbp, kp, &data, flags)) { | 473 | switch (dbp->seq(dbp, kp, &data, flags)) { |
411 | case 0: | 474 | case 0: |
412 | (void)write(ofd, data.data, data.size); | 475 | (void)write(ofd, data.data, data.size); |
476 | if (ofd == STDOUT_FILENO) | ||
477 | (void)write(ofd, "\n", 1); | ||
413 | break; | 478 | break; |
414 | case -1: | 479 | case -1: |
415 | err("line %lu: seq: %s", lineno, strerror(errno)); | 480 | err("line %lu: seq: %s", lineno, strerror(errno)); |
416 | /* NOTREACHED */ | 481 | /* NOTREACHED */ |
417 | case 1: | 482 | case 1: |
418 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | 483 | #define NOSUCHKEY "seq failed, no such key\n" |
484 | if (ofd != STDOUT_FILENO) | ||
485 | (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); | ||
486 | else if (flags == R_CURSOR) | ||
487 | (void)fprintf(stderr, "%d: %.*s: %s", | ||
488 | lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); | ||
489 | else | ||
490 | (void)fprintf(stderr, | ||
491 | "%d: seq (%s) failed\n", lineno, sflags(flags)); | ||
492 | #undef NOSUCHKEY | ||
419 | break; | 493 | break; |
420 | } | 494 | } |
421 | } | 495 | } |
@@ -436,9 +510,11 @@ dump(dbp, rev) | |||
436 | nflags = R_NEXT; | 510 | nflags = R_NEXT; |
437 | } | 511 | } |
438 | for (;; flags = nflags) | 512 | for (;; flags = nflags) |
439 | switch(dbp->seq(dbp, &key, &data, flags)) { | 513 | switch (dbp->seq(dbp, &key, &data, flags)) { |
440 | case 0: | 514 | case 0: |
441 | (void)write(ofd, data.data, data.size); | 515 | (void)write(ofd, data.data, data.size); |
516 | if (ofd == STDOUT_FILENO) | ||
517 | (void)write(ofd, "\n", 1); | ||
442 | break; | 518 | break; |
443 | case 1: | 519 | case 1: |
444 | goto done; | 520 | goto done; |
@@ -457,31 +533,42 @@ setflags(s) | |||
457 | char *p, *index(); | 533 | char *p, *index(); |
458 | 534 | ||
459 | for (; isspace(*s); ++s); | 535 | for (; isspace(*s); ++s); |
460 | if (*s == '\n') | 536 | if (*s == '\n' || *s == '\0') |
461 | return (0); | 537 | return (0); |
462 | if ((p = index(s, '\n')) != NULL) | 538 | if ((p = index(s, '\n')) != NULL) |
463 | *p = '\0'; | 539 | *p = '\0'; |
464 | if (!strcmp(s, "R_CURSOR")) | 540 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); |
465 | return (R_CURSOR); | 541 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); |
466 | if (!strcmp(s, "R_FIRST")) | 542 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); |
467 | return (R_FIRST); | 543 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); |
468 | if (!strcmp(s, "R_IAFTER")) | 544 | if (!strcmp(s, "R_LAST")) return (R_LAST); |
469 | return (R_IAFTER); | 545 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); |
470 | if (!strcmp(s, "R_IBEFORE")) | 546 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); |
471 | return (R_IBEFORE); | 547 | if (!strcmp(s, "R_PREV")) return (R_PREV); |
472 | if (!strcmp(s, "R_LAST")) | 548 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); |
473 | return (R_LAST); | 549 | |
474 | if (!strcmp(s, "R_NEXT")) | ||
475 | return (R_NEXT); | ||
476 | if (!strcmp(s, "R_NOOVERWRITE")) | ||
477 | return (R_NOOVERWRITE); | ||
478 | if (!strcmp(s, "R_PREV")) | ||
479 | return (R_PREV); | ||
480 | if (!strcmp(s, "R_SETCURSOR")) | ||
481 | return (R_SETCURSOR); | ||
482 | err("line %lu: %s: unknown flag", lineno, s); | 550 | err("line %lu: %s: unknown flag", lineno, s); |
483 | /* NOTREACHED */ | 551 | /* NOTREACHED */ |
484 | } | 552 | } |
553 | |||
554 | char * | ||
555 | sflags(flags) | ||
556 | int flags; | ||
557 | { | ||
558 | switch (flags) { | ||
559 | case R_CURSOR: return ("R_CURSOR"); | ||
560 | case R_FIRST: return ("R_FIRST"); | ||
561 | case R_IAFTER: return ("R_IAFTER"); | ||
562 | case R_IBEFORE: return ("R_IBEFORE"); | ||
563 | case R_LAST: return ("R_LAST"); | ||
564 | case R_NEXT: return ("R_NEXT"); | ||
565 | case R_NOOVERWRITE: return ("R_NOOVERWRITE"); | ||
566 | case R_PREV: return ("R_PREV"); | ||
567 | case R_SETCURSOR: return ("R_SETCURSOR"); | ||
568 | } | ||
569 | |||
570 | return ("UNKNOWN!"); | ||
571 | } | ||
485 | 572 | ||
486 | DBTYPE | 573 | DBTYPE |
487 | dbtype(s) | 574 | dbtype(s) |
@@ -513,7 +600,7 @@ setinfo(type, s) | |||
513 | if (!isdigit(*eq)) | 600 | if (!isdigit(*eq)) |
514 | err("%s: structure set statement must be a number", s); | 601 | err("%s: structure set statement must be a number", s); |
515 | 602 | ||
516 | switch(type) { | 603 | switch (type) { |
517 | case DB_BTREE: | 604 | case DB_BTREE: |
518 | if (!strcmp("flags", s)) { | 605 | if (!strcmp("flags", s)) { |
519 | ib.flags = atoi(eq); | 606 | ib.flags = atoi(eq); |
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test index 4073310a31..acbd3f49e1 100644 --- a/src/regress/lib/libc/db/run.test +++ b/src/regress/lib/libc/db/run.test | |||
@@ -1,19 +1,27 @@ | |||
1 | #!/bin/sh - | 1 | #!/bin/sh - |
2 | # $NetBSD: run.test,v 1.7 1995/04/20 22:39:27 cgd Exp $ | ||
3 | # | 2 | # |
4 | # @(#)run.test 8.8 (Berkeley) 6/16/94 | 3 | # $NetBSD: run.test,v 1.8 1996/05/03 21:57:51 cgd Exp $ |
4 | # @(#)run.test 8.10 (Berkeley) 7/26/94 | ||
5 | # | 5 | # |
6 | 6 | ||
7 | # db regression tests | 7 | # db regression tests |
8 | main() | 8 | main() |
9 | { | 9 | { |
10 | 10 | ||
11 | DICT=/usr/share/dict/web2 | 11 | PROG=./dbtest |
12 | PROG=./dbtest | 12 | TMP1=t1 |
13 | TMP1=t1 | 13 | TMP2=t2 |
14 | TMP2=t2 | 14 | TMP3=t3 |
15 | TMP3=t3 | ||
16 | 15 | ||
16 | if [ -f /usr/share/dict/words ]; then | ||
17 | DICT=/usr/share/dict/words | ||
18 | elif [ -f /usr/dict/words ]; then | ||
19 | DICT=/usr/dict/words | ||
20 | else | ||
21 | echo 'run.test: no dictionary' | ||
22 | exit 1 | ||
23 | fi | ||
24 | |||
17 | if [ $# -eq 0 ]; then | 25 | if [ $# -eq 0 ]; then |
18 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | 26 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do |
19 | test$t | 27 | test$t |
@@ -345,7 +353,7 @@ test7() | |||
345 | for (i = 1; i <= 120; ++i) | 353 | for (i = 1; i <= 120; ++i) |
346 | printf("%05d: input key %d: %s\n", i, i, $0); | 354 | printf("%05d: input key %d: %s\n", i, i, $0); |
347 | printf("%05d: input key %d: %s\n", 120, 120, $0); | 355 | printf("%05d: input key %d: %s\n", 120, 120, $0); |
348 | printf("get failed, no such key\n"); | 356 | printf("seq failed, no such key\n"); |
349 | printf("%05d: input key %d: %s\n", 1, 1, $0); | 357 | printf("%05d: input key %d: %s\n", 1, 1, $0); |
350 | printf("%05d: input key %d: %s\n", 2, 2, $0); | 358 | printf("%05d: input key %d: %s\n", 2, 2, $0); |
351 | exit; | 359 | exit; |
@@ -364,10 +372,10 @@ test7() | |||
364 | for (i = 1; i <= 120; ++i) | 372 | for (i = 1; i <= 120; ++i) |
365 | printf("s\n"); | 373 | printf("s\n"); |
366 | printf("fR_CURSOR\ns\nk120\n"); | 374 | printf("fR_CURSOR\ns\nk120\n"); |
367 | printf("r\nk120\n"); | 375 | printf("r\n"); |
368 | printf("fR_NEXT\ns\n"); | 376 | printf("fR_NEXT\ns\n"); |
369 | printf("fR_CURSOR\ns\nk1\n"); | 377 | printf("fR_CURSOR\ns\nk1\n"); |
370 | printf("r\nk1\n"); | 378 | printf("r\n"); |
371 | printf("fR_FIRST\ns\n"); | 379 | printf("fR_FIRST\ns\n"); |
372 | }' > $TMP2 | 380 | }' > $TMP2 |
373 | $PROG -o $TMP3 recno $TMP2 | 381 | $PROG -o $TMP3 recno $TMP2 |
@@ -397,8 +405,6 @@ test8() | |||
397 | printf("e\t%d of 10 \n", i); | 405 | printf("e\t%d of 10 \n", i); |
398 | printf("r\nkkey1\nr\nkkey2\n"); | 406 | printf("r\nkkey1\nr\nkkey2\n"); |
399 | } | 407 | } |
400 | printf("e\n"); | ||
401 | printf("eend of test8 run\n"); | ||
402 | }' > $TMP1 | 408 | }' > $TMP1 |
403 | $PROG btree $TMP1 | 409 | $PROG btree $TMP1 |
404 | # $PROG hash $TMP1 | 410 | # $PROG hash $TMP1 |
@@ -459,7 +465,7 @@ test10() | |||
459 | printf("p\nk%d\nd%s\n", ++i, $0); | 465 | printf("p\nk%d\nd%s\n", ++i, $0); |
460 | } | 466 | } |
461 | END { | 467 | END { |
462 | printf("fR_CURSOR\nr\nk1\n"); | 468 | printf("fR_CURSOR\nr\n"); |
463 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | 469 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); |
464 | }' > $TMP2 | 470 | }' > $TMP2 |
465 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | 471 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 |
@@ -573,7 +579,8 @@ test13() | |||
573 | echo g | 579 | echo g |
574 | echo k$i | 580 | echo k$i |
575 | done > $TMP2 | 581 | done > $TMP2 |
576 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | 582 | $PROG -s \ |
583 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
577 | if (cmp -s $TMP1 $TMP3) ; then : | 584 | if (cmp -s $TMP1 $TMP3) ; then : |
578 | else | 585 | else |
579 | echo "test13: $type/$order get failed" | 586 | echo "test13: $type/$order get failed" |