3 # @(#)run.test 8.10 (Berkeley) 7/26/94
15 if [ -f /usr/share/dict/words ]; then
16 DICT=/usr/share/dict/words
17 elif [ -f /usr/dict/words ]; then
20 echo 'run.test: no dictionary'
25 for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do
36 for t in 1 2 3 7 8 9 10 12 13; do
40 for t in 1 2 3 8 13 20; do
44 for t in 1 2 3 4 5 6 7 10 11; do
48 echo "run.test: unknown test $1"
49 echo "usage: run.test test# | type"
55 rm -f $TMP1 $TMP2 $TMP3
59 # Take the first hundred entries in the dictionary, and make them
63 echo "Test 1: btree, hash: small key, small data pairs"
64 sed 200q $DICT > $TMP1
65 for type in btree hash; do
67 for i in `sed 200q $DICT`; do
74 $PROG -o $TMP3 $type $TMP2
75 if (cmp -s $TMP1 $TMP3) ; then :
77 echo "test1: type $type: failed"
81 echo "Test 1: recno: small key, small data pairs"
86 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
88 $PROG -o $TMP3 recno $TMP2
89 if (cmp -s $TMP1 $TMP3) ; then :
91 echo "test1: type recno: failed"
96 # Take the first 200 entries in the dictionary, and give them
97 # each a medium size data entry.
100 echo "Test 2: btree, hash: small key, medium data pairs"
101 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
103 awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
104 for type in hash btree; do
106 for i in `sed 200q $DICT`; do
113 $PROG -o $TMP3 $type $TMP2
114 if (cmp -s $TMP1 $TMP3) ; then :
116 echo "test2: type $type: failed"
120 echo "Test 2: recno: small key, medium data pairs"
123 awk '{ for (i = 1; i < 201; ++i)
124 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
126 $PROG -o $TMP3 recno $TMP2
127 if (cmp -s $TMP1 $TMP3) ; then :
129 echo "test2: type recno: failed"
134 # Insert the programs in /bin with their paths as their keys.
137 echo "Test 3: hash: small key, big data pairs"
139 (find /bin -type f -print | xargs cat) > $TMP1
142 for i in `find /bin -type f -print`; do
149 $PROG -o $TMP3 $type $TMP2
150 if (cmp -s $TMP1 $TMP3) ; then :
152 echo "test3: $type: failed"
156 echo "Test 3: btree: small key, big data pairs"
157 for psize in 512 16384 65536; do
158 echo " page size $psize"
159 for type in btree; do
161 for i in `find /bin -type f -print`; do
168 $PROG -i psize=$psize -o $TMP3 $type $TMP2
169 if (cmp -s $TMP1 $TMP3) ; then :
171 echo "test3: $type: page size $psize: failed"
176 echo "Test 3: recno: big data pairs"
178 find /bin -type f -print |
181 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
183 for psize in 512 16384 65536; do
184 echo " page size $psize"
185 $PROG -i psize=$psize -o $TMP3 recno $TMP2
186 if (cmp -s $TMP1 $TMP3) ; then :
188 echo "test3: recno: page size $psize: failed"
194 # Do random recno entries.
197 echo "Test 4: recno: random entries"
198 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
200 for (i = 37; i <= 37 + 88 * 17; i += 17) {
202 s = substr($0, 1, i % 41);
205 printf("input key %d: %s\n", i, s);
207 for (i = 1; i <= 15; ++i) {
209 s = substr($0, 1, i % 41);
212 printf("input key %d: %s\n", i, s);
214 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
216 s = substr($0, 1, i % 41);
219 printf("input key %d: %s\n", i, s);
230 printf("p\nk%d\nd%s\n", i, $0);
231 if (i == 19234 + 61 * 27)
233 if (i == 37 + 88 * 17) {
236 } else if (i == 15) {
243 for (i = 37; i <= 37 + 88 * 17; i += 17)
244 printf("g\nk%d\n", i);
245 for (i = 1; i <= 15; ++i)
246 printf("g\nk%d\n", i);
247 for (i = 19234; i <= 19234 + 61 * 27; i += 27)
248 printf("g\nk%d\n", i);
250 $PROG -o $TMP3 recno $TMP2
251 if (cmp -s $TMP1 $TMP3) ; then :
253 echo "test4: type recno: failed"
258 # Do reverse order recno entries.
261 echo "Test 5: recno: reverse order entries"
262 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
264 for (i = 1500; i; --i) {
266 s = substr($0, 1, i % 34);
269 printf("input key %d: %s\n", i, s);
279 printf("p\nk%d\nd%s\n", i, $0);
283 for (i = 1500; i; --i)
284 printf("g\nk%d\n", i);
286 $PROG -o $TMP3 recno $TMP2
287 if (cmp -s $TMP1 $TMP3) ; then :
289 echo "test5: type recno: failed"
294 # Do alternating order recno entries.
297 echo "Test 6: recno: alternating order entries"
298 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
300 for (i = 1; i < 1200; i += 2) {
302 s = substr($0, 1, i % 34);
305 printf("input key %d: %s\n", i, s);
307 for (i = 2; i < 1200; i += 2) {
309 s = substr($0, 1, i % 34);
312 printf("input key %d: %s\n", i, s);
323 printf("p\nk%d\nd%s\n", i, $0);
333 for (i = 1; i < 1200; ++i)
334 printf("g\nk%d\n", i);
336 $PROG -o $TMP3 recno $TMP2
339 if (cmp -s $TMP1 $TMP3) ; then :
341 echo "test6: type recno: failed"
346 # Delete cursor record
349 echo "Test 7: btree, recno: delete cursor record"
350 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
352 for (i = 1; i <= 120; ++i)
353 printf("%05d: input key %d: %s\n", i, i, $0);
354 printf("%05d: input key %d: %s\n", 120, 120, $0);
355 printf("seq failed, no such key\n");
356 printf("%05d: input key %d: %s\n", 1, 1, $0);
357 printf("%05d: input key %d: %s\n", 2, 2, $0);
362 for type in btree recno; do
367 printf("p\nk%d\nd%s\n", ++i, $0);
371 for (i = 1; i <= 120; ++i)
373 printf("fR_CURSOR\ns\nk120\n");
375 printf("fR_NEXT\ns\n");
376 printf("fR_CURSOR\ns\nk1\n");
378 printf("fR_FIRST\ns\n");
380 $PROG -o $TMP3 recno $TMP2
381 if (cmp -s $TMP1 $TMP3) ; then :
383 echo "test7: type $type: failed"
389 # Make sure that overflow pages are reused.
392 echo "Test 8: btree, hash: repeated small key, big data pairs"
396 for (i = 1; i <= 10; ++i) {
397 printf("p\nkkey1\nD/bin/sh\n");
398 printf("p\nkkey2\nD/bin/csh\n");
400 printf("c\nkkey2\nD/bin/csh\n");
401 printf("c\nkkey1\nD/bin/sh\n");
402 printf("e\t%d of 10 (comparison)\n", i);
404 printf("e\t%d of 10 \n", i);
405 printf("r\nkkey1\nr\nkkey2\n");
410 # No explicit test for success.
413 # Test btree duplicate keys
416 echo "Test 9: btree: duplicate keys"
417 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
419 for (i = 1; i <= 543; ++i)
420 printf("%05d: input key %d: %s\n", i, i, $0);
425 for type in btree; do
429 printf("p\nkduplicatekey\nd%s\n", $0);
431 printf("p\nkunique%dkey\nd%s\n", i, $0);
436 $PROG -iflags=1 -o $TMP3 $type $TMP2
438 if (cmp -s $TMP1 $TMP3) ; then :
440 echo "test9: type $type: failed"
446 # Test use of cursor flags without initialization
449 echo "Test 10: btree, recno: test cursor flag use"
450 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
452 for (i = 1; i <= 20; ++i)
453 printf("%05d: input key %d: %s\n", i, i, $0);
458 # Test that R_CURSOR doesn't succeed before cursor initialized
459 for type in btree recno; do
464 printf("p\nk%d\nd%s\n", ++i, $0);
467 printf("fR_CURSOR\nr\n");
468 printf("eR_CURSOR SHOULD HAVE FAILED\n");
470 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
471 if [ -s $TMP3 ] ; then
472 echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED"
476 for type in btree recno; do
481 printf("p\nk%d\nd%s\n", ++i, $0);
484 printf("fR_CURSOR\np\nk1\ndsome data\n");
485 printf("eR_CURSOR SHOULD HAVE FAILED\n");
487 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
488 if [ -s $TMP3 ] ; then
489 echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED"
495 # Test insert in reverse order.
498 echo "Test 11: recno: reverse order insert"
499 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
501 for (i = 1; i <= 779; ++i)
502 printf("%05d: input key %d: %s\n", i, i, $0);
507 for type in recno; do
512 printf("p\nk1\nd%s\n", $0);
513 printf("%s\n", "fR_IBEFORE");
515 printf("p\nk1\nd%s\n", $0);
520 $PROG -o $TMP3 $type $TMP2
521 if (cmp -s $TMP1 $TMP3) ; then :
523 echo "test11: type $type: failed"
529 # Take the first 20000 entries in the dictionary, reverse them, and give
530 # them each a small size data entry. Use a small page size to make sure
531 # the btree split code gets hammered.
534 echo "Test 12: btree: lots of keys, small page size"
535 mdata=abcdefghijklmnopqrstuvwxy
537 awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1
538 for type in btree; do
540 for i in `sed 20000q $DICT | rev`; do
547 $PROG -i psize=512 -o $TMP3 $type $TMP2
548 if (cmp -s $TMP1 $TMP3) ; then :
550 echo "test12: type $type: failed"
556 # Test different byte orders.
559 echo "Test 13: btree, hash: differing byte orders"
560 sed 50q $DICT > $TMP1
561 for order in 1234 4321; do
562 for type in btree hash; do
563 rm -f byte.file $TMP2 $TMP3
564 for i in `sed 50q $DICT`; do
571 $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
572 if (cmp -s $TMP1 $TMP3) ; then :
574 echo "test13: $type/$order put failed"
577 for i in `sed 50q $DICT`; do
582 -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
583 if (cmp -s $TMP1 $TMP3) ; then :
585 echo "test13: $type/$order get failed"
593 # Try a variety of bucketsizes and fill factors for hashing
597 "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536"
598 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
600 for (i = 1; i <= 10000; ++i) {
602 s = substr($0, 1, i % 34);
611 ds="abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"
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 :
633 echo "test20: type hash:\
634 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
639 for ffactor in 21 28 43; do
640 echo " bucketsize $bsize, fill factor $ffactor"
642 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
644 if (cmp -s $TMP1 $TMP3) ; then :
646 echo "test20: type hash:\
647 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
652 for ffactor in 43 57 85; do
653 echo " bucketsize $bsize, fill factor $ffactor"
655 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
657 if (cmp -s $TMP1 $TMP3) ; then :
659 echo "test20: type hash:\
660 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
665 for ffactor in 85 114 171; do
666 echo " bucketsize $bsize, fill factor $ffactor"
668 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
670 if (cmp -s $TMP1 $TMP3) ; then :
672 echo "test20: type hash:\
673 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
678 for ffactor in 171 228 341; do
679 echo " bucketsize $bsize, fill factor $ffactor"
681 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
683 if (cmp -s $TMP1 $TMP3) ; then :
685 echo "test20: type hash:\
686 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
691 for ffactor in 341 455 683; do
692 echo " bucketsize $bsize, fill factor $ffactor"
694 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
696 if (cmp -s $TMP1 $TMP3) ; then :
698 echo "test20: type hash:\
699 bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"