1#!/bin/sh - 2# 3# Copyright (c) 1992 The Regents of the University of California. 4# All rights reserved. 5# 6# %sccs.include.redist.sh% 7# 8# @(#)run.test 5.16 (Berkeley) 05/01/93 9# 10 11# db regression tests 12 13main() 14{ 15 DICT=/usr/share/dict/words 16 PROG=obj/dbtest 17 TMP1=t1 18 TMP2=t2 19 TMP3=t3 20 21 test1 22 test2 23 test3 24 test4 25 test5 26 test6 27 test7 28 test8 29 test9 30 test10 31 test11 32 test12 33 test13 34 test20 35 rm -f $TMP1 $TMP2 $TMP3 36 exit 0 37} 38 39# Take the first hundred entries in the dictionary, and make them 40# be key/data pairs. 41test1() 42{ 43 printf "Test 1: btree, hash: small key, small data pairs\n" 44 sed 200q $DICT > $TMP1 45 for type in btree hash; do 46 rm -f $TMP2 $TMP3 47 for i in `sed 200q $DICT`; do 48 printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i 49 done > $TMP2 50 $PROG -o $TMP3 $type $TMP2 51 if (cmp -s $TMP1 $TMP3) ; then : 52 else 53 printf "test1: type %s: failed\n" $type 54 exit 1 55 fi 56 done 57 printf "Test 1: recno: small key, small data pairs\n" 58 rm -f $TMP2 $TMP3 59 sed 200q $DICT | 60 awk '{ 61 ++i; 62 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); 63 }' > $TMP2 64 $PROG -o $TMP3 recno $TMP2 65 if (cmp -s $TMP1 $TMP3) ; then : 66 else 67 printf "test1: type recno: failed\n" 68 exit 1 69 fi 70} 71 72# Take the first 200 entries in the dictionary, and give them 73# each a medium size data entry. 74test2() 75{ 76 printf "Test 2: btree, hash: small key, medium data pairs\n" 77 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz 78 echo $mdata | 79 awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 80 for type in hash btree; do 81 rm -f $TMP2 $TMP3 82 for i in `sed 200q $DICT`; do 83 printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i 84 done > $TMP2 85 $PROG -o $TMP3 $type $TMP2 86 if (cmp -s $TMP1 $TMP3) ; then : 87 else 88 printf "test2: type %s: failed\n" $type 89 exit 1 90 fi 91 done 92 printf "Test 2: recno: small key, medium data pairs\n" 93 rm -f $TMP2 $TMP3 94 echo $mdata | 95 awk '{ for (i = 1; i < 201; ++i) 96 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); 97 }' > $TMP2 98 $PROG -o $TMP3 recno $TMP2 99 if (cmp -s $TMP1 $TMP3) ; then : 100 else 101 printf "test2: type recno: failed\n" 102 exit 1 103 fi 104} 105 106# Insert the programs in /bin with their paths as their keys. 107test3() 108{ 109 printf "Test 3: btree, hash: small key, big data pairs\n" 110 rm -f $TMP1 111 (find /bin -type f -print | xargs cat) > $TMP1 112 for type in hash btree; do 113 rm -f $TMP2 $TMP3 114 for i in `find /bin -type f -print`; do 115 printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i 116 done > $TMP2 117 $PROG -o $TMP3 $type $TMP2 118 if (cmp -s $TMP1 $TMP3) ; then : 119 else 120 printf "test3: type %s: failed\n" $type 121 exit 1 122 fi 123 done 124 printf "Test 3: recno: big data pairs\n" 125 rm -f $TMP2 $TMP3 126 find /bin -type f -print | 127 awk '{ 128 ++i; 129 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); 130 }' > $TMP2 131 $PROG -o $TMP3 recno $TMP2 132 if (cmp -s $TMP1 $TMP3) ; then : 133 else 134 printf "test3: type recno: failed\n" 135 exit 1 136 fi 137} 138 139# Do random recno entries. 140test4() 141{ 142 printf "Test 4: recno: random entries\n" 143 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 144 awk '{ 145 for (i = 37; i <= 37 + 88 * 17; i += 17) 146 printf("input key %d: %.*s\n", i, i % 41, $0); 147 for (i = 1; i <= 15; ++i) 148 printf("input key %d: %.*s\n", i, i % 41, $0); 149 for (i = 19234; i <= 19234 + 61 * 27; i += 27) 150 printf("input key %d: %.*s\n", i, i % 41, $0); 151 exit 152 }' > $TMP1 153 rm -f TMP2 $TMP3 154 cat $TMP1 | 155 awk 'BEGIN { 156 i = 37; 157 incr = 17; 158 } 159 { 160 printf("p\nk%d\nd%s\n", i, $0); 161 if (i == 19234 + 61 * 27) 162 exit; 163 if (i == 37 + 88 * 17) { 164 i = 1; 165 incr = 1; 166 } else if (i == 15) { 167 i = 19234; 168 incr = 27; 169 } else 170 i += incr; 171 } 172 END { 173 for (i = 37; i <= 37 + 88 * 17; i += 17) 174 printf("g\nk%d\n", i); 175 for (i = 1; i <= 15; ++i) 176 printf("g\nk%d\n", i); 177 for (i = 19234; i <= 19234 + 61 * 27; i += 27) 178 printf("g\nk%d\n", i); 179 }' > $TMP2 180 $PROG -o $TMP3 recno $TMP2 181 if (cmp -s $TMP1 $TMP3) ; then : 182 else 183 printf "test4: type recno: failed\n" 184 exit 1 185 fi 186} 187 188# Do reverse order recno entries. 189test5() 190{ 191 printf "Test 5: recno: reverse order entries\n" 192 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 193 awk ' { 194 for (i = 1500; i; --i) 195 printf("input key %d: %.*s\n", i, i % 34, $0); 196 exit; 197 }' > $TMP1 198 rm -f TMP2 $TMP3 199 cat $TMP1 | 200 awk 'BEGIN { 201 i = 1500; 202 } 203 { 204 printf("p\nk%d\nd%s\n", i, $0); 205 --i; 206 } 207 END { 208 for (i = 1500; i; --i) 209 printf("g\nk%d\n", i); 210 }' > $TMP2 211 $PROG -o $TMP3 recno $TMP2 212 if (cmp -s $TMP1 $TMP3) ; then : 213 else 214 printf "test5: type recno: failed\n" 215 exit 1 216 fi 217} 218 219# Do alternating order recno entries. 220test6() 221{ 222 printf "Test 6: recno: alternating order entries\n" 223 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 224 awk ' { 225 for (i = 1; i < 1200; i += 2) 226 printf("input key %d: %.*s\n", i, i % 34, $0); 227 for (i = 2; i < 1200; i += 2) 228 printf("input key %d: %.*s\n", i, i % 34, $0); 229 exit; 230 }' > $TMP1 231 rm -f TMP2 $TMP3 232 cat $TMP1 | 233 awk 'BEGIN { 234 i = 1; 235 even = 0; 236 } 237 { 238 printf("p\nk%d\nd%s\n", i, $0); 239 i += 2; 240 if (i >= 1200) { 241 if (even == 1) 242 exit; 243 even = 1; 244 i = 2; 245 } 246 } 247 END { 248 for (i = 1; i < 1200; ++i) 249 printf("g\nk%d\n", i); 250 }' > $TMP2 251 $PROG -o $TMP3 recno $TMP2 252 sort -o $TMP1 $TMP1 253 sort -o $TMP3 $TMP3 254 if (cmp -s $TMP1 $TMP3) ; then : 255 else 256 printf "test6: type recno: failed\n" 257 exit 1 258 fi 259} 260 261# Delete cursor record 262test7() 263{ 264 printf "Test 7: btree, recno: delete cursor record\n" 265 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 266 awk '{ 267 for (i = 1; i <= 120; ++i) 268 printf("%05d: input key %d: %s\n", i, i, $0); 269 printf("%05d: input key %d: %s\n", 120, 120, $0); 270 printf("get failed, no such key\n"); 271 printf("%05d: input key %d: %s\n", 1, 1, $0); 272 printf("%05d: input key %d: %s\n", 2, 2, $0); 273 exit; 274 }' > $TMP1 275 rm -f TMP2 $TMP3 276 277 for type in btree recno; do 278 cat $TMP1 | 279 awk '{ 280 if (i == 120) 281 exit; 282 printf("p\nk%d\nd%s\n", ++i, $0); 283 } 284 END { 285 printf("fR_NEXT\n"); 286 for (i = 1; i <= 120; ++i) 287 printf("s\n"); 288 printf("fR_CURSOR\ns\nk120\n"); 289 printf("r\nk120\n"); 290 printf("fR_NEXT\ns\n"); 291 printf("fR_CURSOR\ns\nk1\n"); 292 printf("r\nk1\n"); 293 printf("fR_FIRST\ns\n"); 294 }' > $TMP2 295 $PROG -o $TMP3 recno $TMP2 296 if (cmp -s $TMP1 $TMP3) ; then : 297 else 298 printf "test7: type $type: failed\n" 299 exit 1 300 fi 301 done 302} 303 304# Make sure that overflow pages are reused. 305test8() 306{ 307 printf "Test 8: btree, hash: repeated small key, big data pairs\n" 308 rm -f $TMP1 309 awk 'BEGIN { 310 for (i = 1; i <= 10; ++i) { 311 printf("p\nkkey1\nD/bin/sh\n"); 312 printf("p\nkkey2\nD/bin/csh\n"); 313 if (i % 8 == 0) { 314 printf("c\nkkey2\nD/bin/csh\n"); 315 printf("c\nkkey1\nD/bin/sh\n"); 316 printf("e\t%d of 10 (comparison)\r\n", i); 317 } else 318 printf("e\t%d of 10 \r\n", i); 319 printf("r\nkkey1\nr\nkkey2\n"); 320 } 321 printf("e\n"); 322 printf("eend of test8 run\n"); 323 }' > $TMP1 324 $PROG btree $TMP1 325 $PROG hash $TMP1 326 # No explicit test for success. 327} 328 329# Test btree duplicate keys 330test9() 331{ 332 printf "Test 9: btree: duplicate keys\n" 333 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 334 awk '{ 335 for (i = 1; i <= 543; ++i) 336 printf("%05d: input key %d: %s\n", i, i, $0); 337 exit; 338 }' > $TMP1 339 rm -f TMP2 $TMP3 340 341 for type in btree; do 342 cat $TMP1 | 343 awk '{ 344 if (i++ % 2) 345 printf("p\nkduplicatekey\nd%s\n", $0); 346 else 347 printf("p\nkunique%dkey\nd%s\n", i, $0); 348 } 349 END { 350 printf("o\n"); 351 }' > $TMP2 352 $PROG -iflags=1 -o $TMP3 $type $TMP2 353 sort -o $TMP3 $TMP3 354 if (cmp -s $TMP1 $TMP3) ; then : 355 else 356 printf "test9: type $type: failed\n" 357 exit 1 358 fi 359 done 360} 361 362# Test use of cursor flags without initialization 363test10() 364{ 365 printf "Test 10: btree, recno: test cursor flag use\n" 366 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 367 awk '{ 368 for (i = 1; i <= 20; ++i) 369 printf("%05d: input key %d: %s\n", i, i, $0); 370 exit; 371 }' > $TMP1 372 rm -f TMP2 $TMP3 373 374 # Test that R_CURSOR doesn't succeed before cursor initialized 375 for type in btree recno; do 376 cat $TMP1 | 377 awk '{ 378 if (i == 10) 379 exit; 380 printf("p\nk%d\nd%s\n", ++i, $0); 381 } 382 END { 383 printf("fR_CURSOR\nr\nk1\n"); 384 printf("eR_CURSOR SHOULD HAVE FAILED\n"); 385 }' > $TMP2 386 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 387 if [ -s $TMP3 ] ; then 388 printf "Test 10: delete: R_CURSOR SHOULD HAVE FAILED\n" 389 exit 1 390 fi 391 done 392 for type in btree recno; do 393 cat $TMP1 | 394 awk '{ 395 if (i == 10) 396 exit; 397 printf("p\nk%d\nd%s\n", ++i, $0); 398 } 399 END { 400 printf("fR_CURSOR\np\nk1\ndsome data\n"); 401 printf("eR_CURSOR SHOULD HAVE FAILED\n"); 402 }' > $TMP2 403 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 404 if [ -s $TMP3 ] ; then 405 printf "Test 10: put: R_CURSOR SHOULD HAVE FAILED\n" 406 exit 1 407 fi 408 done 409} 410 411# Test insert in reverse order. 412test11() 413{ 414 printf "Test 11: recno: reverse order insert\n" 415 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | 416 awk '{ 417 for (i = 1; i <= 779; ++i) 418 printf("%05d: input key %d: %s\n", i, i, $0); 419 exit; 420 }' > $TMP1 421 rm -f TMP2 $TMP3 422 423 for type in recno; do 424 cat $TMP1 | 425 awk '{ 426 if (i == 0) { 427 i = 1; 428 printf("p\nk1\nd%s\n", $0); 429 printf("%s\n", "fR_IBEFORE"); 430 } else 431 printf("p\nk1\nd%s\n", $0); 432 } 433 END { 434 printf("or\n"); 435 }' > $TMP2 436 $PROG -o $TMP3 $type $TMP2 437 if (cmp -s $TMP1 $TMP3) ; then : 438 else 439 printf "test11: type $type: failed\n" 440 exit 1 441 fi 442 done 443} 444 445# Take the first 20000 entries in the dictionary, reverse them, and give 446# them each a small size data entry. Use a small page size to make sure 447# the btree split code gets hammered. 448test12() 449{ 450 printf "Test 12: btree: lots of keys, small page size\n" 451 mdata=abcdefghijklmnopqrstuvwxy 452 echo $mdata | 453 awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1 454 for type in btree; do 455 rm -f $TMP2 $TMP3 456 for i in `sed 20000q $DICT | rev`; do 457 printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i 458 done > $TMP2 459 $PROG -i psize=512 -o $TMP3 $type $TMP2 460 if (cmp -s $TMP1 $TMP3) ; then : 461 else 462 printf "test12: type %s: failed\n" $type 463 exit 1 464 fi 465 done 466} 467 468# Test different byte orders. 469test13() 470{ 471 printf "Test 13: btree, hash: differing byte orders\n" 472 sed 50q $DICT > $TMP1 473 for order in 1234 4321; do 474 for type in btree hash; do 475 rm -f byte.file $TMP2 $TMP3 476 for i in `sed 50q $DICT`; do 477 printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i 478 done > $TMP2 479 $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 480 if (cmp -s $TMP1 $TMP3) ; then : 481 else 482 printf "test13: %s/%s put failed\n" $type $order 483 exit 1 484 fi 485 for i in `sed 50q $DICT`; do 486 printf "g\nk%s\n" $i 487 done > $TMP2 488 $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 489 if (cmp -s $TMP1 $TMP3) ; then : 490 else 491 printf "test13: %s/%s get failed\n" $type $order 492 exit 1 493 fi 494 done 495 done 496 rm -f byte.file 497} 498 499# Try a variety of bucketsizes and fill factors for hashing 500test20() 501{ 502 printf\ 503 "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n" 504 awk 'BEGIN { 505 for (i = 1; i <= 10000; ++i) 506 printf("%.*s\n", i % 34, 507 "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 508 }' > $TMP1 509 sed 10000q $DICT | 510 awk '{ 511 ++i; 512 printf("p\nk%s\nd%.*s\n", $0, i % 34, 513 "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg"); 514 }' > $TMP2 515 sed 10000q $DICT | 516 awk '{ 517 ++i; 518 printf("g\nk%s\n", $0); 519 }' >> $TMP2 520 bsize=256 521 for ffactor in 11 14 21; do 522 printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor 523 $PROG -o$TMP3 \ 524 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 525 hash $TMP2 526 if (cmp -s $TMP1 $TMP3) ; then : 527 else 528 printf "test20: type hash:\ 529bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 530 exit 1 531 fi 532 done 533 bsize=512 534 for ffactor in 21 28 43; do 535 printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor 536 $PROG -o$TMP3 \ 537 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 538 hash $TMP2 539 if (cmp -s $TMP1 $TMP3) ; then : 540 else 541 printf "test20: type hash:\ 542bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 543 exit 1 544 fi 545 done 546 bsize=1024 547 for ffactor in 43 57 85; do 548 printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor 549 $PROG -o$TMP3 \ 550 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 551 hash $TMP2 552 if (cmp -s $TMP1 $TMP3) ; then : 553 else 554 printf "test20: type hash:\ 555bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 556 exit 1 557 fi 558 done 559 bsize=2048 560 for ffactor in 85 114 171; do 561 printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor 562 $PROG -o$TMP3 \ 563 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 564 hash $TMP2 565 if (cmp -s $TMP1 $TMP3) ; then : 566 else 567 printf "test20: type hash:\ 568bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 569 exit 1 570 fi 571 done 572 bsize=4096 573 for ffactor in 171 228 341; do 574 printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor 575 $PROG -o$TMP3 \ 576 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 577 hash $TMP2 578 if (cmp -s $TMP1 $TMP3) ; then : 579 else 580 printf "test20: type hash:\ 581bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 582 exit 1 583 fi 584 done 585 bsize=8192 586 for ffactor in 341 455 683; do 587 printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor 588 $PROG -o$TMP3 \ 589 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\ 590 hash $TMP2 591 if (cmp -s $TMP1 $TMP3) ; then : 592 else 593 printf "test20: type hash:\ 594bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n" 595 exit 1 596 fi 597 done 598} 599 600main 601