#!/bin/sh - # # Copyright (c) 1992 The Regents of the University of California. # All rights reserved. # # %sccs.include.redist.sh% # # @(#)run.test 5.3 (Berkeley) 08/27/92 # # db regression tests main() { DICT=/usr/share/dict/words PROG=obj/dbtest TMP1=t1 TMP2=t2 TMP3=t3 test1 test2 test3 test4 test5 test6 test7 rm -f $TMP1 $TMP2 $TMP3 } # Take the first hundred entries in the dictionary, and make them # be key/data pairs. test1() { printf "Test 1: btree, hash: small key, small data pairs\n" for i in `sed 200q $DICT`; do printf "%s\n" $i done > $TMP1 for type in btree hash; do rm -f $TMP2 $TMP3 for i in `sed 200q $DICT`; do printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i done > $TMP2 $PROG -o $TMP3 $type $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test1: type %s: failed\n" $type exit 1 fi done printf "Test 1: recno: small key, small data pairs\n" rm -f $TMP2 $TMP3 sed 200q $DICT | awk '{ ++i; printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test1: type recno: failed\n" exit 1 fi } # Take the first hundred entries in the dictionary, and give them # each a medium size data entry. test2() { printf "Test 2: btree, hash: small key, medium data pairs\n" mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz echo $mdata | awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1 for type in hash btree; do rm -f $TMP2 $TMP3 for i in `sed 200q $DICT`; do printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i done > $TMP2 $PROG -o $TMP3 $type $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test2: type %s: failed\n" $type exit 1 fi done printf "Test 2: recno: small key, medium data pairs\n" rm -f $TMP2 $TMP3 echo $mdata | awk '{ for (i = 1; i < 201; ++i) printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test2: type recno: failed\n" exit 1 fi } # Insert the programs in /bin with their paths as their keys. test3() { printf "Test 3: btree, hash: small key, big data pairs\n" rm -f $TMP1 (find /bin -type f -print | xargs cat) > $TMP1 for type in hash btree; do rm -f $TMP2 $TMP3 for i in `find /bin -type f -print`; do printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i done > $TMP2 $PROG -o $TMP3 $type $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test2: type %s: failed\n" $type exit 1 fi done printf "Test 3: recno: big data pairs\n" rm -f $TMP2 $TMP3 find /bin -type f -print | awk '{ ++i; printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test3: type recno: failed\n" exit 1 fi } # Do random recno entries. test4() { printf "Test 4: recno: random entries\n" echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | awk '{ for (i = 37; i <= 37 + 88 * 17; i += 17) printf("input key %d: %.*s\n", i, i % 41, $0); for (i = 1; i <= 15; ++i) printf("input key %d: %.*s\n", i, i % 41, $0); for (i = 19234; i <= 19234 + 61 * 27; i += 27) printf("input key %d: %.*s\n", i, i % 41, $0); exit }' > $TMP1 rm -f TMP2 $TMP3 cat $TMP1 | awk 'BEGIN { i = 37; incr = 17; } { printf("p\nk%d\nd%s\n", i, $0); if (i == 19234 + 61 * 27) exit; if (i == 37 + 88 * 17) { i = 1; incr = 1; } else if (i == 15) { i = 19234; incr = 27; } else i += incr; } END { for (i = 37; i <= 37 + 88 * 17; i += 17) printf("g\nk%d\n", i); for (i = 1; i <= 15; ++i) printf("g\nk%d\n", i); for (i = 19234; i <= 19234 + 61 * 27; i += 27) printf("g\nk%d\n", i); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test4: type recno: failed\n" exit 1 fi } # Do reverse order recno entries. test5() { printf "Test 5: recno: reverse order entries\n" echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | awk ' { for (i = 1500; i; --i) printf("input key %d: %.*s\n", i, i % 34, $0); exit; }' > $TMP1 rm -f TMP2 $TMP3 cat $TMP1 | awk 'BEGIN { i = 1500; } { printf("p\nk%d\nd%s\n", i, $0); --i; } END { for (i = 1500; i; --i) printf("g\nk%d\n", i); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test5: type recno: failed\n" exit 1 fi } # Do alternating order recno entries. test6() { printf "Test 6: recno: alternating order entries\n" echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | awk ' { for (i = 1; i < 1200; i += 2) printf("input key %d: %.*s\n", i, i % 34, $0); for (i = 2; i < 1200; i += 2) printf("input key %d: %.*s\n", i, i % 34, $0); exit; }' > $TMP1 rm -f TMP2 $TMP3 cat $TMP1 | awk 'BEGIN { i = 1; even = 0; } { printf("p\nk%d\nd%s\n", i, $0); i += 2; if (i >= 1200) { if (even == 1) exit; even = 1; i = 2; } } END { for (i = 1; i < 1200; ++i) printf("g\nk%d\n", i); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 sort -o $TMP1 $TMP1 sort -o $TMP3 $TMP3 if (cmp -s $TMP1 $TMP3) ; then else printf "test6: type recno: failed\n" exit 1 fi } # Delete cursor record test7() { printf "Test 7: btree, recno: delete cursor record\n" echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" | awk '{ for (i = 1; i <= 120; ++i) printf("%05d: input key %d: %s\n", i, i, $0); printf("%05d: input key %d: %s\n", 120, 120, $0); printf("get failed, no such key\n"); printf("%05d: input key %d: %s\n", 1, 1, $0); printf("%05d: input key %d: %s\n", 2, 2, $0); exit; }' > $TMP1 rm -f TMP2 $TMP3 for type in btree recno; do cat $TMP1 | awk '{ if (i == 120) exit; printf("p\nk%d\nd%s\n", ++i, $0); } END { printf("fR_NEXT\n"); for (i = 1; i <= 120; ++i) printf("s\n"); printf("fR_CURSOR\ns\nk120\n"); printf("r\nk120\n"); printf("fR_NEXT\ns\n"); printf("fR_CURSOR\ns\nk1\n"); printf("r\nk1\n"); printf("fR_FIRST\ns\n"); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 if (cmp -s $TMP1 $TMP3) ; then else printf "test7: type $type: failed\n" exit 1 fi done } main