156038Sbostic#!/bin/sh - 256038Sbostic# 356038Sbostic# Copyright (c) 1992 The Regents of the University of California. 456038Sbostic# All rights reserved. 556038Sbostic# 656038Sbostic# %sccs.include.redist.sh% 756038Sbostic# 8*56085Sbostic# @(#)run.test 5.4 (Berkeley) 08/28/92 956038Sbostic# 1056038Sbostic 1156038Sbostic# db regression tests 1256038Sbostic 1356038Sbosticmain() 1456038Sbostic{ 1556038Sbostic DICT=/usr/share/dict/words 1656058Sbostic PROG=obj/dbtest 1756038Sbostic TMP1=t1 1856038Sbostic TMP2=t2 1956038Sbostic TMP3=t3 2056038Sbostic 2156038Sbostic test1 2256038Sbostic test2 2356038Sbostic test3 2456038Sbostic test4 2556050Sbostic test5 2656050Sbostic test6 2756058Sbostic test7 28*56085Sbostic test8 2956038Sbostic rm -f $TMP1 $TMP2 $TMP3 3056038Sbostic} 3156038Sbostic 3256038Sbostic# Take the first hundred entries in the dictionary, and make them 3356038Sbostic# be key/data pairs. 3456038Sbostictest1() 3556038Sbostic{ 3656050Sbostic printf "Test 1: btree, hash: small key, small data pairs\n" 37*56085Sbostic sed 200q $DICT > $TMP1 3856038Sbostic for type in btree hash; do 3956038Sbostic rm -f $TMP2 $TMP3 4056038Sbostic for i in `sed 200q $DICT`; do 4156038Sbostic printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i 4256038Sbostic done > $TMP2 4356058Sbostic $PROG -o $TMP3 $type $TMP2 4456038Sbostic if (cmp -s $TMP1 $TMP3) ; then 4556038Sbostic else 4656038Sbostic printf "test1: type %s: failed\n" $type 4756038Sbostic exit 1 4856038Sbostic fi 4956038Sbostic done 5056050Sbostic printf "Test 1: recno: small key, small data pairs\n" 5156038Sbostic rm -f $TMP2 $TMP3 5256038Sbostic sed 200q $DICT | 5356058Sbostic awk '{ 5456058Sbostic ++i; 5556058Sbostic printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); 5656058Sbostic }' > $TMP2 5756058Sbostic $PROG -o $TMP3 recno $TMP2 5856038Sbostic if (cmp -s $TMP1 $TMP3) ; then 5956038Sbostic else 6056038Sbostic printf "test1: type recno: failed\n" 6156038Sbostic exit 1 6256038Sbostic fi 6356038Sbostic} 6456038Sbostic 6556038Sbostic# Take the first hundred entries in the dictionary, and give them 6656038Sbostic# each a medium size data entry. 6756038Sbostictest2() 6856038Sbostic{ 6956050Sbostic printf "Test 2: btree, hash: small key, medium data pairs\n" 7056038Sbostic mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 7156038Sbostic echo $mdata | 7256058Sbostic awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 7356038Sbostic for type in hash btree; do 7456038Sbostic rm -f $TMP2 $TMP3 7556038Sbostic for i in `sed 200q $DICT`; do 7656038Sbostic printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i 7756038Sbostic done > $TMP2 7856058Sbostic $PROG -o $TMP3 $type $TMP2 7956038Sbostic if (cmp -s $TMP1 $TMP3) ; then 8056038Sbostic else 8156038Sbostic printf "test2: type %s: failed\n" $type 8256038Sbostic exit 1 8356038Sbostic fi 8456038Sbostic done 8556050Sbostic printf "Test 2: recno: small key, medium data pairs\n" 8656038Sbostic rm -f $TMP2 $TMP3 8756038Sbostic echo $mdata | 8856058Sbostic awk '{ for (i = 1; i < 201; ++i) 8956058Sbostic printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); 9056058Sbostic }' > $TMP2 9156058Sbostic $PROG -o $TMP3 recno $TMP2 9256038Sbostic if (cmp -s $TMP1 $TMP3) ; then 9356038Sbostic else 9456038Sbostic printf "test2: type recno: failed\n" 9556038Sbostic exit 1 9656038Sbostic fi 9756038Sbostic} 9856038Sbostic 9956038Sbostic# Insert the programs in /bin with their paths as their keys. 10056038Sbostictest3() 10156038Sbostic{ 10256050Sbostic printf "Test 3: btree, hash: small key, big data pairs\n" 10356038Sbostic rm -f $TMP1 10456038Sbostic (find /bin -type f -print | xargs cat) > $TMP1 10556038Sbostic for type in hash btree; do 10656038Sbostic rm -f $TMP2 $TMP3 10756038Sbostic for i in `find /bin -type f -print`; do 10856038Sbostic printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i 10956038Sbostic done > $TMP2 11056058Sbostic $PROG -o $TMP3 $type $TMP2 11156038Sbostic if (cmp -s $TMP1 $TMP3) ; then 11256038Sbostic else 11356038Sbostic printf "test2: type %s: failed\n" $type 11456038Sbostic exit 1 11556038Sbostic fi 11656038Sbostic done 11756050Sbostic printf "Test 3: recno: big data pairs\n" 11856038Sbostic rm -f $TMP2 $TMP3 11956038Sbostic find /bin -type f -print | 12056058Sbostic awk '{ 12156058Sbostic ++i; 12256058Sbostic printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); 12356058Sbostic }' > $TMP2 12456058Sbostic $PROG -o $TMP3 recno $TMP2 12556038Sbostic if (cmp -s $TMP1 $TMP3) ; then 12656038Sbostic else 12756038Sbostic printf "test3: type recno: failed\n" 12856038Sbostic exit 1 12956038Sbostic fi 13056038Sbostic} 13156038Sbostic 13256038Sbostic# Do random recno entries. 13356038Sbostictest4() 13456038Sbostic{ 13556050Sbostic printf "Test 4: recno: random entries\n" 13656050Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 13756058Sbostic awk '{ 13856058Sbostic for (i = 37; i <= 37 + 88 * 17; i += 17) 13956058Sbostic printf("input key %d: %.*s\n", i, i % 41, $0); 14056058Sbostic for (i = 1; i <= 15; ++i) 14156058Sbostic printf("input key %d: %.*s\n", i, i % 41, $0); 14256058Sbostic for (i = 19234; i <= 19234 + 61 * 27; i += 27) 14356058Sbostic printf("input key %d: %.*s\n", i, i % 41, $0); 14456058Sbostic exit 14556058Sbostic }' > $TMP1 14656058Sbostic rm -f TMP2 $TMP3 14756058Sbostic cat $TMP1 | 14856058Sbostic awk 'BEGIN { 14956058Sbostic i = 37; 15056058Sbostic incr = 17; 15156058Sbostic } 15256058Sbostic { 15356058Sbostic printf("p\nk%d\nd%s\n", i, $0); 15456058Sbostic if (i == 19234 + 61 * 27) 15556058Sbostic exit; 15656058Sbostic if (i == 37 + 88 * 17) { 15756058Sbostic i = 1; 15856058Sbostic incr = 1; 15956058Sbostic } else if (i == 15) { 16056058Sbostic i = 19234; 16156058Sbostic incr = 27; 16256058Sbostic } else 16356058Sbostic i += incr; 16456058Sbostic } 16556058Sbostic END { 16656038Sbostic for (i = 37; i <= 37 + 88 * 17; i += 17) 16756058Sbostic printf("g\nk%d\n", i); 16856038Sbostic for (i = 1; i <= 15; ++i) 16956058Sbostic printf("g\nk%d\n", i); 17056038Sbostic for (i = 19234; i <= 19234 + 61 * 27; i += 27) 17156058Sbostic printf("g\nk%d\n", i); 17256058Sbostic }' > $TMP2 17356058Sbostic $PROG -o $TMP3 recno $TMP2 17456038Sbostic if (cmp -s $TMP1 $TMP3) ; then 17556038Sbostic else 17656038Sbostic printf "test4: type recno: failed\n" 17756038Sbostic exit 1 17856038Sbostic fi 17956038Sbostic} 18056050Sbostic 18156050Sbostic# Do reverse order recno entries. 18256050Sbostictest5() 18356050Sbostic{ 18456050Sbostic printf "Test 5: recno: reverse order entries\n" 18556050Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 18656058Sbostic awk ' { 18756058Sbostic for (i = 1500; i; --i) 18856058Sbostic printf("input key %d: %.*s\n", i, i % 34, $0); 18956058Sbostic exit; 19056058Sbostic }' > $TMP1 19156050Sbostic rm -f TMP2 $TMP3 19256058Sbostic cat $TMP1 | 19356058Sbostic awk 'BEGIN { 19456058Sbostic i = 1500; 19556058Sbostic } 19656058Sbostic { 19756058Sbostic printf("p\nk%d\nd%s\n", i, $0); 19856058Sbostic --i; 19956058Sbostic } 20056058Sbostic END { 20156058Sbostic for (i = 1500; i; --i) 20256058Sbostic printf("g\nk%d\n", i); 20356058Sbostic }' > $TMP2 20456058Sbostic $PROG -o $TMP3 recno $TMP2 20556050Sbostic if (cmp -s $TMP1 $TMP3) ; then 20656050Sbostic else 20756050Sbostic printf "test5: type recno: failed\n" 20856050Sbostic exit 1 20956050Sbostic fi 21056050Sbostic} 21156038Sbostic 21256050Sbostic# Do alternating order recno entries. 21356050Sbostictest6() 21456050Sbostic{ 21556050Sbostic printf "Test 6: recno: alternating order entries\n" 21656050Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 21756058Sbostic awk ' { 21856058Sbostic for (i = 1; i < 1200; i += 2) 21956058Sbostic printf("input key %d: %.*s\n", i, i % 34, $0); 22056058Sbostic for (i = 2; i < 1200; i += 2) 22156058Sbostic printf("input key %d: %.*s\n", i, i % 34, $0); 22256058Sbostic exit; 22356058Sbostic }' > $TMP1 22456050Sbostic rm -f TMP2 $TMP3 22556058Sbostic cat $TMP1 | 22656058Sbostic awk 'BEGIN { 22756058Sbostic i = 1; 22856058Sbostic even = 0; 22956058Sbostic } 23056058Sbostic { 23156058Sbostic printf("p\nk%d\nd%s\n", i, $0); 23256058Sbostic i += 2; 23356058Sbostic if (i >= 1200) { 23456058Sbostic if (even == 1) 23556058Sbostic exit; 23656058Sbostic even = 1; 23756058Sbostic i = 2; 23856050Sbostic } 23956058Sbostic } 24056058Sbostic END { 24156058Sbostic for (i = 1; i < 1200; ++i) 24256058Sbostic printf("g\nk%d\n", i); 24356058Sbostic }' > $TMP2 24456058Sbostic $PROG -o $TMP3 recno $TMP2 24556050Sbostic sort -o $TMP1 $TMP1 24656050Sbostic sort -o $TMP3 $TMP3 24756050Sbostic if (cmp -s $TMP1 $TMP3) ; then 24856050Sbostic else 24956050Sbostic printf "test6: type recno: failed\n" 25056050Sbostic exit 1 25156050Sbostic fi 25256050Sbostic} 25356050Sbostic 25456058Sbostic# Delete cursor record 25556058Sbostictest7() 25656058Sbostic{ 25756058Sbostic printf "Test 7: btree, recno: delete cursor record\n" 25856058Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 25956058Sbostic awk '{ 26056058Sbostic for (i = 1; i <= 120; ++i) 26156058Sbostic printf("%05d: input key %d: %s\n", i, i, $0); 26256058Sbostic printf("%05d: input key %d: %s\n", 120, 120, $0); 26356058Sbostic printf("get failed, no such key\n"); 26456058Sbostic printf("%05d: input key %d: %s\n", 1, 1, $0); 26556058Sbostic printf("%05d: input key %d: %s\n", 2, 2, $0); 26656058Sbostic exit; 26756058Sbostic }' > $TMP1 26856058Sbostic rm -f TMP2 $TMP3 26956058Sbostic for type in btree recno; do 27056058Sbostic cat $TMP1 | 27156058Sbostic awk '{ 27256058Sbostic if (i == 120) 27356058Sbostic exit; 27456058Sbostic printf("p\nk%d\nd%s\n", ++i, $0); 27556058Sbostic } 27656058Sbostic END { 27756058Sbostic printf("fR_NEXT\n"); 27856058Sbostic for (i = 1; i <= 120; ++i) 27956058Sbostic printf("s\n"); 28056058Sbostic printf("fR_CURSOR\ns\nk120\n"); 28156058Sbostic printf("r\nk120\n"); 28256058Sbostic printf("fR_NEXT\ns\n"); 28356058Sbostic printf("fR_CURSOR\ns\nk1\n"); 28456058Sbostic printf("r\nk1\n"); 28556058Sbostic printf("fR_FIRST\ns\n"); 28656058Sbostic }' > $TMP2 28756058Sbostic $PROG -o $TMP3 recno $TMP2 28856058Sbostic if (cmp -s $TMP1 $TMP3) ; then 28956058Sbostic else 29056058Sbostic printf "test7: type $type: failed\n" 29156058Sbostic exit 1 29256058Sbostic fi 29356058Sbostic done 29456058Sbostic} 29556058Sbostic 296*56085Sbostic# Try a variety of bucketsizes and fill factors for hashing 297*56085Sbostictest8() 298*56085Sbostic{ 299*56085Sbostic printf\ 300*56085Sbostic "Test 8: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n" 301*56085Sbostic awk 'BEGIN { 302*56085Sbostic for (i = 1; i <= 10000; ++i) 303*56085Sbostic printf("%.*s\n", i % 34, 304*56085Sbostic "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 305*56085Sbostic }' > $TMP1 306*56085Sbostic sed 10000q $DICT | 307*56085Sbostic awk '{ 308*56085Sbostic ++i; 309*56085Sbostic printf("p\nk%s\nd%.*s\n", $0, i % 34, 310*56085Sbostic "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 311*56085Sbostic }' > $TMP2 312*56085Sbostic sed 10000q $DICT | 313*56085Sbostic awk '{ 314*56085Sbostic ++i; 315*56085Sbostic printf("g\nk%s\n", $0); 316*56085Sbostic }' >> $TMP2 317*56085Sbostic bsize=256 318*56085Sbostic for ffactor in 11 14 21; do 319*56085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 320*56085Sbostic $PROG -ot3 \ 321*56085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 322*56085Sbostic hash $TMP2 323*56085Sbostic if (cmp -s $TMP1 $TMP3) ; then 324*56085Sbostic else 325*56085Sbostic printf "test8: type hash:\ 326*56085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 327*56085Sbostic exit 1 328*56085Sbostic fi 329*56085Sbostic done 330*56085Sbostic bsize=512 331*56085Sbostic for ffactor in 21 28 43; do 332*56085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 333*56085Sbostic $PROG -ot3 \ 334*56085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 335*56085Sbostic hash $TMP2 336*56085Sbostic if (cmp -s $TMP1 $TMP3) ; then 337*56085Sbostic else 338*56085Sbostic printf "test8: type hash:\ 339*56085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 340*56085Sbostic exit 1 341*56085Sbostic fi 342*56085Sbostic done 343*56085Sbostic bsize=1024 344*56085Sbostic for ffactor in 43 57 85; do 345*56085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 346*56085Sbostic $PROG -ot3 \ 347*56085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 348*56085Sbostic hash $TMP2 349*56085Sbostic if (cmp -s $TMP1 $TMP3) ; then 350*56085Sbostic else 351*56085Sbostic printf "test8: type hash:\ 352*56085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 353*56085Sbostic exit 1 354*56085Sbostic fi 355*56085Sbostic done 356*56085Sbostic bsize=2048 357*56085Sbostic for ffactor in 85 114 171; do 358*56085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 359*56085Sbostic $PROG -ot3 \ 360*56085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 361*56085Sbostic hash $TMP2 362*56085Sbostic if (cmp -s $TMP1 $TMP3) ; then 363*56085Sbostic else 364*56085Sbostic printf "test8: type hash:\ 365*56085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 366*56085Sbostic exit 1 367*56085Sbostic fi 368*56085Sbostic done 369*56085Sbostic bsize=4096 370*56085Sbostic for ffactor in 171 228 341; do 371*56085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 372*56085Sbostic $PROG -ot3 \ 373*56085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 374*56085Sbostic hash $TMP2 375*56085Sbostic if (cmp -s $TMP1 $TMP3) ; then 376*56085Sbostic else 377*56085Sbostic printf "test8: type hash:\ 378*56085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 379*56085Sbostic exit 1 380*56085Sbostic fi 381*56085Sbostic done 382*56085Sbostic bsize=8192 383*56085Sbostic for ffactor in 341 455 683; do 384*56085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 385*56085Sbostic $PROG -ot3 \ 386*56085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 387*56085Sbostic hash $TMP2 388*56085Sbostic if (cmp -s $TMP1 $TMP3) ; then 389*56085Sbostic else 390*56085Sbostic printf "test8: type hash:\ 391*56085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 392*56085Sbostic exit 1 393*56085Sbostic fi 394*56085Sbostic done 395*56085Sbostic} 396*56085Sbostic 39756038Sbosticmain 398