xref: /csrg-svn/lib/libc/db/test/run.test (revision 56763)
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*56763Sbostic#	@(#)run.test	5.9 (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
3056038Sbostic	rm -f $TMP1 $TMP2 $TMP3
3156038Sbostic}
3256038Sbostic
3356038Sbostic# Take the first hundred entries in the dictionary, and make them
3456038Sbostic# be key/data pairs.
3556038Sbostictest1()
3656038Sbostic{
3756050Sbostic	printf "Test 1: btree, hash: small key, small data pairs\n"
3856085Sbostic	sed 200q $DICT > $TMP1
3956038Sbostic	for type in btree hash; do
4056038Sbostic		rm -f $TMP2 $TMP3
4156038Sbostic		for i in `sed 200q $DICT`; do
4256038Sbostic			printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
4356038Sbostic		done > $TMP2
4456058Sbostic		$PROG -o $TMP3 $type $TMP2
4556038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
4656038Sbostic		else
4756038Sbostic			printf "test1: type %s: failed\n" $type
4856038Sbostic			exit 1
4956038Sbostic		fi
5056038Sbostic	done
5156050Sbostic	printf "Test 1: recno: small key, small data pairs\n"
5256038Sbostic	rm -f $TMP2 $TMP3
5356038Sbostic	sed 200q $DICT |
5456058Sbostic	awk '{
5556058Sbostic		++i;
5656058Sbostic		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
5756058Sbostic	}' > $TMP2
5856058Sbostic	$PROG -o $TMP3 recno $TMP2
5956038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
6056038Sbostic	else
6156038Sbostic		printf "test1: type recno: failed\n"
6256038Sbostic		exit 1
6356038Sbostic	fi
6456038Sbostic}
6556038Sbostic
6656038Sbostic# Take the first hundred entries in the dictionary, and give them
6756038Sbostic# each a medium size data entry.
6856038Sbostictest2()
6956038Sbostic{
7056050Sbostic	printf "Test 2: btree, hash: small key, medium data pairs\n"
7156038Sbostic	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
7256038Sbostic	echo $mdata |
7356058Sbostic	awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
7456038Sbostic	for type in hash btree; do
7556038Sbostic		rm -f $TMP2 $TMP3
7656038Sbostic		for i in `sed 200q $DICT`; do
7756038Sbostic			printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
7856038Sbostic		done > $TMP2
7956058Sbostic		$PROG -o $TMP3 $type $TMP2
8056038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
8156038Sbostic		else
8256038Sbostic			printf "test2: type %s: failed\n" $type
8356038Sbostic			exit 1
8456038Sbostic		fi
8556038Sbostic	done
8656050Sbostic	printf "Test 2: recno: small key, medium data pairs\n"
8756038Sbostic	rm -f $TMP2 $TMP3
8856038Sbostic	echo $mdata |
8956058Sbostic	awk '{  for (i = 1; i < 201; ++i)
9056058Sbostic		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
9156058Sbostic	}' > $TMP2
9256058Sbostic	$PROG -o $TMP3 recno $TMP2
9356038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
9456038Sbostic	else
9556038Sbostic		printf "test2: type recno: failed\n"
9656038Sbostic		exit 1
9756038Sbostic	fi
9856038Sbostic}
9956038Sbostic
10056038Sbostic# Insert the programs in /bin with their paths as their keys.
10156038Sbostictest3()
10256038Sbostic{
10356050Sbostic	printf "Test 3: btree, hash: small key, big data pairs\n"
10456038Sbostic	rm -f $TMP1
10556038Sbostic	(find /bin -type f -print | xargs cat) > $TMP1
10656038Sbostic	for type in hash btree; do
10756038Sbostic		rm -f $TMP2 $TMP3
10856038Sbostic		for i in `find /bin -type f -print`; do
10956038Sbostic			printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
11056038Sbostic		done > $TMP2
11156058Sbostic		$PROG -o $TMP3 $type $TMP2
11256038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
11356038Sbostic		else
11456385Sbostic			printf "test3: type %s: failed\n" $type
11556038Sbostic			exit 1
11656038Sbostic		fi
11756038Sbostic	done
11856050Sbostic	printf "Test 3: recno: big data pairs\n"
11956038Sbostic	rm -f $TMP2 $TMP3
12056038Sbostic	find /bin -type f -print |
12156058Sbostic	awk '{
12256058Sbostic		++i;
12356058Sbostic		printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
12456058Sbostic	}' > $TMP2
12556058Sbostic	$PROG -o $TMP3 recno $TMP2
12656038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
12756038Sbostic	else
12856038Sbostic		printf "test3: type recno: failed\n"
12956038Sbostic		exit 1
13056038Sbostic	fi
13156038Sbostic}
13256038Sbostic
13356038Sbostic# Do random recno entries.
13456038Sbostictest4()
13556038Sbostic{
13656050Sbostic	printf "Test 4: recno: random entries\n"
13756050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
13856058Sbostic	awk '{
13956058Sbostic		for (i = 37; i <= 37 + 88 * 17; i += 17)
14056058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
14156058Sbostic		for (i = 1; i <= 15; ++i)
14256058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
14356058Sbostic		for (i = 19234; i <= 19234 + 61 * 27; i += 27)
14456058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
14556058Sbostic		exit
14656058Sbostic	}' > $TMP1
14756058Sbostic	rm -f TMP2 $TMP3
14856058Sbostic	cat $TMP1 |
14956058Sbostic	awk 'BEGIN {
15056058Sbostic			i = 37;
15156058Sbostic			incr = 17;
15256058Sbostic		}
15356058Sbostic		{
15456058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
15556058Sbostic			if (i == 19234 + 61 * 27)
15656058Sbostic				exit;
15756058Sbostic			if (i == 37 + 88 * 17) {
15856058Sbostic				i = 1;
15956058Sbostic				incr = 1;
16056058Sbostic			} else if (i == 15) {
16156058Sbostic				i = 19234;
16256058Sbostic				incr = 27;
16356058Sbostic			} else
16456058Sbostic				i += incr;
16556058Sbostic		}
16656058Sbostic		END {
16756038Sbostic			for (i = 37; i <= 37 + 88 * 17; i += 17)
16856058Sbostic				printf("g\nk%d\n", i);
16956038Sbostic			for (i = 1; i <= 15; ++i)
17056058Sbostic				printf("g\nk%d\n", i);
17156038Sbostic			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
17256058Sbostic				printf("g\nk%d\n", i);
17356058Sbostic		}' > $TMP2
17456058Sbostic	$PROG -o $TMP3 recno $TMP2
17556038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
17656038Sbostic	else
17756038Sbostic		printf "test4: type recno: failed\n"
17856038Sbostic		exit 1
17956038Sbostic	fi
18056038Sbostic}
18156050Sbostic
18256050Sbostic# Do reverse order recno entries.
18356050Sbostictest5()
18456050Sbostic{
18556050Sbostic	printf "Test 5: recno: reverse order entries\n"
18656050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
18756058Sbostic	awk ' {
18856058Sbostic		for (i = 1500; i; --i)
18956058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
19056058Sbostic		exit;
19156058Sbostic	}' > $TMP1
19256050Sbostic	rm -f TMP2 $TMP3
19356058Sbostic	cat $TMP1 |
19456058Sbostic	awk 'BEGIN {
19556058Sbostic			i = 1500;
19656058Sbostic		}
19756058Sbostic		{
19856058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
19956058Sbostic			--i;
20056058Sbostic		}
20156058Sbostic		END {
20256058Sbostic			for (i = 1500; i; --i)
20356058Sbostic				printf("g\nk%d\n", i);
20456058Sbostic		}' > $TMP2
20556058Sbostic	$PROG -o $TMP3 recno $TMP2
20656050Sbostic	if (cmp -s $TMP1 $TMP3) ; then
20756050Sbostic	else
20856050Sbostic		printf "test5: type recno: failed\n"
20956050Sbostic		exit 1
21056050Sbostic	fi
21156050Sbostic}
21256038Sbostic
21356050Sbostic# Do alternating order recno entries.
21456050Sbostictest6()
21556050Sbostic{
21656050Sbostic	printf "Test 6: recno: alternating order entries\n"
21756050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
21856058Sbostic	awk ' {
21956058Sbostic		for (i = 1; i < 1200; i += 2)
22056058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
22156058Sbostic		for (i = 2; i < 1200; i += 2)
22256058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
22356058Sbostic		exit;
22456058Sbostic	}' > $TMP1
22556050Sbostic	rm -f TMP2 $TMP3
22656058Sbostic	cat $TMP1 |
22756058Sbostic	awk 'BEGIN {
22856058Sbostic			i = 1;
22956058Sbostic			even = 0;
23056058Sbostic		}
23156058Sbostic		{
23256058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
23356058Sbostic			i += 2;
23456058Sbostic			if (i >= 1200) {
23556058Sbostic				if (even == 1)
23656058Sbostic					exit;
23756058Sbostic				even = 1;
23856058Sbostic				i = 2;
23956050Sbostic			}
24056058Sbostic		}
24156058Sbostic		END {
24256058Sbostic			for (i = 1; i < 1200; ++i)
24356058Sbostic				printf("g\nk%d\n", i);
24456058Sbostic		}' > $TMP2
24556058Sbostic	$PROG -o $TMP3 recno $TMP2
24656050Sbostic	sort -o $TMP1 $TMP1
24756050Sbostic	sort -o $TMP3 $TMP3
24856050Sbostic	if (cmp -s $TMP1 $TMP3) ; then
24956050Sbostic	else
25056050Sbostic		printf "test6: type recno: failed\n"
25156050Sbostic		exit 1
25256050Sbostic	fi
25356050Sbostic}
25456050Sbostic
25556058Sbostic# Delete cursor record
25656058Sbostictest7()
25756058Sbostic{
25856058Sbostic	printf "Test 7: btree, recno: delete cursor record\n"
25956058Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
26056058Sbostic	awk '{
26156058Sbostic		for (i = 1; i <= 120; ++i)
26256058Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
26356058Sbostic		printf("%05d: input key %d: %s\n", 120, 120, $0);
26456058Sbostic		printf("get failed, no such key\n");
26556058Sbostic		printf("%05d: input key %d: %s\n", 1, 1, $0);
26656058Sbostic		printf("%05d: input key %d: %s\n", 2, 2, $0);
26756058Sbostic		exit;
26856058Sbostic	}' > $TMP1
26956058Sbostic	rm -f TMP2 $TMP3
270*56763Sbostic
271*56763Sbostic	# Test that R_CURSOR doesn't succeed before cursor initialized
27256058Sbostic	for type in btree recno; do
27356058Sbostic		cat $TMP1 |
27456058Sbostic		awk '{
275*56763Sbostic			if (i == 10)
276*56763Sbostic				exit;
277*56763Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
278*56763Sbostic		}
279*56763Sbostic		END {
280*56763Sbostic			printf("fR_CURSOR\nr\nk1\n");
281*56763Sbostic			printf("etest7 R_CURSOR SHOULD HAVE FAILED\n");
282*56763Sbostic		}' > $TMP2
283*56763Sbostic		$PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
284*56763Sbostic		if [ -s $TMP3 ] ; then
285*56763Sbostic			printf "test7: R_CURSOR SHOULD HAVE FAILED\n"
286*56763Sbostic			exit 1
287*56763Sbostic		fi
288*56763Sbostic	done
289*56763Sbostic
290*56763Sbostic	for type in btree recno; do
291*56763Sbostic		cat $TMP1 |
292*56763Sbostic		awk '{
29356058Sbostic			if (i == 120)
29456058Sbostic				exit;
29556058Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
29656058Sbostic		}
29756058Sbostic		END {
29856058Sbostic			printf("fR_NEXT\n");
29956058Sbostic			for (i = 1; i <= 120; ++i)
30056058Sbostic				printf("s\n");
30156058Sbostic			printf("fR_CURSOR\ns\nk120\n");
30256058Sbostic			printf("r\nk120\n");
30356058Sbostic			printf("fR_NEXT\ns\n");
30456058Sbostic			printf("fR_CURSOR\ns\nk1\n");
30556058Sbostic			printf("r\nk1\n");
30656058Sbostic			printf("fR_FIRST\ns\n");
30756058Sbostic		}' > $TMP2
30856058Sbostic		$PROG -o $TMP3 recno $TMP2
30956058Sbostic		if (cmp -s $TMP1 $TMP3) ; then
31056058Sbostic		else
31156058Sbostic			printf "test7: type $type: failed\n"
31256058Sbostic			exit 1
31356058Sbostic		fi
31456058Sbostic	done
31556058Sbostic}
31656058Sbostic
31756495Sbostic# Make sure that overflow pages are reused.
31856085Sbostictest8()
31956085Sbostic{
32056495Sbostic	printf "Test 8: btree, hash: repeated small key, big data pairs\n"
32156495Sbostic	rm -f $TMP1
32256495Sbostic	awk 'BEGIN {
32356556Sbostic		for (i = 1; i <= 10; ++i) {
32456495Sbostic			printf("p\nkkey1\nD/bin/sh\n");
32556495Sbostic			printf("p\nkkey2\nD/bin/csh\n");
32656554Sbostic			if (i % 8 == 0) {
32756554Sbostic				printf("c\nkkey2\nD/bin/csh\n");
32856554Sbostic				printf("c\nkkey1\nD/bin/sh\n");
329*56763Sbostic				printf("e\t%d of 10 (comparison)\r\n", i);
33056554Sbostic			} else
331*56763Sbostic				printf("e\t%d of 10             \r\n", i);
33256495Sbostic			printf("r\nkkey1\nr\nkkey2\n");
33356495Sbostic		}
33456556Sbostic		printf("e\n");
33556556Sbostic		printf("eend of test8 run\n");
33656495Sbostic	}' > $TMP1
33756554Sbostic	$PROG btree $TMP1
33856554Sbostic	$PROG hash $TMP1
33956495Sbostic	# No explicit test for success.
34056495Sbostic}
34156495Sbostic
34256495Sbostic# Try a variety of bucketsizes and fill factors for hashing
34356495Sbostictest9()
34456495Sbostic{
34556085Sbostic	printf\
34656495Sbostic    "Test 9: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n"
34756085Sbostic	awk 'BEGIN {
34856085Sbostic		for (i = 1; i <= 10000; ++i)
34956085Sbostic			printf("%.*s\n", i % 34,
35056085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
35156085Sbostic	}' > $TMP1
35256085Sbostic	sed 10000q $DICT |
35356085Sbostic	awk '{
35456085Sbostic		++i;
35556085Sbostic		printf("p\nk%s\nd%.*s\n", $0, i % 34,
35656085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
35756085Sbostic	}' > $TMP2
35856085Sbostic	sed 10000q $DICT |
35956085Sbostic	awk '{
36056085Sbostic		++i;
36156085Sbostic		printf("g\nk%s\n", $0);
36256085Sbostic	}' >> $TMP2
36356085Sbostic	bsize=256
36456085Sbostic	for ffactor in 11 14 21; do
36556085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
36656495Sbostic		$PROG -o$TMP3 \
36756085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
36856085Sbostic		    hash $TMP2
36956085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
37056085Sbostic		else
37156495Sbostic			printf "test9: type hash:\
37256085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
37356085Sbostic			exit 1
37456085Sbostic		fi
37556085Sbostic	done
37656085Sbostic	bsize=512
37756085Sbostic	for ffactor in 21 28 43; do
37856085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
37956495Sbostic		$PROG -o$TMP3 \
38056085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
38156085Sbostic		    hash $TMP2
38256085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
38356085Sbostic		else
38456495Sbostic			printf "test9: type hash:\
38556085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
38656085Sbostic			exit 1
38756085Sbostic		fi
38856085Sbostic	done
38956085Sbostic	bsize=1024
39056085Sbostic	for ffactor in 43 57 85; do
39156085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
39256495Sbostic		$PROG -o$TMP3 \
39356085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
39456085Sbostic		    hash $TMP2
39556085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
39656085Sbostic		else
39756495Sbostic			printf "test9: type hash:\
39856085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
39956085Sbostic			exit 1
40056085Sbostic		fi
40156085Sbostic	done
40256085Sbostic	bsize=2048
40356085Sbostic	for ffactor in 85 114 171; do
40456085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
40556495Sbostic		$PROG -o$TMP3 \
40656085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
40756085Sbostic		    hash $TMP2
40856085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
40956085Sbostic		else
41056495Sbostic			printf "test9: type hash:\
41156085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
41256085Sbostic			exit 1
41356085Sbostic		fi
41456085Sbostic	done
41556085Sbostic	bsize=4096
41656085Sbostic	for ffactor in 171 228 341; do
41756085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
41856495Sbostic		$PROG -o$TMP3 \
41956085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
42056085Sbostic		    hash $TMP2
42156085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
42256085Sbostic		else
42356495Sbostic			printf "test9: type hash:\
42456085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
42556085Sbostic			exit 1
42656085Sbostic		fi
42756085Sbostic	done
42856085Sbostic	bsize=8192
42956085Sbostic	for ffactor in 341 455 683; do
43056085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
43156495Sbostic		$PROG -o$TMP3 \
43256085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
43356085Sbostic		    hash $TMP2
43456085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
43556085Sbostic		else
43656495Sbostic			printf "test9: type hash:\
43756085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
43856085Sbostic			exit 1
43956085Sbostic		fi
44056085Sbostic	done
44156085Sbostic}
44256085Sbostic
44356038Sbosticmain
444