xref: /csrg-svn/lib/libc/db/test/run.test (revision 56495)
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*56495Sbostic#	@(#)run.test	5.6 (Berkeley) 10/09/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
29*56495Sbostic	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
297*56495Sbostic# Make sure that overflow pages are reused.
29856085Sbostictest8()
29956085Sbostic{
300*56495Sbostic	printf "Test 8: btree, hash: repeated small key, big data pairs\n"
301*56495Sbostic	rm -f $TMP1
302*56495Sbostic	awk 'BEGIN {
303*56495Sbostic		for (i = 1; i <= 100; ++i) {
304*56495Sbostic			printf("p\nkkey1\nD/bin/sh\n");
305*56495Sbostic			printf("p\nkkey2\nD/bin/csh\n");
306*56495Sbostic			printf("r\nkkey1\nr\nkkey2\n");
307*56495Sbostic		}
308*56495Sbostic	}' > $TMP1
309*56495Sbostic	$PROG -o $TMP2 btree $TMP1
310*56495Sbostic	$PROG -o $TMP2 hash $TMP1
311*56495Sbostic	# No explicit test for success.
312*56495Sbostic}
313*56495Sbostic
314*56495Sbostic# Try a variety of bucketsizes and fill factors for hashing
315*56495Sbostictest9()
316*56495Sbostic{
31756085Sbostic	printf\
318*56495Sbostic    "Test 9: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n"
31956085Sbostic	awk 'BEGIN {
32056085Sbostic		for (i = 1; i <= 10000; ++i)
32156085Sbostic			printf("%.*s\n", i % 34,
32256085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
32356085Sbostic	}' > $TMP1
32456085Sbostic	sed 10000q $DICT |
32556085Sbostic	awk '{
32656085Sbostic		++i;
32756085Sbostic		printf("p\nk%s\nd%.*s\n", $0, i % 34,
32856085Sbostic		    "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
32956085Sbostic	}' > $TMP2
33056085Sbostic	sed 10000q $DICT |
33156085Sbostic	awk '{
33256085Sbostic		++i;
33356085Sbostic		printf("g\nk%s\n", $0);
33456085Sbostic	}' >> $TMP2
33556085Sbostic	bsize=256
33656085Sbostic	for ffactor in 11 14 21; do
33756085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
338*56495Sbostic		$PROG -o$TMP3 \
33956085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
34056085Sbostic		    hash $TMP2
34156085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
34256085Sbostic		else
343*56495Sbostic			printf "test9: type hash:\
34456085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
34556085Sbostic			exit 1
34656085Sbostic		fi
34756085Sbostic	done
34856085Sbostic	bsize=512
34956085Sbostic	for ffactor in 21 28 43; do
35056085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
351*56495Sbostic		$PROG -o$TMP3 \
35256085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
35356085Sbostic		    hash $TMP2
35456085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
35556085Sbostic		else
356*56495Sbostic			printf "test9: type hash:\
35756085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
35856085Sbostic			exit 1
35956085Sbostic		fi
36056085Sbostic	done
36156085Sbostic	bsize=1024
36256085Sbostic	for ffactor in 43 57 85; do
36356085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
364*56495Sbostic		$PROG -o$TMP3 \
36556085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
36656085Sbostic		    hash $TMP2
36756085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
36856085Sbostic		else
369*56495Sbostic			printf "test9: type hash:\
37056085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
37156085Sbostic			exit 1
37256085Sbostic		fi
37356085Sbostic	done
37456085Sbostic	bsize=2048
37556085Sbostic	for ffactor in 85 114 171; do
37656085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
377*56495Sbostic		$PROG -o$TMP3 \
37856085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
37956085Sbostic		    hash $TMP2
38056085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
38156085Sbostic		else
382*56495Sbostic			printf "test9: type hash:\
38356085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
38456085Sbostic			exit 1
38556085Sbostic		fi
38656085Sbostic	done
38756085Sbostic	bsize=4096
38856085Sbostic	for ffactor in 171 228 341; do
38956085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
390*56495Sbostic		$PROG -o$TMP3 \
39156085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
39256085Sbostic		    hash $TMP2
39356085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
39456085Sbostic		else
395*56495Sbostic			printf "test9: type hash:\
39656085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
39756085Sbostic			exit 1
39856085Sbostic		fi
39956085Sbostic	done
40056085Sbostic	bsize=8192
40156085Sbostic	for ffactor in 341 455 683; do
40256085Sbostic		printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
403*56495Sbostic		$PROG -o$TMP3 \
40456085Sbostic		    -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
40556085Sbostic		    hash $TMP2
40656085Sbostic		if (cmp -s $TMP1 $TMP3) ; then
40756085Sbostic		else
408*56495Sbostic			printf "test9: type hash:\
40956085Sbosticbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
41056085Sbostic			exit 1
41156085Sbostic		fi
41256085Sbostic	done
41356085Sbostic}
41456085Sbostic
41556038Sbosticmain
416