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
41 atf_fail "no dictionary found"
48 echo /usr/share/dict/words
52 SEVEN_SEVEN="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg"
54 atf_test_case small_btree
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."
62 atf_set "require.files" /usr/share/dict/words
67 TMPDIR="$(pwd)/db_dir"; export TMPDIR
72 for i in `sed 200q $(dict)`; do
80 atf_check -o file:exp "$(prog)" btree in
83 atf_test_case small_hash
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."
91 atf_set "require.files" /usr/share/dict/words
96 TMPDIR="$(pwd)/db_dir"; export TMPDIR
101 for i in `sed 200q $(dict)`; do
109 atf_check -o file:exp "$(prog)" hash in
112 atf_test_case small_recno
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."
120 atf_set "require.files" /usr/share/dict/words
125 TMPDIR="$(pwd)/db_dir"; export TMPDIR
128 sed 200q $(dict) >exp
133 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
136 atf_check -o file:exp "$(prog)" recno in
139 atf_test_case medium_btree
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."
147 atf_set "require.files" /usr/share/dict/words
152 TMPDIR="$(pwd)/db_dir"; export TMPDIR
155 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
157 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
159 for i in $(sed 200q $(dict)); do
167 atf_check -o file:exp "$(prog)" btree in
170 atf_test_case medium_hash
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."
178 atf_set "require.files" /usr/share/dict/words
183 TMPDIR="$(pwd)/db_dir"; export TMPDIR
186 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
188 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
190 for i in $(sed 200q $(dict)); do
198 atf_check -o file:exp "$(prog)" hash in
201 atf_test_case medium_recno
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."
211 TMPDIR="$(pwd)/db_dir"; export TMPDIR
214 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
216 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
219 awk '{ for (i = 1; i < 201; ++i)
220 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
223 atf_check -o file:exp "$(prog)" recno in
226 atf_test_case big_btree
230 "Checks btree database using small keys and big data" \
231 "pairs: inserts the programs in /bin with their paths" \
236 TMPDIR="$(pwd)/db_dir"; export TMPDIR
239 (find /bin -type f -print | xargs cat) >exp
241 for psize in 512 16384 65536; do
242 echo "checking page size: $psize"
244 for i in `find /bin -type f -print`; do
252 atf_check "$(prog)" -o out btree in
253 cmp -s exp out || atf_fail "test failed for page size: $psize"
257 atf_test_case big_hash
261 "Checks hash database using small keys and big data" \
262 "pairs: inserts the programs in /bin with their paths" \
267 TMPDIR="$(pwd)/db_dir"; export TMPDIR
270 (find /bin -type f -print | xargs cat) >exp
272 for i in `find /bin -type f -print`; do
280 atf_check "$(prog)" -o out hash in
281 cmp -s exp out || atf_fail "test failed"
284 atf_test_case big_recno
288 "Checks recno database using small keys and big data" \
289 "pairs: inserts the programs in /bin with their paths" \
294 TMPDIR="$(pwd)/db_dir"; export TMPDIR
297 (find /bin -type f -print | xargs cat) >exp
299 find /bin -type f -print |
302 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
305 for psize in 512 16384 65536; do
306 echo "checking page size: $psize"
308 atf_check "$(prog)" -o out recno in
309 cmp -s exp out || atf_fail "test failed for page size: $psize"
313 atf_test_case random_recno
316 atf_set "descr" "Checks recno database using random entries"
320 TMPDIR="$(pwd)/db_dir"; export TMPDIR
325 for (i = 37; i <= 37 + 88 * 17; i += 17) {
327 s = substr($0, 1, i % 41);
330 printf("input key %d: %s\n", i, s);
332 for (i = 1; i <= 15; ++i) {
334 s = substr($0, 1, i % 41);
337 printf("input key %d: %s\n", i, s);
339 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
341 s = substr($0, 1, i % 41);
344 printf("input key %d: %s\n", i, s);
355 printf("p\nk%d\nd%s\n", i, $0);
356 if (i == 19234 + 61 * 27)
358 if (i == 37 + 88 * 17) {
361 } else if (i == 15) {
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);
376 atf_check -o file:exp "$(prog)" recno in
379 atf_test_case reverse_recno
382 atf_set "descr" "Checks recno database using reverse order entries"
386 TMPDIR="$(pwd)/db_dir"; export TMPDIR
391 for (i = 1500; i; --i) {
393 s = substr($0, 1, i % 34);
396 printf("input key %d: %s\n", i, s);
406 printf("p\nk%d\nd%s\n", i, $0);
410 for (i = 1500; i; --i)
411 printf("g\nk%d\n", i);
414 atf_check -o file:exp "$(prog)" recno in
417 atf_test_case alternate_recno
418 alternate_recno_head()
420 atf_set "descr" "Checks recno database using alternating order entries"
422 alternate_recno_body()
424 TMPDIR="$(pwd)/db_dir"; export TMPDIR
429 for (i = 1; i < 1200; i += 2) {
431 s = substr($0, 1, i % 34);
434 printf("input key %d: %s\n", i, s);
436 for (i = 2; i < 1200; i += 2) {
438 s = substr($0, 1, i % 34);
441 printf("input key %d: %s\n", i, s);
452 printf("p\nk%d\nd%s\n", i, $0);
462 for (i = 1; i < 1200; ++i)
463 printf("g\nk%d\n", i);
466 atf_check "$(prog)" -o out recno in
471 cmp -s exp out || atf_fail "test failed"
476 TMPDIR="$(pwd)/db_dir"; export TMPDIR
483 for (i = 1; i <= 120; ++i)
484 printf("%05d: input key %d: %s\n", i, i, $0);
489 printf("p\nk%d\nd%s\n", ++i, $0);
493 for (i = 1; i <= 120; ++i)
495 printf("fR_CURSOR\ns\nkXX\n");
497 printf("fR_NEXT\ns\n");
498 printf("fR_CURSOR\ns\nk1\n");
500 printf("fR_FIRST\ns\n");
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.
507 if [ "$type" = "btree" ] ; then
508 sed -e 's/kXX/k99/' < in > tmp
510 sort -d -k4 < exp > tmp
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);
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
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);
535 atf_check "$(prog)" -o out $type in
536 atf_check -o file:exp cat out
539 atf_test_case delete_btree
542 atf_set "descr" "Checks removing records in btree database"
549 atf_test_case delete_recno
552 atf_set "descr" "Checks removing records in recno database"
561 TMPDIR="$(pwd)/db_dir"; export TMPDIR
566 for (i = 1; i <= 10; ++i) {
567 printf("p\nkkey1\nD/bin/sh\n");
568 printf("p\nkkey2\nD/bin/csh\n");
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);
574 printf("e\t%d of 10 \n", i);
575 printf("r\nkkey1\nr\nkkey2\n");
582 atf_test_case repeated_btree
583 repeated_btree_head()
586 "Checks btree database with repeated small keys and" \
587 "big data pairs. Makes sure that overflow pages are reused"
589 repeated_btree_body()
594 atf_test_case repeated_hash
598 "Checks hash database with repeated small keys and" \
599 "big data pairs. Makes sure that overflow pages are reused"
606 atf_test_case duplicate_btree
607 duplicate_btree_head()
609 atf_set "descr" "Checks btree database with duplicate keys"
611 duplicate_btree_body()
613 TMPDIR="$(pwd)/db_dir"; export TMPDIR
618 for (i = 1; i <= 543; ++i)
619 printf("%05d: input key %d: %s\n", i, i, $0);
626 printf("p\nkduplicatekey\nd%s\n", $0);
628 printf("p\nkunique%dkey\nd%s\n", i, $0);
634 atf_check -o file:exp -x "$(prog) -iflags=1 btree in | sort"
639 TMPDIR="$(pwd)/db_dir"; export TMPDIR
646 for (i = 1; i <= 20; ++i)
647 printf("%05d: input key %d: %s\n", i, i, $0);
651 # Test that R_CURSOR doesn't succeed before cursor initialized
656 printf("p\nk%d\nd%s\n", ++i, $0);
659 printf("fR_CURSOR\nr\n");
660 printf("eR_CURSOR SHOULD HAVE FAILED\n");
663 atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
664 atf_check -s ne:0 test -s out
670 printf("p\nk%d\nd%s\n", ++i, $0);
673 printf("fR_CURSOR\np\nk1\ndsome data\n");
674 printf("eR_CURSOR SHOULD HAVE FAILED\n");
677 atf_check -o ignore -e ignore -s ne:0 "$(prog)" -o out $type in
678 atf_check -s ne:0 test -s out
681 atf_test_case cursor_flags_btree
682 cursor_flags_btree_head()
685 "Checks use of cursor flags without initialization in btree database"
687 cursor_flags_btree_body()
692 atf_test_case cursor_flags_recno
693 cursor_flags_recno_head()
696 "Checks use of cursor flags without initialization in recno database"
698 cursor_flags_recno_body()
703 atf_test_case reverse_order_recno
704 reverse_order_recno_head()
706 atf_set "descr" "Checks reverse order inserts in recno database"
708 reverse_order_recno_body()
710 TMPDIR="$(pwd)/db_dir"; export TMPDIR
715 for (i = 1; i <= 779; ++i)
716 printf("%05d: input key %d: %s\n", i, i, $0);
724 printf("p\nk1\nd%s\n", $0);
725 printf("%s\n", "fR_IBEFORE");
727 printf("p\nk1\nd%s\n", $0);
733 atf_check -o file:exp "$(prog)" recno in
736 atf_test_case small_page_btree
737 small_page_btree_head()
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."
746 atf_set "require.files" /usr/share/dict/words
749 small_page_btree_body()
751 TMPDIR="$(pwd)/db_dir"; export TMPDIR
754 mdata=abcdefghijklmnopqrstuvwxy
756 awk '{ for (i = 1; i < 20001; ++i) print $0 }' >exp
758 for i in `sed 20000q $(dict) | rev`; do
766 atf_check -o file:exp "$(prog)" -i psize=512 btree in
771 TMPDIR="$(pwd)/db_dir"; export TMPDIR
777 for order in 1234 4321; do
778 for i in `sed 50q $(dict)`; do
786 atf_check -o file:exp "$(prog)" -ilorder=$order -f byte.file $type in
788 for i in `sed 50q $(dict)`; do
793 atf_check -o file:exp "$(prog)" -s -ilorder=$order -f byte.file $type in
797 atf_test_case byte_orders_btree
798 byte_orders_btree_head()
800 atf_set "descr" "Checks btree database using differing byte orders"
802 atf_set "require.files" /usr/share/dict/words
805 byte_orders_btree_body()
810 atf_test_case byte_orders_hash
811 byte_orders_hash_head()
813 atf_set "descr" "Checks hash database using differing byte orders"
815 byte_orders_hash_body()
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
830 atf_test_case bsize_ffactor
833 atf_set "timeout" "480"
834 atf_set "descr" "Checks hash database with various" \
835 "bucketsizes and fill factors"
837 atf_set "require.files" /usr/share/dict/words
842 TMPDIR="$(pwd)/db_dir"; export TMPDIR
847 for (i = 1; i <= 10000; ++i) {
849 s = substr($0, 1, i % 34);
864 s = substr(ds, 1, i % 34);
867 printf("p\nk%s\nd%s\n", $0, s);
873 printf("g\nk%s\n", $0);
876 h_bsize_ffactor 256 11
877 h_bsize_ffactor 256 14
878 h_bsize_ffactor 256 21
880 h_bsize_ffactor 512 21
881 h_bsize_ffactor 512 28
882 h_bsize_ffactor 512 43
884 h_bsize_ffactor 1024 43
885 h_bsize_ffactor 1024 57
886 h_bsize_ffactor 1024 85
888 h_bsize_ffactor 2048 85
889 h_bsize_ffactor 2048 114
890 h_bsize_ffactor 2048 171
892 h_bsize_ffactor 4096 171
893 h_bsize_ffactor 4096 228
894 h_bsize_ffactor 4096 341
896 h_bsize_ffactor 8192 341
897 h_bsize_ffactor 8192 455
898 h_bsize_ffactor 8192 683
901 # FIXME: what does it test?
902 atf_test_case four_char_hash
903 four_char_hash_head()
906 "Checks hash database with 4 char key and" \
907 "value insert on a 65536 bucket size"
909 four_char_hash_body()
911 TMPDIR="$(pwd)/db_dir"; export TMPDIR
924 atf_check "$(prog)" -i bsize=32768 hash in
927 atf_check "$(prog)" -i bsize=65536 hash in
933 atf_init_test_cases()
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