xref: /csrg-svn/lib/libc/db/test/run.test (revision 64444)
156038Sbostic#!/bin/sh -
256038Sbostic#
3*64444Sbostic#	@(#)run.test	8.3 (Berkeley) 09/06/93
456038Sbostic#
556038Sbostic
656038Sbostic# db regression tests
756038Sbosticmain()
856038Sbostic{
9*64444Sbostic
10*64444Sbostic	DICT=/usr/dict/words
11*64444Sbostic	PROG=dbtest
1256038Sbostic	TMP1=t1
1356038Sbostic	TMP2=t2
1456038Sbostic	TMP3=t3
1556038Sbostic
16*64444Sbostic	if [ $# -ge 1 ]; then
17*64444Sbostic		for i in "$*"; do
18*64444Sbostic			test$i
19*64444Sbostic		done
20*64444Sbostic	else
21*64444Sbostic		test1
22*64444Sbostic		test2
23*64444Sbostic		test3
24*64444Sbostic		test4
25*64444Sbostic		test5
26*64444Sbostic		test6
27*64444Sbostic		test7
28*64444Sbostic		test8
29*64444Sbostic		test9
30*64444Sbostic		test10
31*64444Sbostic		test11
32*64444Sbostic		test12
33*64444Sbostic		test13
34*64444Sbostic		test20
35*64444Sbostic		rm -f $TMP1 $TMP2 $TMP3
36*64444Sbostic	fi
3756999Sbostic	exit 0
3856038Sbostic}
3956038Sbostic
4056038Sbostic# Take the first hundred entries in the dictionary, and make them
4156038Sbostic# be key/data pairs.
4256038Sbostictest1()
4356038Sbostic{
44*64444Sbostic	echo "Test 1: btree, hash: small key, small data pairs"
4556085Sbostic	sed 200q $DICT > $TMP1
4656038Sbostic	for type in btree hash; do
4756038Sbostic		rm -f $TMP2 $TMP3
4856038Sbostic		for i in `sed 200q $DICT`; do
49*64444Sbostic			echo p
50*64444Sbostic			echo k$i
51*64444Sbostic			echo d$i
52*64444Sbostic			echo g
53*64444Sbostic			echo k$i
5456038Sbostic		done > $TMP2
5556058Sbostic		$PROG -o $TMP3 $type $TMP2
5657460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
5756038Sbostic		else
58*64444Sbostic			echo "test1: type $type: failed"
5956038Sbostic			exit 1
6056038Sbostic		fi
6156038Sbostic	done
62*64444Sbostic	echo "Test 1: recno: small key, small data pairs"
6356038Sbostic	rm -f $TMP2 $TMP3
6456038Sbostic	sed 200q $DICT |
6556058Sbostic	awk '{
6656058Sbostic		++i;
6756058Sbostic		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
6856058Sbostic	}' > $TMP2
6956058Sbostic	$PROG -o $TMP3 recno $TMP2
7057460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
7156038Sbostic	else
72*64444Sbostic		echo "test1: type recno: failed"
7356038Sbostic		exit 1
7456038Sbostic	fi
7556038Sbostic}
7656038Sbostic
7757455Sbostic# Take the first 200 entries in the dictionary, and give them
7856038Sbostic# each a medium size data entry.
7956038Sbostictest2()
8056038Sbostic{
81*64444Sbostic	echo "Test 2: btree, hash: small key, medium data pairs"
8256038Sbostic	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
8356038Sbostic	echo $mdata |
8456058Sbostic	awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
8556038Sbostic	for type in hash btree; do
8656038Sbostic		rm -f $TMP2 $TMP3
8756038Sbostic		for i in `sed 200q $DICT`; do
88*64444Sbostic			echo p
89*64444Sbostic			echo k$i
90*64444Sbostic			echo d$mdata
91*64444Sbostic			echo g
92*64444Sbostic			echo k$i
9356038Sbostic		done > $TMP2
9456058Sbostic		$PROG -o $TMP3 $type $TMP2
9557460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
9656038Sbostic		else
97*64444Sbostic			echo "test2: type $type: failed"
9856038Sbostic			exit 1
9956038Sbostic		fi
10056038Sbostic	done
101*64444Sbostic	echo "Test 2: recno: small key, medium data pairs"
10256038Sbostic	rm -f $TMP2 $TMP3
10356038Sbostic	echo $mdata |
10456058Sbostic	awk '{  for (i = 1; i < 201; ++i)
10556058Sbostic		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
10656058Sbostic	}' > $TMP2
10756058Sbostic	$PROG -o $TMP3 recno $TMP2
10857460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
10956038Sbostic	else
110*64444Sbostic		echo "test2: type recno: failed"
11156038Sbostic		exit 1
11256038Sbostic	fi
11356038Sbostic}
11456038Sbostic
11556038Sbostic# Insert the programs in /bin with their paths as their keys.
11656038Sbostictest3()
11756038Sbostic{
118*64444Sbostic	echo "Test 3: hash: small key, big data pairs"
11956038Sbostic	rm -f $TMP1
12056038Sbostic	(find /bin -type f -print | xargs cat) > $TMP1
12160233Sbostic	for type in hash; do
12256038Sbostic		rm -f $TMP2 $TMP3
12356038Sbostic		for i in `find /bin -type f -print`; do
124*64444Sbostic			echo p
125*64444Sbostic			echo k$i
126*64444Sbostic			echo D$i
127*64444Sbostic			echo g
128*64444Sbostic			echo k$i
12956038Sbostic		done > $TMP2
13056058Sbostic		$PROG -o $TMP3 $type $TMP2
13157460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
13256038Sbostic		else
133*64444Sbostic			echo "test3: $type: failed"
13456038Sbostic			exit 1
13556038Sbostic		fi
13656038Sbostic	done
137*64444Sbostic	echo "Test 3: btree: small key, big data pairs"
13860233Sbostic	for psize in 512 16384 65536; do
139*64444Sbostic		echo "    page size $psize"
14060233Sbostic		for type in btree; do
14160233Sbostic			rm -f $TMP2 $TMP3
14260233Sbostic			for i in `find /bin -type f -print`; do
143*64444Sbostic				echo p
144*64444Sbostic				echo k$i
145*64444Sbostic				echo D$i
146*64444Sbostic				echo g
147*64444Sbostic				echo k$i
14860233Sbostic			done > $TMP2
14960233Sbostic			$PROG -i psize=$psize -o $TMP3 $type $TMP2
15060233Sbostic			if (cmp -s $TMP1 $TMP3) ; then :
15160233Sbostic			else
152*64444Sbostic				echo "test3: $type: page size $psize: failed"
15360233Sbostic				exit 1
15460233Sbostic			fi
15560233Sbostic		done
15660233Sbostic	done
157*64444Sbostic	echo "Test 3: recno: big data pairs"
15856038Sbostic	rm -f $TMP2 $TMP3
15956038Sbostic	find /bin -type f -print |
16056058Sbostic	awk '{
16156058Sbostic		++i;
16256058Sbostic		printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
16356058Sbostic	}' > $TMP2
16460233Sbostic	for psize in 512 16384 65536; do
165*64444Sbostic		echo "    page size $psize"
16660233Sbostic		$PROG -i psize=$psize -o $TMP3 recno $TMP2
16760233Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
16860233Sbostic		else
169*64444Sbostic			echo "test3: recno: page size $psize: failed"
17060233Sbostic			exit 1
17160233Sbostic		fi
17260233Sbostic	done
17356038Sbostic}
17456038Sbostic
17556038Sbostic# Do random recno entries.
17656038Sbostictest4()
17756038Sbostic{
178*64444Sbostic	echo "Test 4: recno: random entries"
17956050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
18056058Sbostic	awk '{
181*64444Sbostic		for (i = 37; i <= 37 + 88 * 17; i += 17) {
182*64444Sbostic			s = substr($0, 1, i % 41);
183*64444Sbostic			printf("input key %d: %s\n", i, s);
184*64444Sbostic		}
185*64444Sbostic		for (i = 1; i <= 15; ++i) {
186*64444Sbostic			s = substr($0, 1, i % 41);
187*64444Sbostic			printf("input key %d: %s\n", i, s);
188*64444Sbostic		}
189*64444Sbostic		for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
190*64444Sbostic			s = substr($0, 1, i % 41);
191*64444Sbostic			printf("input key %d: %s\n", i, s);
192*64444Sbostic		}
19356058Sbostic		exit
19456058Sbostic	}' > $TMP1
19564287Sbostic	rm -f $TMP2 $TMP3
19656058Sbostic	cat $TMP1 |
19756058Sbostic	awk 'BEGIN {
19856058Sbostic			i = 37;
19956058Sbostic			incr = 17;
20056058Sbostic		}
20156058Sbostic		{
20256058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
20356058Sbostic			if (i == 19234 + 61 * 27)
20456058Sbostic				exit;
20556058Sbostic			if (i == 37 + 88 * 17) {
20656058Sbostic				i = 1;
20756058Sbostic				incr = 1;
20856058Sbostic			} else if (i == 15) {
20956058Sbostic				i = 19234;
21056058Sbostic				incr = 27;
21156058Sbostic			} else
21256058Sbostic				i += incr;
21356058Sbostic		}
21456058Sbostic		END {
21556038Sbostic			for (i = 37; i <= 37 + 88 * 17; i += 17)
21656058Sbostic				printf("g\nk%d\n", i);
21756038Sbostic			for (i = 1; i <= 15; ++i)
21856058Sbostic				printf("g\nk%d\n", i);
21956038Sbostic			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
22056058Sbostic				printf("g\nk%d\n", i);
22156058Sbostic		}' > $TMP2
22256058Sbostic	$PROG -o $TMP3 recno $TMP2
22357460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
22456038Sbostic	else
225*64444Sbostic		echo "test4: type recno: failed"
22656038Sbostic		exit 1
22756038Sbostic	fi
22856038Sbostic}
22956050Sbostic
23056050Sbostic# Do reverse order recno entries.
23156050Sbostictest5()
23256050Sbostic{
233*64444Sbostic	echo "Test 5: recno: reverse order entries"
23456050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
23556058Sbostic	awk ' {
236*64444Sbostic		for (i = 1500; i; --i) {
237*64444Sbostic			s = substr($0, 1, i % 34);
238*64444Sbostic			printf("input key %d: %s\n", i, s);
239*64444Sbostic		}
24056058Sbostic		exit;
24156058Sbostic	}' > $TMP1
24264287Sbostic	rm -f $TMP2 $TMP3
24356058Sbostic	cat $TMP1 |
24456058Sbostic	awk 'BEGIN {
24556058Sbostic			i = 1500;
24656058Sbostic		}
24756058Sbostic		{
24856058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
24956058Sbostic			--i;
25056058Sbostic		}
25156058Sbostic		END {
25256058Sbostic			for (i = 1500; i; --i)
25356058Sbostic				printf("g\nk%d\n", i);
25456058Sbostic		}' > $TMP2
25556058Sbostic	$PROG -o $TMP3 recno $TMP2
25657460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
25756050Sbostic	else
258*64444Sbostic		echo "test5: type recno: failed"
25956050Sbostic		exit 1
26056050Sbostic	fi
26156050Sbostic}
26256038Sbostic
26356050Sbostic# Do alternating order recno entries.
26456050Sbostictest6()
26556050Sbostic{
266*64444Sbostic	echo "Test 6: recno: alternating order entries"
26756050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
26856058Sbostic	awk ' {
269*64444Sbostic		for (i = 1; i < 1200; i += 2) {
270*64444Sbostic			s = substr($0, 1, i % 34);
271*64444Sbostic			printf("input key %d: %s\n", i, s);
272*64444Sbostic		}
273*64444Sbostic		for (i = 2; i < 1200; i += 2) {
274*64444Sbostic			s = substr($0, 1, i % 34);
275*64444Sbostic			printf("input key %d: %s\n", i, s);
276*64444Sbostic		}
27756058Sbostic		exit;
27856058Sbostic	}' > $TMP1
279*64444Sbostic	rm -f $TMP2 $TMP3
28056058Sbostic	cat $TMP1 |
28156058Sbostic	awk 'BEGIN {
28256058Sbostic			i = 1;
28356058Sbostic			even = 0;
28456058Sbostic		}
28556058Sbostic		{
28656058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
28756058Sbostic			i += 2;
28856058Sbostic			if (i >= 1200) {
28956058Sbostic				if (even == 1)
29056058Sbostic					exit;
29156058Sbostic				even = 1;
29256058Sbostic				i = 2;
29356050Sbostic			}
29456058Sbostic		}
29556058Sbostic		END {
29656058Sbostic			for (i = 1; i < 1200; ++i)
29756058Sbostic				printf("g\nk%d\n", i);
29856058Sbostic		}' > $TMP2
29956058Sbostic	$PROG -o $TMP3 recno $TMP2
30056050Sbostic	sort -o $TMP1 $TMP1
30156050Sbostic	sort -o $TMP3 $TMP3
30257460Sbostic	if (cmp -s $TMP1 $TMP3) ; then :
30356050Sbostic	else
304*64444Sbostic		echo "test6: type recno: failed"
30556050Sbostic		exit 1
30656050Sbostic	fi
30756050Sbostic}
30856050Sbostic
30956058Sbostic# Delete cursor record
31056058Sbostictest7()
31156058Sbostic{
312*64444Sbostic	echo "Test 7: btree, recno: delete cursor record"
31356058Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
31456058Sbostic	awk '{
31556058Sbostic		for (i = 1; i <= 120; ++i)
31656058Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
31756058Sbostic		printf("%05d: input key %d: %s\n", 120, 120, $0);
31856058Sbostic		printf("get failed, no such key\n");
31956058Sbostic		printf("%05d: input key %d: %s\n", 1, 1, $0);
32056058Sbostic		printf("%05d: input key %d: %s\n", 2, 2, $0);
32156058Sbostic		exit;
32256058Sbostic	}' > $TMP1
323*64444Sbostic	rm -f $TMP2 $TMP3
32456763Sbostic
32556058Sbostic	for type in btree recno; do
32656058Sbostic		cat $TMP1 |
32756058Sbostic		awk '{
32856058Sbostic			if (i == 120)
32956058Sbostic				exit;
33056058Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
33156058Sbostic		}
33256058Sbostic		END {
33356058Sbostic			printf("fR_NEXT\n");
33456058Sbostic			for (i = 1; i <= 120; ++i)
33556058Sbostic				printf("s\n");
33656058Sbostic			printf("fR_CURSOR\ns\nk120\n");
33756058Sbostic			printf("r\nk120\n");
33856058Sbostic			printf("fR_NEXT\ns\n");
33956058Sbostic			printf("fR_CURSOR\ns\nk1\n");
34056058Sbostic			printf("r\nk1\n");
34156058Sbostic			printf("fR_FIRST\ns\n");
34256058Sbostic		}' > $TMP2
34356058Sbostic		$PROG -o $TMP3 recno $TMP2
34457460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
34556058Sbostic		else
346*64444Sbostic			echo "test7: type $type: failed"
34756058Sbostic			exit 1
34856058Sbostic		fi
34956058Sbostic	done
35056058Sbostic}
35156058Sbostic
35256495Sbostic# Make sure that overflow pages are reused.
35356085Sbostictest8()
35456085Sbostic{
355*64444Sbostic	echo "Test 8: btree, hash: repeated small key, big data pairs"
35656495Sbostic	rm -f $TMP1
357*64444Sbostic	echo "" |
35856495Sbostic	awk 'BEGIN {
35956556Sbostic		for (i = 1; i <= 10; ++i) {
36056495Sbostic			printf("p\nkkey1\nD/bin/sh\n");
36156495Sbostic			printf("p\nkkey2\nD/bin/csh\n");
36256554Sbostic			if (i % 8 == 0) {
36356554Sbostic				printf("c\nkkey2\nD/bin/csh\n");
36456554Sbostic				printf("c\nkkey1\nD/bin/sh\n");
36556763Sbostic				printf("e\t%d of 10 (comparison)\r\n", i);
36656554Sbostic			} else
36756763Sbostic				printf("e\t%d of 10             \r\n", i);
36856495Sbostic			printf("r\nkkey1\nr\nkkey2\n");
36956495Sbostic		}
37056556Sbostic		printf("e\n");
37156556Sbostic		printf("eend of test8 run\n");
37256495Sbostic	}' > $TMP1
37356554Sbostic	$PROG btree $TMP1
374*64444Sbostic#	$PROG hash $TMP1
37556495Sbostic	# No explicit test for success.
37656495Sbostic}
37756495Sbostic
37857001Sbostic# Test btree duplicate keys
37957001Sbostictest9()
38057001Sbostic{
381*64444Sbostic	echo "Test 9: btree: duplicate keys"
38257001Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
38357001Sbostic	awk '{
38457001Sbostic		for (i = 1; i <= 543; ++i)
38557001Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
38657001Sbostic		exit;
38757001Sbostic	}' > $TMP1
388*64444Sbostic	rm -f $TMP2 $TMP3
38957001Sbostic
39057001Sbostic	for type in btree; do
39157001Sbostic		cat $TMP1 |
39257001Sbostic		awk '{
39357001Sbostic			if (i++ % 2)
39457001Sbostic				printf("p\nkduplicatekey\nd%s\n", $0);
39557001Sbostic			else
39657001Sbostic				printf("p\nkunique%dkey\nd%s\n", i, $0);
39757001Sbostic		}
39857001Sbostic		END {
39957001Sbostic				printf("o\n");
40057001Sbostic		}' > $TMP2
40157001Sbostic		$PROG -iflags=1 -o $TMP3 $type $TMP2
40257001Sbostic		sort -o $TMP3 $TMP3
40357460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
40457001Sbostic		else
405*64444Sbostic			echo "test9: type $type: failed"
40657001Sbostic			exit 1
40757001Sbostic		fi
40857001Sbostic	done
40957001Sbostic}
41057001Sbostic
41156999Sbostic# Test use of cursor flags without initialization
41256999Sbostictest10()
41356999Sbostic{
414*64444Sbostic	echo "Test 10: btree, recno: test cursor flag use"
41556999Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
41656999Sbostic	awk '{
41756999Sbostic		for (i = 1; i <= 20; ++i)
41856999Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
41956999Sbostic		exit;
42056999Sbostic	}' > $TMP1
421*64444Sbostic	rm -f $TMP2 $TMP3
42256999Sbostic
42356999Sbostic	# Test that R_CURSOR doesn't succeed before cursor initialized
42456999Sbostic	for type in btree recno; do
42556999Sbostic		cat $TMP1 |
42656999Sbostic		awk '{
42756999Sbostic			if (i == 10)
42856999Sbostic				exit;
42956999Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
43056999Sbostic		}
43156999Sbostic		END {
43256999Sbostic			printf("fR_CURSOR\nr\nk1\n");
43356999Sbostic			printf("eR_CURSOR SHOULD HAVE FAILED\n");
43456999Sbostic		}' > $TMP2
43556999Sbostic		$PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
43656999Sbostic		if [ -s $TMP3 ] ; then
437*64444Sbostic			echo "Test 10: delete: R_CURSOR SHOULD HAVE FAILED"
43856999Sbostic			exit 1
43956999Sbostic		fi
44056999Sbostic	done
44156999Sbostic	for type in btree recno; do
44256999Sbostic		cat $TMP1 |
44356999Sbostic		awk '{
44456999Sbostic			if (i == 10)
44556999Sbostic				exit;
44656999Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
44756999Sbostic		}
44856999Sbostic		END {
44956999Sbostic			printf("fR_CURSOR\np\nk1\ndsome data\n");
45056999Sbostic			printf("eR_CURSOR SHOULD HAVE FAILED\n");
45156999Sbostic		}' > $TMP2
45256999Sbostic		$PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
45356999Sbostic		if [ -s $TMP3 ] ; then
454*64444Sbostic			echo "Test 10: put: R_CURSOR SHOULD HAVE FAILED"
45556999Sbostic			exit 1
45656999Sbostic		fi
45756999Sbostic	done
45856999Sbostic}
45956999Sbostic
46056999Sbostic# Test insert in reverse order.
46156999Sbostictest11()
46256999Sbostic{
463*64444Sbostic	echo "Test 11: recno: reverse order insert"
46456999Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
46556999Sbostic	awk '{
46656999Sbostic		for (i = 1; i <= 779; ++i)
46756999Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
46856999Sbostic		exit;
46956999Sbostic	}' > $TMP1
470*64444Sbostic	rm -f $TMP2 $TMP3
47156999Sbostic
47256999Sbostic	for type in recno; do
47356999Sbostic		cat $TMP1 |
47456999Sbostic		awk '{
47556999Sbostic			if (i == 0) {
47656999Sbostic				i = 1;
47756999Sbostic				printf("p\nk1\nd%s\n", $0);
47856999Sbostic				printf("%s\n", "fR_IBEFORE");
47956999Sbostic			} else
48056999Sbostic				printf("p\nk1\nd%s\n", $0);
48156999Sbostic		}
48256999Sbostic		END {
48356999Sbostic				printf("or\n");
48456999Sbostic		}' > $TMP2
48556999Sbostic		$PROG -o $TMP3 $type $TMP2
48657460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
48756999Sbostic		else
488*64444Sbostic			echo "test11: type $type: failed"
48956999Sbostic			exit 1
49056999Sbostic		fi
49156999Sbostic	done
49256999Sbostic}
49356999Sbostic
49457455Sbostic# Take the first 20000 entries in the dictionary, reverse them, and give
49557455Sbostic# them each a small size data entry.  Use a small page size to make sure
49657455Sbostic# the btree split code gets hammered.
49757455Sbostictest12()
49857455Sbostic{
499*64444Sbostic	echo "Test 12: btree: lots of keys, small page size"
50057455Sbostic	mdata=abcdefghijklmnopqrstuvwxy
50157455Sbostic	echo $mdata |
50257455Sbostic	awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1
50357455Sbostic	for type in btree; do
50457455Sbostic		rm -f $TMP2 $TMP3
50557455Sbostic		for i in `sed 20000q $DICT | rev`; do
506*64444Sbostic			echo p
507*64444Sbostic			echo k$i
508*64444Sbostic			echo d$mdata
509*64444Sbostic			echo g
510*64444Sbostic			echo k$i
51157455Sbostic		done > $TMP2
51257455Sbostic		$PROG -i psize=512 -o $TMP3 $type $TMP2
51357460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
51457455Sbostic		else
515*64444Sbostic			echo "test12: type $type: failed"
51657455Sbostic			exit 1
51757455Sbostic		fi
51857455Sbostic	done
51957455Sbostic}
52057455Sbostic
52159633Sbostic# Test different byte orders.
52259633Sbostictest13()
52359633Sbostic{
524*64444Sbostic	echo "Test 13: btree, hash: differing byte orders"
52559633Sbostic	sed 50q $DICT > $TMP1
52659633Sbostic	for order in 1234 4321; do
52759633Sbostic		for type in btree hash; do
52859633Sbostic			rm -f byte.file $TMP2 $TMP3
52959633Sbostic			for i in `sed 50q $DICT`; do
530*64444Sbostic				echo p
531*64444Sbostic				echo k$i
532*64444Sbostic				echo d$i
533*64444Sbostic				echo g
534*64444Sbostic				echo k$i
53559633Sbostic			done > $TMP2
53659633Sbostic			$PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
53759633Sbostic			if (cmp -s $TMP1 $TMP3) ; then :
53859633Sbostic			else
539*64444Sbostic				echo "test13: $type/$order put failed"
54059633Sbostic				exit 1
54159633Sbostic			fi
54259633Sbostic			for i in `sed 50q $DICT`; do
543*64444Sbostic				echo g
544*64444Sbostic				echo k$i
54559633Sbostic			done > $TMP2
54659633Sbostic			$PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
54759633Sbostic			if (cmp -s $TMP1 $TMP3) ; then :
54859633Sbostic			else
549*64444Sbostic				echo "test13: $type/$order get failed"
55059633Sbostic				exit 1
55159633Sbostic			fi
55259633Sbostic		done
55359633Sbostic	done
55459633Sbostic	rm -f byte.file
55559633Sbostic}
55659633Sbostic
55756495Sbostic# Try a variety of bucketsizes and fill factors for hashing
55856999Sbostictest20()
55956495Sbostic{
560*64444Sbostic	echo\
561*64444Sbostic    "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536"
56256085Sbostic	awk 'BEGIN {
56356085Sbostic		for (i = 1; i <= 10000; ++i)
56456085Sbostic			printf("%.*s\n", i % 34,
56556085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
56656085Sbostic	}' > $TMP1
56756085Sbostic	sed 10000q $DICT |
56856085Sbostic	awk '{
56956085Sbostic		++i;
57056085Sbostic		printf("p\nk%s\nd%.*s\n", $0, i % 34,
57156085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
57256085Sbostic	}' > $TMP2
57356085Sbostic	sed 10000q $DICT |
57456085Sbostic	awk '{
57556085Sbostic		++i;
57656085Sbostic		printf("g\nk%s\n", $0);
57756085Sbostic	}' >> $TMP2
57856085Sbostic	bsize=256
57956085Sbostic	for ffactor in 11 14 21; do
580*64444Sbostic		echo "    bucketsize $bsize, fill factor $ffactor"
58156495Sbostic		$PROG -o$TMP3 \
58256085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
58356085Sbostic		    hash $TMP2
58457460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
58556085Sbostic		else
586*64444Sbostic			echo "test20: type hash:\
587*64444Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
58856085Sbostic			exit 1
58956085Sbostic		fi
59056085Sbostic	done
59156085Sbostic	bsize=512
59256085Sbostic	for ffactor in 21 28 43; do
593*64444Sbostic		echo "    bucketsize $bsize, fill factor $ffactor"
59456495Sbostic		$PROG -o$TMP3 \
59556085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
59656085Sbostic		    hash $TMP2
59757460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
59856085Sbostic		else
599*64444Sbostic			echo "test20: type hash:\
600*64444Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
60156085Sbostic			exit 1
60256085Sbostic		fi
60356085Sbostic	done
60456085Sbostic	bsize=1024
60556085Sbostic	for ffactor in 43 57 85; do
606*64444Sbostic		echo "    bucketsize $bsize, fill factor $ffactor"
60756495Sbostic		$PROG -o$TMP3 \
60856085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
60956085Sbostic		    hash $TMP2
61057460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
61156085Sbostic		else
612*64444Sbostic			echo "test20: type hash:\
613*64444Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
61456085Sbostic			exit 1
61556085Sbostic		fi
61656085Sbostic	done
61756085Sbostic	bsize=2048
61856085Sbostic	for ffactor in 85 114 171; do
619*64444Sbostic		echo "    bucketsize $bsize, fill factor $ffactor"
62056495Sbostic		$PROG -o$TMP3 \
62156085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
62256085Sbostic		    hash $TMP2
62357460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
62456085Sbostic		else
625*64444Sbostic			echo "test20: type hash:\
626*64444Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
62756085Sbostic			exit 1
62856085Sbostic		fi
62956085Sbostic	done
63056085Sbostic	bsize=4096
63156085Sbostic	for ffactor in 171 228 341; do
632*64444Sbostic		echo "    bucketsize $bsize, fill factor $ffactor"
63356495Sbostic		$PROG -o$TMP3 \
63456085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
63556085Sbostic		    hash $TMP2
63657460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
63756085Sbostic		else
638*64444Sbostic			echo "test20: type hash:\
639*64444Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
64056085Sbostic			exit 1
64156085Sbostic		fi
64256085Sbostic	done
64356085Sbostic	bsize=8192
64456085Sbostic	for ffactor in 341 455 683; do
645*64444Sbostic		echo "    bucketsize $bsize, fill factor $ffactor"
64656495Sbostic		$PROG -o$TMP3 \
64756085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
64856085Sbostic		    hash $TMP2
64957460Sbostic		if (cmp -s $TMP1 $TMP3) ; then :
65056085Sbostic		else
651*64444Sbostic			echo "test20: type hash:\
652*64444Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
65356085Sbostic			exit 1
65456085Sbostic		fi
65556085Sbostic	done
65656085Sbostic}
65756085Sbostic
658*64444Sbosticmain $*
659