xref: /csrg-svn/lib/libc/db/test/run.test (revision 64287)
156038Sbostic#!/bin/sh -
256038Sbostic#
3*64287Sbostic#	@(#)run.test	8.2 (Berkeley) 08/17/93
456038Sbostic#
556038Sbostic
656038Sbostic# db regression tests
756038Sbostic
856038Sbosticmain()
956038Sbostic{
1056038Sbostic	DICT=/usr/share/dict/words
1156058Sbostic	PROG=obj/dbtest
1256038Sbostic	TMP1=t1
1356038Sbostic	TMP2=t2
1456038Sbostic	TMP3=t3
1556038Sbostic
1656038Sbostic	test1
1756038Sbostic	test2
1856038Sbostic	test3
1956038Sbostic	test4
2056050Sbostic	test5
2156050Sbostic	test6
2256058Sbostic	test7
2356085Sbostic	test8
2457001Sbostic	test9
2556765Sbostic	test10
2656999Sbostic	test11
2757455Sbostic	test12
2859633Sbostic	test13
2956999Sbostic	test20
3056038Sbostic	rm -f $TMP1 $TMP2 $TMP3
3156999Sbostic	exit 0
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
4657460Sbostic		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
6057460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
6156038Sbostic	else
6256038Sbostic		printf "test1: type recno: failed\n"
6356038Sbostic		exit 1
6456038Sbostic	fi
6556038Sbostic}
6656038Sbostic
6757455Sbostic# Take the first 200 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
8157460Sbostic		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
9457460Sbostic	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{
10460233Sbostic	printf "Test 3: hash: small key, big data pairs\n"
10556038Sbostic	rm -f $TMP1
10656038Sbostic	(find /bin -type f -print | xargs cat) > $TMP1
10760233Sbostic	for type in hash; 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
11357460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
11456038Sbostic		else
115*64287Sbostic			printf "test3: %s: failed\n" $type
11656038Sbostic			exit 1
11756038Sbostic		fi
11856038Sbostic	done
11960233Sbostic	printf "Test 3: btree: small key, big data pairs\n"
12060233Sbostic	for psize in 512 16384 65536; do
12160233Sbostic		printf "\tpage size %d\n" $psize
12260233Sbostic		for type in btree; do
12360233Sbostic			rm -f $TMP2 $TMP3
12460233Sbostic			for i in `find /bin -type f -print`; do
12560233Sbostic				printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
12660233Sbostic			done > $TMP2
12760233Sbostic			$PROG -i psize=$psize -o $TMP3 $type $TMP2
12860233Sbostic			if (cmp -s $TMP1 $TMP3) ; then :
12960233Sbostic			else
13060233Sbostic				printf "test3: %s: page size %d: failed\n" \
13160233Sbostic				    $type $psize
13260233Sbostic				exit 1
13360233Sbostic			fi
13460233Sbostic		done
13560233Sbostic	done
13656050Sbostic	printf "Test 3: recno: big data pairs\n"
13756038Sbostic	rm -f $TMP2 $TMP3
13856038Sbostic	find /bin -type f -print |
13956058Sbostic	awk '{
14056058Sbostic		++i;
14156058Sbostic		printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
14256058Sbostic	}' > $TMP2
14360233Sbostic	for psize in 512 16384 65536; do
14460233Sbostic		printf "\tpage size %d\n" $psize
14560233Sbostic		$PROG -i psize=$psize -o $TMP3 recno $TMP2
14660233Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
14760233Sbostic		else
14860233Sbostic			printf "test3: recno: page size %d: failed\n" $psize
14960233Sbostic			exit 1
15060233Sbostic		fi
15160233Sbostic	done
15256038Sbostic}
15356038Sbostic
15456038Sbostic# Do random recno entries.
15556038Sbostictest4()
15656038Sbostic{
15756050Sbostic	printf "Test 4: recno: random entries\n"
15856050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
15956058Sbostic	awk '{
16056058Sbostic		for (i = 37; i <= 37 + 88 * 17; i += 17)
16156058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
16256058Sbostic		for (i = 1; i <= 15; ++i)
16356058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
16456058Sbostic		for (i = 19234; i <= 19234 + 61 * 27; i += 27)
16556058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
16656058Sbostic		exit
16756058Sbostic	}' > $TMP1
168*64287Sbostic	rm -f $TMP2 $TMP3
16956058Sbostic	cat $TMP1 |
17056058Sbostic	awk 'BEGIN {
17156058Sbostic			i = 37;
17256058Sbostic			incr = 17;
17356058Sbostic		}
17456058Sbostic		{
17556058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
17656058Sbostic			if (i == 19234 + 61 * 27)
17756058Sbostic				exit;
17856058Sbostic			if (i == 37 + 88 * 17) {
17956058Sbostic				i = 1;
18056058Sbostic				incr = 1;
18156058Sbostic			} else if (i == 15) {
18256058Sbostic				i = 19234;
18356058Sbostic				incr = 27;
18456058Sbostic			} else
18556058Sbostic				i += incr;
18656058Sbostic		}
18756058Sbostic		END {
18856038Sbostic			for (i = 37; i <= 37 + 88 * 17; i += 17)
18956058Sbostic				printf("g\nk%d\n", i);
19056038Sbostic			for (i = 1; i <= 15; ++i)
19156058Sbostic				printf("g\nk%d\n", i);
19256038Sbostic			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
19356058Sbostic				printf("g\nk%d\n", i);
19456058Sbostic		}' > $TMP2
19556058Sbostic	$PROG -o $TMP3 recno $TMP2
19657460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
19756038Sbostic	else
19856038Sbostic		printf "test4: type recno: failed\n"
19956038Sbostic		exit 1
20056038Sbostic	fi
20156038Sbostic}
20256050Sbostic
20356050Sbostic# Do reverse order recno entries.
20456050Sbostictest5()
20556050Sbostic{
20656050Sbostic	printf "Test 5: recno: reverse order entries\n"
20756050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
20856058Sbostic	awk ' {
20956058Sbostic		for (i = 1500; i; --i)
21056058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
21156058Sbostic		exit;
21256058Sbostic	}' > $TMP1
213*64287Sbostic	rm -f $TMP2 $TMP3
21456058Sbostic	cat $TMP1 |
21556058Sbostic	awk 'BEGIN {
21656058Sbostic			i = 1500;
21756058Sbostic		}
21856058Sbostic		{
21956058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
22056058Sbostic			--i;
22156058Sbostic		}
22256058Sbostic		END {
22356058Sbostic			for (i = 1500; i; --i)
22456058Sbostic				printf("g\nk%d\n", i);
22556058Sbostic		}' > $TMP2
22656058Sbostic	$PROG -o $TMP3 recno $TMP2
22757460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
22856050Sbostic	else
22956050Sbostic		printf "test5: type recno: failed\n"
23056050Sbostic		exit 1
23156050Sbostic	fi
23256050Sbostic}
23356038Sbostic
23456050Sbostic# Do alternating order recno entries.
23556050Sbostictest6()
23656050Sbostic{
23756050Sbostic	printf "Test 6: recno: alternating order entries\n"
23856050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
23956058Sbostic	awk ' {
24056058Sbostic		for (i = 1; i < 1200; i += 2)
24156058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
24256058Sbostic		for (i = 2; i < 1200; i += 2)
24356058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
24456058Sbostic		exit;
24556058Sbostic	}' > $TMP1
24656050Sbostic	rm -f TMP2 $TMP3
24756058Sbostic	cat $TMP1 |
24856058Sbostic	awk 'BEGIN {
24956058Sbostic			i = 1;
25056058Sbostic			even = 0;
25156058Sbostic		}
25256058Sbostic		{
25356058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
25456058Sbostic			i += 2;
25556058Sbostic			if (i >= 1200) {
25656058Sbostic				if (even == 1)
25756058Sbostic					exit;
25856058Sbostic				even = 1;
25956058Sbostic				i = 2;
26056050Sbostic			}
26156058Sbostic		}
26256058Sbostic		END {
26356058Sbostic			for (i = 1; i < 1200; ++i)
26456058Sbostic				printf("g\nk%d\n", i);
26556058Sbostic		}' > $TMP2
26656058Sbostic	$PROG -o $TMP3 recno $TMP2
26756050Sbostic	sort -o $TMP1 $TMP1
26856050Sbostic	sort -o $TMP3 $TMP3
26957460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
27056050Sbostic	else
27156050Sbostic		printf "test6: type recno: failed\n"
27256050Sbostic		exit 1
27356050Sbostic	fi
27456050Sbostic}
27556050Sbostic
27656058Sbostic# Delete cursor record
27756058Sbostictest7()
27856058Sbostic{
27956058Sbostic	printf "Test 7: btree, recno: delete cursor record\n"
28056058Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
28156058Sbostic	awk '{
28256058Sbostic		for (i = 1; i <= 120; ++i)
28356058Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
28456058Sbostic		printf("%05d: input key %d: %s\n", 120, 120, $0);
28556058Sbostic		printf("get failed, no such key\n");
28656058Sbostic		printf("%05d: input key %d: %s\n", 1, 1, $0);
28756058Sbostic		printf("%05d: input key %d: %s\n", 2, 2, $0);
28856058Sbostic		exit;
28956058Sbostic	}' > $TMP1
29056058Sbostic	rm -f TMP2 $TMP3
29156763Sbostic
29256058Sbostic	for type in btree recno; do
29356058Sbostic		cat $TMP1 |
29456058Sbostic		awk '{
29556058Sbostic			if (i == 120)
29656058Sbostic				exit;
29756058Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
29856058Sbostic		}
29956058Sbostic		END {
30056058Sbostic			printf("fR_NEXT\n");
30156058Sbostic			for (i = 1; i <= 120; ++i)
30256058Sbostic				printf("s\n");
30356058Sbostic			printf("fR_CURSOR\ns\nk120\n");
30456058Sbostic			printf("r\nk120\n");
30556058Sbostic			printf("fR_NEXT\ns\n");
30656058Sbostic			printf("fR_CURSOR\ns\nk1\n");
30756058Sbostic			printf("r\nk1\n");
30856058Sbostic			printf("fR_FIRST\ns\n");
30956058Sbostic		}' > $TMP2
31056058Sbostic		$PROG -o $TMP3 recno $TMP2
31157460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
31256058Sbostic		else
31356058Sbostic			printf "test7: type $type: failed\n"
31456058Sbostic			exit 1
31556058Sbostic		fi
31656058Sbostic	done
31756058Sbostic}
31856058Sbostic
31956495Sbostic# Make sure that overflow pages are reused.
32056085Sbostictest8()
32156085Sbostic{
32256495Sbostic	printf "Test 8: btree, hash: repeated small key, big data pairs\n"
32356495Sbostic	rm -f $TMP1
32456495Sbostic	awk 'BEGIN {
32556556Sbostic		for (i = 1; i <= 10; ++i) {
32656495Sbostic			printf("p\nkkey1\nD/bin/sh\n");
32756495Sbostic			printf("p\nkkey2\nD/bin/csh\n");
32856554Sbostic			if (i % 8 == 0) {
32956554Sbostic				printf("c\nkkey2\nD/bin/csh\n");
33056554Sbostic				printf("c\nkkey1\nD/bin/sh\n");
33156763Sbostic				printf("e\t%d of 10 (comparison)\r\n", i);
33256554Sbostic			} else
33356763Sbostic				printf("e\t%d of 10             \r\n", i);
33456495Sbostic			printf("r\nkkey1\nr\nkkey2\n");
33556495Sbostic		}
33656556Sbostic		printf("e\n");
33756556Sbostic		printf("eend of test8 run\n");
33856495Sbostic	}' > $TMP1
33956554Sbostic	$PROG btree $TMP1
34056554Sbostic	$PROG hash $TMP1
34156495Sbostic	# No explicit test for success.
34256495Sbostic}
34356495Sbostic
34457001Sbostic# Test btree duplicate keys
34557001Sbostictest9()
34657001Sbostic{
34757001Sbostic	printf "Test 9: btree: duplicate keys\n"
34857001Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
34957001Sbostic	awk '{
35057001Sbostic		for (i = 1; i <= 543; ++i)
35157001Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
35257001Sbostic		exit;
35357001Sbostic	}' > $TMP1
35457001Sbostic	rm -f TMP2 $TMP3
35557001Sbostic
35657001Sbostic	for type in btree; do
35757001Sbostic		cat $TMP1 |
35857001Sbostic		awk '{
35957001Sbostic			if (i++ % 2)
36057001Sbostic				printf("p\nkduplicatekey\nd%s\n", $0);
36157001Sbostic			else
36257001Sbostic				printf("p\nkunique%dkey\nd%s\n", i, $0);
36357001Sbostic		}
36457001Sbostic		END {
36557001Sbostic				printf("o\n");
36657001Sbostic		}' > $TMP2
36757001Sbostic		$PROG -iflags=1 -o $TMP3 $type $TMP2
36857001Sbostic		sort -o $TMP3 $TMP3
36957460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
37057001Sbostic		else
37157001Sbostic			printf "test9: type $type: failed\n"
37257001Sbostic			exit 1
37357001Sbostic		fi
37457001Sbostic	done
37557001Sbostic}
37657001Sbostic
37756999Sbostic# Test use of cursor flags without initialization
37856999Sbostictest10()
37956999Sbostic{
38056999Sbostic	printf "Test 10: btree, recno: test cursor flag use\n"
38156999Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
38256999Sbostic	awk '{
38356999Sbostic		for (i = 1; i <= 20; ++i)
38456999Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
38556999Sbostic		exit;
38656999Sbostic	}' > $TMP1
38756999Sbostic	rm -f TMP2 $TMP3
38856999Sbostic
38956999Sbostic	# Test that R_CURSOR doesn't succeed before cursor initialized
39056999Sbostic	for type in btree recno; do
39156999Sbostic		cat $TMP1 |
39256999Sbostic		awk '{
39356999Sbostic			if (i == 10)
39456999Sbostic				exit;
39556999Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
39656999Sbostic		}
39756999Sbostic		END {
39856999Sbostic			printf("fR_CURSOR\nr\nk1\n");
39956999Sbostic			printf("eR_CURSOR SHOULD HAVE FAILED\n");
40056999Sbostic		}' > $TMP2
40156999Sbostic		$PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
40256999Sbostic		if [ -s $TMP3 ] ; then
40356999Sbostic			printf "Test 10: delete: R_CURSOR SHOULD HAVE FAILED\n"
40456999Sbostic			exit 1
40556999Sbostic		fi
40656999Sbostic	done
40756999Sbostic	for type in btree recno; do
40856999Sbostic		cat $TMP1 |
40956999Sbostic		awk '{
41056999Sbostic			if (i == 10)
41156999Sbostic				exit;
41256999Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
41356999Sbostic		}
41456999Sbostic		END {
41556999Sbostic			printf("fR_CURSOR\np\nk1\ndsome data\n");
41656999Sbostic			printf("eR_CURSOR SHOULD HAVE FAILED\n");
41756999Sbostic		}' > $TMP2
41856999Sbostic		$PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
41956999Sbostic		if [ -s $TMP3 ] ; then
42056999Sbostic			printf "Test 10: put: R_CURSOR SHOULD HAVE FAILED\n"
42156999Sbostic			exit 1
42256999Sbostic		fi
42356999Sbostic	done
42456999Sbostic}
42556999Sbostic
42656999Sbostic# Test insert in reverse order.
42756999Sbostictest11()
42856999Sbostic{
42956999Sbostic	printf "Test 11: recno: reverse order insert\n"
43056999Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
43156999Sbostic	awk '{
43256999Sbostic		for (i = 1; i <= 779; ++i)
43356999Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
43456999Sbostic		exit;
43556999Sbostic	}' > $TMP1
43656999Sbostic	rm -f TMP2 $TMP3
43756999Sbostic
43856999Sbostic	for type in recno; do
43956999Sbostic		cat $TMP1 |
44056999Sbostic		awk '{
44156999Sbostic			if (i == 0) {
44256999Sbostic				i = 1;
44356999Sbostic				printf("p\nk1\nd%s\n", $0);
44456999Sbostic				printf("%s\n", "fR_IBEFORE");
44556999Sbostic			} else
44656999Sbostic				printf("p\nk1\nd%s\n", $0);
44756999Sbostic		}
44856999Sbostic		END {
44956999Sbostic				printf("or\n");
45056999Sbostic		}' > $TMP2
45156999Sbostic		$PROG -o $TMP3 $type $TMP2
45257460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
45356999Sbostic		else
45456999Sbostic			printf "test11: type $type: failed\n"
45556999Sbostic			exit 1
45656999Sbostic		fi
45756999Sbostic	done
45856999Sbostic}
45956999Sbostic
46057455Sbostic# Take the first 20000 entries in the dictionary, reverse them, and give
46157455Sbostic# them each a small size data entry.  Use a small page size to make sure
46257455Sbostic# the btree split code gets hammered.
46357455Sbostictest12()
46457455Sbostic{
46557455Sbostic	printf "Test 12: btree: lots of keys, small page size\n"
46657455Sbostic	mdata=abcdefghijklmnopqrstuvwxy
46757455Sbostic	echo $mdata |
46857455Sbostic	awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1
46957455Sbostic	for type in btree; do
47057455Sbostic		rm -f $TMP2 $TMP3
47157455Sbostic		for i in `sed 20000q $DICT | rev`; do
47257455Sbostic			printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
47357455Sbostic		done > $TMP2
47457455Sbostic		$PROG -i psize=512 -o $TMP3 $type $TMP2
47557460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
47657455Sbostic		else
47757455Sbostic			printf "test12: type %s: failed\n" $type
47857455Sbostic			exit 1
47957455Sbostic		fi
48057455Sbostic	done
48157455Sbostic}
48257455Sbostic
48359633Sbostic# Test different byte orders.
48459633Sbostictest13()
48559633Sbostic{
48659633Sbostic	printf "Test 13: btree, hash: differing byte orders\n"
48759633Sbostic	sed 50q $DICT > $TMP1
48859633Sbostic	for order in 1234 4321; do
48959633Sbostic		for type in btree hash; do
49059633Sbostic			rm -f byte.file $TMP2 $TMP3
49159633Sbostic			for i in `sed 50q $DICT`; do
49259633Sbostic				printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
49359633Sbostic			done > $TMP2
49459633Sbostic			$PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
49559633Sbostic			if (cmp -s $TMP1 $TMP3) ; then :
49659633Sbostic			else
49759633Sbostic				printf "test13: %s/%s put failed\n" $type $order
49859633Sbostic				exit 1
49959633Sbostic			fi
50059633Sbostic			for i in `sed 50q $DICT`; do
50159633Sbostic				printf "g\nk%s\n" $i
50259633Sbostic			done > $TMP2
50359633Sbostic			$PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
50459633Sbostic			if (cmp -s $TMP1 $TMP3) ; then :
50559633Sbostic			else
50659633Sbostic				printf "test13: %s/%s get failed\n" $type $order
50759633Sbostic				exit 1
50859633Sbostic			fi
50959633Sbostic		done
51059633Sbostic	done
51159633Sbostic	rm -f byte.file
51259633Sbostic}
51359633Sbostic
51456495Sbostic# Try a variety of bucketsizes and fill factors for hashing
51556999Sbostictest20()
51656495Sbostic{
51756085Sbostic	printf\
51856999Sbostic    "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n"
51956085Sbostic	awk 'BEGIN {
52056085Sbostic		for (i = 1; i <= 10000; ++i)
52156085Sbostic			printf("%.*s\n", i % 34,
52256085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
52356085Sbostic	}' > $TMP1
52456085Sbostic	sed 10000q $DICT |
52556085Sbostic	awk '{
52656085Sbostic		++i;
52756085Sbostic		printf("p\nk%s\nd%.*s\n", $0, i % 34,
52856085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
52956085Sbostic	}' > $TMP2
53056085Sbostic	sed 10000q $DICT |
53156085Sbostic	awk '{
53256085Sbostic		++i;
53356085Sbostic		printf("g\nk%s\n", $0);
53456085Sbostic	}' >> $TMP2
53556085Sbostic	bsize=256
53656085Sbostic	for ffactor in 11 14 21; do
53759494Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
53856495Sbostic		$PROG -o$TMP3 \
53956085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
54056085Sbostic		    hash $TMP2
54157460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
54256085Sbostic		else
54356999Sbostic			printf "test20: type hash:\
54456085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
54556085Sbostic			exit 1
54656085Sbostic		fi
54756085Sbostic	done
54856085Sbostic	bsize=512
54956085Sbostic	for ffactor in 21 28 43; do
55059494Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
55156495Sbostic		$PROG -o$TMP3 \
55256085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
55356085Sbostic		    hash $TMP2
55457460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
55556085Sbostic		else
55656999Sbostic			printf "test20: type hash:\
55756085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
55856085Sbostic			exit 1
55956085Sbostic		fi
56056085Sbostic	done
56156085Sbostic	bsize=1024
56256085Sbostic	for ffactor in 43 57 85; do
56359494Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
56456495Sbostic		$PROG -o$TMP3 \
56556085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
56656085Sbostic		    hash $TMP2
56757460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
56856085Sbostic		else
56956999Sbostic			printf "test20: type hash:\
57056085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
57156085Sbostic			exit 1
57256085Sbostic		fi
57356085Sbostic	done
57456085Sbostic	bsize=2048
57556085Sbostic	for ffactor in 85 114 171; do
57659494Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
57756495Sbostic		$PROG -o$TMP3 \
57856085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
57956085Sbostic		    hash $TMP2
58057460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
58156085Sbostic		else
58256999Sbostic			printf "test20: type hash:\
58356085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
58456085Sbostic			exit 1
58556085Sbostic		fi
58656085Sbostic	done
58756085Sbostic	bsize=4096
58856085Sbostic	for ffactor in 171 228 341; do
58959494Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
59056495Sbostic		$PROG -o$TMP3 \
59156085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
59256085Sbostic		    hash $TMP2
59357460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
59456085Sbostic		else
59556999Sbostic			printf "test20: type hash:\
59656085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
59756085Sbostic			exit 1
59856085Sbostic		fi
59956085Sbostic	done
60056085Sbostic	bsize=8192
60156085Sbostic	for ffactor in 341 455 683; do
60259494Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
60356495Sbostic		$PROG -o$TMP3 \
60456085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
60556085Sbostic		    hash $TMP2
60657460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
60756085Sbostic		else
60856999Sbostic			printf "test20: type hash:\
60956085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
61056085Sbostic			exit 1
61156085Sbostic		fi
61256085Sbostic	done
61356085Sbostic}
61456085Sbostic
61556038Sbosticmain
616