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*56385Sbostic# @(#)run.test 5.5 (Berkeley) 10/01/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 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" 3756085Sbostic 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 113*56385Sbostic printf "test3: 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 29656085Sbostic# Try a variety of bucketsizes and fill factors for hashing 29756085Sbostictest8() 29856085Sbostic{ 29956085Sbostic printf\ 30056085Sbostic "Test 8: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n" 30156085Sbostic awk 'BEGIN { 30256085Sbostic for (i = 1; i <= 10000; ++i) 30356085Sbostic printf("%.*s\n", i % 34, 30456085Sbostic "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 30556085Sbostic }' > $TMP1 30656085Sbostic sed 10000q $DICT | 30756085Sbostic awk '{ 30856085Sbostic ++i; 30956085Sbostic printf("p\nk%s\nd%.*s\n", $0, i % 34, 31056085Sbostic "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 31156085Sbostic }' > $TMP2 31256085Sbostic sed 10000q $DICT | 31356085Sbostic awk '{ 31456085Sbostic ++i; 31556085Sbostic printf("g\nk%s\n", $0); 31656085Sbostic }' >> $TMP2 31756085Sbostic bsize=256 31856085Sbostic for ffactor in 11 14 21; do 31956085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 32056085Sbostic $PROG -ot3 \ 32156085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 32256085Sbostic hash $TMP2 32356085Sbostic if (cmp -s $TMP1 $TMP3) ; then 32456085Sbostic else 32556085Sbostic printf "test8: type hash:\ 32656085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 32756085Sbostic exit 1 32856085Sbostic fi 32956085Sbostic done 33056085Sbostic bsize=512 33156085Sbostic for ffactor in 21 28 43; do 33256085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 33356085Sbostic $PROG -ot3 \ 33456085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 33556085Sbostic hash $TMP2 33656085Sbostic if (cmp -s $TMP1 $TMP3) ; then 33756085Sbostic else 33856085Sbostic printf "test8: type hash:\ 33956085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 34056085Sbostic exit 1 34156085Sbostic fi 34256085Sbostic done 34356085Sbostic bsize=1024 34456085Sbostic for ffactor in 43 57 85; do 34556085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 34656085Sbostic $PROG -ot3 \ 34756085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 34856085Sbostic hash $TMP2 34956085Sbostic if (cmp -s $TMP1 $TMP3) ; then 35056085Sbostic else 35156085Sbostic printf "test8: type hash:\ 35256085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 35356085Sbostic exit 1 35456085Sbostic fi 35556085Sbostic done 35656085Sbostic bsize=2048 35756085Sbostic for ffactor in 85 114 171; do 35856085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 35956085Sbostic $PROG -ot3 \ 36056085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 36156085Sbostic hash $TMP2 36256085Sbostic if (cmp -s $TMP1 $TMP3) ; then 36356085Sbostic else 36456085Sbostic printf "test8: type hash:\ 36556085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 36656085Sbostic exit 1 36756085Sbostic fi 36856085Sbostic done 36956085Sbostic bsize=4096 37056085Sbostic for ffactor in 171 228 341; do 37156085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 37256085Sbostic $PROG -ot3 \ 37356085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 37456085Sbostic hash $TMP2 37556085Sbostic if (cmp -s $TMP1 $TMP3) ; then 37656085Sbostic else 37756085Sbostic printf "test8: type hash:\ 37856085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 37956085Sbostic exit 1 38056085Sbostic fi 38156085Sbostic done 38256085Sbostic bsize=8192 38356085Sbostic for ffactor in 341 455 683; do 38456085Sbostic printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor 38556085Sbostic $PROG -ot3 \ 38656085Sbostic -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 38756085Sbostic hash $TMP2 38856085Sbostic if (cmp -s $TMP1 $TMP3) ; then 38956085Sbostic else 39056085Sbostic printf "test8: type hash:\ 39156085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 39256085Sbostic exit 1 39356085Sbostic fi 39456085Sbostic done 39556085Sbostic} 39656085Sbostic 39756038Sbosticmain 398