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