diff options
Diffstat (limited to 'src/regress/lib/libc/db')
-rw-r--r-- | src/regress/lib/libc/db/Makefile | 17 | ||||
-rw-r--r-- | src/regress/lib/libc/db/README | 68 | ||||
-rw-r--r-- | src/regress/lib/libc/db/dbtest.c | 759 | ||||
-rw-r--r-- | src/regress/lib/libc/db/run.test | 706 |
4 files changed, 1550 insertions, 0 deletions
diff --git a/src/regress/lib/libc/db/Makefile b/src/regress/lib/libc/db/Makefile new file mode 100644 index 0000000000..d42dc96315 --- /dev/null +++ b/src/regress/lib/libc/db/Makefile | |||
@@ -0,0 +1,17 @@ | |||
1 | # $NetBSD: Makefile,v 1.11 1995/12/12 01:54:15 cgd Exp $ | ||
2 | # @(#)Makefile 8.1 (Berkeley) 6/4/93 | ||
3 | |||
4 | PROG= dbtest | ||
5 | |||
6 | # add -DSTATISTICS to CFLAGS to get usage statistics. Note that | ||
7 | # for this to work, libc must be compiled with -DSTATISTICS as well | ||
8 | CFLAGS+= -g -D__DBINTERFACE_PRIVATE -DDEBUG | ||
9 | NOMAN= noman | ||
10 | CLEANFILES+= t1 t2 t3 | ||
11 | |||
12 | install: | ||
13 | |||
14 | regress: | ||
15 | sh ${.CURDIR}/run.test | ||
16 | |||
17 | .include <bsd.prog.mk> | ||
diff --git a/src/regress/lib/libc/db/README b/src/regress/lib/libc/db/README new file mode 100644 index 0000000000..fddf5c3d5a --- /dev/null +++ b/src/regress/lib/libc/db/README | |||
@@ -0,0 +1,68 @@ | |||
1 | # $NetBSD: README,v 1.5 1996/05/03 21:54:19 cgd Exp $ | ||
2 | # @(#)README 8.8 (Berkeley) 7/31/94 | ||
3 | |||
4 | To run the tests, enter "make regress". | ||
5 | |||
6 | Fairly large files (the command files) are built in this directory during | ||
7 | the test runs, and even larger files (the database files) are created in | ||
8 | "/var/tmp". If the latter directory doesn't exist, set the environmental | ||
9 | variable TMPDIR to a directory where the files can be built. | ||
10 | |||
11 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= | ||
12 | The script file consists of lines with an initial character which is | ||
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: | ||
17 | |||
18 | c: compare a record | ||
19 | + must be followed by [kK][dD]; the data value in the database | ||
20 | associated with the specified key is compared to the specified | ||
21 | data value. | ||
22 | e: echo a string | ||
23 | + writes out the rest of the line into the output file; if the | ||
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 | ||
27 | g: do a get command | ||
28 | + must be followed by [kK] | ||
29 | + writes out the retrieved data DBT. | ||
30 | o [r]: dump [reverse] | ||
31 | + dump the database out, if 'r' is set, in reverse order. | ||
32 | p: do a put command | ||
33 | + must be followed by [kK][dD] | ||
34 | r: do a del command | ||
35 | + must be followed by [kK] unless R_CURSOR flag set. | ||
36 | S: sync the database | ||
37 | s: do a seq command | ||
38 | + must be followed by [kK] if R_CURSOR flag set. | ||
39 | + writes out the retrieved data DBT. | ||
40 | |||
41 | Legal key/data characters are as follows: | ||
42 | |||
43 | D [file]: data file | ||
44 | + set the current data value to the contents of the file | ||
45 | d [data]: | ||
46 | + set the current key value to the contents of the line. | ||
47 | K [file]: key file | ||
48 | + set the current key value to the contents of the file | ||
49 | k [data]: | ||
50 | + set the current key value to the contents of the line. | ||
51 | |||
52 | Blank lines, lines with leading white space, and lines with leading | ||
53 | hash marks (#) are ignored. | ||
54 | |||
55 | Options to dbtest are as follows: | ||
56 | |||
57 | -d: Set the DB_LOCK flag. | ||
58 | -f: Use the file argument as the database file. | ||
59 | -i: Use the rest of the argument to set elements in the info | ||
60 | structure. If the type is btree, then "-i cachesize=10240" | ||
61 | will set BTREEINFO.cachesize to 10240. | ||
62 | -o: The rest of the argument is the output file instead of | ||
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. | ||
66 | |||
67 | Dbtest requires two arguments, the type of access "hash", "recno" | ||
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 new file mode 100644 index 0000000000..6ccfba5011 --- /dev/null +++ b/src/regress/lib/libc/db/dbtest.c | |||
@@ -0,0 +1,759 @@ | |||
1 | /* $NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $ */ | ||
2 | |||
3 | /*- | ||
4 | * Copyright (c) 1992, 1993, 1994 | ||
5 | * The Regents of the University of California. All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. All advertising materials mentioning features or use of this software | ||
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by the University of | ||
18 | * California, Berkeley and its contributors. | ||
19 | * 4. Neither the name of the University nor the names of its contributors | ||
20 | * may be used to endorse or promote products derived from this software | ||
21 | * without specific prior written permission. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
33 | * SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | #ifndef lint | ||
37 | static char copyright[] = | ||
38 | "@(#) Copyright (c) 1992, 1993, 1994\n\ | ||
39 | The Regents of the University of California. All rights reserved.\n"; | ||
40 | #endif /* not lint */ | ||
41 | |||
42 | #ifndef lint | ||
43 | #if 0 | ||
44 | static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; | ||
45 | #else | ||
46 | static char rcsid[] = "$NetBSD: dbtest.c,v 1.8 1996/05/03 21:57:48 cgd Exp $"; | ||
47 | #endif | ||
48 | #endif /* not lint */ | ||
49 | |||
50 | #include <sys/param.h> | ||
51 | #include <sys/stat.h> | ||
52 | |||
53 | #include <ctype.h> | ||
54 | #include <errno.h> | ||
55 | #include <fcntl.h> | ||
56 | #include <limits.h> | ||
57 | #include <stdio.h> | ||
58 | #include <stdlib.h> | ||
59 | #include <string.h> | ||
60 | #include <unistd.h> | ||
61 | |||
62 | #include <db.h> | ||
63 | |||
64 | enum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA }; | ||
65 | |||
66 | void compare __P((DBT *, DBT *)); | ||
67 | DBTYPE dbtype __P((char *)); | ||
68 | void dump __P((DB *, int)); | ||
69 | void err __P((const char *, ...)); | ||
70 | void get __P((DB *, DBT *)); | ||
71 | void getdata __P((DB *, DBT *, DBT *)); | ||
72 | void put __P((DB *, DBT *, DBT *)); | ||
73 | void rem __P((DB *, DBT *)); | ||
74 | char *sflags __P((int)); | ||
75 | void synk __P((DB *)); | ||
76 | void *rfile __P((char *, size_t *)); | ||
77 | void seq __P((DB *, DBT *)); | ||
78 | u_int setflags __P((char *)); | ||
79 | void *setinfo __P((DBTYPE, char *)); | ||
80 | void usage __P((void)); | ||
81 | void *xmalloc __P((char *, size_t)); | ||
82 | |||
83 | DBTYPE type; /* Database type. */ | ||
84 | void *infop; /* Iflags. */ | ||
85 | u_long lineno; /* Current line in test script. */ | ||
86 | u_int flags; /* Current DB flags. */ | ||
87 | int ofd = STDOUT_FILENO; /* Standard output fd. */ | ||
88 | |||
89 | DB *XXdbp; /* Global for gdb. */ | ||
90 | int XXlineno; /* Fast breakpoint for gdb. */ | ||
91 | |||
92 | int | ||
93 | main(argc, argv) | ||
94 | int argc; | ||
95 | char *argv[]; | ||
96 | { | ||
97 | extern int optind; | ||
98 | extern char *optarg; | ||
99 | enum S command, state; | ||
100 | DB *dbp; | ||
101 | DBT data, key, keydata; | ||
102 | size_t len; | ||
103 | int ch, oflags, sflag; | ||
104 | char *fname, *infoarg, *p, *t, buf[8 * 1024]; | ||
105 | |||
106 | infoarg = NULL; | ||
107 | fname = NULL; | ||
108 | oflags = O_CREAT | O_RDWR; | ||
109 | sflag = 0; | ||
110 | while ((ch = getopt(argc, argv, "f:i:lo:s")) != -1) | ||
111 | switch (ch) { | ||
112 | case 'f': | ||
113 | fname = optarg; | ||
114 | break; | ||
115 | case 'i': | ||
116 | infoarg = optarg; | ||
117 | break; | ||
118 | case 'l': | ||
119 | oflags |= DB_LOCK; | ||
120 | break; | ||
121 | case 'o': | ||
122 | if ((ofd = open(optarg, | ||
123 | O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | ||
124 | err("%s: %s", optarg, strerror(errno)); | ||
125 | break; | ||
126 | case 's': | ||
127 | sflag = 1; | ||
128 | break; | ||
129 | case '?': | ||
130 | default: | ||
131 | usage(); | ||
132 | } | ||
133 | argc -= optind; | ||
134 | argv += optind; | ||
135 | |||
136 | if (argc != 2) | ||
137 | usage(); | ||
138 | |||
139 | /* Set the type. */ | ||
140 | type = dbtype(*argv++); | ||
141 | |||
142 | /* Open the descriptor file. */ | ||
143 | if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) | ||
144 | err("%s: %s", *argv, strerror(errno)); | ||
145 | |||
146 | /* Set up the db structure as necessary. */ | ||
147 | if (infoarg == NULL) | ||
148 | infop = NULL; | ||
149 | else | ||
150 | for (p = strtok(infoarg, ",\t "); p != NULL; | ||
151 | p = strtok(0, ",\t ")) | ||
152 | if (*p != '\0') | ||
153 | infop = setinfo(type, p); | ||
154 | |||
155 | /* | ||
156 | * Open the DB. Delete any preexisting copy, you almost never | ||
157 | * want it around, and it often screws up tests. | ||
158 | */ | ||
159 | if (fname == NULL) { | ||
160 | p = getenv("TMPDIR"); | ||
161 | if (p == NULL) | ||
162 | p = "/var/tmp"; | ||
163 | (void)sprintf(buf, "%s/__dbtest", p); | ||
164 | fname = buf; | ||
165 | (void)unlink(buf); | ||
166 | } else if (!sflag) | ||
167 | (void)unlink(fname); | ||
168 | |||
169 | if ((dbp = dbopen(fname, | ||
170 | oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) | ||
171 | err("dbopen: %s", strerror(errno)); | ||
172 | XXdbp = dbp; | ||
173 | |||
174 | state = COMMAND; | ||
175 | for (lineno = 1; | ||
176 | (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { | ||
177 | /* Delete the newline, displaying the key/data is easier. */ | ||
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) { | ||
187 | case 'c': /* compare */ | ||
188 | if (state != COMMAND) | ||
189 | err("line %lu: not expecting command", lineno); | ||
190 | state = KEY; | ||
191 | command = COMPARE; | ||
192 | break; | ||
193 | case 'e': /* echo */ | ||
194 | if (state != COMMAND) | ||
195 | err("line %lu: not expecting command", lineno); | ||
196 | /* Don't display the newline, if CR at EOL. */ | ||
197 | if (p[len - 2] == '\r') | ||
198 | --len; | ||
199 | if (write(ofd, p + 1, len - 1) != len - 1 || | ||
200 | write(ofd, "\n", 1) != 1) | ||
201 | err("write: %s", strerror(errno)); | ||
202 | break; | ||
203 | case 'g': /* get */ | ||
204 | if (state != COMMAND) | ||
205 | err("line %lu: not expecting command", lineno); | ||
206 | state = KEY; | ||
207 | command = GET; | ||
208 | break; | ||
209 | case 'p': /* put */ | ||
210 | if (state != COMMAND) | ||
211 | err("line %lu: not expecting command", lineno); | ||
212 | state = KEY; | ||
213 | command = PUT; | ||
214 | break; | ||
215 | case 'r': /* remove */ | ||
216 | if (state != COMMAND) | ||
217 | err("line %lu: not expecting command", lineno); | ||
218 | if (flags == R_CURSOR) { | ||
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; | ||
231 | break; | ||
232 | case 's': /* seq */ | ||
233 | if (state != COMMAND) | ||
234 | err("line %lu: not expecting command", lineno); | ||
235 | if (flags == R_CURSOR) { | ||
236 | state = KEY; | ||
237 | command = SEQ; | ||
238 | } else | ||
239 | seq(dbp, &key); | ||
240 | break; | ||
241 | case 'f': | ||
242 | flags = setflags(p + 1); | ||
243 | break; | ||
244 | case 'D': /* data file */ | ||
245 | if (state != DATA) | ||
246 | err("line %lu: not expecting data", lineno); | ||
247 | data.data = rfile(p + 1, &data.size); | ||
248 | goto ldata; | ||
249 | case 'd': /* data */ | ||
250 | if (state != DATA) | ||
251 | err("line %lu: not expecting data", lineno); | ||
252 | data.data = xmalloc(p + 1, len - 1); | ||
253 | data.size = len - 1; | ||
254 | ldata: switch (command) { | ||
255 | case COMPARE: | ||
256 | compare(&keydata, &data); | ||
257 | break; | ||
258 | case PUT: | ||
259 | put(dbp, &key, &data); | ||
260 | break; | ||
261 | default: | ||
262 | err("line %lu: command doesn't take data", | ||
263 | lineno); | ||
264 | } | ||
265 | if (type != DB_RECNO) | ||
266 | free(key.data); | ||
267 | free(data.data); | ||
268 | state = COMMAND; | ||
269 | break; | ||
270 | case 'K': /* key file */ | ||
271 | if (state != KEY) | ||
272 | err("line %lu: not expecting a key", lineno); | ||
273 | if (type == DB_RECNO) | ||
274 | err("line %lu: 'K' not available for recno", | ||
275 | lineno); | ||
276 | key.data = rfile(p + 1, &key.size); | ||
277 | goto lkey; | ||
278 | case 'k': /* key */ | ||
279 | if (state != KEY) | ||
280 | err("line %lu: not expecting a key", lineno); | ||
281 | if (type == DB_RECNO) { | ||
282 | static recno_t recno; | ||
283 | recno = atoi(p + 1); | ||
284 | key.data = &recno; | ||
285 | key.size = sizeof(recno); | ||
286 | } else { | ||
287 | key.data = xmalloc(p + 1, len - 1); | ||
288 | key.size = len - 1; | ||
289 | } | ||
290 | lkey: switch (command) { | ||
291 | case COMPARE: | ||
292 | getdata(dbp, &key, &keydata); | ||
293 | state = DATA; | ||
294 | break; | ||
295 | case GET: | ||
296 | get(dbp, &key); | ||
297 | if (type != DB_RECNO) | ||
298 | free(key.data); | ||
299 | state = COMMAND; | ||
300 | break; | ||
301 | case PUT: | ||
302 | state = DATA; | ||
303 | break; | ||
304 | case REMOVE: | ||
305 | rem(dbp, &key); | ||
306 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
307 | free(key.data); | ||
308 | state = COMMAND; | ||
309 | break; | ||
310 | case SEQ: | ||
311 | seq(dbp, &key); | ||
312 | if ((type != DB_RECNO) && (flags != R_CURSOR)) | ||
313 | free(key.data); | ||
314 | state = COMMAND; | ||
315 | break; | ||
316 | default: | ||
317 | err("line %lu: command doesn't take a key", | ||
318 | lineno); | ||
319 | } | ||
320 | break; | ||
321 | case 'o': | ||
322 | dump(dbp, p[1] == 'r'); | ||
323 | break; | ||
324 | default: | ||
325 | err("line %lu: %s: unknown command character", | ||
326 | lineno, p); | ||
327 | } | ||
328 | } | ||
329 | #ifdef STATISTICS | ||
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) | ||
335 | __bt_stat(dbp); | ||
336 | #endif | ||
337 | if (dbp->close(dbp)) | ||
338 | err("db->close: %s", strerror(errno)); | ||
339 | (void)close(ofd); | ||
340 | exit(0); | ||
341 | } | ||
342 | |||
343 | #define NOOVERWRITE "put failed, would overwrite key\n" | ||
344 | |||
345 | void | ||
346 | compare(db1, db2) | ||
347 | DBT *db1, *db2; | ||
348 | { | ||
349 | register size_t len; | ||
350 | register u_char *p1, *p2; | ||
351 | |||
352 | if (db1->size != db2->size) | ||
353 | printf("compare failed: key->data len %lu != data len %lu\n", | ||
354 | db1->size, db2->size); | ||
355 | |||
356 | len = MIN(db1->size, db2->size); | ||
357 | for (p1 = db1->data, p2 = db2->data; len--;) | ||
358 | if (*p1++ != *p2++) { | ||
359 | printf("compare failed at offset %d\n", | ||
360 | p1 - (u_char *)db1->data); | ||
361 | break; | ||
362 | } | ||
363 | } | ||
364 | |||
365 | void | ||
366 | get(dbp, kp) | ||
367 | DB *dbp; | ||
368 | DBT *kp; | ||
369 | { | ||
370 | DBT data; | ||
371 | |||
372 | switch (dbp->get(dbp, kp, &data, flags)) { | ||
373 | case 0: | ||
374 | (void)write(ofd, data.data, data.size); | ||
375 | if (ofd == STDOUT_FILENO) | ||
376 | (void)write(ofd, "\n", 1); | ||
377 | break; | ||
378 | case -1: | ||
379 | err("line %lu: get: %s", lineno, strerror(errno)); | ||
380 | /* NOTREACHED */ | ||
381 | case 1: | ||
382 | #define NOSUCHKEY "get failed, no such key\n" | ||
383 | if (ofd != STDOUT_FILENO) | ||
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 | ||
389 | break; | ||
390 | } | ||
391 | } | ||
392 | |||
393 | void | ||
394 | getdata(dbp, kp, dp) | ||
395 | DB *dbp; | ||
396 | DBT *kp, *dp; | ||
397 | { | ||
398 | switch (dbp->get(dbp, kp, dp, flags)) { | ||
399 | case 0: | ||
400 | return; | ||
401 | case -1: | ||
402 | err("line %lu: getdata: %s", lineno, strerror(errno)); | ||
403 | /* NOTREACHED */ | ||
404 | case 1: | ||
405 | err("line %lu: getdata failed, no such key", lineno); | ||
406 | /* NOTREACHED */ | ||
407 | } | ||
408 | } | ||
409 | |||
410 | void | ||
411 | put(dbp, kp, dp) | ||
412 | DB *dbp; | ||
413 | DBT *kp, *dp; | ||
414 | { | ||
415 | switch (dbp->put(dbp, kp, dp, flags)) { | ||
416 | case 0: | ||
417 | break; | ||
418 | case -1: | ||
419 | err("line %lu: put: %s", lineno, strerror(errno)); | ||
420 | /* NOTREACHED */ | ||
421 | case 1: | ||
422 | (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1); | ||
423 | break; | ||
424 | } | ||
425 | } | ||
426 | |||
427 | void | ||
428 | rem(dbp, kp) | ||
429 | DB *dbp; | ||
430 | DBT *kp; | ||
431 | { | ||
432 | switch (dbp->del(dbp, kp, flags)) { | ||
433 | case 0: | ||
434 | break; | ||
435 | case -1: | ||
436 | err("line %lu: rem: %s", lineno, strerror(errno)); | ||
437 | /* NOTREACHED */ | ||
438 | case 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 | ||
449 | break; | ||
450 | } | ||
451 | } | ||
452 | |||
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 | ||
467 | seq(dbp, kp) | ||
468 | DB *dbp; | ||
469 | DBT *kp; | ||
470 | { | ||
471 | DBT data; | ||
472 | |||
473 | switch (dbp->seq(dbp, kp, &data, flags)) { | ||
474 | case 0: | ||
475 | (void)write(ofd, data.data, data.size); | ||
476 | if (ofd == STDOUT_FILENO) | ||
477 | (void)write(ofd, "\n", 1); | ||
478 | break; | ||
479 | case -1: | ||
480 | err("line %lu: seq: %s", lineno, strerror(errno)); | ||
481 | /* NOTREACHED */ | ||
482 | case 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 | ||
493 | break; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | void | ||
498 | dump(dbp, rev) | ||
499 | DB *dbp; | ||
500 | int rev; | ||
501 | { | ||
502 | DBT key, data; | ||
503 | int flags, nflags; | ||
504 | |||
505 | if (rev) { | ||
506 | flags = R_LAST; | ||
507 | nflags = R_PREV; | ||
508 | } else { | ||
509 | flags = R_FIRST; | ||
510 | nflags = R_NEXT; | ||
511 | } | ||
512 | for (;; flags = nflags) | ||
513 | switch (dbp->seq(dbp, &key, &data, flags)) { | ||
514 | case 0: | ||
515 | (void)write(ofd, data.data, data.size); | ||
516 | if (ofd == STDOUT_FILENO) | ||
517 | (void)write(ofd, "\n", 1); | ||
518 | break; | ||
519 | case 1: | ||
520 | goto done; | ||
521 | case -1: | ||
522 | err("line %lu: (dump) seq: %s", | ||
523 | lineno, strerror(errno)); | ||
524 | /* NOTREACHED */ | ||
525 | } | ||
526 | done: return; | ||
527 | } | ||
528 | |||
529 | u_int | ||
530 | setflags(s) | ||
531 | char *s; | ||
532 | { | ||
533 | char *p; | ||
534 | |||
535 | for (; isspace(*s); ++s); | ||
536 | if (*s == '\n' || *s == '\0') | ||
537 | return (0); | ||
538 | if ((p = strchr(s, '\n')) != NULL) | ||
539 | *p = '\0'; | ||
540 | if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); | ||
541 | if (!strcmp(s, "R_FIRST")) return (R_FIRST); | ||
542 | if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); | ||
543 | if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); | ||
544 | if (!strcmp(s, "R_LAST")) return (R_LAST); | ||
545 | if (!strcmp(s, "R_NEXT")) return (R_NEXT); | ||
546 | if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); | ||
547 | if (!strcmp(s, "R_PREV")) return (R_PREV); | ||
548 | if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); | ||
549 | |||
550 | err("line %lu: %s: unknown flag", lineno, s); | ||
551 | /* NOTREACHED */ | ||
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 | } | ||
572 | |||
573 | DBTYPE | ||
574 | dbtype(s) | ||
575 | char *s; | ||
576 | { | ||
577 | if (!strcmp(s, "btree")) | ||
578 | return (DB_BTREE); | ||
579 | if (!strcmp(s, "hash")) | ||
580 | return (DB_HASH); | ||
581 | if (!strcmp(s, "recno")) | ||
582 | return (DB_RECNO); | ||
583 | err("%s: unknown type (use btree, hash or recno)", s); | ||
584 | /* NOTREACHED */ | ||
585 | } | ||
586 | |||
587 | void * | ||
588 | setinfo(type, s) | ||
589 | DBTYPE type; | ||
590 | char *s; | ||
591 | { | ||
592 | static BTREEINFO ib; | ||
593 | static HASHINFO ih; | ||
594 | static RECNOINFO rh; | ||
595 | char *eq; | ||
596 | |||
597 | if ((eq = strchr(s, '=')) == NULL) | ||
598 | err("%s: illegal structure set statement", s); | ||
599 | *eq++ = '\0'; | ||
600 | if (!isdigit(*eq)) | ||
601 | err("%s: structure set statement must be a number", s); | ||
602 | |||
603 | switch (type) { | ||
604 | case DB_BTREE: | ||
605 | if (!strcmp("flags", s)) { | ||
606 | ib.flags = atoi(eq); | ||
607 | return (&ib); | ||
608 | } | ||
609 | if (!strcmp("cachesize", s)) { | ||
610 | ib.cachesize = atoi(eq); | ||
611 | return (&ib); | ||
612 | } | ||
613 | if (!strcmp("maxkeypage", s)) { | ||
614 | ib.maxkeypage = atoi(eq); | ||
615 | return (&ib); | ||
616 | } | ||
617 | if (!strcmp("minkeypage", s)) { | ||
618 | ib.minkeypage = atoi(eq); | ||
619 | return (&ib); | ||
620 | } | ||
621 | if (!strcmp("lorder", s)) { | ||
622 | ib.lorder = atoi(eq); | ||
623 | return (&ib); | ||
624 | } | ||
625 | if (!strcmp("psize", s)) { | ||
626 | ib.psize = atoi(eq); | ||
627 | return (&ib); | ||
628 | } | ||
629 | break; | ||
630 | case DB_HASH: | ||
631 | if (!strcmp("bsize", s)) { | ||
632 | ih.bsize = atoi(eq); | ||
633 | return (&ih); | ||
634 | } | ||
635 | if (!strcmp("ffactor", s)) { | ||
636 | ih.ffactor = atoi(eq); | ||
637 | return (&ih); | ||
638 | } | ||
639 | if (!strcmp("nelem", s)) { | ||
640 | ih.nelem = atoi(eq); | ||
641 | return (&ih); | ||
642 | } | ||
643 | if (!strcmp("cachesize", s)) { | ||
644 | ih.cachesize = atoi(eq); | ||
645 | return (&ih); | ||
646 | } | ||
647 | if (!strcmp("lorder", s)) { | ||
648 | ih.lorder = atoi(eq); | ||
649 | return (&ih); | ||
650 | } | ||
651 | break; | ||
652 | case DB_RECNO: | ||
653 | if (!strcmp("flags", s)) { | ||
654 | rh.flags = atoi(eq); | ||
655 | return (&rh); | ||
656 | } | ||
657 | if (!strcmp("cachesize", s)) { | ||
658 | rh.cachesize = atoi(eq); | ||
659 | return (&rh); | ||
660 | } | ||
661 | if (!strcmp("lorder", s)) { | ||
662 | rh.lorder = atoi(eq); | ||
663 | return (&rh); | ||
664 | } | ||
665 | if (!strcmp("reclen", s)) { | ||
666 | rh.reclen = atoi(eq); | ||
667 | return (&rh); | ||
668 | } | ||
669 | if (!strcmp("bval", s)) { | ||
670 | rh.bval = atoi(eq); | ||
671 | return (&rh); | ||
672 | } | ||
673 | if (!strcmp("psize", s)) { | ||
674 | rh.psize = atoi(eq); | ||
675 | return (&rh); | ||
676 | } | ||
677 | break; | ||
678 | } | ||
679 | err("%s: unknown structure value", s); | ||
680 | /* NOTREACHED */ | ||
681 | } | ||
682 | |||
683 | void * | ||
684 | rfile(name, lenp) | ||
685 | char *name; | ||
686 | size_t *lenp; | ||
687 | { | ||
688 | struct stat sb; | ||
689 | void *p; | ||
690 | int fd; | ||
691 | char *np; | ||
692 | |||
693 | for (; isspace(*name); ++name); | ||
694 | if ((np = strchr(name, '\n')) != NULL) | ||
695 | *np = '\0'; | ||
696 | if ((fd = open(name, O_RDONLY, 0)) < 0 || | ||
697 | fstat(fd, &sb)) | ||
698 | err("%s: %s\n", name, strerror(errno)); | ||
699 | #ifdef NOT_PORTABLE | ||
700 | if (sb.st_size > (off_t)SIZE_T_MAX) | ||
701 | err("%s: %s\n", name, strerror(E2BIG)); | ||
702 | #endif | ||
703 | if ((p = (void *)malloc((u_int)sb.st_size)) == NULL) | ||
704 | err("%s", strerror(errno)); | ||
705 | (void)read(fd, p, (int)sb.st_size); | ||
706 | *lenp = sb.st_size; | ||
707 | (void)close(fd); | ||
708 | return (p); | ||
709 | } | ||
710 | |||
711 | void * | ||
712 | xmalloc(text, len) | ||
713 | char *text; | ||
714 | size_t len; | ||
715 | { | ||
716 | void *p; | ||
717 | |||
718 | if ((p = (void *)malloc(len)) == NULL) | ||
719 | err("%s", strerror(errno)); | ||
720 | memmove(p, text, len); | ||
721 | return (p); | ||
722 | } | ||
723 | |||
724 | void | ||
725 | usage() | ||
726 | { | ||
727 | (void)fprintf(stderr, | ||
728 | "usage: dbtest [-l] [-f file] [-i info] [-o file] type script\n"); | ||
729 | exit(1); | ||
730 | } | ||
731 | |||
732 | #ifdef __STDC__ | ||
733 | #include <stdarg.h> | ||
734 | #else | ||
735 | #include <varargs.h> | ||
736 | #endif | ||
737 | |||
738 | void | ||
739 | #ifdef __STDC__ | ||
740 | err(const char *fmt, ...) | ||
741 | #else | ||
742 | err(fmt, va_alist) | ||
743 | char *fmt; | ||
744 | va_dcl | ||
745 | #endif | ||
746 | { | ||
747 | va_list ap; | ||
748 | #ifdef __STDC__ | ||
749 | va_start(ap, fmt); | ||
750 | #else | ||
751 | va_start(ap); | ||
752 | #endif | ||
753 | (void)fprintf(stderr, "dbtest: "); | ||
754 | (void)vfprintf(stderr, fmt, ap); | ||
755 | va_end(ap); | ||
756 | (void)fprintf(stderr, "\n"); | ||
757 | exit(1); | ||
758 | /* NOTREACHED */ | ||
759 | } | ||
diff --git a/src/regress/lib/libc/db/run.test b/src/regress/lib/libc/db/run.test new file mode 100644 index 0000000000..acbd3f49e1 --- /dev/null +++ b/src/regress/lib/libc/db/run.test | |||
@@ -0,0 +1,706 @@ | |||
1 | #!/bin/sh - | ||
2 | # | ||
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 | # | ||
6 | |||
7 | # db regression tests | ||
8 | main() | ||
9 | { | ||
10 | |||
11 | PROG=./dbtest | ||
12 | TMP1=t1 | ||
13 | TMP2=t2 | ||
14 | TMP3=t3 | ||
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 | |||
25 | if [ $# -eq 0 ]; then | ||
26 | for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do | ||
27 | test$t | ||
28 | done | ||
29 | else | ||
30 | while [ $# -gt 0 ] | ||
31 | do case "$1" in | ||
32 | test*) | ||
33 | $1;; | ||
34 | [0-9]*) | ||
35 | test$1;; | ||
36 | btree) | ||
37 | for t in 1 2 3 7 8 9 10 12 13; do | ||
38 | test$t | ||
39 | done;; | ||
40 | hash) | ||
41 | for t in 1 2 3 8 13 20; do | ||
42 | test$t | ||
43 | done;; | ||
44 | recno) | ||
45 | for t in 1 2 3 4 5 6 7 10 11; do | ||
46 | test$t | ||
47 | done;; | ||
48 | *) | ||
49 | echo "run.test: unknown test $1" | ||
50 | echo "usage: run.test test# | type" | ||
51 | exit 1 | ||
52 | esac | ||
53 | shift | ||
54 | done | ||
55 | fi | ||
56 | rm -f $TMP1 $TMP2 $TMP3 | ||
57 | exit 0 | ||
58 | } | ||
59 | |||
60 | # Take the first hundred entries in the dictionary, and make them | ||
61 | # be key/data pairs. | ||
62 | test1() | ||
63 | { | ||
64 | echo "Test 1: btree, hash: small key, small data pairs" | ||
65 | sed 200q $DICT > $TMP1 | ||
66 | for type in btree hash; do | ||
67 | rm -f $TMP2 $TMP3 | ||
68 | for i in `sed 200q $DICT`; do | ||
69 | echo p | ||
70 | echo k$i | ||
71 | echo d$i | ||
72 | echo g | ||
73 | echo k$i | ||
74 | done > $TMP2 | ||
75 | $PROG -o $TMP3 $type $TMP2 | ||
76 | if (cmp -s $TMP1 $TMP3) ; then : | ||
77 | else | ||
78 | echo "test1: type $type: failed" | ||
79 | exit 1 | ||
80 | fi | ||
81 | done | ||
82 | echo "Test 1: recno: small key, small data pairs" | ||
83 | rm -f $TMP2 $TMP3 | ||
84 | sed 200q $DICT | | ||
85 | awk '{ | ||
86 | ++i; | ||
87 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
88 | }' > $TMP2 | ||
89 | $PROG -o $TMP3 recno $TMP2 | ||
90 | if (cmp -s $TMP1 $TMP3) ; then : | ||
91 | else | ||
92 | echo "test1: type recno: failed" | ||
93 | exit 1 | ||
94 | fi | ||
95 | } | ||
96 | |||
97 | # Take the first 200 entries in the dictionary, and give them | ||
98 | # each a medium size data entry. | ||
99 | test2() | ||
100 | { | ||
101 | echo "Test 2: btree, hash: small key, medium data pairs" | ||
102 | mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz | ||
103 | echo $mdata | | ||
104 | awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 | ||
105 | for type in hash btree; do | ||
106 | rm -f $TMP2 $TMP3 | ||
107 | for i in `sed 200q $DICT`; do | ||
108 | echo p | ||
109 | echo k$i | ||
110 | echo d$mdata | ||
111 | echo g | ||
112 | echo k$i | ||
113 | done > $TMP2 | ||
114 | $PROG -o $TMP3 $type $TMP2 | ||
115 | if (cmp -s $TMP1 $TMP3) ; then : | ||
116 | else | ||
117 | echo "test2: type $type: failed" | ||
118 | exit 1 | ||
119 | fi | ||
120 | done | ||
121 | echo "Test 2: recno: small key, medium data pairs" | ||
122 | rm -f $TMP2 $TMP3 | ||
123 | echo $mdata | | ||
124 | awk '{ for (i = 1; i < 201; ++i) | ||
125 | printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); | ||
126 | }' > $TMP2 | ||
127 | $PROG -o $TMP3 recno $TMP2 | ||
128 | if (cmp -s $TMP1 $TMP3) ; then : | ||
129 | else | ||
130 | echo "test2: type recno: failed" | ||
131 | exit 1 | ||
132 | fi | ||
133 | } | ||
134 | |||
135 | # Insert the programs in /bin with their paths as their keys. | ||
136 | test3() | ||
137 | { | ||
138 | echo "Test 3: hash: small key, big data pairs" | ||
139 | rm -f $TMP1 | ||
140 | (find /bin -type f -print | xargs cat) > $TMP1 | ||
141 | for type in hash; do | ||
142 | rm -f $TMP2 $TMP3 | ||
143 | for i in `find /bin -type f -print`; do | ||
144 | echo p | ||
145 | echo k$i | ||
146 | echo D$i | ||
147 | echo g | ||
148 | echo k$i | ||
149 | done > $TMP2 | ||
150 | $PROG -o $TMP3 $type $TMP2 | ||
151 | if (cmp -s $TMP1 $TMP3) ; then : | ||
152 | else | ||
153 | echo "test3: $type: failed" | ||
154 | exit 1 | ||
155 | fi | ||
156 | done | ||
157 | echo "Test 3: btree: small key, big data pairs" | ||
158 | for psize in 512 16384 65536; do | ||
159 | echo " page size $psize" | ||
160 | for type in btree; do | ||
161 | rm -f $TMP2 $TMP3 | ||
162 | for i in `find /bin -type f -print`; do | ||
163 | echo p | ||
164 | echo k$i | ||
165 | echo D$i | ||
166 | echo g | ||
167 | echo k$i | ||
168 | done > $TMP2 | ||
169 | $PROG -i psize=$psize -o $TMP3 $type $TMP2 | ||
170 | if (cmp -s $TMP1 $TMP3) ; then : | ||
171 | else | ||
172 | echo "test3: $type: page size $psize: failed" | ||
173 | exit 1 | ||
174 | fi | ||
175 | done | ||
176 | done | ||
177 | echo "Test 3: recno: big data pairs" | ||
178 | rm -f $TMP2 $TMP3 | ||
179 | find /bin -type f -print | | ||
180 | awk '{ | ||
181 | ++i; | ||
182 | printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); | ||
183 | }' > $TMP2 | ||
184 | for psize in 512 16384 65536; do | ||
185 | echo " page size $psize" | ||
186 | $PROG -i psize=$psize -o $TMP3 recno $TMP2 | ||
187 | if (cmp -s $TMP1 $TMP3) ; then : | ||
188 | else | ||
189 | echo "test3: recno: page size $psize: failed" | ||
190 | exit 1 | ||
191 | fi | ||
192 | done | ||
193 | } | ||
194 | |||
195 | # Do random recno entries. | ||
196 | test4() | ||
197 | { | ||
198 | echo "Test 4: recno: random entries" | ||
199 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
200 | awk '{ | ||
201 | for (i = 37; i <= 37 + 88 * 17; i += 17) { | ||
202 | if (i % 41) | ||
203 | s = substr($0, 1, i % 41); | ||
204 | else | ||
205 | s = substr($0, 1); | ||
206 | printf("input key %d: %s\n", i, s); | ||
207 | } | ||
208 | for (i = 1; i <= 15; ++i) { | ||
209 | if (i % 41) | ||
210 | s = substr($0, 1, i % 41); | ||
211 | else | ||
212 | s = substr($0, 1); | ||
213 | printf("input key %d: %s\n", i, s); | ||
214 | } | ||
215 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) { | ||
216 | if (i % 41) | ||
217 | s = substr($0, 1, i % 41); | ||
218 | else | ||
219 | s = substr($0, 1); | ||
220 | printf("input key %d: %s\n", i, s); | ||
221 | } | ||
222 | exit | ||
223 | }' > $TMP1 | ||
224 | rm -f $TMP2 $TMP3 | ||
225 | cat $TMP1 | | ||
226 | awk 'BEGIN { | ||
227 | i = 37; | ||
228 | incr = 17; | ||
229 | } | ||
230 | { | ||
231 | printf("p\nk%d\nd%s\n", i, $0); | ||
232 | if (i == 19234 + 61 * 27) | ||
233 | exit; | ||
234 | if (i == 37 + 88 * 17) { | ||
235 | i = 1; | ||
236 | incr = 1; | ||
237 | } else if (i == 15) { | ||
238 | i = 19234; | ||
239 | incr = 27; | ||
240 | } else | ||
241 | i += incr; | ||
242 | } | ||
243 | END { | ||
244 | for (i = 37; i <= 37 + 88 * 17; i += 17) | ||
245 | printf("g\nk%d\n", i); | ||
246 | for (i = 1; i <= 15; ++i) | ||
247 | printf("g\nk%d\n", i); | ||
248 | for (i = 19234; i <= 19234 + 61 * 27; i += 27) | ||
249 | printf("g\nk%d\n", i); | ||
250 | }' > $TMP2 | ||
251 | $PROG -o $TMP3 recno $TMP2 | ||
252 | if (cmp -s $TMP1 $TMP3) ; then : | ||
253 | else | ||
254 | echo "test4: type recno: failed" | ||
255 | exit 1 | ||
256 | fi | ||
257 | } | ||
258 | |||
259 | # Do reverse order recno entries. | ||
260 | test5() | ||
261 | { | ||
262 | echo "Test 5: recno: reverse order entries" | ||
263 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
264 | awk ' { | ||
265 | for (i = 1500; i; --i) { | ||
266 | if (i % 34) | ||
267 | s = substr($0, 1, i % 34); | ||
268 | else | ||
269 | s = substr($0, 1); | ||
270 | printf("input key %d: %s\n", i, s); | ||
271 | } | ||
272 | exit; | ||
273 | }' > $TMP1 | ||
274 | rm -f $TMP2 $TMP3 | ||
275 | cat $TMP1 | | ||
276 | awk 'BEGIN { | ||
277 | i = 1500; | ||
278 | } | ||
279 | { | ||
280 | printf("p\nk%d\nd%s\n", i, $0); | ||
281 | --i; | ||
282 | } | ||
283 | END { | ||
284 | for (i = 1500; i; --i) | ||
285 | printf("g\nk%d\n", i); | ||
286 | }' > $TMP2 | ||
287 | $PROG -o $TMP3 recno $TMP2 | ||
288 | if (cmp -s $TMP1 $TMP3) ; then : | ||
289 | else | ||
290 | echo "test5: type recno: failed" | ||
291 | exit 1 | ||
292 | fi | ||
293 | } | ||
294 | |||
295 | # Do alternating order recno entries. | ||
296 | test6() | ||
297 | { | ||
298 | echo "Test 6: recno: alternating order entries" | ||
299 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
300 | awk ' { | ||
301 | for (i = 1; i < 1200; i += 2) { | ||
302 | if (i % 34) | ||
303 | s = substr($0, 1, i % 34); | ||
304 | else | ||
305 | s = substr($0, 1); | ||
306 | printf("input key %d: %s\n", i, s); | ||
307 | } | ||
308 | for (i = 2; i < 1200; i += 2) { | ||
309 | if (i % 34) | ||
310 | s = substr($0, 1, i % 34); | ||
311 | else | ||
312 | s = substr($0, 1); | ||
313 | printf("input key %d: %s\n", i, s); | ||
314 | } | ||
315 | exit; | ||
316 | }' > $TMP1 | ||
317 | rm -f $TMP2 $TMP3 | ||
318 | cat $TMP1 | | ||
319 | awk 'BEGIN { | ||
320 | i = 1; | ||
321 | even = 0; | ||
322 | } | ||
323 | { | ||
324 | printf("p\nk%d\nd%s\n", i, $0); | ||
325 | i += 2; | ||
326 | if (i >= 1200) { | ||
327 | if (even == 1) | ||
328 | exit; | ||
329 | even = 1; | ||
330 | i = 2; | ||
331 | } | ||
332 | } | ||
333 | END { | ||
334 | for (i = 1; i < 1200; ++i) | ||
335 | printf("g\nk%d\n", i); | ||
336 | }' > $TMP2 | ||
337 | $PROG -o $TMP3 recno $TMP2 | ||
338 | sort -o $TMP1 $TMP1 | ||
339 | sort -o $TMP3 $TMP3 | ||
340 | if (cmp -s $TMP1 $TMP3) ; then : | ||
341 | else | ||
342 | echo "test6: type recno: failed" | ||
343 | exit 1 | ||
344 | fi | ||
345 | } | ||
346 | |||
347 | # Delete cursor record | ||
348 | test7() | ||
349 | { | ||
350 | echo "Test 7: btree, recno: delete cursor record" | ||
351 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
352 | awk '{ | ||
353 | for (i = 1; i <= 120; ++i) | ||
354 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
355 | printf("%05d: input key %d: %s\n", 120, 120, $0); | ||
356 | printf("seq failed, no such key\n"); | ||
357 | printf("%05d: input key %d: %s\n", 1, 1, $0); | ||
358 | printf("%05d: input key %d: %s\n", 2, 2, $0); | ||
359 | exit; | ||
360 | }' > $TMP1 | ||
361 | rm -f $TMP2 $TMP3 | ||
362 | |||
363 | for type in btree recno; do | ||
364 | cat $TMP1 | | ||
365 | awk '{ | ||
366 | if (i == 120) | ||
367 | exit; | ||
368 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
369 | } | ||
370 | END { | ||
371 | printf("fR_NEXT\n"); | ||
372 | for (i = 1; i <= 120; ++i) | ||
373 | printf("s\n"); | ||
374 | printf("fR_CURSOR\ns\nk120\n"); | ||
375 | printf("r\n"); | ||
376 | printf("fR_NEXT\ns\n"); | ||
377 | printf("fR_CURSOR\ns\nk1\n"); | ||
378 | printf("r\n"); | ||
379 | printf("fR_FIRST\ns\n"); | ||
380 | }' > $TMP2 | ||
381 | $PROG -o $TMP3 recno $TMP2 | ||
382 | if (cmp -s $TMP1 $TMP3) ; then : | ||
383 | else | ||
384 | echo "test7: type $type: failed" | ||
385 | exit 1 | ||
386 | fi | ||
387 | done | ||
388 | } | ||
389 | |||
390 | # Make sure that overflow pages are reused. | ||
391 | test8() | ||
392 | { | ||
393 | echo "Test 8: btree, hash: repeated small key, big data pairs" | ||
394 | rm -f $TMP1 | ||
395 | echo "" | | ||
396 | awk 'BEGIN { | ||
397 | for (i = 1; i <= 10; ++i) { | ||
398 | printf("p\nkkey1\nD/bin/sh\n"); | ||
399 | printf("p\nkkey2\nD/bin/csh\n"); | ||
400 | if (i % 8 == 0) { | ||
401 | printf("c\nkkey2\nD/bin/csh\n"); | ||
402 | printf("c\nkkey1\nD/bin/sh\n"); | ||
403 | printf("e\t%d of 10 (comparison)\n", i); | ||
404 | } else | ||
405 | printf("e\t%d of 10 \n", i); | ||
406 | printf("r\nkkey1\nr\nkkey2\n"); | ||
407 | } | ||
408 | }' > $TMP1 | ||
409 | $PROG btree $TMP1 | ||
410 | # $PROG hash $TMP1 | ||
411 | # No explicit test for success. | ||
412 | } | ||
413 | |||
414 | # Test btree duplicate keys | ||
415 | test9() | ||
416 | { | ||
417 | echo "Test 9: btree: duplicate keys" | ||
418 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
419 | awk '{ | ||
420 | for (i = 1; i <= 543; ++i) | ||
421 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
422 | exit; | ||
423 | }' > $TMP1 | ||
424 | rm -f $TMP2 $TMP3 | ||
425 | |||
426 | for type in btree; do | ||
427 | cat $TMP1 | | ||
428 | awk '{ | ||
429 | if (i++ % 2) | ||
430 | printf("p\nkduplicatekey\nd%s\n", $0); | ||
431 | else | ||
432 | printf("p\nkunique%dkey\nd%s\n", i, $0); | ||
433 | } | ||
434 | END { | ||
435 | printf("o\n"); | ||
436 | }' > $TMP2 | ||
437 | $PROG -iflags=1 -o $TMP3 $type $TMP2 | ||
438 | sort -o $TMP3 $TMP3 | ||
439 | if (cmp -s $TMP1 $TMP3) ; then : | ||
440 | else | ||
441 | echo "test9: type $type: failed" | ||
442 | exit 1 | ||
443 | fi | ||
444 | done | ||
445 | } | ||
446 | |||
447 | # Test use of cursor flags without initialization | ||
448 | test10() | ||
449 | { | ||
450 | echo "Test 10: btree, recno: test cursor flag use" | ||
451 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
452 | awk '{ | ||
453 | for (i = 1; i <= 20; ++i) | ||
454 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
455 | exit; | ||
456 | }' > $TMP1 | ||
457 | rm -f $TMP2 $TMP3 | ||
458 | |||
459 | # Test that R_CURSOR doesn't succeed before cursor initialized | ||
460 | for type in btree recno; do | ||
461 | cat $TMP1 | | ||
462 | awk '{ | ||
463 | if (i == 10) | ||
464 | exit; | ||
465 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
466 | } | ||
467 | END { | ||
468 | printf("fR_CURSOR\nr\n"); | ||
469 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
470 | }' > $TMP2 | ||
471 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
472 | if [ -s $TMP3 ] ; then | ||
473 | echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED" | ||
474 | exit 1 | ||
475 | fi | ||
476 | done | ||
477 | for type in btree recno; do | ||
478 | cat $TMP1 | | ||
479 | awk '{ | ||
480 | if (i == 10) | ||
481 | exit; | ||
482 | printf("p\nk%d\nd%s\n", ++i, $0); | ||
483 | } | ||
484 | END { | ||
485 | printf("fR_CURSOR\np\nk1\ndsome data\n"); | ||
486 | printf("eR_CURSOR SHOULD HAVE FAILED\n"); | ||
487 | }' > $TMP2 | ||
488 | $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 | ||
489 | if [ -s $TMP3 ] ; then | ||
490 | echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED" | ||
491 | exit 1 | ||
492 | fi | ||
493 | done | ||
494 | } | ||
495 | |||
496 | # Test insert in reverse order. | ||
497 | test11() | ||
498 | { | ||
499 | echo "Test 11: recno: reverse order insert" | ||
500 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
501 | awk '{ | ||
502 | for (i = 1; i <= 779; ++i) | ||
503 | printf("%05d: input key %d: %s\n", i, i, $0); | ||
504 | exit; | ||
505 | }' > $TMP1 | ||
506 | rm -f $TMP2 $TMP3 | ||
507 | |||
508 | for type in recno; do | ||
509 | cat $TMP1 | | ||
510 | awk '{ | ||
511 | if (i == 0) { | ||
512 | i = 1; | ||
513 | printf("p\nk1\nd%s\n", $0); | ||
514 | printf("%s\n", "fR_IBEFORE"); | ||
515 | } else | ||
516 | printf("p\nk1\nd%s\n", $0); | ||
517 | } | ||
518 | END { | ||
519 | printf("or\n"); | ||
520 | }' > $TMP2 | ||
521 | $PROG -o $TMP3 $type $TMP2 | ||
522 | if (cmp -s $TMP1 $TMP3) ; then : | ||
523 | else | ||
524 | echo "test11: type $type: failed" | ||
525 | exit 1 | ||
526 | fi | ||
527 | done | ||
528 | } | ||
529 | |||
530 | # Take the first 20000 entries in the dictionary, reverse them, and give | ||
531 | # them each a small size data entry. Use a small page size to make sure | ||
532 | # the btree split code gets hammered. | ||
533 | test12() | ||
534 | { | ||
535 | echo "Test 12: btree: lots of keys, small page size" | ||
536 | mdata=abcdefghijklmnopqrstuvwxy | ||
537 | echo $mdata | | ||
538 | awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1 | ||
539 | for type in btree; do | ||
540 | rm -f $TMP2 $TMP3 | ||
541 | for i in `sed 20000q $DICT | rev`; do | ||
542 | echo p | ||
543 | echo k$i | ||
544 | echo d$mdata | ||
545 | echo g | ||
546 | echo k$i | ||
547 | done > $TMP2 | ||
548 | $PROG -i psize=512 -o $TMP3 $type $TMP2 | ||
549 | if (cmp -s $TMP1 $TMP3) ; then : | ||
550 | else | ||
551 | echo "test12: type $type: failed" | ||
552 | exit 1 | ||
553 | fi | ||
554 | done | ||
555 | } | ||
556 | |||
557 | # Test different byte orders. | ||
558 | test13() | ||
559 | { | ||
560 | echo "Test 13: btree, hash: differing byte orders" | ||
561 | sed 50q $DICT > $TMP1 | ||
562 | for order in 1234 4321; do | ||
563 | for type in btree hash; do | ||
564 | rm -f byte.file $TMP2 $TMP3 | ||
565 | for i in `sed 50q $DICT`; do | ||
566 | echo p | ||
567 | echo k$i | ||
568 | echo d$i | ||
569 | echo g | ||
570 | echo k$i | ||
571 | done > $TMP2 | ||
572 | $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
573 | if (cmp -s $TMP1 $TMP3) ; then : | ||
574 | else | ||
575 | echo "test13: $type/$order put failed" | ||
576 | exit 1 | ||
577 | fi | ||
578 | for i in `sed 50q $DICT`; do | ||
579 | echo g | ||
580 | echo k$i | ||
581 | done > $TMP2 | ||
582 | $PROG -s \ | ||
583 | -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 | ||
584 | if (cmp -s $TMP1 $TMP3) ; then : | ||
585 | else | ||
586 | echo "test13: $type/$order get failed" | ||
587 | exit 1 | ||
588 | fi | ||
589 | done | ||
590 | done | ||
591 | rm -f byte.file | ||
592 | } | ||
593 | |||
594 | # Try a variety of bucketsizes and fill factors for hashing | ||
595 | test20() | ||
596 | { | ||
597 | echo\ | ||
598 | "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536" | ||
599 | echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | | ||
600 | awk '{ | ||
601 | for (i = 1; i <= 10000; ++i) { | ||
602 | if (i % 34) | ||
603 | s = substr($0, 1, i % 34); | ||
604 | else | ||
605 | s = substr($0, 1); | ||
606 | printf("%s\n", s); | ||
607 | } | ||
608 | exit; | ||
609 | }' > $TMP1 | ||
610 | sed 10000q $DICT | | ||
611 | awk 'BEGIN { | ||
612 | ds="abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | ||
613 | } | ||
614 | { | ||
615 | if (++i % 34) | ||
616 | s = substr(ds, 1, i % 34); | ||
617 | else | ||
618 | s = substr(ds, 1); | ||
619 | printf("p\nk%s\nd%s\n", $0, s); | ||
620 | }' > $TMP2 | ||
621 | sed 10000q $DICT | | ||
622 | awk '{ | ||
623 | ++i; | ||
624 | printf("g\nk%s\n", $0); | ||
625 | }' >> $TMP2 | ||
626 | bsize=256 | ||
627 | for ffactor in 11 14 21; do | ||
628 | echo " bucketsize $bsize, fill factor $ffactor" | ||
629 | $PROG -o$TMP3 \ | ||
630 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
631 | hash $TMP2 | ||
632 | if (cmp -s $TMP1 $TMP3) ; then : | ||
633 | else | ||
634 | echo "test20: type hash:\ | ||
635 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
636 | exit 1 | ||
637 | fi | ||
638 | done | ||
639 | bsize=512 | ||
640 | for ffactor in 21 28 43; do | ||
641 | echo " bucketsize $bsize, fill factor $ffactor" | ||
642 | $PROG -o$TMP3 \ | ||
643 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
644 | hash $TMP2 | ||
645 | if (cmp -s $TMP1 $TMP3) ; then : | ||
646 | else | ||
647 | echo "test20: type hash:\ | ||
648 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
649 | exit 1 | ||
650 | fi | ||
651 | done | ||
652 | bsize=1024 | ||
653 | for ffactor in 43 57 85; do | ||
654 | echo " bucketsize $bsize, fill factor $ffactor" | ||
655 | $PROG -o$TMP3 \ | ||
656 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
657 | hash $TMP2 | ||
658 | if (cmp -s $TMP1 $TMP3) ; then : | ||
659 | else | ||
660 | echo "test20: type hash:\ | ||
661 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
662 | exit 1 | ||
663 | fi | ||
664 | done | ||
665 | bsize=2048 | ||
666 | for ffactor in 85 114 171; do | ||
667 | echo " bucketsize $bsize, fill factor $ffactor" | ||
668 | $PROG -o$TMP3 \ | ||
669 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
670 | hash $TMP2 | ||
671 | if (cmp -s $TMP1 $TMP3) ; then : | ||
672 | else | ||
673 | echo "test20: type hash:\ | ||
674 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
675 | exit 1 | ||
676 | fi | ||
677 | done | ||
678 | bsize=4096 | ||
679 | for ffactor in 171 228 341; do | ||
680 | echo " bucketsize $bsize, fill factor $ffactor" | ||
681 | $PROG -o$TMP3 \ | ||
682 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
683 | hash $TMP2 | ||
684 | if (cmp -s $TMP1 $TMP3) ; then : | ||
685 | else | ||
686 | echo "test20: type hash:\ | ||
687 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
688 | exit 1 | ||
689 | fi | ||
690 | done | ||
691 | bsize=8192 | ||
692 | for ffactor in 341 455 683; do | ||
693 | echo " bucketsize $bsize, fill factor $ffactor" | ||
694 | $PROG -o$TMP3 \ | ||
695 | -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ | ||
696 | hash $TMP2 | ||
697 | if (cmp -s $TMP1 $TMP3) ; then : | ||
698 | else | ||
699 | echo "test20: type hash:\ | ||
700 | bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" | ||
701 | exit 1 | ||
702 | fi | ||
703 | done | ||
704 | } | ||
705 | |||
706 | main $* | ||