Fix up mix of man(7)/mdoc(7).
[netbsd-mini2440.git] / regress / lib / libc / db / run.test
blob06b2a51860f5c8df2cb6ced92ad8db15af1b8fbc
1 #!/bin/sh -
3 # $NetBSD: run.test,v 1.10 2007/02/03 20:39:05 christos Exp $
4 # @(#)run.test 8.10 (Berkeley) 7/26/94
7 # db regression tests
9 PNAME="$(basename "$0")"
11 usage() {
12 echo "Usage: $PNAME [-p <binary>] test# ... | [hash|btree|recno]" 1>&2
13 exit 1
16 main()
18 PROG=./dbtest
19 while getopts p: f; do
20 case $f in
21 p) PROG="$OPTARG";;
22 *) usage;;
23 esac
24 done
25 shift $(expr $OPTIND - 1)
26 TMP1=t1
27 TMP2=t2
28 TMP3=t3
29 SEVEN_SEVEN="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg"
31 trap "rm -f $TMP1 $TMP2 $TMP3" 0 1 2 3 15
33 if [ -f /usr/share/dict/words ]; then
34 DICT=/usr/share/dict/words
35 elif [ -f /usr/dict/words ]; then
36 DICT=/usr/dict/words
37 else
38 echo "$PNAME: no dictionary" 1>&2
39 exit 1
42 if [ $# -eq 0 ]; then
43 for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20 21; do
44 test$t
45 done
46 else
47 while [ $# -gt 0 ]; do
48 case "$1" in
49 test*)
50 $1;;
51 [0-9]*)
52 test$1;;
53 btree)
54 for t in 1 2 3 7 8 9 10 12 13; do
55 test$t
56 done;;
57 hash)
58 for t in 1 2 3 8 13 20; do
59 test$t
60 done;;
61 recno)
62 for t in 1 2 3 4 5 6 7 10 11; do
63 test$t
64 done;;
66 echo "$PNAME: unknown test $1" 1>&2
67 usage
68 esac
69 shift
70 done
72 exit 0
75 # Take the first hundred entries in the dictionary, and make them
76 # be key/data pairs.
77 test1()
79 echo "Test 1: btree, hash: small key, small data pairs"
80 sed 200q $DICT > $TMP1
81 for type in btree hash; do
82 rm -f $TMP2 $TMP3
83 for i in `sed 200q $DICT`; do
84 echo p
85 echo k$i
86 echo d$i
87 echo g
88 echo k$i
89 done > $TMP2
90 $PROG -o $TMP3 $type $TMP2
91 if ! cmp -s $TMP1 $TMP3; then
92 echo "$PNAME: test1: type $type: failed" 1>&2
93 exit 1
95 done
96 echo "Test 1: recno: small key, small data pairs"
97 rm -f $TMP2 $TMP3
98 sed 200q $DICT |
99 awk '{
100 ++i;
101 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
102 }' > $TMP2
103 $PROG -o $TMP3 recno $TMP2
104 if ! cmp -s $TMP1 $TMP3; then
105 echo "$PNAME: test1: type recno: failed" 1>&2
106 exit 1
110 # Take the first 200 entries in the dictionary, and give them
111 # each a medium size data entry.
112 test2()
114 echo "Test 2: btree, hash: small key, medium data pairs"
115 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
116 echo $mdata |
117 awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
118 for type in hash btree; do
119 rm -f $TMP2 $TMP3
120 for i in $(sed 200q $DICT); do
121 echo p
122 echo k$i
123 echo d$mdata
124 echo g
125 echo k$i
126 done > $TMP2
127 $PROG -o $TMP3 $type $TMP2
128 if ! cmp -s $TMP1 $TMP3; then
129 echo "$PNAME: test2: type $type: failed" 1>&2
130 exit 1
132 done
133 echo "Test 2: recno: small key, medium data pairs"
134 rm -f $TMP2 $TMP3
135 echo $mdata |
136 awk '{ for (i = 1; i < 201; ++i)
137 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
138 }' > $TMP2
139 $PROG -o $TMP3 recno $TMP2
140 if ! cmp -s $TMP1 $TMP3; then
141 echo "$PNAME: test2: type recno: failed" 1>&2
142 exit 1
146 # Insert the programs in /bin with their paths as their keys.
147 test3()
149 echo "Test 3: hash: small key, big data pairs"
150 rm -f $TMP1
151 (find /bin -type f -print | xargs cat) > $TMP1
152 for type in hash; do
153 rm -f $TMP2 $TMP3
154 for i in `find /bin -type f -print`; do
155 echo p
156 echo k$i
157 echo D$i
158 echo g
159 echo k$i
160 done > $TMP2
161 $PROG -o $TMP3 $type $TMP2
162 if ! cmp -s $TMP1 $TMP3; then
163 echo "$PNAME: test3: $type: failed" 1>&2
164 exit 1
166 done
167 echo "Test 3: btree: small key, big data pairs"
168 for psize in 512 16384 65536; do
169 echo " page size $psize"
170 for type in btree; do
171 rm -f $TMP2 $TMP3
172 for i in `find /bin -type f -print`; do
173 echo p
174 echo k$i
175 echo D$i
176 echo g
177 echo k$i
178 done > $TMP2
179 $PROG -i psize=$psize -o $TMP3 $type $TMP2
180 if ! cmp -s $TMP1 $TMP3; then
181 echo "$PNAME: test3: $type: page size $psize: failed" 1>&2
182 exit 1
184 done
185 done
186 echo "Test 3: recno: big data pairs"
187 rm -f $TMP2 $TMP3
188 find /bin -type f -print |
189 awk '{
190 ++i;
191 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
192 }' > $TMP2
193 for psize in 512 16384 65536; do
194 echo " page size $psize"
195 $PROG -i psize=$psize -o $TMP3 recno $TMP2
196 if ! cmp -s $TMP1 $TMP3; then
197 echo "$PNAME: test3: recno: page size $psize: failed" 1>&2
198 exit 1
200 done
203 # Do random recno entries.
204 test4()
206 echo "Test 4: recno: random entries"
207 echo $SEVEN_SEVEN |
208 awk '{
209 for (i = 37; i <= 37 + 88 * 17; i += 17) {
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);
216 for (i = 1; i <= 15; ++i) {
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);
223 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
224 if (i % 41)
225 s = substr($0, 1, i % 41);
226 else
227 s = substr($0, 1);
228 printf("input key %d: %s\n", i, s);
230 exit
231 }' > $TMP1
232 rm -f $TMP2 $TMP3
233 cat $TMP1 |
234 awk 'BEGIN {
235 i = 37;
236 incr = 17;
239 printf("p\nk%d\nd%s\n", i, $0);
240 if (i == 19234 + 61 * 27)
241 exit;
242 if (i == 37 + 88 * 17) {
243 i = 1;
244 incr = 1;
245 } else if (i == 15) {
246 i = 19234;
247 incr = 27;
248 } else
249 i += incr;
251 END {
252 for (i = 37; i <= 37 + 88 * 17; i += 17)
253 printf("g\nk%d\n", i);
254 for (i = 1; i <= 15; ++i)
255 printf("g\nk%d\n", i);
256 for (i = 19234; i <= 19234 + 61 * 27; i += 27)
257 printf("g\nk%d\n", i);
258 }' > $TMP2
259 $PROG -o $TMP3 recno $TMP2
260 if ! cmp -s $TMP1 $TMP3; then
261 echo "$PNAME: test4: type recno: failed" 1>&2
262 exit 1
266 # Do reverse order recno entries.
267 test5()
269 echo "Test 5: recno: reverse order entries"
270 echo $SEVEN_SEVEN |
271 awk ' {
272 for (i = 1500; i; --i) {
273 if (i % 34)
274 s = substr($0, 1, i % 34);
275 else
276 s = substr($0, 1);
277 printf("input key %d: %s\n", i, s);
279 exit;
280 }' > $TMP1
281 rm -f $TMP2 $TMP3
282 cat $TMP1 |
283 awk 'BEGIN {
284 i = 1500;
287 printf("p\nk%d\nd%s\n", i, $0);
288 --i;
290 END {
291 for (i = 1500; i; --i)
292 printf("g\nk%d\n", i);
293 }' > $TMP2
294 $PROG -o $TMP3 recno $TMP2
295 if ! cmp -s $TMP1 $TMP3; then
296 echo "$PNAME: test5: type recno: failed" 1>&2
297 exit 1
301 # Do alternating order recno entries.
302 test6()
304 echo "Test 6: recno: alternating order entries"
305 echo $SEVEN_SEVEN |
306 awk ' {
307 for (i = 1; i < 1200; i += 2) {
308 if (i % 34)
309 s = substr($0, 1, i % 34);
310 else
311 s = substr($0, 1);
312 printf("input key %d: %s\n", i, s);
314 for (i = 2; i < 1200; i += 2) {
315 if (i % 34)
316 s = substr($0, 1, i % 34);
317 else
318 s = substr($0, 1);
319 printf("input key %d: %s\n", i, s);
321 exit;
322 }' > $TMP1
323 rm -f $TMP2 $TMP3
324 cat $TMP1 |
325 awk 'BEGIN {
326 i = 1;
327 even = 0;
330 printf("p\nk%d\nd%s\n", i, $0);
331 i += 2;
332 if (i >= 1200) {
333 if (even == 1)
334 exit;
335 even = 1;
336 i = 2;
339 END {
340 for (i = 1; i < 1200; ++i)
341 printf("g\nk%d\n", i);
342 }' > $TMP2
343 $PROG -o $TMP3 recno $TMP2
344 sort -o $TMP1 $TMP1
345 sort -o $TMP3 $TMP3
346 if ! cmp -s $TMP1 $TMP3; then
347 echo "$PNAME: test6: type recno: failed" 1>&2
348 exit 1
352 # Delete cursor record
353 test7()
355 echo "Test 7: btree, recno: delete cursor record"
356 echo $SEVEN_SEVEN |
357 awk '{
358 for (i = 1; i <= 120; ++i)
359 printf("%05d: input key %d: %s\n", i, i, $0);
360 printf("%05d: input key %d: %s\n", 120, 120, $0);
361 printf("seq failed, no such key\n");
362 printf("%05d: input key %d: %s\n", 1, 1, $0);
363 printf("%05d: input key %d: %s\n", 2, 2, $0);
364 exit;
365 }' > $TMP1
366 rm -f $TMP2 $TMP3
368 for type in btree recno; do
369 cat $TMP1 |
370 awk '{
371 if (i == 120)
372 exit;
373 printf("p\nk%d\nd%s\n", ++i, $0);
375 END {
376 printf("fR_NEXT\n");
377 for (i = 1; i <= 120; ++i)
378 printf("s\n");
379 printf("fR_CURSOR\ns\nk120\n");
380 printf("r\n");
381 printf("fR_NEXT\ns\n");
382 printf("fR_CURSOR\ns\nk1\n");
383 printf("r\n");
384 printf("fR_FIRST\ns\n");
385 }' > $TMP2
386 $PROG -o $TMP3 recno $TMP2
387 if ! cmp -s $TMP1 $TMP3; then
388 echo "$PNAME: test7: type $type: failed" 1>&2
389 exit 1
391 done
394 # Make sure that overflow pages are reused.
395 test8()
397 echo "Test 8: btree, hash: repeated small key, big data pairs"
398 rm -f $TMP1
399 echo "" |
400 awk 'BEGIN {
401 for (i = 1; i <= 10; ++i) {
402 printf("p\nkkey1\nD/bin/sh\n");
403 printf("p\nkkey2\nD/bin/csh\n");
404 if (i % 8 == 0) {
405 printf("c\nkkey2\nD/bin/csh\n");
406 printf("c\nkkey1\nD/bin/sh\n");
407 printf("e\t%d of 10 (comparison)\n", i);
408 } else
409 printf("e\t%d of 10 \n", i);
410 printf("r\nkkey1\nr\nkkey2\n");
412 }' > $TMP1
413 $PROG btree $TMP1
414 # $PROG hash $TMP1
415 # No explicit test for success.
418 # Test btree duplicate keys
419 test9()
421 echo "Test 9: btree: duplicate keys"
422 echo $SEVEN_SEVEN |
423 awk '{
424 for (i = 1; i <= 543; ++i)
425 printf("%05d: input key %d: %s\n", i, i, $0);
426 exit;
427 }' > $TMP1
428 rm -f $TMP2 $TMP3
430 for type in btree; do
431 cat $TMP1 |
432 awk '{
433 if (i++ % 2)
434 printf("p\nkduplicatekey\nd%s\n", $0);
435 else
436 printf("p\nkunique%dkey\nd%s\n", i, $0);
438 END {
439 printf("o\n");
440 }' > $TMP2
441 $PROG -iflags=1 -o $TMP3 $type $TMP2
442 sort -o $TMP3 $TMP3
443 if ! cmp -s $TMP1 $TMP3; then
444 echo "$PNAME: test9: type $type: failed" 1>&2
445 exit 1
447 done
450 # Test use of cursor flags without initialization
451 test10()
453 echo "Test 10: btree, recno: test cursor flag use"
454 echo $SEVEN_SEVEN |
455 awk '{
456 for (i = 1; i <= 20; ++i)
457 printf("%05d: input key %d: %s\n", i, i, $0);
458 exit;
459 }' > $TMP1
460 rm -f $TMP2 $TMP3
462 # Test that R_CURSOR doesn't succeed before cursor initialized
463 for type in btree recno; do
464 cat $TMP1 |
465 awk '{
466 if (i == 10)
467 exit;
468 printf("p\nk%d\nd%s\n", ++i, $0);
470 END {
471 printf("fR_CURSOR\nr\n");
472 printf("eR_CURSOR SHOULD HAVE FAILED\n");
473 }' > $TMP2
474 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
475 if [ -s $TMP3 ] ; then
476 echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED"
477 exit 1
479 done
480 for type in btree recno; do
481 cat $TMP1 |
482 awk '{
483 if (i == 10)
484 exit;
485 printf("p\nk%d\nd%s\n", ++i, $0);
487 END {
488 printf("fR_CURSOR\np\nk1\ndsome data\n");
489 printf("eR_CURSOR SHOULD HAVE FAILED\n");
490 }' > $TMP2
491 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
492 if [ -s $TMP3 ] ; then
493 echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED"
494 exit 1
496 done
499 # Test insert in reverse order.
500 test11()
502 echo "Test 11: recno: reverse order insert"
503 echo $SEVEN_SEVEN |
504 awk '{
505 for (i = 1; i <= 779; ++i)
506 printf("%05d: input key %d: %s\n", i, i, $0);
507 exit;
508 }' > $TMP1
509 rm -f $TMP2 $TMP3
511 for type in recno; do
512 cat $TMP1 |
513 awk '{
514 if (i == 0) {
515 i = 1;
516 printf("p\nk1\nd%s\n", $0);
517 printf("%s\n", "fR_IBEFORE");
518 } else
519 printf("p\nk1\nd%s\n", $0);
521 END {
522 printf("or\n");
523 }' > $TMP2
524 $PROG -o $TMP3 $type $TMP2
525 if ! cmp -s $TMP1 $TMP3; then
526 echo "$PNAME: test11: type $type: failed" 1>&2
527 exit 1
529 done
532 # Take the first 20000 entries in the dictionary, reverse them, and give
533 # them each a small size data entry. Use a small page size to make sure
534 # the btree split code gets hammered.
535 test12()
537 echo "Test 12: btree: lots of keys, small page size"
538 mdata=abcdefghijklmnopqrstuvwxy
539 echo $mdata |
540 awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1
541 for type in btree; do
542 rm -f $TMP2 $TMP3
543 for i in `sed 20000q $DICT | rev`; do
544 echo p
545 echo k$i
546 echo d$mdata
547 echo g
548 echo k$i
549 done > $TMP2
550 $PROG -i psize=512 -o $TMP3 $type $TMP2
551 if ! cmp -s $TMP1 $TMP3; then
552 echo "$PNAME: test12: type $type: failed" 1>&2
553 exit 1
555 done
558 # Test different byte orders.
559 test13()
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 echo "$PNAME: test13: $type/$order put failed" 1>&2
576 exit 1
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 echo "$PNAME: test13: $type/$order get failed" 1>&2
586 exit 1
588 done
589 done
590 rm -f byte.file
593 # Try a variety of bucketsizes and fill factors for hashing
594 test20()
596 echo\
597 "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536"
598 echo $SEVEN_SEVEN |
599 awk '{
600 for (i = 1; i <= 10000; ++i) {
601 if (i % 34)
602 s = substr($0, 1, i % 34);
603 else
604 s = substr($0, 1);
605 printf("%s\n", s);
607 exit;
608 }' > $TMP1
609 sed 10000q $DICT |
610 awk 'BEGIN {
611 ds="'$SEVEN_SEVEN'"
614 if (++i % 34)
615 s = substr(ds, 1, i % 34);
616 else
617 s = substr(ds, 1);
618 printf("p\nk%s\nd%s\n", $0, s);
619 }' > $TMP2
620 sed 10000q $DICT |
621 awk '{
622 ++i;
623 printf("g\nk%s\n", $0);
624 }' >> $TMP2
625 bsize=256
626 for ffactor in 11 14 21; do
627 echo " bucketsize $bsize, fill factor $ffactor"
628 $PROG -o$TMP3 \
629 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
630 hash $TMP2
631 if ! cmp -s $TMP1 $TMP3; then
632 echo "$PNAME: test20: type hash:\
633 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" 1>&2
634 exit 1
636 done
637 bsize=512
638 for ffactor in 21 28 43; do
639 echo " bucketsize $bsize, fill factor $ffactor"
640 $PROG -o$TMP3 \
641 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
642 hash $TMP2
643 if ! cmp -s $TMP1 $TMP3; then
644 echo "$PNAME: test20: type hash:\
645 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" 1>&2
646 exit 1
648 done
649 bsize=1024
650 for ffactor in 43 57 85; do
651 echo " bucketsize $bsize, fill factor $ffactor"
652 $PROG -o$TMP3 \
653 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
654 hash $TMP2
655 if ! cmp -s $TMP1 $TMP3; then
656 echo "$PNAME: test20: type hash:\
657 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" 1>&2
658 exit 1
660 done
661 bsize=2048
662 for ffactor in 85 114 171; do
663 echo " bucketsize $bsize, fill factor $ffactor"
664 $PROG -o$TMP3 \
665 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
666 hash $TMP2
667 if ! cmp -s $TMP1 $TMP3; then
668 echo "$PNAME: test20: type hash:\
669 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" 1>&2
670 exit 1
672 done
673 bsize=4096
674 for ffactor in 171 228 341; do
675 echo " bucketsize $bsize, fill factor $ffactor"
676 $PROG -o$TMP3 \
677 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
678 hash $TMP2
679 if ! cmp -s $TMP1 $TMP3; then
680 echo "$PNAME: test20: type hash:\
681 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" 1>&2
682 exit 1
684 done
685 bsize=8192
686 for ffactor in 341 455 683; do
687 echo " bucketsize $bsize, fill factor $ffactor"
688 $PROG -o$TMP3 \
689 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
690 hash $TMP2
691 if ! cmp -s $TMP1 $TMP3; then
692 echo "$PNAME: test20: type hash:\
693 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed" 1>&2
694 exit 1
696 done
699 test21() {
700 cat << _EOF | $PROG -i bsize=65536 hash /dev/stdin
702 k1234
703 d1234
705 k1234
706 _EOF
709 main "$@"