xref: /csrg-svn/lib/libc/db/test/run.test (revision 56050)
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*56050Sbostic#	@(#)run.test	5.2 (Berkeley) 08/26/92
956038Sbostic#
1056038Sbostic
1156038Sbostic# db regression tests
1256038Sbostic
1356038Sbosticmain()
1456038Sbostic{
1556038Sbostic	DICT=/usr/share/dict/words
1656038Sbostic	TMP1=t1
1756038Sbostic	TMP2=t2
1856038Sbostic	TMP3=t3
1956038Sbostic
2056038Sbostic	test1
2156038Sbostic	test2
2256038Sbostic	test3
2356038Sbostic	test4
24*56050Sbostic	test5
25*56050Sbostic	test6
2656038Sbostic	rm -f $TMP1 $TMP2 $TMP3
2756038Sbostic}
2856038Sbostic
2956038Sbostic# Take the first hundred entries in the dictionary, and make them
3056038Sbostic# be key/data pairs.
3156038Sbostictest1()
3256038Sbostic{
33*56050Sbostic	printf "Test 1: btree, hash: small key, small data pairs\n"
3456038Sbostic	for i in `sed 200q $DICT`; do
3556038Sbostic		printf "%s\n" $i
3656038Sbostic	done > $TMP1
3756038Sbostic	for type in btree hash; do
3856038Sbostic		rm -f $TMP2 $TMP3
3956038Sbostic		for i in `sed 200q $DICT`; do
4056038Sbostic			printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
4156038Sbostic		done > $TMP2
4256038Sbostic		./dbtest -o $TMP3 $type $TMP2
4356038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
4456038Sbostic		else
4556038Sbostic			printf "test1: type %s: failed\n" $type
4656038Sbostic			exit 1
4756038Sbostic		fi
4856038Sbostic	done
49*56050Sbostic	printf "Test 1: recno: small key, small data pairs\n"
5056038Sbostic	rm -f $TMP2 $TMP3
5156038Sbostic	sed 200q $DICT |
5256038Sbostic		awk '{
5356038Sbostic			++i;
5456038Sbostic	    		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
5556038Sbostic		}' > $TMP2
5656038Sbostic	./dbtest -o $TMP3 recno $TMP2
5756038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
5856038Sbostic	else
5956038Sbostic		printf "test1: type recno: failed\n"
6056038Sbostic		exit 1
6156038Sbostic	fi
6256038Sbostic}
6356038Sbostic
6456038Sbostic# Take the first hundred entries in the dictionary, and give them
6556038Sbostic# each a medium size data entry.
6656038Sbostictest2()
6756038Sbostic{
68*56050Sbostic	printf "Test 2: btree, hash: small key, medium data pairs\n"
6956038Sbostic	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
7056038Sbostic	echo $mdata |
7156038Sbostic	    awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
7256038Sbostic	for type in hash btree; do
7356038Sbostic		rm -f $TMP2 $TMP3
7456038Sbostic		for i in `sed 200q $DICT`; do
7556038Sbostic			printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
7656038Sbostic		done > $TMP2
7756038Sbostic		./dbtest -o $TMP3 $type $TMP2
7856038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
7956038Sbostic		else
8056038Sbostic			printf "test2: type %s: failed\n" $type
8156038Sbostic			exit 1
8256038Sbostic		fi
8356038Sbostic	done
84*56050Sbostic	printf "Test 2: recno: small key, medium data pairs\n"
8556038Sbostic	rm -f $TMP2 $TMP3
8656038Sbostic	echo $mdata |
8756038Sbostic		awk '{  for (i = 1; i < 201; ++i)
8856038Sbostic	    		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
8956038Sbostic		}' > $TMP2
9056038Sbostic	./dbtest -o $TMP3 recno $TMP2
9156038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
9256038Sbostic	else
9356038Sbostic		printf "test2: type recno: failed\n"
9456038Sbostic		exit 1
9556038Sbostic	fi
9656038Sbostic}
9756038Sbostic
9856038Sbostic# Insert the programs in /bin with their paths as their keys.
9956038Sbostictest3()
10056038Sbostic{
101*56050Sbostic	printf "Test 3: btree, hash: small key, big data pairs\n"
10256038Sbostic	rm -f $TMP1
10356038Sbostic	(find /bin -type f -print | xargs cat) > $TMP1
10456038Sbostic	for type in hash btree; do
10556038Sbostic		rm -f $TMP2 $TMP3
10656038Sbostic		for i in `find /bin -type f -print`; do
10756038Sbostic			printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
10856038Sbostic		done > $TMP2
10956038Sbostic		./dbtest -o $TMP3 $type $TMP2
11056038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
11156038Sbostic		else
11256038Sbostic			printf "test2: type %s: failed\n" $type
11356038Sbostic			exit 1
11456038Sbostic		fi
11556038Sbostic	done
116*56050Sbostic	printf "Test 3: recno: big data pairs\n"
11756038Sbostic	rm -f $TMP2 $TMP3
11856038Sbostic	find /bin -type f -print |
11956038Sbostic		awk '{
12056038Sbostic			++i;
12156038Sbostic			printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
12256038Sbostic		}' > $TMP2
12356038Sbostic	./dbtest -o $TMP3 recno $TMP2
12456038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
12556038Sbostic	else
12656038Sbostic		printf "test3: type recno: failed\n"
12756038Sbostic		exit 1
12856038Sbostic	fi
12956038Sbostic}
13056038Sbostic
13156038Sbostic# Do random recno entries.
13256038Sbostictest4()
13356038Sbostic{
134*56050Sbostic	printf "Test 4: recno: random entries\n"
135*56050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
13656038Sbostic		awk '{
13756038Sbostic			for (i = 37; i <= 37 + 88 * 17; i += 17)
138*56050Sbostic				printf("input key %d: %.*s\n", i, i % 41, $0);
13956038Sbostic			for (i = 1; i <= 15; ++i)
140*56050Sbostic				printf("input key %d: %.*s\n", i, i % 41, $0);
14156038Sbostic			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
142*56050Sbostic				printf("input key %d: %.*s\n", i, i % 41, $0);
14356038Sbostic			exit
14456038Sbostic		}' > $TMP1
14556038Sbostic	rm -f TMP2 $TMP3
14656038Sbostic	cat $TMP1 | awk 'BEGIN {
14756038Sbostic				i = 37;
14856038Sbostic				incr = 17;
14956038Sbostic			}
15056038Sbostic			{
15156038Sbostic				printf("p\nk%d\nd%s\n", i, $0);
15256038Sbostic				if (i == 19234 + 61 * 27)
15356038Sbostic					exit;
15456038Sbostic				if (i == 37 + 88 * 17) {
15556038Sbostic					i = 1;
15656038Sbostic					incr = 1;
15756038Sbostic				} else if (i == 15) {
15856038Sbostic					i = 19234;
15956038Sbostic					incr = 27;
16056038Sbostic				} else
16156038Sbostic					i += incr;
16256038Sbostic			}
16356038Sbostic			END {
16456038Sbostic				for (i = 37; i <= 37 + 88 * 17; i += 17)
16556038Sbostic					printf("g\nk%d\n", i);
16656038Sbostic				for (i = 1; i <= 15; ++i)
16756038Sbostic					printf("g\nk%d\n", i);
16856038Sbostic				for (i = 19234; i <= 19234 + 61 * 27; i += 27)
16956038Sbostic					printf("g\nk%d\n", i);
17056038Sbostic			}' > $TMP2
17156038Sbostic	./dbtest -o $TMP3 recno $TMP2
17256038Sbostic	if (cmp -s $TMP1 $TMP3) ; then
17356038Sbostic	else
17456038Sbostic		printf "test4: type recno: failed\n"
17556038Sbostic		exit 1
17656038Sbostic	fi
17756038Sbostic}
178*56050Sbostic
179*56050Sbostic# Do reverse order recno entries.
180*56050Sbostictest5()
181*56050Sbostic{
182*56050Sbostic	printf "Test 5: recno: reverse order entries\n"
183*56050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
184*56050Sbostic		awk ' {
185*56050Sbostic			for (i = 1500; i; --i)
186*56050Sbostic				printf("input key %d: %.*s\n", i, i % 34, $0);
187*56050Sbostic			exit;
188*56050Sbostic		}' > $TMP1
189*56050Sbostic	rm -f TMP2 $TMP3
190*56050Sbostic	cat $TMP1 | awk 'BEGIN {
191*56050Sbostic				i = 1500;
192*56050Sbostic			}
193*56050Sbostic			{
194*56050Sbostic				printf("p\nk%d\nd%s\n", i, $0);
195*56050Sbostic				--i;
196*56050Sbostic			}
197*56050Sbostic			END {
198*56050Sbostic				for (i = 1500; i; --i)
199*56050Sbostic					printf("g\nk%d\n", i);
200*56050Sbostic			}' > $TMP2
201*56050Sbostic	./dbtest -o $TMP3 recno $TMP2
202*56050Sbostic	if (cmp -s $TMP1 $TMP3) ; then
203*56050Sbostic	else
204*56050Sbostic		printf "test5: type recno: failed\n"
205*56050Sbostic		exit 1
206*56050Sbostic	fi
207*56050Sbostic}
20856038Sbostic
209*56050Sbostic# Do alternating order recno entries.
210*56050Sbostictest6()
211*56050Sbostic{
212*56050Sbostic	printf "Test 6: recno: alternating order entries\n"
213*56050Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
214*56050Sbostic		awk ' {
215*56050Sbostic			for (i = 1; i < 1200; i += 2)
216*56050Sbostic				printf("input key %d: %.*s\n", i, i % 34, $0);
217*56050Sbostic			for (i = 2; i < 1200; i += 2)
218*56050Sbostic				printf("input key %d: %.*s\n", i, i % 34, $0);
219*56050Sbostic			exit;
220*56050Sbostic		}' > $TMP1
221*56050Sbostic	rm -f TMP2 $TMP3
222*56050Sbostic	cat $TMP1 | awk 'BEGIN {
223*56050Sbostic				i = 1;
224*56050Sbostic				even = 0;
225*56050Sbostic			}
226*56050Sbostic			{
227*56050Sbostic				printf("p\nk%d\nd%s\n", i, $0);
228*56050Sbostic				i += 2;
229*56050Sbostic				if (i >= 1200) {
230*56050Sbostic					if (even == 1)
231*56050Sbostic						exit;
232*56050Sbostic					even = 1;
233*56050Sbostic					i = 2;
234*56050Sbostic				}
235*56050Sbostic			}
236*56050Sbostic			END {
237*56050Sbostic				for (i = 1; i < 1200; ++i)
238*56050Sbostic					printf("g\nk%d\n", i);
239*56050Sbostic			}' > $TMP2
240*56050Sbostic	./dbtest -o $TMP3 recno $TMP2
241*56050Sbostic	sort -o $TMP1 $TMP1
242*56050Sbostic	sort -o $TMP3 $TMP3
243*56050Sbostic	if (cmp -s $TMP1 $TMP3) ; then
244*56050Sbostic	else
245*56050Sbostic		printf "test6: type recno: failed\n"
246*56050Sbostic		exit 1
247*56050Sbostic	fi
248*56050Sbostic}
249*56050Sbostic
25056038Sbosticmain
251