t_db.sh revision 276478
1# $NetBSD: t_db.sh,v 1.4 2013/07/29 10:43:15 skrll Exp $
2#
3# Copyright (c) 2008 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28prog()
29{
30	echo $(atf_get_srcdir)/h_db
31}
32
33dict()
34{
35	if [ -f /usr/share/dict/words ]; then
36		echo /usr/share/dict/words
37	elif [ -f /usr/dict/words ]; then
38		echo /usr/dict/words
39	else
40		atf_fail "no dictionary found"
41	fi
42}
43
44# Begin FreeBSD
45dict()
46{
47	if [ -f /usr/share/dict/words ]; then
48		echo /usr/share/dict/words
49	else
50		echo /nonexistent
51		atf_skip "Test requires dict/words"
52	fi
53}
54# End FreeBSD
55
56SEVEN_SEVEN="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg"
57
58atf_test_case small_btree
59small_btree_head()
60{
61	atf_set "descr" \
62		"Checks btree database using small keys and small data" \
63		"pairs: takes the first hundred entries in the dictionary," \
64		"and makes them be key/data pairs."
65}
66small_btree_body()
67{
68	TMPDIR="$(pwd)/db_dir"; export TMPDIR
69	mkdir ${TMPDIR}
70
71	sed 200q $(dict) >exp
72
73	for i in `sed 200q $(dict)`; do
74		echo p
75		echo k$i
76		echo d$i
77		echo g
78		echo k$i
79	done >in
80
81	atf_check -o file:exp "$(prog)" btree in
82}
83
84atf_test_case small_hash
85small_hash_head()
86{
87	atf_set "descr" \
88		"Checks hash database using small keys and small data" \
89		"pairs: takes the first hundred entries in the dictionary," \
90		"and makes them be key/data pairs."
91}
92small_hash_body()
93{
94	TMPDIR="$(pwd)/db_dir"; export TMPDIR
95	mkdir ${TMPDIR}
96
97	sed 200q $(dict) >exp
98
99	for i in `sed 200q $(dict)`; do
100		echo p
101		echo k$i
102		echo d$i
103		echo g
104		echo k$i
105	done >in
106
107	atf_check -o file:exp "$(prog)" hash in
108}
109
110atf_test_case small_recno
111small_recno_head()
112{
113	atf_set "descr" \
114		"Checks recno database using small keys and small data" \
115		"pairs: takes the first hundred entries in the dictionary," \
116		"and makes them be key/data pairs."
117}
118small_recno_body()
119{
120	TMPDIR="$(pwd)/db_dir"; export TMPDIR
121	mkdir ${TMPDIR}
122
123	sed 200q $(dict) >exp
124
125	sed 200q $(dict) |
126	awk '{ 
127		++i;
128		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
129	}' >in
130
131	atf_check -o file:exp "$(prog)" recno in
132}
133
134atf_test_case medium_btree
135medium_btree_head()
136{
137	atf_set "descr" \
138		"Checks btree database using small keys and medium" \
139		"data pairs: takes the first 200 entries in the" \
140		"dictionary, and gives them each a medium size data entry."
141}
142medium_btree_body()
143{
144	TMPDIR="$(pwd)/db_dir"; export TMPDIR
145	mkdir ${TMPDIR}
146
147	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
148	echo $mdata |
149	awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
150
151	for i in $(sed 200q $(dict)); do
152		echo p
153		echo k$i
154		echo d$mdata
155		echo g
156		echo k$i
157	done >in
158
159	atf_check -o file:exp "$(prog)" btree in
160}
161
162atf_test_case medium_hash
163medium_hash_head()
164{
165	atf_set "descr" \
166		"Checks hash database using small keys and medium" \
167		"data pairs: takes the first 200 entries in the" \
168		"dictionary, and gives them each a medium size data entry."
169}
170medium_hash_body()
171{
172	TMPDIR="$(pwd)/db_dir"; export TMPDIR
173	mkdir ${TMPDIR}
174
175	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
176	echo $mdata |
177	awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
178
179	for i in $(sed 200q $(dict)); do
180		echo p
181		echo k$i
182		echo d$mdata
183		echo g
184		echo k$i
185	done >in
186
187	atf_check -o file:exp "$(prog)" hash in
188}
189
190atf_test_case medium_recno
191medium_recno_head()
192{
193	atf_set "descr" \
194		"Checks recno database using small keys and medium" \
195		"data pairs: takes the first 200 entries in the" \
196		"dictionary, and gives them each a medium size data entry."
197}
198medium_recno_body()
199{
200	TMPDIR="$(pwd)/db_dir"; export TMPDIR
201	mkdir ${TMPDIR}
202
203	mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
204	echo $mdata |
205	awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
206
207	echo $mdata | 
208	awk '{  for (i = 1; i < 201; ++i)
209		printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
210	}' >in
211
212	atf_check -o file:exp "$(prog)" recno in
213}
214
215atf_test_case big_btree
216big_btree_head()
217{
218	atf_set "descr" \
219		"Checks btree database using small keys and big data" \
220		"pairs: inserts the programs in /bin with their paths" \
221		"as their keys."
222}
223big_btree_body()
224{
225	TMPDIR="$(pwd)/db_dir"; export TMPDIR
226	mkdir ${TMPDIR}
227
228	(find /bin -type f -print | xargs cat) >exp
229
230	for psize in 512 16384 65536; do
231		echo "checking page size: $psize"
232
233		for i in `find /bin -type f -print`; do
234			echo p
235			echo k$i
236			echo D$i
237			echo g
238			echo k$i
239		done >in
240
241		atf_check "$(prog)" -o out btree in
242		cmp -s exp out || atf_fail "test failed for page size: $psize"
243	done
244}
245
246atf_test_case big_hash
247big_hash_head()
248{
249	atf_set "descr" \
250		"Checks hash database using small keys and big data" \
251		"pairs: inserts the programs in /bin with their paths" \
252		"as their keys."
253}
254big_hash_body()
255{
256	TMPDIR="$(pwd)/db_dir"; export TMPDIR
257	mkdir ${TMPDIR}
258
259	(find /bin -type f -print | xargs cat) >exp
260
261	for i in `find /bin -type f -print`; do
262		echo p
263		echo k$i
264		echo D$i
265		echo g
266		echo k$i
267	done >in
268
269	atf_check "$(prog)" -o out hash in
270	cmp -s exp out || atf_fail "test failed"
271}
272
273atf_test_case big_recno
274big_recno_head()
275{
276	atf_set "descr" \
277		"Checks recno database using small keys and big data" \
278		"pairs: inserts the programs in /bin with their paths" \
279		"as their keys."
280}
281big_recno_body()
282{
283	TMPDIR="$(pwd)/db_dir"; export TMPDIR
284	mkdir ${TMPDIR}
285
286	(find /bin -type f -print | xargs cat) >exp
287
288	find /bin -type f -print | 
289	awk '{
290		++i;
291		printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
292	}' >in
293
294	for psize in 512 16384 65536; do
295		echo "checking page size: $psize"
296
297		atf_check "$(prog)" -o out recno in
298		cmp -s exp out || atf_fail "test failed for page size: $psize"
299	done
300}
301
302atf_test_case random_recno
303random_recno_head()
304{
305	atf_set "descr" "Checks recno database using random entries"
306}
307random_recno_body()
308{
309	TMPDIR="$(pwd)/db_dir"; export TMPDIR
310	mkdir ${TMPDIR}
311
312	echo $SEVEN_SEVEN |
313	awk '{
314		for (i = 37; i <= 37 + 88 * 17; i += 17) {
315			if (i % 41)
316				s = substr($0, 1, i % 41);
317			else
318				s = substr($0, 1);
319			printf("input key %d: %s\n", i, s);
320		}
321		for (i = 1; i <= 15; ++i) {
322			if (i % 41)
323				s = substr($0, 1, i % 41);
324			else
325				s = substr($0, 1);
326			printf("input key %d: %s\n", i, s);
327		}
328		for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
329			if (i % 41)
330				s = substr($0, 1, i % 41);
331			else
332				s = substr($0, 1);
333			printf("input key %d: %s\n", i, s);
334		}
335		exit
336	}' >exp
337
338	cat exp |
339	awk 'BEGIN {
340			i = 37;
341			incr = 17;
342		}
343		{
344			printf("p\nk%d\nd%s\n", i, $0);
345			if (i == 19234 + 61 * 27)
346				exit;
347			if (i == 37 + 88 * 17) {
348				i = 1;
349				incr = 1;
350			} else if (i == 15) {
351				i = 19234;
352				incr = 27;
353			} else
354				i += incr;
355		}
356		END {
357			for (i = 37; i <= 37 + 88 * 17; i += 17)
358				printf("g\nk%d\n", i);
359			for (i = 1; i <= 15; ++i)
360				printf("g\nk%d\n", i);
361			for (i = 19234; i <= 19234 + 61 * 27; i += 27)
362				printf("g\nk%d\n", i);
363		}' >in
364
365	atf_check -o file:exp "$(prog)" recno in
366}
367
368atf_test_case reverse_recno
369reverse_recno_head()
370{
371	atf_set "descr" "Checks recno database using reverse order entries"
372}
373reverse_recno_body()
374{
375	TMPDIR="$(pwd)/db_dir"; export TMPDIR
376	mkdir ${TMPDIR}
377
378	echo $SEVEN_SEVEN |
379	awk ' {
380		for (i = 1500; i; --i) {
381			if (i % 34)
382				s = substr($0, 1, i % 34);
383			else
384				s = substr($0, 1);
385			printf("input key %d: %s\n", i, s);
386		}
387		exit;
388	}' >exp
389
390	cat exp |
391	awk 'BEGIN {
392			i = 1500;
393		}
394		{
395			printf("p\nk%d\nd%s\n", i, $0);
396			--i;
397		}
398		END {
399			for (i = 1500; i; --i) 
400				printf("g\nk%d\n", i);
401		}' >in
402
403	atf_check -o file:exp "$(prog)" recno in
404}
405		
406atf_test_case alternate_recno
407alternate_recno_head()
408{
409	atf_set "descr" "Checks recno database using alternating order entries"
410}
411alternate_recno_body()
412{
413	TMPDIR="$(pwd)/db_dir"; export TMPDIR
414	mkdir ${TMPDIR}
415
416	echo $SEVEN_SEVEN |
417	awk ' {
418		for (i = 1; i < 1200; i += 2) {
419			if (i % 34)
420				s = substr($0, 1, i % 34);
421			else
422				s = substr($0, 1);
423			printf("input key %d: %s\n", i, s);
424		}
425		for (i = 2; i < 1200; i += 2) {
426			if (i % 34)
427				s = substr($0, 1, i % 34);
428			else
429				s = substr($0, 1);
430			printf("input key %d: %s\n", i, s);
431		}
432		exit;
433	}' >exp
434
435	cat exp |
436	awk 'BEGIN {
437			i = 1;
438			even = 0;
439		}
440		{
441			printf("p\nk%d\nd%s\n", i, $0);
442			i += 2;
443			if (i >= 1200) {
444				if (even == 1)
445					exit;
446				even = 1;
447				i = 2;
448			}
449		}
450		END {
451			for (i = 1; i < 1200; ++i) 
452				printf("g\nk%d\n", i);
453		}' >in
454
455	atf_check "$(prog)" -o out recno in
456	
457	sort -o exp exp
458	sort -o out out
459
460	cmp -s exp out || atf_fail "test failed"
461}
462
463h_delete()
464{
465	TMPDIR="$(pwd)/db_dir"; export TMPDIR
466	mkdir ${TMPDIR}
467
468	type=$1
469
470	echo $SEVEN_SEVEN |
471	awk '{
472		for (i = 1; i <= 120; ++i)
473			printf("%05d: input key %d: %s\n", i, i, $0);
474	}' >exp
475
476	cat exp |
477	awk '{
478		printf("p\nk%d\nd%s\n", ++i, $0);
479	}
480	END {
481		printf("fR_NEXT\n");
482		for (i = 1; i <= 120; ++i)
483			printf("s\n");
484		printf("fR_CURSOR\ns\nkXX\n");
485		printf("r\n");
486		printf("fR_NEXT\ns\n");
487		printf("fR_CURSOR\ns\nk1\n");
488		printf("r\n");
489		printf("fR_FIRST\ns\n");
490	}' >in
491
492	# For btree, the records are ordered by the string representation
493	# of the key value.  So sort the expected output file accordingly,
494	# and set the seek_last key to the last expected key value.
495
496	if [ "$type" = "btree" ] ; then
497		sed -e 's/kXX/k99/' < in > tmp
498		mv tmp in
499		sort -d -k4 < exp > tmp
500		mv tmp exp
501		echo $SEVEN_SEVEN |
502		awk '{
503			printf("%05d: input key %d: %s\n", 99, 99, $0);
504			printf("seq failed, no such key\n");
505			printf("%05d: input key %d: %s\n", 1, 1, $0);
506			printf("%05d: input key %d: %s\n", 10, 10, $0);
507			exit;
508		}' >> exp
509	else
510	# For recno, records are ordered by numerical key value.  No sort
511	# is needed, but still need to set proper seek_last key value.
512		sed -e 's/kXX/k120/' < in > tmp
513		mv tmp in
514		echo $SEVEN_SEVEN |
515		awk '{
516			printf("%05d: input key %d: %s\n", 120, 120, $0);
517			printf("seq failed, no such key\n");
518			printf("%05d: input key %d: %s\n", 1, 1, $0);
519			printf("%05d: input key %d: %s\n", 2, 2, $0);
520			exit;
521		}' >> exp
522	fi
523
524	atf_check "$(prog)" -o out $type in
525	atf_check -o file:exp cat out
526}
527
528atf_test_case delete_btree
529delete_btree_head()
530{
531	atf_set "descr" "Checks removing records in btree database"
532}
533delete_btree_body()
534{
535	h_delete btree
536}
537
538atf_test_case delete_recno
539delete_recno_head()
540{
541	atf_set "descr" "Checks removing records in recno database"
542}
543delete_recno_body()
544{
545	h_delete recno
546}
547
548h_repeated()
549{
550	TMPDIR="$(pwd)/db_dir"; export TMPDIR
551	mkdir ${TMPDIR}
552
553	echo "" | 
554	awk 'BEGIN {
555		for (i = 1; i <= 10; ++i) {
556			printf("p\nkkey1\nD/bin/sh\n");
557			printf("p\nkkey2\nD/bin/csh\n");
558			if (i % 8 == 0) {
559				printf("c\nkkey2\nD/bin/csh\n");
560				printf("c\nkkey1\nD/bin/sh\n");
561				printf("e\t%d of 10 (comparison)\n", i);
562			} else
563				printf("e\t%d of 10             \n", i);
564			printf("r\nkkey1\nr\nkkey2\n");
565		}
566	}' >in
567
568	$(prog) btree in
569}
570
571atf_test_case repeated_btree
572repeated_btree_head()
573{
574	atf_set "descr" \
575		"Checks btree database with repeated small keys and" \
576		"big data pairs. Makes sure that overflow pages are reused"
577}
578repeated_btree_body()
579{
580	h_repeated btree
581}
582
583atf_test_case repeated_hash
584repeated_hash_head()
585{
586	atf_set "descr" \
587		"Checks hash database with repeated small keys and" \
588		"big data pairs. Makes sure that overflow pages are reused"
589}
590repeated_hash_body()
591{
592	h_repeated hash
593}
594
595atf_test_case duplicate_btree
596duplicate_btree_head()
597{
598	atf_set "descr" "Checks btree database with duplicate keys"
599}
600duplicate_btree_body()
601{
602	TMPDIR="$(pwd)/db_dir"; export TMPDIR
603	mkdir ${TMPDIR}
604
605	echo $SEVEN_SEVEN |
606	awk '{
607		for (i = 1; i <= 543; ++i)
608			printf("%05d: input key %d: %s\n", i, i, $0);
609		exit;
610	}' >exp
611
612	cat exp | 
613	awk '{
614		if (i++ % 2)
615			printf("p\nkduplicatekey\nd%s\n", $0);
616		else
617			printf("p\nkunique%dkey\nd%s\n", i, $0);
618	}
619	END {
620			printf("o\n");
621	}' >in
622
623	atf_check -o file:exp -x "$(prog) -iflags=1 btree in | sort"
624}
625
626h_cursor_flags()
627{
628	TMPDIR="$(pwd)/db_dir"; export TMPDIR
629	mkdir ${TMPDIR}
630
631	type=$1
632
633	echo $SEVEN_SEVEN |
634	awk '{
635		for (i = 1; i <= 20; ++i)
636			printf("%05d: input key %d: %s\n", i, i, $0);
637		exit;
638	}' >exp
639
640	# Test that R_CURSOR doesn't succeed before cursor initialized
641	cat exp |
642	awk '{
643		if (i == 10)
644			exit;
645		printf("p\nk%d\nd%s\n", ++i, $0);
646	}
647	END {
648		printf("fR_CURSOR\nr\n");
649		printf("eR_CURSOR SHOULD HAVE FAILED\n");
650	}' >in
651
652	atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
653	atf_check -s ne:0 test -s out
654
655	cat exp |
656	awk '{
657		if (i == 10)
658			exit;
659		printf("p\nk%d\nd%s\n", ++i, $0);
660	}
661	END {
662		printf("fR_CURSOR\np\nk1\ndsome data\n");
663		printf("eR_CURSOR SHOULD HAVE FAILED\n");
664	}' >in
665
666	atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
667	atf_check -s ne:0 test -s out
668}
669
670atf_test_case cursor_flags_btree
671cursor_flags_btree_head()
672{
673	atf_set "descr" \
674		"Checks use of cursor flags without initialization in btree database"
675}
676cursor_flags_btree_body()
677{
678	h_cursor_flags btree
679}
680
681atf_test_case cursor_flags_recno
682cursor_flags_recno_head()
683{
684	atf_set "descr" \
685		"Checks use of cursor flags without initialization in recno database"
686}
687cursor_flags_recno_body()
688{
689	h_cursor_flags recno
690}
691
692atf_test_case reverse_order_recno
693reverse_order_recno_head()
694{
695	atf_set "descr" "Checks reverse order inserts in recno database"
696}
697reverse_order_recno_body()
698{
699	TMPDIR="$(pwd)/db_dir"; export TMPDIR
700	mkdir ${TMPDIR}
701
702	echo $SEVEN_SEVEN |
703	awk '{
704		for (i = 1; i <= 779; ++i)
705			printf("%05d: input key %d: %s\n", i, i, $0);
706		exit;
707	}' >exp
708
709	cat exp |
710	awk '{
711		if (i == 0) {
712			i = 1;
713			printf("p\nk1\nd%s\n", $0);
714			printf("%s\n", "fR_IBEFORE");
715		} else
716			printf("p\nk1\nd%s\n", $0);
717	}
718	END {
719			printf("or\n");
720	}' >in
721
722	atf_check -o file:exp "$(prog)" recno in
723}
724
725atf_test_case small_page_btree
726small_page_btree_head()
727{
728	atf_set "descr" \
729		"Checks btree database with lots of keys and small page" \
730		"size: takes the first 20000 entries in the dictionary," \
731		"reverses them, and gives them each a small size data" \
732		"entry. Uses a small page size to make sure the btree" \
733		"split code gets hammered."
734}
735small_page_btree_body()
736{
737	TMPDIR="$(pwd)/db_dir"; export TMPDIR
738	mkdir ${TMPDIR}
739
740	mdata=abcdefghijklmnopqrstuvwxy
741	echo $mdata |
742	awk '{ for (i = 1; i < 20001; ++i) print $0 }' >exp
743
744	for i in `sed 20000q $(dict) | rev`; do
745		echo p
746		echo k$i
747		echo d$mdata
748		echo g
749		echo k$i
750	done >in
751
752	atf_check -o file:exp "$(prog)" -i psize=512 btree in
753}
754
755h_byte_orders()
756{
757	TMPDIR="$(pwd)/db_dir"; export TMPDIR
758	mkdir ${TMPDIR}
759
760	type=$1
761
762	sed 50q $(dict) >exp
763	for order in 1234 4321; do
764		for i in `sed 50q $(dict)`; do
765			echo p
766			echo k$i
767			echo d$i
768			echo g
769			echo k$i
770		done >in
771
772		atf_check -o file:exp "$(prog)" -ilorder=$order -f byte.file $type in
773
774		for i in `sed 50q $(dict)`; do
775			echo g
776			echo k$i
777		done >in
778
779		atf_check -o file:exp "$(prog)" -s -ilorder=$order -f byte.file $type in
780	done
781}
782
783atf_test_case byte_orders_btree
784byte_orders_btree_head()
785{
786	atf_set "descr" "Checks btree database using differing byte orders"
787}
788byte_orders_btree_body()
789{
790	h_byte_orders btree
791}
792
793atf_test_case byte_orders_hash
794byte_orders_hash_head()
795{
796	atf_set "descr" "Checks hash database using differing byte orders"
797}
798byte_orders_hash_body()
799{
800	h_byte_orders hash
801}
802
803h_bsize_ffactor()
804{
805	bsize=$1
806	ffactor=$2
807
808	echo "bucketsize $bsize, fill factor $ffactor"
809	atf_check -o file:exp "$(prog)" "-ibsize=$bsize,\
810ffactor=$ffactor,nelem=25000,cachesize=65536" hash in
811}
812
813atf_test_case bsize_ffactor
814bsize_ffactor_head()
815{
816	atf_set "timeout" "480"
817	atf_set "descr" "Checks hash database with various" \
818					"bucketsizes and fill factors"
819}
820bsize_ffactor_body()
821{
822	TMPDIR="$(pwd)/db_dir"; export TMPDIR
823	mkdir ${TMPDIR}
824
825	echo $SEVEN_SEVEN |
826	awk '{
827		for (i = 1; i <= 10000; ++i) {
828			if (i % 34)
829				s = substr($0, 1, i % 34);
830			else
831				s = substr($0, 1);
832			printf("%s\n", s);
833		}
834		exit;
835
836	}' >exp
837
838	sed 10000q $(dict) |
839	awk 'BEGIN {
840		ds="'$SEVEN_SEVEN'"
841	}
842	{
843		if (++i % 34)
844			s = substr(ds, 1, i % 34);
845		else
846			s = substr(ds, 1);
847		printf("p\nk%s\nd%s\n", $0, s);
848	}' >in
849
850	sed 10000q $(dict) |
851	awk '{
852		++i;
853		printf("g\nk%s\n", $0);
854	}' >>in
855
856	h_bsize_ffactor 256 11
857	h_bsize_ffactor 256 14
858	h_bsize_ffactor 256 21
859
860	h_bsize_ffactor 512 21
861	h_bsize_ffactor 512 28
862	h_bsize_ffactor 512 43
863
864	h_bsize_ffactor 1024 43
865	h_bsize_ffactor 1024 57
866	h_bsize_ffactor 1024 85
867
868	h_bsize_ffactor 2048 85
869	h_bsize_ffactor 2048 114
870	h_bsize_ffactor 2048 171
871
872	h_bsize_ffactor 4096 171
873	h_bsize_ffactor 4096 228
874	h_bsize_ffactor 4096 341
875
876	h_bsize_ffactor 8192 341
877	h_bsize_ffactor 8192 455
878	h_bsize_ffactor 8192 683
879}
880
881# FIXME: what does it test?
882atf_test_case four_char_hash
883four_char_hash_head()
884{
885	atf_set "descr" \
886		"Checks hash database with 4 char key and" \
887		"value insert on a 65536 bucket size"
888}
889four_char_hash_body()
890{
891	TMPDIR="$(pwd)/db_dir"; export TMPDIR
892	mkdir ${TMPDIR}
893
894	cat >in <<EOF
895p
896k1234
897d1234
898r
899k1234
900EOF
901
902	# Begin FreeBSD
903	if true; then
904		atf_check "$(prog)" -i bsize=32768 hash in
905	else
906	# End FreeBSD
907	atf_check "$(prog)" -i bsize=65536 hash in
908	# Begin FreeBSD
909	fi
910	# End FreeBSD
911}
912
913atf_init_test_cases()
914{
915	atf_add_test_case small_btree
916	atf_add_test_case small_hash
917	atf_add_test_case small_recno
918	atf_add_test_case medium_btree
919	atf_add_test_case medium_hash
920	atf_add_test_case medium_recno
921	atf_add_test_case big_btree
922	atf_add_test_case big_hash
923	atf_add_test_case big_recno
924	atf_add_test_case random_recno
925	atf_add_test_case reverse_recno
926	atf_add_test_case alternate_recno
927	atf_add_test_case delete_btree
928	atf_add_test_case delete_recno
929	atf_add_test_case repeated_btree
930	atf_add_test_case repeated_hash
931	atf_add_test_case duplicate_btree
932	atf_add_test_case cursor_flags_btree
933	atf_add_test_case cursor_flags_recno
934	atf_add_test_case reverse_order_recno
935	atf_add_test_case small_page_btree
936	atf_add_test_case byte_orders_btree
937	atf_add_test_case byte_orders_hash
938	atf_add_test_case bsize_ffactor
939	atf_add_test_case four_char_hash
940}
941