1 # $NetBSD: t_db.sh,v 1.6 2015/11/18 18:35:35 christos 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 echo $(atf_get_srcdir)/h_lfsr
40 if [ -f /usr/share/dict/words ]; then
41 echo /usr/share/dict/words
42 elif [ -f /usr/dict/words ]; then
46 atf_fail "no dictionary found"
53 echo /usr/share/dict/words
57 SEVEN_SEVEN="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg"
59 atf_test_case small_btree
63 "Checks btree database using small keys and small data" \
64 "pairs: takes the first hundred entries in the dictionary," \
65 "and makes them be key/data pairs."
67 atf_set "require.files" /usr/share/dict/words
72 TMPDIR="$(pwd)/db_dir"; export TMPDIR
77 for i in `sed 200q $(dict)`; do
85 atf_check -o file:exp "$(prog_db)" btree in
88 atf_test_case small_hash
92 "Checks hash database using small keys and small data" \
93 "pairs: takes the first hundred entries in the dictionary," \
94 "and makes them be key/data pairs."
96 atf_set "require.files" /usr/share/dict/words
101 TMPDIR="$(pwd)/db_dir"; export TMPDIR
104 sed 200q $(dict) >exp
106 for i in `sed 200q $(dict)`; do
114 atf_check -o file:exp "$(prog_db)" hash in
117 atf_test_case small_recno
121 "Checks recno database using small keys and small data" \
122 "pairs: takes the first hundred entries in the dictionary," \
123 "and makes them be key/data pairs."
125 atf_set "require.files" /usr/share/dict/words
130 TMPDIR="$(pwd)/db_dir"; export TMPDIR
133 sed 200q $(dict) >exp
138 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
141 atf_check -o file:exp "$(prog_db)" recno in
144 atf_test_case medium_btree
148 "Checks btree database using small keys and medium" \
149 "data pairs: takes the first 200 entries in the" \
150 "dictionary, and gives them each a medium size data entry."
152 atf_set "require.files" /usr/share/dict/words
157 TMPDIR="$(pwd)/db_dir"; export TMPDIR
160 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
162 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
164 for i in $(sed 200q $(dict)); do
172 atf_check -o file:exp "$(prog_db)" btree in
175 atf_test_case medium_hash
179 "Checks hash database using small keys and medium" \
180 "data pairs: takes the first 200 entries in the" \
181 "dictionary, and gives them each a medium size data entry."
183 atf_set "require.files" /usr/share/dict/words
188 TMPDIR="$(pwd)/db_dir"; export TMPDIR
191 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
193 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
195 for i in $(sed 200q $(dict)); do
203 atf_check -o file:exp "$(prog_db)" hash in
206 atf_test_case medium_recno
210 "Checks recno database using small keys and medium" \
211 "data pairs: takes the first 200 entries in the" \
212 "dictionary, and gives them each a medium size data entry."
216 TMPDIR="$(pwd)/db_dir"; export TMPDIR
219 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
221 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
224 awk '{ for (i = 1; i < 201; ++i)
225 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
228 atf_check -o file:exp "$(prog_db)" recno in
231 atf_test_case big_btree
235 "Checks btree database using small keys and big data" \
236 "pairs: inserts the programs in /bin with their paths" \
241 TMPDIR="$(pwd)/db_dir"; export TMPDIR
244 (find /bin -type f -print | xargs cat) >exp
246 for psize in 512 16384 65536; do
247 echo "checking page size: $psize"
249 for i in `find /bin -type f -print`; do
257 atf_check "$(prog_db)" -o out btree in
258 cmp -s exp out || atf_fail "test failed for page size: $psize"
262 atf_test_case big_hash
266 "Checks hash database using small keys and big data" \
267 "pairs: inserts the programs in /bin with their paths" \
272 TMPDIR="$(pwd)/db_dir"; export TMPDIR
275 (find /bin -type f -print | xargs cat) >exp
277 for i in `find /bin -type f -print`; do
285 atf_check "$(prog_db)" -o out hash in
286 cmp -s exp out || atf_fail "test failed"
289 atf_test_case big_recno
293 "Checks recno database using small keys and big data" \
294 "pairs: inserts the programs in /bin with their paths" \
299 TMPDIR="$(pwd)/db_dir"; export TMPDIR
302 (find /bin -type f -print | xargs cat) >exp
304 find /bin -type f -print |
307 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
310 for psize in 512 16384 65536; do
311 echo "checking page size: $psize"
313 atf_check "$(prog_db)" -o out recno in
314 cmp -s exp out || atf_fail "test failed for page size: $psize"
318 atf_test_case random_recno
321 atf_set "descr" "Checks recno database using random entries"
325 TMPDIR="$(pwd)/db_dir"; export TMPDIR
330 for (i = 37; i <= 37 + 88 * 17; i += 17) {
332 s = substr($0, 1, i % 41);
335 printf("input key %d: %s\n", i, s);
337 for (i = 1; i <= 15; ++i) {
339 s = substr($0, 1, i % 41);
342 printf("input key %d: %s\n", i, s);
344 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
346 s = substr($0, 1, i % 41);
349 printf("input key %d: %s\n", i, s);
360 printf("p\nk%d\nd%s\n", i, $0);
361 if (i == 19234 + 61 * 27)
363 if (i == 37 + 88 * 17) {
366 } else if (i == 15) {
373 for (i = 37; i <= 37 + 88 * 17; i += 17)
374 printf("g\nk%d\n", i);
375 for (i = 1; i <= 15; ++i)
376 printf("g\nk%d\n", i);
377 for (i = 19234; i <= 19234 + 61 * 27; i += 27)
378 printf("g\nk%d\n", i);
381 atf_check -o file:exp "$(prog_db)" recno in
384 atf_test_case reverse_recno
387 atf_set "descr" "Checks recno database using reverse order entries"
391 TMPDIR="$(pwd)/db_dir"; export TMPDIR
396 for (i = 1500; i; --i) {
398 s = substr($0, 1, i % 34);
401 printf("input key %d: %s\n", i, s);
411 printf("p\nk%d\nd%s\n", i, $0);
415 for (i = 1500; i; --i)
416 printf("g\nk%d\n", i);
419 atf_check -o file:exp "$(prog_db)" recno in
422 atf_test_case alternate_recno
423 alternate_recno_head()
425 atf_set "descr" "Checks recno database using alternating order entries"
427 alternate_recno_body()
429 TMPDIR="$(pwd)/db_dir"; export TMPDIR
434 for (i = 1; i < 1200; i += 2) {
436 s = substr($0, 1, i % 34);
439 printf("input key %d: %s\n", i, s);
441 for (i = 2; i < 1200; i += 2) {
443 s = substr($0, 1, i % 34);
446 printf("input key %d: %s\n", i, s);
457 printf("p\nk%d\nd%s\n", i, $0);
467 for (i = 1; i < 1200; ++i)
468 printf("g\nk%d\n", i);
471 atf_check "$(prog_db)" -o out recno in
476 cmp -s exp out || atf_fail "test failed"
481 TMPDIR="$(pwd)/db_dir"; export TMPDIR
488 for (i = 1; i <= 120; ++i)
489 printf("%05d: input key %d: %s\n", i, i, $0);
494 printf("p\nk%d\nd%s\n", ++i, $0);
498 for (i = 1; i <= 120; ++i)
500 printf("fR_CURSOR\ns\nkXX\n");
502 printf("fR_NEXT\ns\n");
503 printf("fR_CURSOR\ns\nk1\n");
505 printf("fR_FIRST\ns\n");
508 # For btree, the records are ordered by the string representation
509 # of the key value. So sort the expected output file accordingly,
510 # and set the seek_last key to the last expected key value.
512 if [ "$type" = "btree" ] ; then
513 sed -e 's/kXX/k99/' < in > tmp
515 sort -d -k4 < exp > tmp
519 printf("%05d: input key %d: %s\n", 99, 99, $0);
520 printf("seq failed, no such key\n");
521 printf("%05d: input key %d: %s\n", 1, 1, $0);
522 printf("%05d: input key %d: %s\n", 10, 10, $0);
526 # For recno, records are ordered by numerical key value. No sort
527 # is needed, but still need to set proper seek_last key value.
528 sed -e 's/kXX/k120/' < in > tmp
532 printf("%05d: input key %d: %s\n", 120, 120, $0);
533 printf("seq failed, no such key\n");
534 printf("%05d: input key %d: %s\n", 1, 1, $0);
535 printf("%05d: input key %d: %s\n", 2, 2, $0);
540 atf_check "$(prog_db)" -o out $type in
541 atf_check -o file:exp cat out
544 atf_test_case delete_btree
547 atf_set "descr" "Checks removing records in btree database"
554 atf_test_case delete_recno
557 atf_set "descr" "Checks removing records in recno database"
566 TMPDIR="$(pwd)/db_dir"; export TMPDIR
571 for (i = 1; i <= 10; ++i) {
572 printf("p\nkkey1\nD/bin/sh\n");
573 printf("p\nkkey2\nD/bin/csh\n");
575 printf("c\nkkey2\nD/bin/csh\n");
576 printf("c\nkkey1\nD/bin/sh\n");
577 printf("e\t%d of 10 (comparison)\n", i);
579 printf("e\t%d of 10 \n", i);
580 printf("r\nkkey1\nr\nkkey2\n");
587 atf_test_case repeated_btree
588 repeated_btree_head()
591 "Checks btree database with repeated small keys and" \
592 "big data pairs. Makes sure that overflow pages are reused"
594 repeated_btree_body()
599 atf_test_case repeated_hash
603 "Checks hash database with repeated small keys and" \
604 "big data pairs. Makes sure that overflow pages are reused"
611 atf_test_case duplicate_btree
612 duplicate_btree_head()
614 atf_set "descr" "Checks btree database with duplicate keys"
616 duplicate_btree_body()
618 TMPDIR="$(pwd)/db_dir"; export TMPDIR
623 for (i = 1; i <= 543; ++i)
624 printf("%05d: input key %d: %s\n", i, i, $0);
631 printf("p\nkduplicatekey\nd%s\n", $0);
633 printf("p\nkunique%dkey\nd%s\n", i, $0);
639 atf_check -o file:exp -x "$(prog_db) -iflags=1 btree in | sort"
644 TMPDIR="$(pwd)/db_dir"; export TMPDIR
651 for (i = 1; i <= 20; ++i)
652 printf("%05d: input key %d: %s\n", i, i, $0);
656 # Test that R_CURSOR doesn't succeed before cursor initialized
661 printf("p\nk%d\nd%s\n", ++i, $0);
664 printf("fR_CURSOR\nr\n");
665 printf("eR_CURSOR SHOULD HAVE FAILED\n");
668 atf_check -o ignore -e ignore -s ne:0 "$(prog_db)" -o out $type in
669 atf_check -s ne:0 test -s out
675 printf("p\nk%d\nd%s\n", ++i, $0);
678 printf("fR_CURSOR\np\nk1\ndsome data\n");
679 printf("eR_CURSOR SHOULD HAVE FAILED\n");
682 atf_check -o ignore -e ignore -s ne:0 "$(prog_db)" -o out $type in
683 atf_check -s ne:0 test -s out
686 atf_test_case cursor_flags_btree
687 cursor_flags_btree_head()
690 "Checks use of cursor flags without initialization in btree database"
692 cursor_flags_btree_body()
697 atf_test_case cursor_flags_recno
698 cursor_flags_recno_head()
701 "Checks use of cursor flags without initialization in recno database"
703 cursor_flags_recno_body()
708 atf_test_case reverse_order_recno
709 reverse_order_recno_head()
711 atf_set "descr" "Checks reverse order inserts in recno database"
713 reverse_order_recno_body()
715 TMPDIR="$(pwd)/db_dir"; export TMPDIR
720 for (i = 1; i <= 779; ++i)
721 printf("%05d: input key %d: %s\n", i, i, $0);
729 printf("p\nk1\nd%s\n", $0);
730 printf("%s\n", "fR_IBEFORE");
732 printf("p\nk1\nd%s\n", $0);
738 atf_check -o file:exp "$(prog_db)" recno in
741 atf_test_case small_page_btree
742 small_page_btree_head()
745 "Checks btree database with lots of keys and small page" \
746 "size: takes the first 20000 entries in the dictionary," \
747 "reverses them, and gives them each a small size data" \
748 "entry. Uses a small page size to make sure the btree" \
749 "split code gets hammered."
751 atf_set "require.files" /usr/share/dict/words
754 small_page_btree_body()
756 TMPDIR="$(pwd)/db_dir"; export TMPDIR
759 mdata=abcdefghijklmnopqrstuvwxy
761 awk '{ for (i = 1; i < 20001; ++i) print $0 }' >exp
763 for i in `sed 20000q $(dict) | rev`; do
771 atf_check -o file:exp "$(prog_db)" -i psize=512 btree in
776 TMPDIR="$(pwd)/db_dir"; export TMPDIR
782 for order in 1234 4321; do
783 for i in `sed 50q $(dict)`; do
791 atf_check -o file:exp "$(prog_db)" -ilorder=$order -f byte.file $type in
793 for i in `sed 50q $(dict)`; do
798 atf_check -o file:exp "$(prog_db)" -s -ilorder=$order -f byte.file $type in
802 atf_test_case byte_orders_btree
803 byte_orders_btree_head()
805 atf_set "descr" "Checks btree database using differing byte orders"
807 atf_set "require.files" /usr/share/dict/words
810 byte_orders_btree_body()
815 atf_test_case byte_orders_hash
816 byte_orders_hash_head()
818 atf_set "descr" "Checks hash database using differing byte orders"
820 byte_orders_hash_body()
830 echo "bucketsize $bsize, fill factor $ffactor"
831 atf_check -o file:exp "$(prog_db)" "-ibsize=$bsize,\
832 ffactor=$ffactor,nelem=25000,cachesize=65536" hash in
835 atf_test_case bsize_ffactor
838 atf_set "timeout" "1800"
839 atf_set "descr" "Checks hash database with various" \
840 "bucketsizes and fill factors"
842 atf_set "require.files" /usr/share/dict/words
847 TMPDIR="$(pwd)/db_dir"; export TMPDIR
852 for (i = 1; i <= 10000; ++i) {
854 s = substr($0, 1, i % 34);
869 s = substr(ds, 1, i % 34);
872 printf("p\nk%s\nd%s\n", $0, s);
878 printf("g\nk%s\n", $0);
881 h_bsize_ffactor 256 11
882 h_bsize_ffactor 256 14
883 h_bsize_ffactor 256 21
885 h_bsize_ffactor 512 21
886 h_bsize_ffactor 512 28
887 h_bsize_ffactor 512 43
889 h_bsize_ffactor 1024 43
890 h_bsize_ffactor 1024 57
891 h_bsize_ffactor 1024 85
893 h_bsize_ffactor 2048 85
894 h_bsize_ffactor 2048 114
895 h_bsize_ffactor 2048 171
897 h_bsize_ffactor 4096 171
898 h_bsize_ffactor 4096 228
899 h_bsize_ffactor 4096 341
901 h_bsize_ffactor 8192 341
902 h_bsize_ffactor 8192 455
903 h_bsize_ffactor 8192 683
905 h_bsize_ffactor 16384 341
906 h_bsize_ffactor 16384 455
907 h_bsize_ffactor 16384 683
909 h_bsize_ffactor 32768 341
910 h_bsize_ffactor 32768 455
911 h_bsize_ffactor 32768 683
916 h_bsize_ffactor 65536 341
917 h_bsize_ffactor 65536 455
918 h_bsize_ffactor 65536 683
924 # This tests 64K block size addition/removal
925 atf_test_case four_char_hash
926 four_char_hash_head()
929 "Checks hash database with 4 char key and" \
930 "value insert on a 65536 bucket size"
932 four_char_hash_body()
934 TMPDIR="$(pwd)/db_dir"; export TMPDIR
947 atf_check "$(prog_db)" -i bsize=32768 hash in
950 atf_check "$(prog_db)" -i bsize=65536 hash in
957 atf_test_case bsize_torture
960 atf_set "timeout" "36000"
961 atf_set "descr" "Checks hash database with various bucket sizes"
965 TMPDIR="$(pwd)/db_dir"; export TMPDIR
969 # db(3) doesn't support 64kB bucket sizes
970 for i in 2048 4096 8192 16384 32768 # 65536
973 atf_check "$(prog_lfsr)" $i
977 atf_init_test_cases()
979 atf_add_test_case small_btree
980 atf_add_test_case small_hash
981 atf_add_test_case small_recno
982 atf_add_test_case medium_btree
983 atf_add_test_case medium_hash
984 atf_add_test_case medium_recno
985 atf_add_test_case big_btree
986 atf_add_test_case big_hash
987 atf_add_test_case big_recno
988 atf_add_test_case random_recno
989 atf_add_test_case reverse_recno
990 atf_add_test_case alternate_recno
991 atf_add_test_case delete_btree
992 atf_add_test_case delete_recno
993 atf_add_test_case repeated_btree
994 atf_add_test_case repeated_hash
995 atf_add_test_case duplicate_btree
996 atf_add_test_case cursor_flags_btree
997 atf_add_test_case cursor_flags_recno
998 atf_add_test_case reverse_order_recno
999 atf_add_test_case small_page_btree
1000 atf_add_test_case byte_orders_btree
1001 atf_add_test_case byte_orders_hash
1002 atf_add_test_case bsize_ffactor
1003 atf_add_test_case four_char_hash
1004 atf_add_test_case bsize_torture