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