xref: /csrg-svn/lib/libc/db/test/run.test (revision 56058)
1#!/bin/sh -
2#
3# Copyright (c) 1992 The Regents of the University of California.
4# All rights reserved.
5#
6# %sccs.include.redist.sh%
7#
8#	@(#)run.test	5.3 (Berkeley) 08/27/92
9#
10
11# db regression tests
12
13main()
14{
15	DICT=/usr/share/dict/words
16	PROG=obj/dbtest
17	TMP1=t1
18	TMP2=t2
19	TMP3=t3
20
21	test1
22	test2
23	test3
24	test4
25	test5
26	test6
27	test7
28	rm -f $TMP1 $TMP2 $TMP3
29}
30
31# Take the first hundred entries in the dictionary, and make them
32# be key/data pairs.
33test1()
34{
35	printf "Test 1: btree, hash: small key, small data pairs\n"
36	for i in `sed 200q $DICT`; do
37		printf "%s\n" $i
38	done > $TMP1
39	for type in btree hash; do
40		rm -f $TMP2 $TMP3
41		for i in `sed 200q $DICT`; do
42			printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
43		done > $TMP2
44		$PROG -o $TMP3 $type $TMP2
45		if (cmp -s $TMP1 $TMP3) ; then
46		else
47			printf "test1: type %s: failed\n" $type
48			exit 1
49		fi
50	done
51	printf "Test 1: recno: small key, small data pairs\n"
52	rm -f $TMP2 $TMP3
53	sed 200q $DICT |
54	awk '{
55		++i;
56		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
57	}' > $TMP2
58	$PROG -o $TMP3 recno $TMP2
59	if (cmp -s $TMP1 $TMP3) ; then
60	else
61		printf "test1: type recno: failed\n"
62		exit 1
63	fi
64}
65
66# Take the first hundred entries in the dictionary, and give them
67# each a medium size data entry.
68test2()
69{
70	printf "Test 2: btree, hash: small key, medium data pairs\n"
71	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
72	echo $mdata |
73	awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
74	for type in hash btree; do
75		rm -f $TMP2 $TMP3
76		for i in `sed 200q $DICT`; do
77			printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
78		done > $TMP2
79		$PROG -o $TMP3 $type $TMP2
80		if (cmp -s $TMP1 $TMP3) ; then
81		else
82			printf "test2: type %s: failed\n" $type
83			exit 1
84		fi
85	done
86	printf "Test 2: recno: small key, medium data pairs\n"
87	rm -f $TMP2 $TMP3
88	echo $mdata |
89	awk '{  for (i = 1; i < 201; ++i)
90		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
91	}' > $TMP2
92	$PROG -o $TMP3 recno $TMP2
93	if (cmp -s $TMP1 $TMP3) ; then
94	else
95		printf "test2: type recno: failed\n"
96		exit 1
97	fi
98}
99
100# Insert the programs in /bin with their paths as their keys.
101test3()
102{
103	printf "Test 3: btree, hash: small key, big data pairs\n"
104	rm -f $TMP1
105	(find /bin -type f -print | xargs cat) > $TMP1
106	for type in hash btree; do
107		rm -f $TMP2 $TMP3
108		for i in `find /bin -type f -print`; do
109			printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
110		done > $TMP2
111		$PROG -o $TMP3 $type $TMP2
112		if (cmp -s $TMP1 $TMP3) ; then
113		else
114			printf "test2: type %s: failed\n" $type
115			exit 1
116		fi
117	done
118	printf "Test 3: recno: big data pairs\n"
119	rm -f $TMP2 $TMP3
120	find /bin -type f -print |
121	awk '{
122		++i;
123		printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
124	}' > $TMP2
125	$PROG -o $TMP3 recno $TMP2
126	if (cmp -s $TMP1 $TMP3) ; then
127	else
128		printf "test3: type recno: failed\n"
129		exit 1
130	fi
131}
132
133# Do random recno entries.
134test4()
135{
136	printf "Test 4: recno: random entries\n"
137	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
138	awk '{
139		for (i = 37; i <= 37 + 88 * 17; i += 17)
140			printf("input key %d: %.*s\n", i, i % 41, $0);
141		for (i = 1; i <= 15; ++i)
142			printf("input key %d: %.*s\n", i, i % 41, $0);
143		for (i = 19234; i <= 19234 + 61 * 27; i += 27)
144			printf("input key %d: %.*s\n", i, i % 41, $0);
145		exit
146	}' > $TMP1
147	rm -f TMP2 $TMP3
148	cat $TMP1 |
149	awk 'BEGIN {
150			i = 37;
151			incr = 17;
152		}
153		{
154			printf("p\nk%d\nd%s\n", i, $0);
155			if (i == 19234 + 61 * 27)
156				exit;
157			if (i == 37 + 88 * 17) {
158				i = 1;
159				incr = 1;
160			} else if (i == 15) {
161				i = 19234;
162				incr = 27;
163			} else
164				i += incr;
165		}
166		END {
167			for (i = 37; i <= 37 + 88 * 17; i += 17)
168				printf("g\nk%d\n", i);
169			for (i = 1; i <= 15; ++i)
170				printf("g\nk%d\n", i);
171			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
172				printf("g\nk%d\n", i);
173		}' > $TMP2
174	$PROG -o $TMP3 recno $TMP2
175	if (cmp -s $TMP1 $TMP3) ; then
176	else
177		printf "test4: type recno: failed\n"
178		exit 1
179	fi
180}
181
182# Do reverse order recno entries.
183test5()
184{
185	printf "Test 5: recno: reverse order entries\n"
186	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
187	awk ' {
188		for (i = 1500; i; --i)
189			printf("input key %d: %.*s\n", i, i % 34, $0);
190		exit;
191	}' > $TMP1
192	rm -f TMP2 $TMP3
193	cat $TMP1 |
194	awk 'BEGIN {
195			i = 1500;
196		}
197		{
198			printf("p\nk%d\nd%s\n", i, $0);
199			--i;
200		}
201		END {
202			for (i = 1500; i; --i)
203				printf("g\nk%d\n", i);
204		}' > $TMP2
205	$PROG -o $TMP3 recno $TMP2
206	if (cmp -s $TMP1 $TMP3) ; then
207	else
208		printf "test5: type recno: failed\n"
209		exit 1
210	fi
211}
212
213# Do alternating order recno entries.
214test6()
215{
216	printf "Test 6: recno: alternating order entries\n"
217	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
218	awk ' {
219		for (i = 1; i < 1200; i += 2)
220			printf("input key %d: %.*s\n", i, i % 34, $0);
221		for (i = 2; i < 1200; i += 2)
222			printf("input key %d: %.*s\n", i, i % 34, $0);
223		exit;
224	}' > $TMP1
225	rm -f TMP2 $TMP3
226	cat $TMP1 |
227	awk 'BEGIN {
228			i = 1;
229			even = 0;
230		}
231		{
232			printf("p\nk%d\nd%s\n", i, $0);
233			i += 2;
234			if (i >= 1200) {
235				if (even == 1)
236					exit;
237				even = 1;
238				i = 2;
239			}
240		}
241		END {
242			for (i = 1; i < 1200; ++i)
243				printf("g\nk%d\n", i);
244		}' > $TMP2
245	$PROG -o $TMP3 recno $TMP2
246	sort -o $TMP1 $TMP1
247	sort -o $TMP3 $TMP3
248	if (cmp -s $TMP1 $TMP3) ; then
249	else
250		printf "test6: type recno: failed\n"
251		exit 1
252	fi
253}
254
255# Delete cursor record
256test7()
257{
258	printf "Test 7: btree, recno: delete cursor record\n"
259	echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
260	awk '{
261		for (i = 1; i <= 120; ++i)
262			printf("%05d: input key %d: %s\n", i, i, $0);
263		printf("%05d: input key %d: %s\n", 120, 120, $0);
264		printf("get failed, no such key\n");
265		printf("%05d: input key %d: %s\n", 1, 1, $0);
266		printf("%05d: input key %d: %s\n", 2, 2, $0);
267		exit;
268	}' > $TMP1
269	rm -f TMP2 $TMP3
270	for type in btree recno; do
271		cat $TMP1 |
272		awk '{
273			if (i == 120)
274				exit;
275			printf("p\nk%d\nd%s\n", ++i, $0);
276		}
277		END {
278			printf("fR_NEXT\n");
279			for (i = 1; i <= 120; ++i)
280				printf("s\n");
281			printf("fR_CURSOR\ns\nk120\n");
282			printf("r\nk120\n");
283			printf("fR_NEXT\ns\n");
284			printf("fR_CURSOR\ns\nk1\n");
285			printf("r\nk1\n");
286			printf("fR_FIRST\ns\n");
287		}' > $TMP2
288		$PROG -o $TMP3 recno $TMP2
289		if (cmp -s $TMP1 $TMP3) ; then
290		else
291			printf "test7: type $type: failed\n"
292			exit 1
293		fi
294	done
295}
296
297main
298