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