1 # $NetBSD: t_db.sh,v 1.5 2015/02/26 13:00:26 martin 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"
44 SEVEN_SEVEN
="abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg|abcdefg"
46 atf_test_case small_btree
50 "Checks btree database using small keys and small data" \
51 "pairs: takes the first hundred entries in the dictionary," \
52 "and makes them be key/data pairs."
56 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
61 for i
in `sed 200q $(dict)`; do
69 atf_check
-o file:exp
"$(prog)" btree
in
72 atf_test_case small_hash
76 "Checks hash database using small keys and small data" \
77 "pairs: takes the first hundred entries in the dictionary," \
78 "and makes them be key/data pairs."
82 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
87 for i
in `sed 200q $(dict)`; do
95 atf_check
-o file:exp
"$(prog)" hash in
98 atf_test_case small_recno
102 "Checks recno database using small keys and small data" \
103 "pairs: takes the first hundred entries in the dictionary," \
104 "and makes them be key/data pairs."
108 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
111 sed 200q $
(dict
) >exp
116 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
119 atf_check
-o file:exp
"$(prog)" recno
in
122 atf_test_case medium_btree
126 "Checks btree database using small keys and medium" \
127 "data pairs: takes the first 200 entries in the" \
128 "dictionary, and gives them each a medium size data entry."
132 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
135 mdata
=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
137 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
139 for i
in $
(sed 200q $
(dict
)); do
147 atf_check
-o file:exp
"$(prog)" btree
in
150 atf_test_case medium_hash
154 "Checks hash database using small keys and medium" \
155 "data pairs: takes the first 200 entries in the" \
156 "dictionary, and gives them each a medium size data entry."
160 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
163 mdata
=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
165 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
167 for i
in $
(sed 200q $
(dict
)); do
175 atf_check
-o file:exp
"$(prog)" hash in
178 atf_test_case medium_recno
182 "Checks recno database using small keys and medium" \
183 "data pairs: takes the first 200 entries in the" \
184 "dictionary, and gives them each a medium size data entry."
188 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
191 mdata
=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
193 awk '{ for (i = 1; i < 201; ++i) print $0 }' >exp
196 awk '{ for (i = 1; i < 201; ++i)
197 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
200 atf_check
-o file:exp
"$(prog)" recno
in
203 atf_test_case big_btree
207 "Checks btree database using small keys and big data" \
208 "pairs: inserts the programs in /bin with their paths" \
213 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
216 (find /bin
-type f
-print |
xargs cat) >exp
218 for psize
in 512 16384 65536; do
219 echo "checking page size: $psize"
221 for i
in `find /bin -type f -print`; do
229 atf_check
"$(prog)" -o out btree
in
230 cmp -s exp out || atf_fail
"test failed for page size: $psize"
234 atf_test_case big_hash
238 "Checks hash database using small keys and big data" \
239 "pairs: inserts the programs in /bin with their paths" \
244 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
247 (find /bin
-type f
-print |
xargs cat) >exp
249 for i
in `find /bin -type f -print`; do
257 atf_check
"$(prog)" -o out
hash in
258 cmp -s exp out || atf_fail
"test failed"
261 atf_test_case big_recno
265 "Checks recno database using small keys and big data" \
266 "pairs: inserts the programs in /bin with their paths" \
271 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
274 (find /bin
-type f
-print |
xargs cat) >exp
276 find /bin
-type f
-print |
279 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
282 for psize
in 512 16384 65536; do
283 echo "checking page size: $psize"
285 atf_check
"$(prog)" -o out recno
in
286 cmp -s exp out || atf_fail
"test failed for page size: $psize"
290 atf_test_case random_recno
293 atf_set
"descr" "Checks recno database using random entries"
297 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
302 for (i = 37; i <= 37 + 88 * 17; i += 17) {
304 s = substr($0, 1, i % 41);
307 printf("input key %d: %s\n", i, s);
309 for (i = 1; i <= 15; ++i) {
311 s = substr($0, 1, i % 41);
314 printf("input key %d: %s\n", i, s);
316 for (i = 19234; i <= 19234 + 61 * 27; i += 27) {
318 s = substr($0, 1, i % 41);
321 printf("input key %d: %s\n", i, s);
332 printf("p\nk%d\nd%s\n", i, $0);
333 if (i == 19234 + 61 * 27)
335 if (i == 37 + 88 * 17) {
338 } else if (i == 15) {
345 for (i = 37; i <= 37 + 88 * 17; i += 17)
346 printf("g\nk%d\n", i);
347 for (i = 1; i <= 15; ++i)
348 printf("g\nk%d\n", i);
349 for (i = 19234; i <= 19234 + 61 * 27; i += 27)
350 printf("g\nk%d\n", i);
353 atf_check
-o file:exp
"$(prog)" recno
in
356 atf_test_case reverse_recno
359 atf_set
"descr" "Checks recno database using reverse order entries"
363 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
368 for (i = 1500; i; --i) {
370 s = substr($0, 1, i % 34);
373 printf("input key %d: %s\n", i, s);
383 printf("p\nk%d\nd%s\n", i, $0);
387 for (i = 1500; i; --i)
388 printf("g\nk%d\n", i);
391 atf_check
-o file:exp
"$(prog)" recno
in
394 atf_test_case alternate_recno
395 alternate_recno_head
()
397 atf_set
"descr" "Checks recno database using alternating order entries"
399 alternate_recno_body
()
401 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
406 for (i = 1; i < 1200; i += 2) {
408 s = substr($0, 1, i % 34);
411 printf("input key %d: %s\n", i, s);
413 for (i = 2; i < 1200; i += 2) {
415 s = substr($0, 1, i % 34);
418 printf("input key %d: %s\n", i, s);
429 printf("p\nk%d\nd%s\n", i, $0);
439 for (i = 1; i < 1200; ++i)
440 printf("g\nk%d\n", i);
443 atf_check
"$(prog)" -o out recno
in
448 cmp -s exp out || atf_fail
"test failed"
453 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
460 for (i = 1; i <= 120; ++i)
461 printf("%05d: input key %d: %s\n", i, i, $0);
466 printf("p\nk%d\nd%s\n", ++i, $0);
470 for (i = 1; i <= 120; ++i)
472 printf("fR_CURSOR\ns\nkXX\n");
474 printf("fR_NEXT\ns\n");
475 printf("fR_CURSOR\ns\nk1\n");
477 printf("fR_FIRST\ns\n");
480 # For btree, the records are ordered by the string representation
481 # of the key value. So sort the expected output file accordingly,
482 # and set the seek_last key to the last expected key value.
484 if [ "$type" = "btree" ] ; then
485 sed -e 's/kXX/k99/' < in > tmp
487 sort -d -k4 < exp
> tmp
491 printf("%05d: input key %d: %s\n", 99, 99, $0);
492 printf("seq failed, no such key\n");
493 printf("%05d: input key %d: %s\n", 1, 1, $0);
494 printf("%05d: input key %d: %s\n", 10, 10, $0);
498 # For recno, records are ordered by numerical key value. No sort
499 # is needed, but still need to set proper seek_last key value.
500 sed -e 's/kXX/k120/' < in > tmp
504 printf("%05d: input key %d: %s\n", 120, 120, $0);
505 printf("seq failed, no such key\n");
506 printf("%05d: input key %d: %s\n", 1, 1, $0);
507 printf("%05d: input key %d: %s\n", 2, 2, $0);
512 atf_check
"$(prog)" -o out
$type in
513 atf_check
-o file:exp
cat out
516 atf_test_case delete_btree
519 atf_set
"descr" "Checks removing records in btree database"
526 atf_test_case delete_recno
529 atf_set
"descr" "Checks removing records in recno database"
538 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
543 for (i = 1; i <= 10; ++i) {
544 printf("p\nkkey1\nD/bin/sh\n");
545 printf("p\nkkey2\nD/bin/csh\n");
547 printf("c\nkkey2\nD/bin/csh\n");
548 printf("c\nkkey1\nD/bin/sh\n");
549 printf("e\t%d of 10 (comparison)\n", i);
551 printf("e\t%d of 10 \n", i);
552 printf("r\nkkey1\nr\nkkey2\n");
559 atf_test_case repeated_btree
560 repeated_btree_head
()
563 "Checks btree database with repeated small keys and" \
564 "big data pairs. Makes sure that overflow pages are reused"
566 repeated_btree_body
()
571 atf_test_case repeated_hash
575 "Checks hash database with repeated small keys and" \
576 "big data pairs. Makes sure that overflow pages are reused"
583 atf_test_case duplicate_btree
584 duplicate_btree_head
()
586 atf_set
"descr" "Checks btree database with duplicate keys"
588 duplicate_btree_body
()
590 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
595 for (i = 1; i <= 543; ++i)
596 printf("%05d: input key %d: %s\n", i, i, $0);
603 printf("p\nkduplicatekey\nd%s\n", $0);
605 printf("p\nkunique%dkey\nd%s\n", i, $0);
611 atf_check
-o file:exp
-x "$(prog) -iflags=1 btree in | sort"
616 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
623 for (i = 1; i <= 20; ++i)
624 printf("%05d: input key %d: %s\n", i, i, $0);
628 # Test that R_CURSOR doesn't succeed before cursor initialized
633 printf("p\nk%d\nd%s\n", ++i, $0);
636 printf("fR_CURSOR\nr\n");
637 printf("eR_CURSOR SHOULD HAVE FAILED\n");
640 atf_check
-o ignore
-e ignore
-s ne
:0 "$(prog)" -o out
$type in
641 atf_check
-s ne
:0 test -s out
647 printf("p\nk%d\nd%s\n", ++i, $0);
650 printf("fR_CURSOR\np\nk1\ndsome data\n");
651 printf("eR_CURSOR SHOULD HAVE FAILED\n");
654 atf_check
-o ignore
-e ignore
-s ne
:0 "$(prog)" -o out
$type in
655 atf_check
-s ne
:0 test -s out
658 atf_test_case cursor_flags_btree
659 cursor_flags_btree_head
()
662 "Checks use of cursor flags without initialization in btree database"
664 cursor_flags_btree_body
()
669 atf_test_case cursor_flags_recno
670 cursor_flags_recno_head
()
673 "Checks use of cursor flags without initialization in recno database"
675 cursor_flags_recno_body
()
680 atf_test_case reverse_order_recno
681 reverse_order_recno_head
()
683 atf_set
"descr" "Checks reverse order inserts in recno database"
685 reverse_order_recno_body
()
687 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
692 for (i = 1; i <= 779; ++i)
693 printf("%05d: input key %d: %s\n", i, i, $0);
701 printf("p\nk1\nd%s\n", $0);
702 printf("%s\n", "fR_IBEFORE");
704 printf("p\nk1\nd%s\n", $0);
710 atf_check
-o file:exp
"$(prog)" recno
in
713 atf_test_case small_page_btree
714 small_page_btree_head
()
717 "Checks btree database with lots of keys and small page" \
718 "size: takes the first 20000 entries in the dictionary," \
719 "reverses them, and gives them each a small size data" \
720 "entry. Uses a small page size to make sure the btree" \
721 "split code gets hammered."
723 small_page_btree_body
()
725 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
728 mdata
=abcdefghijklmnopqrstuvwxy
730 awk '{ for (i = 1; i < 20001; ++i) print $0 }' >exp
732 for i
in `sed 20000q $(dict) | rev`; do
740 atf_check
-o file:exp
"$(prog)" -i psize
=512 btree
in
745 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
751 for order
in 1234 4321; do
752 for i
in `sed 50q $(dict)`; do
760 atf_check
-o file:exp
"$(prog)" -ilorder=$order -f byte.
file $type in
762 for i
in `sed 50q $(dict)`; do
767 atf_check
-o file:exp
"$(prog)" -s -ilorder=$order -f byte.
file $type in
771 atf_test_case byte_orders_btree
772 byte_orders_btree_head
()
774 atf_set
"descr" "Checks btree database using differing byte orders"
776 byte_orders_btree_body
()
781 atf_test_case byte_orders_hash
782 byte_orders_hash_head
()
784 atf_set
"descr" "Checks hash database using differing byte orders"
786 byte_orders_hash_body
()
796 echo "bucketsize $bsize, fill factor $ffactor"
797 atf_check
-o file:exp
"$(prog)" "-ibsize=$bsize,\
798 ffactor=$ffactor,nelem=25000,cachesize=65536" hash in
801 atf_test_case bsize_ffactor
804 atf_set
"timeout" "1800"
805 atf_set
"descr" "Checks hash database with various" \
806 "bucketsizes and fill factors"
810 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
815 for (i = 1; i <= 10000; ++i) {
817 s = substr($0, 1, i % 34);
832 s = substr(ds, 1, i % 34);
835 printf("p\nk%s\nd%s\n", $0, s);
841 printf("g\nk%s\n", $0);
844 h_bsize_ffactor
256 11
845 h_bsize_ffactor
256 14
846 h_bsize_ffactor
256 21
848 h_bsize_ffactor
512 21
849 h_bsize_ffactor
512 28
850 h_bsize_ffactor
512 43
852 h_bsize_ffactor
1024 43
853 h_bsize_ffactor
1024 57
854 h_bsize_ffactor
1024 85
856 h_bsize_ffactor
2048 85
857 h_bsize_ffactor
2048 114
858 h_bsize_ffactor
2048 171
860 h_bsize_ffactor
4096 171
861 h_bsize_ffactor
4096 228
862 h_bsize_ffactor
4096 341
864 h_bsize_ffactor
8192 341
865 h_bsize_ffactor
8192 455
866 h_bsize_ffactor
8192 683
869 # FIXME: what does it test?
870 atf_test_case four_char_hash
871 four_char_hash_head
()
874 "Checks hash database with 4 char key and" \
875 "value insert on a 65536 bucket size"
877 four_char_hash_body
()
879 TMPDIR
="$(pwd)/db_dir"; export TMPDIR
890 atf_check
"$(prog)" -i bsize
=65536 hash in
893 atf_init_test_cases
()
895 atf_add_test_case small_btree
896 atf_add_test_case small_hash
897 atf_add_test_case small_recno
898 atf_add_test_case medium_btree
899 atf_add_test_case medium_hash
900 atf_add_test_case medium_recno
901 atf_add_test_case big_btree
902 atf_add_test_case big_hash
903 atf_add_test_case big_recno
904 atf_add_test_case random_recno
905 atf_add_test_case reverse_recno
906 atf_add_test_case alternate_recno
907 atf_add_test_case delete_btree
908 atf_add_test_case delete_recno
909 atf_add_test_case repeated_btree
910 atf_add_test_case repeated_hash
911 atf_add_test_case duplicate_btree
912 atf_add_test_case cursor_flags_btree
913 atf_add_test_case cursor_flags_recno
914 atf_add_test_case reverse_order_recno
915 atf_add_test_case small_page_btree
916 atf_add_test_case byte_orders_btree
917 atf_add_test_case byte_orders_hash
918 atf_add_test_case bsize_ffactor
919 atf_add_test_case four_char_hash