xref: /csrg-svn/lib/libc/db/test/run.test (revision 56058)
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*56058Sbostic#	@(#)run.test	5.3 (Berkeley) 08/27/92
956038Sbostic#
1056038Sbostic
1156038Sbostic# db regression tests
1256038Sbostic
1356038Sbosticmain()
1456038Sbostic{
1556038Sbostic	DICT=/usr/share/dict/words
16*56058Sbostic	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
27*56058Sbostic	test7
2856038Sbostic	rm -f $TMP1 $TMP2 $TMP3
2956038Sbostic}
3056038Sbostic
3156038Sbostic# Take the first hundred entries in the dictionary, and make them
3256038Sbostic# be key/data pairs.
3356038Sbostictest1()
3456038Sbostic{
3556050Sbostic	printf "Test 1: btree, hash: small key, small data pairs\n"
3656038Sbostic	for i in `sed 200q $DICT`; do
3756038Sbostic		printf "%s\n" $i
3856038Sbostic	done > $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
44*56058Sbostic		$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 |
54*56058Sbostic	awk '{
55*56058Sbostic		++i;
56*56058Sbostic		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
57*56058Sbostic	}' > $TMP2
58*56058Sbostic	$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 |
73*56058Sbostic	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
79*56058Sbostic		$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 |
89*56058Sbostic	awk '{  for (i = 1; i < 201; ++i)
90*56058Sbostic		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
91*56058Sbostic	}' > $TMP2
92*56058Sbostic	$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
111*56058Sbostic		$PROG -o $TMP3 $type $TMP2
11256038Sbostic		if (cmp -s $TMP1 $TMP3) ; then
11356038Sbostic		else
11456038Sbostic			printf "test2: 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 |
121*56058Sbostic	awk '{
122*56058Sbostic		++i;
123*56058Sbostic		printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
124*56058Sbostic	}' > $TMP2
125*56058Sbostic	$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" |
138*56058Sbostic	awk '{
139*56058Sbostic		for (i = 37; i <= 37 + 88 * 17; i += 17)
140*56058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
141*56058Sbostic		for (i = 1; i <= 15; ++i)
142*56058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
143*56058Sbostic		for (i = 19234; i <= 19234 + 61 * 27; i += 27)
144*56058Sbostic			printf("input key %d: %.*s\n", i, i % 41, $0);
145*56058Sbostic		exit
146*56058Sbostic	}' > $TMP1
147*56058Sbostic	rm -f TMP2 $TMP3
148*56058Sbostic	cat $TMP1 |
149*56058Sbostic	awk 'BEGIN {
150*56058Sbostic			i = 37;
151*56058Sbostic			incr = 17;
152*56058Sbostic		}
153*56058Sbostic		{
154*56058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
155*56058Sbostic			if (i == 19234 + 61 * 27)
156*56058Sbostic				exit;
157*56058Sbostic			if (i == 37 + 88 * 17) {
158*56058Sbostic				i = 1;
159*56058Sbostic				incr = 1;
160*56058Sbostic			} else if (i == 15) {
161*56058Sbostic				i = 19234;
162*56058Sbostic				incr = 27;
163*56058Sbostic			} else
164*56058Sbostic				i += incr;
165*56058Sbostic		}
166*56058Sbostic		END {
16756038Sbostic			for (i = 37; i <= 37 + 88 * 17; i += 17)
168*56058Sbostic				printf("g\nk%d\n", i);
16956038Sbostic			for (i = 1; i <= 15; ++i)
170*56058Sbostic				printf("g\nk%d\n", i);
17156038Sbostic			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
172*56058Sbostic				printf("g\nk%d\n", i);
173*56058Sbostic		}' > $TMP2
174*56058Sbostic	$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" |
187*56058Sbostic	awk ' {
188*56058Sbostic		for (i = 1500; i; --i)
189*56058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
190*56058Sbostic		exit;
191*56058Sbostic	}' > $TMP1
19256050Sbostic	rm -f TMP2 $TMP3
193*56058Sbostic	cat $TMP1 |
194*56058Sbostic	awk 'BEGIN {
195*56058Sbostic			i = 1500;
196*56058Sbostic		}
197*56058Sbostic		{
198*56058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
199*56058Sbostic			--i;
200*56058Sbostic		}
201*56058Sbostic		END {
202*56058Sbostic			for (i = 1500; i; --i)
203*56058Sbostic				printf("g\nk%d\n", i);
204*56058Sbostic		}' > $TMP2
205*56058Sbostic	$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" |
218*56058Sbostic	awk ' {
219*56058Sbostic		for (i = 1; i < 1200; i += 2)
220*56058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
221*56058Sbostic		for (i = 2; i < 1200; i += 2)
222*56058Sbostic			printf("input key %d: %.*s\n", i, i % 34, $0);
223*56058Sbostic		exit;
224*56058Sbostic	}' > $TMP1
22556050Sbostic	rm -f TMP2 $TMP3
226*56058Sbostic	cat $TMP1 |
227*56058Sbostic	awk 'BEGIN {
228*56058Sbostic			i = 1;
229*56058Sbostic			even = 0;
230*56058Sbostic		}
231*56058Sbostic		{
232*56058Sbostic			printf("p\nk%d\nd%s\n", i, $0);
233*56058Sbostic			i += 2;
234*56058Sbostic			if (i >= 1200) {
235*56058Sbostic				if (even == 1)
236*56058Sbostic					exit;
237*56058Sbostic				even = 1;
238*56058Sbostic				i = 2;
23956050Sbostic			}
240*56058Sbostic		}
241*56058Sbostic		END {
242*56058Sbostic			for (i = 1; i < 1200; ++i)
243*56058Sbostic				printf("g\nk%d\n", i);
244*56058Sbostic		}' > $TMP2
245*56058Sbostic	$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
255*56058Sbostic# Delete cursor record
256*56058Sbostictest7()
257*56058Sbostic{
258*56058Sbostic	printf "Test 7: btree, recno: delete cursor record\n"
259*56058Sbostic	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
260*56058Sbostic	awk '{
261*56058Sbostic		for (i = 1; i <= 120; ++i)
262*56058Sbostic			printf("%05d: input key %d: %s\n", i, i, $0);
263*56058Sbostic		printf("%05d: input key %d: %s\n", 120, 120, $0);
264*56058Sbostic		printf("get failed, no such key\n");
265*56058Sbostic		printf("%05d: input key %d: %s\n", 1, 1, $0);
266*56058Sbostic		printf("%05d: input key %d: %s\n", 2, 2, $0);
267*56058Sbostic		exit;
268*56058Sbostic	}' > $TMP1
269*56058Sbostic	rm -f TMP2 $TMP3
270*56058Sbostic	for type in btree recno; do
271*56058Sbostic		cat $TMP1 |
272*56058Sbostic		awk '{
273*56058Sbostic			if (i == 120)
274*56058Sbostic				exit;
275*56058Sbostic			printf("p\nk%d\nd%s\n", ++i, $0);
276*56058Sbostic		}
277*56058Sbostic		END {
278*56058Sbostic			printf("fR_NEXT\n");
279*56058Sbostic			for (i = 1; i <= 120; ++i)
280*56058Sbostic				printf("s\n");
281*56058Sbostic			printf("fR_CURSOR\ns\nk120\n");
282*56058Sbostic			printf("r\nk120\n");
283*56058Sbostic			printf("fR_NEXT\ns\n");
284*56058Sbostic			printf("fR_CURSOR\ns\nk1\n");
285*56058Sbostic			printf("r\nk1\n");
286*56058Sbostic			printf("fR_FIRST\ns\n");
287*56058Sbostic		}' > $TMP2
288*56058Sbostic		$PROG -o $TMP3 recno $TMP2
289*56058Sbostic		if (cmp -s $TMP1 $TMP3) ; then
290*56058Sbostic		else
291*56058Sbostic			printf "test7: type $type: failed\n"
292*56058Sbostic			exit 1
293*56058Sbostic		fi
294*56058Sbostic	done
295*56058Sbostic}
296*56058Sbostic
29756038Sbosticmain
298