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