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*56765Sbostic# @(#)run.test 5.10 (Berkeley) 11/13/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 2856085Sbostic test8 2956495Sbostic test9 30*56765Sbostic test10 3156038Sbostic rm -f $TMP1 $TMP2 $TMP3 3256038Sbostic} 3356038Sbostic 3456038Sbostic# Take the first hundred entries in the dictionary, and make them 3556038Sbostic# be key/data pairs. 3656038Sbostictest1() 3756038Sbostic{ 3856050Sbostic printf "Test 1: btree, hash: small key, small data pairs\n" 3956085Sbostic sed 200q $DICT > $TMP1 4056038Sbostic for type in btree hash; do 4156038Sbostic rm -f $TMP2 $TMP3 4256038Sbostic for i in `sed 200q $DICT`; do 4356038Sbostic printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i 4456038Sbostic done > $TMP2 4556058Sbostic $PROG -o $TMP3 $type $TMP2 4656038Sbostic if (cmp -s $TMP1 $TMP3) ; then 4756038Sbostic else 4856038Sbostic printf "test1: type %s: failed\n" $type 4956038Sbostic exit 1 5056038Sbostic fi 5156038Sbostic done 5256050Sbostic printf "Test 1: recno: small key, small data pairs\n" 5356038Sbostic rm -f $TMP2 $TMP3 5456038Sbostic sed 200q $DICT | 5556058Sbostic awk '{ 5656058Sbostic ++i; 5756058Sbostic printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); 5856058Sbostic }' > $TMP2 5956058Sbostic $PROG -o $TMP3 recno $TMP2 6056038Sbostic if (cmp -s $TMP1 $TMP3) ; then 6156038Sbostic else 6256038Sbostic printf "test1: type recno: failed\n" 6356038Sbostic exit 1 6456038Sbostic fi 6556038Sbostic} 6656038Sbostic 6756038Sbostic# Take the first hundred entries in the dictionary, and give them 6856038Sbostic# each a medium size data entry. 6956038Sbostictest2() 7056038Sbostic{ 7156050Sbostic printf "Test 2: btree, hash: small key, medium data pairs\n" 7256038Sbostic mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 7356038Sbostic echo $mdata | 7456058Sbostic awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 7556038Sbostic for type in hash btree; do 7656038Sbostic rm -f $TMP2 $TMP3 7756038Sbostic for i in `sed 200q $DICT`; do 7856038Sbostic printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i 7956038Sbostic done > $TMP2 8056058Sbostic $PROG -o $TMP3 $type $TMP2 8156038Sbostic if (cmp -s $TMP1 $TMP3) ; then 8256038Sbostic else 8356038Sbostic printf "test2: type %s: failed\n" $type 8456038Sbostic exit 1 8556038Sbostic fi 8656038Sbostic done 8756050Sbostic printf "Test 2: recno: small key, medium data pairs\n" 8856038Sbostic rm -f $TMP2 $TMP3 8956038Sbostic echo $mdata | 9056058Sbostic awk '{ for (i = 1; i < 201; ++i) 9156058Sbostic printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); 9256058Sbostic }' > $TMP2 9356058Sbostic $PROG -o $TMP3 recno $TMP2 9456038Sbostic if (cmp -s $TMP1 $TMP3) ; then 9556038Sbostic else 9656038Sbostic printf "test2: type recno: failed\n" 9756038Sbostic exit 1 9856038Sbostic fi 9956038Sbostic} 10056038Sbostic 10156038Sbostic# Insert the programs in /bin with their paths as their keys. 10256038Sbostictest3() 10356038Sbostic{ 10456050Sbostic printf "Test 3: btree, hash: small key, big data pairs\n" 10556038Sbostic rm -f $TMP1 10656038Sbostic (find /bin -type f -print | xargs cat) > $TMP1 10756038Sbostic for type in hash btree; do 10856038Sbostic rm -f $TMP2 $TMP3 10956038Sbostic for i in `find /bin -type f -print`; do 11056038Sbostic printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i 11156038Sbostic done > $TMP2 11256058Sbostic $PROG -o $TMP3 $type $TMP2 11356038Sbostic if (cmp -s $TMP1 $TMP3) ; then 11456038Sbostic else 11556385Sbostic printf "test3: type %s: failed\n" $type 11656038Sbostic exit 1 11756038Sbostic fi 11856038Sbostic done 11956050Sbostic printf "Test 3: recno: big data pairs\n" 12056038Sbostic rm -f $TMP2 $TMP3 12156038Sbostic find /bin -type f -print | 12256058Sbostic awk '{ 12356058Sbostic ++i; 12456058Sbostic printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); 12556058Sbostic }' > $TMP2 12656058Sbostic $PROG -o $TMP3 recno $TMP2 12756038Sbostic if (cmp -s $TMP1 $TMP3) ; then 12856038Sbostic else 12956038Sbostic printf "test3: type recno: failed\n" 13056038Sbostic exit 1 13156038Sbostic fi 13256038Sbostic} 13356038Sbostic 13456038Sbostic# Do random recno entries. 13556038Sbostictest4() 13656038Sbostic{ 13756050Sbostic printf "Test 4: recno: random entries\n" 13856050Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 13956058Sbostic awk '{ 14056058Sbostic for (i = 37; i <= 37 + 88 * 17; i += 17) 14156058Sbostic printf("input key %d: %.*s\n", i, i % 41, $0); 14256058Sbostic for (i = 1; i <= 15; ++i) 14356058Sbostic printf("input key %d: %.*s\n", i, i % 41, $0); 14456058Sbostic for (i = 19234; i <= 19234 + 61 * 27; i += 27) 14556058Sbostic printf("input key %d: %.*s\n", i, i % 41, $0); 14656058Sbostic exit 14756058Sbostic }' > $TMP1 14856058Sbostic rm -f TMP2 $TMP3 14956058Sbostic cat $TMP1 | 15056058Sbostic awk 'BEGIN { 15156058Sbostic i = 37; 15256058Sbostic incr = 17; 15356058Sbostic } 15456058Sbostic { 15556058Sbostic printf("p\nk%d\nd%s\n", i, $0); 15656058Sbostic if (i == 19234 + 61 * 27) 15756058Sbostic exit; 15856058Sbostic if (i == 37 + 88 * 17) { 15956058Sbostic i = 1; 16056058Sbostic incr = 1; 16156058Sbostic } else if (i == 15) { 16256058Sbostic i = 19234; 16356058Sbostic incr = 27; 16456058Sbostic } else 16556058Sbostic i += incr; 16656058Sbostic } 16756058Sbostic END { 16856038Sbostic for (i = 37; i <= 37 + 88 * 17; i += 17) 16956058Sbostic printf("g\nk%d\n", i); 17056038Sbostic for (i = 1; i <= 15; ++i) 17156058Sbostic printf("g\nk%d\n", i); 17256038Sbostic for (i = 19234; i <= 19234 + 61 * 27; i += 27) 17356058Sbostic printf("g\nk%d\n", i); 17456058Sbostic }' > $TMP2 17556058Sbostic $PROG -o $TMP3 recno $TMP2 17656038Sbostic if (cmp -s $TMP1 $TMP3) ; then 17756038Sbostic else 17856038Sbostic printf "test4: type recno: failed\n" 17956038Sbostic exit 1 18056038Sbostic fi 18156038Sbostic} 18256050Sbostic 18356050Sbostic# Do reverse order recno entries. 18456050Sbostictest5() 18556050Sbostic{ 18656050Sbostic printf "Test 5: recno: reverse order entries\n" 18756050Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 18856058Sbostic awk ' { 18956058Sbostic for (i = 1500; i; --i) 19056058Sbostic printf("input key %d: %.*s\n", i, i % 34, $0); 19156058Sbostic exit; 19256058Sbostic }' > $TMP1 19356050Sbostic rm -f TMP2 $TMP3 19456058Sbostic cat $TMP1 | 19556058Sbostic awk 'BEGIN { 19656058Sbostic i = 1500; 19756058Sbostic } 19856058Sbostic { 19956058Sbostic printf("p\nk%d\nd%s\n", i, $0); 20056058Sbostic --i; 20156058Sbostic } 20256058Sbostic END { 20356058Sbostic for (i = 1500; i; --i) 20456058Sbostic printf("g\nk%d\n", i); 20556058Sbostic }' > $TMP2 20656058Sbostic $PROG -o $TMP3 recno $TMP2 20756050Sbostic if (cmp -s $TMP1 $TMP3) ; then 20856050Sbostic else 20956050Sbostic printf "test5: type recno: failed\n" 21056050Sbostic exit 1 21156050Sbostic fi 21256050Sbostic} 21356038Sbostic 21456050Sbostic# Do alternating order recno entries. 21556050Sbostictest6() 21656050Sbostic{ 21756050Sbostic printf "Test 6: recno: alternating order entries\n" 21856050Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 21956058Sbostic awk ' { 22056058Sbostic for (i = 1; i < 1200; i += 2) 22156058Sbostic printf("input key %d: %.*s\n", i, i % 34, $0); 22256058Sbostic for (i = 2; i < 1200; i += 2) 22356058Sbostic printf("input key %d: %.*s\n", i, i % 34, $0); 22456058Sbostic exit; 22556058Sbostic }' > $TMP1 22656050Sbostic rm -f TMP2 $TMP3 22756058Sbostic cat $TMP1 | 22856058Sbostic awk 'BEGIN { 22956058Sbostic i = 1; 23056058Sbostic even = 0; 23156058Sbostic } 23256058Sbostic { 23356058Sbostic printf("p\nk%d\nd%s\n", i, $0); 23456058Sbostic i += 2; 23556058Sbostic if (i >= 1200) { 23656058Sbostic if (even == 1) 23756058Sbostic exit; 23856058Sbostic even = 1; 23956058Sbostic i = 2; 24056050Sbostic } 24156058Sbostic } 24256058Sbostic END { 24356058Sbostic for (i = 1; i < 1200; ++i) 24456058Sbostic printf("g\nk%d\n", i); 24556058Sbostic }' > $TMP2 24656058Sbostic $PROG -o $TMP3 recno $TMP2 24756050Sbostic sort -o $TMP1 $TMP1 24856050Sbostic sort -o $TMP3 $TMP3 24956050Sbostic if (cmp -s $TMP1 $TMP3) ; then 25056050Sbostic else 25156050Sbostic printf "test6: type recno: failed\n" 25256050Sbostic exit 1 25356050Sbostic fi 25456050Sbostic} 25556050Sbostic 25656058Sbostic# Delete cursor record 25756058Sbostictest7() 25856058Sbostic{ 25956058Sbostic printf "Test 7: btree, recno: delete cursor record\n" 26056058Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 26156058Sbostic awk '{ 26256058Sbostic for (i = 1; i <= 120; ++i) 26356058Sbostic printf("%05d: input key %d: %s\n", i, i, $0); 26456058Sbostic printf("%05d: input key %d: %s\n", 120, 120, $0); 26556058Sbostic printf("get failed, no such key\n"); 26656058Sbostic printf("%05d: input key %d: %s\n", 1, 1, $0); 26756058Sbostic printf("%05d: input key %d: %s\n", 2, 2, $0); 26856058Sbostic exit; 26956058Sbostic }' > $TMP1 27056058Sbostic rm -f TMP2 $TMP3 27156763Sbostic 27256058Sbostic for type in btree recno; do 27356058Sbostic cat $TMP1 | 27456058Sbostic awk '{ 27556058Sbostic if (i == 120) 27656058Sbostic exit; 27756058Sbostic printf("p\nk%d\nd%s\n", ++i, $0); 27856058Sbostic } 27956058Sbostic END { 28056058Sbostic printf("fR_NEXT\n"); 28156058Sbostic for (i = 1; i <= 120; ++i) 28256058Sbostic printf("s\n"); 28356058Sbostic printf("fR_CURSOR\ns\nk120\n"); 28456058Sbostic printf("r\nk120\n"); 28556058Sbostic printf("fR_NEXT\ns\n"); 28656058Sbostic printf("fR_CURSOR\ns\nk1\n"); 28756058Sbostic printf("r\nk1\n"); 28856058Sbostic printf("fR_FIRST\ns\n"); 28956058Sbostic }' > $TMP2 29056058Sbostic $PROG -o $TMP3 recno $TMP2 29156058Sbostic if (cmp -s $TMP1 $TMP3) ; then 29256058Sbostic else 29356058Sbostic printf "test7: type $type: failed\n" 29456058Sbostic exit 1 29556058Sbostic fi 29656058Sbostic done 29756058Sbostic} 29856058Sbostic 29956495Sbostic# Make sure that overflow pages are reused. 30056085Sbostictest8() 30156085Sbostic{ 30256495Sbostic printf "Test 8: btree, hash: repeated small key, big data pairs\n" 30356495Sbostic rm -f $TMP1 30456495Sbostic awk 'BEGIN { 30556556Sbostic for (i = 1; i <= 10; ++i) { 30656495Sbostic printf("p\nkkey1\nD/bin/sh\n"); 30756495Sbostic printf("p\nkkey2\nD/bin/csh\n"); 30856554Sbostic if (i % 8 == 0) { 30956554Sbostic printf("c\nkkey2\nD/bin/csh\n"); 31056554Sbostic printf("c\nkkey1\nD/bin/sh\n"); 31156763Sbostic printf("e\t%d of 10 (comparison)\r\n", i); 31256554Sbostic } else 31356763Sbostic printf("e\t%d of 10 \r\n", i); 31456495Sbostic printf("r\nkkey1\nr\nkkey2\n"); 31556495Sbostic } 31656556Sbostic printf("e\n"); 31756556Sbostic printf("eend of test8 run\n"); 31856495Sbostic }' > $TMP1 31956554Sbostic $PROG btree $TMP1 32056554Sbostic $PROG hash $TMP1 32156495Sbostic # No explicit test for success. 32256495Sbostic} 32356495Sbostic 32456495Sbostic# Try a variety of bucketsizes and fill factors for hashing 32556495Sbostictest9() 32656495Sbostic{ 32756085Sbostic printf\ 32856495Sbostic "Test 9: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n" 32956085Sbostic awk 'BEGIN { 33056085Sbostic for (i = 1; i <= 10000; ++i) 33156085Sbostic printf("%.*s\n", i % 34, 33256085Sbostic "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 33356085Sbostic }' > $TMP1 33456085Sbostic sed 10000q $DICT | 33556085Sbostic awk '{ 33656085Sbostic ++i; 33756085Sbostic printf("p\nk%s\nd%.*s\n", $0, i % 34, 33856085Sbostic "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 33956085Sbostic }' > $TMP2 34056085Sbostic sed 10000q $DICT | 34156085Sbostic awk '{ 34256085Sbostic ++i; 34356085Sbostic printf("g\nk%s\n", $0); 34456085Sbostic }' >> $TMP2 34556085Sbostic bsize=256 34656085Sbostic for ffactor in 11 14 21; do 34756085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 34856495Sbostic $PROG -o$TMP3 \ 34956085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 35056085Sbostic hash $TMP2 35156085Sbostic if (cmp -s $TMP1 $TMP3) ; then 35256085Sbostic else 35356495Sbostic printf "test9: type hash:\ 35456085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 35556085Sbostic exit 1 35656085Sbostic fi 35756085Sbostic done 35856085Sbostic bsize=512 35956085Sbostic for ffactor in 21 28 43; do 36056085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 36156495Sbostic $PROG -o$TMP3 \ 36256085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 36356085Sbostic hash $TMP2 36456085Sbostic if (cmp -s $TMP1 $TMP3) ; then 36556085Sbostic else 36656495Sbostic printf "test9: type hash:\ 36756085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 36856085Sbostic exit 1 36956085Sbostic fi 37056085Sbostic done 37156085Sbostic bsize=1024 37256085Sbostic for ffactor in 43 57 85; do 37356085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 37456495Sbostic $PROG -o$TMP3 \ 37556085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 37656085Sbostic hash $TMP2 37756085Sbostic if (cmp -s $TMP1 $TMP3) ; then 37856085Sbostic else 37956495Sbostic printf "test9: type hash:\ 38056085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 38156085Sbostic exit 1 38256085Sbostic fi 38356085Sbostic done 38456085Sbostic bsize=2048 38556085Sbostic for ffactor in 85 114 171; do 38656085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 38756495Sbostic $PROG -o$TMP3 \ 38856085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 38956085Sbostic hash $TMP2 39056085Sbostic if (cmp -s $TMP1 $TMP3) ; then 39156085Sbostic else 39256495Sbostic printf "test9: type hash:\ 39356085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 39456085Sbostic exit 1 39556085Sbostic fi 39656085Sbostic done 39756085Sbostic bsize=4096 39856085Sbostic for ffactor in 171 228 341; do 39956085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 40056495Sbostic $PROG -o$TMP3 \ 40156085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 40256085Sbostic hash $TMP2 40356085Sbostic if (cmp -s $TMP1 $TMP3) ; then 40456085Sbostic else 40556495Sbostic printf "test9: type hash:\ 40656085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 40756085Sbostic exit 1 40856085Sbostic fi 40956085Sbostic done 41056085Sbostic bsize=8192 41156085Sbostic for ffactor in 341 455 683; do 41256085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 41356495Sbostic $PROG -o$TMP3 \ 41456085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 41556085Sbostic hash $TMP2 41656085Sbostic if (cmp -s $TMP1 $TMP3) ; then 41756085Sbostic else 41856495Sbostic printf "test9: type hash:\ 41956085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 42056085Sbostic exit 1 42156085Sbostic fi 42256085Sbostic done 42356085Sbostic} 42456085Sbostic 425*56765Sbostic# Test use of cursor flags without initialization 426*56765Sbostictest10() 427*56765Sbostic{ 428*56765Sbostic printf "Test 10: btree, recno: test cursor flag use\n" 429*56765Sbostic echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 430*56765Sbostic awk '{ 431*56765Sbostic for (i = 1; i <= 120; ++i) 432*56765Sbostic printf("%05d: input key %d: %s\n", i, i, $0); 433*56765Sbostic printf("%05d: input key %d: %s\n", 120, 120, $0); 434*56765Sbostic printf("get failed, no such key\n"); 435*56765Sbostic printf("%05d: input key %d: %s\n", 1, 1, $0); 436*56765Sbostic printf("%05d: input key %d: %s\n", 2, 2, $0); 437*56765Sbostic exit; 438*56765Sbostic }' > $TMP1 439*56765Sbostic rm -f TMP2 $TMP3 440*56765Sbostic 441*56765Sbostic # Test that R_CURSOR doesn't succeed before cursor initialized 442*56765Sbostic for type in btree recno; do 443*56765Sbostic cat $TMP1 | 444*56765Sbostic awk '{ 445*56765Sbostic if (i == 10) 446*56765Sbostic exit; 447*56765Sbostic printf("p\nk%d\nd%s\n", ++i, $0); 448*56765Sbostic } 449*56765Sbostic END { 450*56765Sbostic printf("fR_CURSOR\nr\nk1\n"); 451*56765Sbostic printf("eR_CURSOR SHOULD HAVE FAILED\n"); 452*56765Sbostic }' > $TMP2 453*56765Sbostic $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 454*56765Sbostic if [ -s $TMP3 ] ; then 455*56765Sbostic printf "Test 10: delete: R_CURSOR SHOULD HAVE FAILED\n" 456*56765Sbostic exit 1 457*56765Sbostic fi 458*56765Sbostic done 459*56765Sbostic for type in btree recno; do 460*56765Sbostic cat $TMP1 | 461*56765Sbostic awk '{ 462*56765Sbostic if (i == 10) 463*56765Sbostic exit; 464*56765Sbostic printf("p\nk%d\nd%s\n", ++i, $0); 465*56765Sbostic } 466*56765Sbostic END { 467*56765Sbostic printf("fR_CURSOR\np\nk1\ndsome data\n"); 468*56765Sbostic printf("eR_CURSOR SHOULD HAVE FAILED\n"); 469*56765Sbostic }' > $TMP2 470*56765Sbostic $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 471*56765Sbostic if [ -s $TMP3 ] ; then 472*56765Sbostic printf "Test 10: put: R_CURSOR SHOULD HAVE FAILED\n" 473*56765Sbostic exit 1 474*56765Sbostic fi 475*56765Sbostic done 476*56765Sbostic} 477*56765Sbostic 47856038Sbosticmain 479