3 # $NetBSD: run.test,v 1.10 2007/02/03 20:39:05 christos Exp $
4 # @(#)run.test 8.10 (Berkeley) 7/26/94
9 PNAME
="$(basename "$0")"
12 echo "Usage: $PNAME [-p <binary>] test# ... | [hash|btree|recno]" 1>&2
19 while getopts p
: f
; do
25 shift $
(expr $OPTIND - 1)
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
38 echo "$PNAME: no dictionary" 1>&2
43 for t
in 1 2 3 4 5 6 7 8 9 10 11 12 13 20 21; do
47 while [ $# -gt 0 ]; do
54 for t
in 1 2 3 7 8 9 10 12 13; do
58 for t
in 1 2 3 8 13 20; do
62 for t
in 1 2 3 4 5 6 7 10 11; do
66 echo "$PNAME: unknown test $1" 1>&2
75 # Take the first hundred entries in the dictionary, and make them
79 echo "Test 1: btree, hash: small key, small data pairs"
80 sed 200q
$DICT > $TMP1
81 for type in btree
hash; do
83 for i
in `sed 200q $DICT`; do
90 $PROG -o $TMP3 $type $TMP2
91 if ! cmp -s $TMP1 $TMP3; then
92 echo "$PNAME: test1: type $type: failed" 1>&2
96 echo "Test 1: recno: small key, small data pairs"
101 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
103 $PROG -o $TMP3 recno
$TMP2
104 if ! cmp -s $TMP1 $TMP3; then
105 echo "$PNAME: test1: type recno: failed" 1>&2
110 # Take the first 200 entries in the dictionary, and give them
111 # each a medium size data entry.
114 echo "Test 2: btree, hash: small key, medium data pairs"
115 mdata
=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
117 awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
118 for type in hash btree
; do
120 for i
in $
(sed 200q
$DICT); do
127 $PROG -o $TMP3 $type $TMP2
128 if ! cmp -s $TMP1 $TMP3; then
129 echo "$PNAME: test2: type $type: failed" 1>&2
133 echo "Test 2: recno: small key, medium data pairs"
136 awk '{ for (i = 1; i < 201; ++i)
137 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
139 $PROG -o $TMP3 recno
$TMP2
140 if ! cmp -s $TMP1 $TMP3; then
141 echo "$PNAME: test2: type recno: failed" 1>&2
146 # Insert the programs in /bin with their paths as their keys.
149 echo "Test 3: hash: small key, big data pairs"
151 (find /bin
-type f
-print |
xargs cat) > $TMP1
154 for i
in `find /bin -type f -print`; do
161 $PROG -o $TMP3 $type $TMP2
162 if ! cmp -s $TMP1 $TMP3; then
163 echo "$PNAME: test3: $type: failed" 1>&2
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
172 for i
in `find /bin -type f -print`; do
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
186 echo "Test 3: recno: big data pairs"
188 find /bin
-type f
-print |
191 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
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
203 # Do random recno entries.
206 echo "Test 4: recno: random entries"
209 for (i = 37; i <= 37 + 88 * 17; i += 17) {
211 s = substr($0, 1, i % 41);
214 printf("input key %d: %s\n", i, s);
216 for (i = 1; i <= 15; ++i) {
218 s = substr($0, 1, i % 41);
221 printf("input key %d: %s\n", i, s);
223 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
225 s = substr($0, 1, i % 41);
228 printf("input key %d: %s\n", i, s);
239 printf("p\nk%d\nd%s\n", i, $0);
240 if (i == 19234 + 61 * 27)
242 if (i == 37 + 88 * 17) {
245 } else if (i == 15) {
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);
259 $PROG -o $TMP3 recno
$TMP2
260 if ! cmp -s $TMP1 $TMP3; then
261 echo "$PNAME: test4: type recno: failed" 1>&2
266 # Do reverse order recno entries.
269 echo "Test 5: recno: reverse order entries"
272 for (i = 1500; i; --i) {
274 s = substr($0, 1, i % 34);
277 printf("input key %d: %s\n", i, s);
287 printf("p\nk%d\nd%s\n", i, $0);
291 for (i = 1500; i; --i)
292 printf("g\nk%d\n", i);
294 $PROG -o $TMP3 recno
$TMP2
295 if ! cmp -s $TMP1 $TMP3; then
296 echo "$PNAME: test5: type recno: failed" 1>&2
301 # Do alternating order recno entries.
304 echo "Test 6: recno: alternating order entries"
307 for (i = 1; i < 1200; i += 2) {
309 s = substr($0, 1, i % 34);
312 printf("input key %d: %s\n", i, s);
314 for (i = 2; i < 1200; i += 2) {
316 s = substr($0, 1, i % 34);
319 printf("input key %d: %s\n", i, s);
330 printf("p\nk%d\nd%s\n", i, $0);
340 for (i = 1; i < 1200; ++i)
341 printf("g\nk%d\n", i);
343 $PROG -o $TMP3 recno
$TMP2
346 if ! cmp -s $TMP1 $TMP3; then
347 echo "$PNAME: test6: type recno: failed" 1>&2
352 # Delete cursor record
355 echo "Test 7: btree, recno: delete cursor record"
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);
368 for type in btree recno
; do
373 printf("p\nk%d\nd%s\n", ++i, $0);
377 for (i = 1; i <= 120; ++i)
379 printf("fR_CURSOR\ns\nk120\n");
381 printf("fR_NEXT\ns\n");
382 printf("fR_CURSOR\ns\nk1\n");
384 printf("fR_FIRST\ns\n");
386 $PROG -o $TMP3 recno
$TMP2
387 if ! cmp -s $TMP1 $TMP3; then
388 echo "$PNAME: test7: type $type: failed" 1>&2
394 # Make sure that overflow pages are reused.
397 echo "Test 8: btree, hash: repeated small key, big data pairs"
401 for (i = 1; i <= 10; ++i) {
402 printf("p\nkkey1\nD/bin/sh\n");
403 printf("p\nkkey2\nD/bin/csh\n");
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);
409 printf("e\t%d of 10 \n", i);
410 printf("r\nkkey1\nr\nkkey2\n");
415 # No explicit test for success.
418 # Test btree duplicate keys
421 echo "Test 9: btree: duplicate keys"
424 for (i = 1; i <= 543; ++i)
425 printf("%05d: input key %d: %s\n", i, i, $0);
430 for type in btree
; do
434 printf("p\nkduplicatekey\nd%s\n", $0);
436 printf("p\nkunique%dkey\nd%s\n", i, $0);
441 $PROG -iflags=1 -o $TMP3 $type $TMP2
443 if ! cmp -s $TMP1 $TMP3; then
444 echo "$PNAME: test9: type $type: failed" 1>&2
450 # Test use of cursor flags without initialization
453 echo "Test 10: btree, recno: test cursor flag use"
456 for (i = 1; i <= 20; ++i)
457 printf("%05d: input key %d: %s\n", i, i, $0);
462 # Test that R_CURSOR doesn't succeed before cursor initialized
463 for type in btree recno
; do
468 printf("p\nk%d\nd%s\n", ++i, $0);
471 printf("fR_CURSOR\nr\n");
472 printf("eR_CURSOR SHOULD HAVE FAILED\n");
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"
480 for type in btree recno
; do
485 printf("p\nk%d\nd%s\n", ++i, $0);
488 printf("fR_CURSOR\np\nk1\ndsome data\n");
489 printf("eR_CURSOR SHOULD HAVE FAILED\n");
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"
499 # Test insert in reverse order.
502 echo "Test 11: recno: reverse order insert"
505 for (i = 1; i <= 779; ++i)
506 printf("%05d: input key %d: %s\n", i, i, $0);
511 for type in recno
; do
516 printf("p\nk1\nd%s\n", $0);
517 printf("%s\n", "fR_IBEFORE");
519 printf("p\nk1\nd%s\n", $0);
524 $PROG -o $TMP3 $type $TMP2
525 if ! cmp -s $TMP1 $TMP3; then
526 echo "$PNAME: test11: type $type: failed" 1>&2
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.
537 echo "Test 12: btree: lots of keys, small page size"
538 mdata
=abcdefghijklmnopqrstuvwxy
540 awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1
541 for type in btree
; do
543 for i
in `sed 20000q $DICT | rev`; do
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
558 # Test different byte orders.
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
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
578 for i
in `sed 50q $DICT`; do
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
593 # Try a variety of bucketsizes and fill factors for hashing
597 "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536"
600 for (i = 1; i <= 10000; ++i) {
602 s = substr($0, 1, i % 34);
615 s = substr(ds, 1, i % 34);
618 printf("p\nk%s\nd%s\n", $0, s);
623 printf("g\nk%s\n", $0);
626 for ffactor
in 11 14 21; do
627 echo " bucketsize $bsize, fill factor $ffactor"
629 -ibsize=$bsize,ffactor
=$ffactor,nelem
=25000,cachesize
=65536\
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
638 for ffactor
in 21 28 43; do
639 echo " bucketsize $bsize, fill factor $ffactor"
641 -ibsize=$bsize,ffactor
=$ffactor,nelem
=25000,cachesize
=65536\
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
650 for ffactor
in 43 57 85; do
651 echo " bucketsize $bsize, fill factor $ffactor"
653 -ibsize=$bsize,ffactor
=$ffactor,nelem
=25000,cachesize
=65536\
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
662 for ffactor
in 85 114 171; do
663 echo " bucketsize $bsize, fill factor $ffactor"
665 -ibsize=$bsize,ffactor
=$ffactor,nelem
=25000,cachesize
=65536\
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
674 for ffactor
in 171 228 341; do
675 echo " bucketsize $bsize, fill factor $ffactor"
677 -ibsize=$bsize,ffactor
=$ffactor,nelem
=25000,cachesize
=65536\
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
686 for ffactor
in 341 455 683; do
687 echo " bucketsize $bsize, fill factor $ffactor"
689 -ibsize=$bsize,ffactor
=$ffactor,nelem
=25000,cachesize
=65536\
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
700 cat << _EOF | $PROG -i bsize=65536 hash /dev/stdin