xref: /csrg-svn/lib/libc/db/test/run.test (revision 56556)
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*56556Sbostic#	@(#)run.test	5.8 (Berkeley) 10/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
27056058Sbostic	for type in btree recno; do
27156058Sbostic		cat $TMP1 |
27256058Sbostic		awk '{
27356058Sbostic			if (i == 120)
27456058Sbostic				exit;
27556058Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
27656058Sbostic		}
27756058Sbostic		END {
27856058Sbostic			printf("fR_NEXT\n");
27956058Sbostic			for (i = 1; i <= 120; ++i)
28056058Sbostic				printf("s\n");
28156058Sbostic			printf("fR_CURSOR\ns\nk120\n");
28256058Sbostic			printf("r\nk120\n");
28356058Sbostic			printf("fR_NEXT\ns\n");
28456058Sbostic			printf("fR_CURSOR\ns\nk1\n");
28556058Sbostic			printf("r\nk1\n");
28656058Sbostic			printf("fR_FIRST\ns\n");
28756058Sbostic		}' > $TMP2
28856058Sbostic		$PROG -o $TMP3 recno $TMP2
28956058Sbostic		if (cmp -s $TMP1 $TMP3) ; then
29056058Sbostic		else
29156058Sbostic			printf "test7: type $type: failed\n"
29256058Sbostic			exit 1
29356058Sbostic		fi
29456058Sbostic	done
29556058Sbostic}
29656058Sbostic
29756495Sbostic# Make sure that overflow pages are reused.
29856085Sbostictest8()
29956085Sbostic{
30056495Sbostic	printf "Test 8: btree, hash: repeated small key, big data pairs\n"
30156495Sbostic	rm -f $TMP1
30256495Sbostic	awk 'BEGIN {
303*56556Sbostic		for (i = 1; i <= 10; ++i) {
30456495Sbostic			printf("p\nkkey1\nD/bin/sh\n");
30556495Sbostic			printf("p\nkkey2\nD/bin/csh\n");
30656554Sbostic			if (i % 8 == 0) {
30756554Sbostic				printf("c\nkkey2\nD/bin/csh\n");
30856554Sbostic				printf("c\nkkey1\nD/bin/sh\n");
30956554Sbostic				printf("e\t%d of 75 (comparison)\r\n", i);
31056554Sbostic			} else
31156554Sbostic				printf("e\t%d of 75             \r\n", i);
31256495Sbostic			printf("r\nkkey1\nr\nkkey2\n");
31356495Sbostic		}
314*56556Sbostic		printf("e\n");
315*56556Sbostic		printf("eend of test8 run\n");
31656495Sbostic	}' > $TMP1
31756554Sbostic	$PROG btree $TMP1
31856554Sbostic	$PROG hash $TMP1
31956495Sbostic	# No explicit test for success.
32056495Sbostic}
32156495Sbostic
32256495Sbostic# Try a variety of bucketsizes and fill factors for hashing
32356495Sbostictest9()
32456495Sbostic{
32556085Sbostic	printf\
32656495Sbostic    "Test 9: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n"
32756085Sbostic	awk 'BEGIN {
32856085Sbostic		for (i = 1; i <= 10000; ++i)
32956085Sbostic			printf("%.*s\n", i % 34,
33056085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
33156085Sbostic	}' > $TMP1
33256085Sbostic	sed 10000q $DICT |
33356085Sbostic	awk '{
33456085Sbostic		++i;
33556085Sbostic		printf("p\nk%s\nd%.*s\n", $0, i % 34,
33656085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
33756085Sbostic	}' > $TMP2
33856085Sbostic	sed 10000q $DICT |
33956085Sbostic	awk '{
34056085Sbostic		++i;
34156085Sbostic		printf("g\nk%s\n", $0);
34256085Sbostic	}' >> $TMP2
34356085Sbostic	bsize=256
34456085Sbostic	for ffactor in 11 14 21; do
34556085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
34656495Sbostic		$PROG -o$TMP3 \
34756085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
34856085Sbostic		    hash $TMP2
34956085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
35056085Sbostic		else
35156495Sbostic			printf "test9: type hash:\
35256085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
35356085Sbostic			exit 1
35456085Sbostic		fi
35556085Sbostic	done
35656085Sbostic	bsize=512
35756085Sbostic	for ffactor in 21 28 43; do
35856085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
35956495Sbostic		$PROG -o$TMP3 \
36056085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
36156085Sbostic		    hash $TMP2
36256085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
36356085Sbostic		else
36456495Sbostic			printf "test9: type hash:\
36556085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
36656085Sbostic			exit 1
36756085Sbostic		fi
36856085Sbostic	done
36956085Sbostic	bsize=1024
37056085Sbostic	for ffactor in 43 57 85; do
37156085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
37256495Sbostic		$PROG -o$TMP3 \
37356085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
37456085Sbostic		    hash $TMP2
37556085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
37656085Sbostic		else
37756495Sbostic			printf "test9: type hash:\
37856085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
37956085Sbostic			exit 1
38056085Sbostic		fi
38156085Sbostic	done
38256085Sbostic	bsize=2048
38356085Sbostic	for ffactor in 85 114 171; do
38456085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
38556495Sbostic		$PROG -o$TMP3 \
38656085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
38756085Sbostic		    hash $TMP2
38856085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
38956085Sbostic		else
39056495Sbostic			printf "test9: type hash:\
39156085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
39256085Sbostic			exit 1
39356085Sbostic		fi
39456085Sbostic	done
39556085Sbostic	bsize=4096
39656085Sbostic	for ffactor in 171 228 341; do
39756085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
39856495Sbostic		$PROG -o$TMP3 \
39956085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
40056085Sbostic		    hash $TMP2
40156085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
40256085Sbostic		else
40356495Sbostic			printf "test9: type hash:\
40456085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
40556085Sbostic			exit 1
40656085Sbostic		fi
40756085Sbostic	done
40856085Sbostic	bsize=8192
40956085Sbostic	for ffactor in 341 455 683; do
41056085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
41156495Sbostic		$PROG -o$TMP3 \
41256085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
41356085Sbostic		    hash $TMP2
41456085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
41556085Sbostic		else
41656495Sbostic			printf "test9: type hash:\
41756085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
41856085Sbostic			exit 1
41956085Sbostic		fi
42056085Sbostic	done
42156085Sbostic}
42256085Sbostic
42356038Sbosticmain
424