1 # $NetBSD: t_db.sh,v 1.4 2013/07/29 10:43:15 skrll Exp $
3 # Copyright (c) 2008 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
30 echo $(atf_get_srcdir)/h_db
35 if [ -f /usr/share/dict/words ]; then
36 echo /usr/share/dict/words
37 elif [ -f /usr/dict/words ]; then
40 atf_fail "no dictionary found"
47 if [ -f /usr/share/dict/words ]; then
48 echo /usr/share/dict/words
51 atf_skip "Test requires dict/words"
56 SEVEN_SEVEN="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg"
58 atf_test_case small_btree
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."
68 TMPDIR="$(pwd)/db_dir"; export TMPDIR
73 for i in `sed 200q $(dict)`; do
81 atf_check -o file:exp "$(prog)" btree in
84 atf_test_case small_hash
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."
94 TMPDIR="$(pwd)/db_dir"; export TMPDIR
99 for i in `sed 200q $(dict)`; do
107 atf_check -o file:exp "$(prog)" hash in
110 atf_test_case small_recno
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."
120 TMPDIR="$(pwd)/db_dir"; export TMPDIR
123 sed 200q $(dict) >exp
128 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
131 atf_check -o file:exp "$(prog)" recno in
134 atf_test_case medium_btree
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."
144 TMPDIR="$(pwd)/db_dir"; export TMPDIR
147 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
149 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
151 for i in $(sed 200q $(dict)); do
159 atf_check -o file:exp "$(prog)" btree in
162 atf_test_case medium_hash
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."
172 TMPDIR="$(pwd)/db_dir"; export TMPDIR
175 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
177 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
179 for i in $(sed 200q $(dict)); do
187 atf_check -o file:exp "$(prog)" hash in
190 atf_test_case medium_recno
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."
200 TMPDIR="$(pwd)/db_dir"; export TMPDIR
203 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
205 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
208 awk '{ for (i = 1; i < 201; ++i)
209 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
212 atf_check -o file:exp "$(prog)" recno in
215 atf_test_case big_btree
219 "Checks btree database using small keys and big data" \
220 "pairs: inserts the programs in /bin with their paths" \
225 TMPDIR="$(pwd)/db_dir"; export TMPDIR
228 (find /bin -type f -print | xargs cat) >exp
230 for psize in 512 16384 65536; do
231 echo "checking page size: $psize"
233 for i in `find /bin -type f -print`; do
241 atf_check "$(prog)" -o out btree in
242 cmp -s exp out || atf_fail "test failed for page size: $psize"
246 atf_test_case big_hash
250 "Checks hash database using small keys and big data" \
251 "pairs: inserts the programs in /bin with their paths" \
256 TMPDIR="$(pwd)/db_dir"; export TMPDIR
259 (find /bin -type f -print | xargs cat) >exp
261 for i in `find /bin -type f -print`; do
269 atf_check "$(prog)" -o out hash in
270 cmp -s exp out || atf_fail "test failed"
273 atf_test_case big_recno
277 "Checks recno database using small keys and big data" \
278 "pairs: inserts the programs in /bin with their paths" \
283 TMPDIR="$(pwd)/db_dir"; export TMPDIR
286 (find /bin -type f -print | xargs cat) >exp
288 find /bin -type f -print |
291 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
294 for psize in 512 16384 65536; do
295 echo "checking page size: $psize"
297 atf_check "$(prog)" -o out recno in
298 cmp -s exp out || atf_fail "test failed for page size: $psize"
302 atf_test_case random_recno
305 atf_set "descr" "Checks recno database using random entries"
309 TMPDIR="$(pwd)/db_dir"; export TMPDIR
314 for (i = 37; i <= 37 + 88 * 17; i += 17) {
316 s = substr($0, 1, i % 41);
319 printf("input key %d: %s\n", i, s);
321 for (i = 1; i <= 15; ++i) {
323 s = substr($0, 1, i % 41);
326 printf("input key %d: %s\n", i, s);
328 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
330 s = substr($0, 1, i % 41);
333 printf("input key %d: %s\n", i, s);
344 printf("p\nk%d\nd%s\n", i, $0);
345 if (i == 19234 + 61 * 27)
347 if (i == 37 + 88 * 17) {
350 } else if (i == 15) {
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);
365 atf_check -o file:exp "$(prog)" recno in
368 atf_test_case reverse_recno
371 atf_set "descr" "Checks recno database using reverse order entries"
375 TMPDIR="$(pwd)/db_dir"; export TMPDIR
380 for (i = 1500; i; --i) {
382 s = substr($0, 1, i % 34);
385 printf("input key %d: %s\n", i, s);
395 printf("p\nk%d\nd%s\n", i, $0);
399 for (i = 1500; i; --i)
400 printf("g\nk%d\n", i);
403 atf_check -o file:exp "$(prog)" recno in
406 atf_test_case alternate_recno
407 alternate_recno_head()
409 atf_set "descr" "Checks recno database using alternating order entries"
411 alternate_recno_body()
413 TMPDIR="$(pwd)/db_dir"; export TMPDIR
418 for (i = 1; i < 1200; i += 2) {
420 s = substr($0, 1, i % 34);
423 printf("input key %d: %s\n", i, s);
425 for (i = 2; i < 1200; i += 2) {
427 s = substr($0, 1, i % 34);
430 printf("input key %d: %s\n", i, s);
441 printf("p\nk%d\nd%s\n", i, $0);
451 for (i = 1; i < 1200; ++i)
452 printf("g\nk%d\n", i);
455 atf_check "$(prog)" -o out recno in
460 cmp -s exp out || atf_fail "test failed"
465 TMPDIR="$(pwd)/db_dir"; export TMPDIR
472 for (i = 1; i <= 120; ++i)
473 printf("%05d: input key %d: %s\n", i, i, $0);
478 printf("p\nk%d\nd%s\n", ++i, $0);
482 for (i = 1; i <= 120; ++i)
484 printf("fR_CURSOR\ns\nkXX\n");
486 printf("fR_NEXT\ns\n");
487 printf("fR_CURSOR\ns\nk1\n");
489 printf("fR_FIRST\ns\n");
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.
496 if [ "$type" = "btree" ] ; then
497 sed -e 's/kXX/k99/' < in > tmp
499 sort -d -k4 < exp > tmp
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);
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
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);
524 atf_check "$(prog)" -o out $type in
525 atf_check -o file:exp cat out
528 atf_test_case delete_btree
531 atf_set "descr" "Checks removing records in btree database"
538 atf_test_case delete_recno
541 atf_set "descr" "Checks removing records in recno database"
550 TMPDIR="$(pwd)/db_dir"; export TMPDIR
555 for (i = 1; i <= 10; ++i) {
556 printf("p\nkkey1\nD/bin/sh\n");
557 printf("p\nkkey2\nD/bin/csh\n");
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);
563 printf("e\t%d of 10 \n", i);
564 printf("r\nkkey1\nr\nkkey2\n");
571 atf_test_case repeated_btree
572 repeated_btree_head()
575 "Checks btree database with repeated small keys and" \
576 "big data pairs. Makes sure that overflow pages are reused"
578 repeated_btree_body()
583 atf_test_case repeated_hash
587 "Checks hash database with repeated small keys and" \
588 "big data pairs. Makes sure that overflow pages are reused"
595 atf_test_case duplicate_btree
596 duplicate_btree_head()
598 atf_set "descr" "Checks btree database with duplicate keys"
600 duplicate_btree_body()
602 TMPDIR="$(pwd)/db_dir"; export TMPDIR
607 for (i = 1; i <= 543; ++i)
608 printf("%05d: input key %d: %s\n", i, i, $0);
615 printf("p\nkduplicatekey\nd%s\n", $0);
617 printf("p\nkunique%dkey\nd%s\n", i, $0);
623 atf_check -o file:exp -x "$(prog) -iflags=1 btree in | sort"
628 TMPDIR="$(pwd)/db_dir"; export TMPDIR
635 for (i = 1; i <= 20; ++i)
636 printf("%05d: input key %d: %s\n", i, i, $0);
640 # Test that R_CURSOR doesn't succeed before cursor initialized
645 printf("p\nk%d\nd%s\n", ++i, $0);
648 printf("fR_CURSOR\nr\n");
649 printf("eR_CURSOR SHOULD HAVE FAILED\n");
652 atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
653 atf_check -s ne:0 test -s out
659 printf("p\nk%d\nd%s\n", ++i, $0);
662 printf("fR_CURSOR\np\nk1\ndsome data\n");
663 printf("eR_CURSOR SHOULD HAVE FAILED\n");
666 atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
667 atf_check -s ne:0 test -s out
670 atf_test_case cursor_flags_btree
671 cursor_flags_btree_head()
674 "Checks use of cursor flags without initialization in btree database"
676 cursor_flags_btree_body()
681 atf_test_case cursor_flags_recno
682 cursor_flags_recno_head()
685 "Checks use of cursor flags without initialization in recno database"
687 cursor_flags_recno_body()
692 atf_test_case reverse_order_recno
693 reverse_order_recno_head()
695 atf_set "descr" "Checks reverse order inserts in recno database"
697 reverse_order_recno_body()
699 TMPDIR="$(pwd)/db_dir"; export TMPDIR
704 for (i = 1; i <= 779; ++i)
705 printf("%05d: input key %d: %s\n", i, i, $0);
713 printf("p\nk1\nd%s\n", $0);
714 printf("%s\n", "fR_IBEFORE");
716 printf("p\nk1\nd%s\n", $0);
722 atf_check -o file:exp "$(prog)" recno in
725 atf_test_case small_page_btree
726 small_page_btree_head()
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."
735 small_page_btree_body()
737 TMPDIR="$(pwd)/db_dir"; export TMPDIR
740 mdata=abcdefghijklmnopqrstuvwxy
742 awk '{ for (i = 1; i < 20001; ++i) print $0 }' >exp
744 for i in `sed 20000q $(dict) | rev`; do
752 atf_check -o file:exp "$(prog)" -i psize=512 btree in
757 TMPDIR="$(pwd)/db_dir"; export TMPDIR
763 for order in 1234 4321; do
764 for i in `sed 50q $(dict)`; do
772 atf_check -o file:exp "$(prog)" -ilorder=$order -f byte.file $type in
774 for i in `sed 50q $(dict)`; do
779 atf_check -o file:exp "$(prog)" -s -ilorder=$order -f byte.file $type in
783 atf_test_case byte_orders_btree
784 byte_orders_btree_head()
786 atf_set "descr" "Checks btree database using differing byte orders"
788 byte_orders_btree_body()
793 atf_test_case byte_orders_hash
794 byte_orders_hash_head()
796 atf_set "descr" "Checks hash database using differing byte orders"
798 byte_orders_hash_body()
808 echo "bucketsize $bsize, fill factor $ffactor"
809 atf_check -o file:exp "$(prog)" "-ibsize=$bsize,\
810 ffactor=$ffactor,nelem=25000,cachesize=65536" hash in
813 atf_test_case bsize_ffactor
816 atf_set "timeout" "480"
817 atf_set "descr" "Checks hash database with various" \
818 "bucketsizes and fill factors"
822 TMPDIR="$(pwd)/db_dir"; export TMPDIR
827 for (i = 1; i <= 10000; ++i) {
829 s = substr($0, 1, i % 34);
844 s = substr(ds, 1, i % 34);
847 printf("p\nk%s\nd%s\n", $0, s);
853 printf("g\nk%s\n", $0);
856 h_bsize_ffactor 256 11
857 h_bsize_ffactor 256 14
858 h_bsize_ffactor 256 21
860 h_bsize_ffactor 512 21
861 h_bsize_ffactor 512 28
862 h_bsize_ffactor 512 43
864 h_bsize_ffactor 1024 43
865 h_bsize_ffactor 1024 57
866 h_bsize_ffactor 1024 85
868 h_bsize_ffactor 2048 85
869 h_bsize_ffactor 2048 114
870 h_bsize_ffactor 2048 171
872 h_bsize_ffactor 4096 171
873 h_bsize_ffactor 4096 228
874 h_bsize_ffactor 4096 341
876 h_bsize_ffactor 8192 341
877 h_bsize_ffactor 8192 455
878 h_bsize_ffactor 8192 683
881 # FIXME: what does it test?
882 atf_test_case four_char_hash
883 four_char_hash_head()
886 "Checks hash database with 4 char key and" \
887 "value insert on a 65536 bucket size"
889 four_char_hash_body()
891 TMPDIR="$(pwd)/db_dir"; export TMPDIR
904 atf_check "$(prog)" -i bsize=32768 hash in
907 atf_check "$(prog)" -i bsize=65536 hash in
913 atf_init_test_cases()
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