casea 1.32 KB
#!/bin/bash

TESTFILE=testfile.$$

./mkcart > $TESTFILE
. ./testlib.sh

export BBC_BAD_BLKS=
export BBC_READ_DBE_BLKS=
export BBC_WRITE_ERR_BLKS=

echo "Test (10) Replace existing file $1 with bad block"

##### Add file first (already tested in case 1)
st=$(($RANDOM % 256))
dd if=common/rdata of=tmp.$$ bs=1 count=16384 skip=$st >$OUTPUT 2>&1
emsh << END_OF_FILE >$OUTPUT 2>&1
u ./$TESTFILE
B
F
A
P$2 tmp.$$
END_OF_FILE

cp ./$TESTFILE bkup.$$

export BBC_BAD_BLKS=4078
st=$(($RANDOM % 256))
dd if=common/rdata of=tmp2.$$ bs=1 count=16384 skip=$st >$OUTPUT 2>&1
emsh << END_OF_FILE >outa.$$ 2>erra.$$
u ./$TESTFILE
B
A
P$2 tmp2.$$
G$2 tmp1.$$
END_OF_FILE

check_log a out
check_log a err

if ! cmp tmp2.$$ tmp1.$$; then
   echo "Failed (10): File not replaced"
   exit
fi
sz=4077
check_unchange bkup.$$ ./$TESTFILE 0 $sz "input" "result"
check_unchange bkup.$$ ./$TESTFILE $(($sz + 1)) 1 "input" "result"

sz=$((4077 * 16400))
dd if=./$TESTFILE of=tmp.$$ skip=$sz bs=1 count=16384  >$OUTPUT 2>&1
if ! cmp tmp.$$ tmp2.$$; then
    echo "Failed (10): File not write at block 4077"
    exit
fi

gzip  -d -c Golden/$TESTID/fata.gz > out.$$
sz=$((4080 * 16400))
dd if=./$TESTFILE of=tmp.$$ skip=$sz bs=1 >$OUTPUT 2>&1
if ! cmp tmp.$$ out.$$; then
    echo "Failed fat does not match"
    exit
fi
rm -rf  ./$TESTFILE erra.$$ out.$$ tmp*.$$  bkup.$$

exit 0