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