You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
954 B
55 lines
954 B
4 years ago
|
#!/bin/bash
|
||
|
|
||
|
TFILE=/tmp/shuffle3-test-$(uuidgen)
|
||
|
TFILE2=$TFILE-cmp
|
||
|
|
||
|
FSIZE=${FSIZE:-$(( 1024 * 1024 * 10))}
|
||
|
FCNT=${FCNT:-4}
|
||
|
|
||
|
TRUE_SIZE=$(( FSIZE * FCNT))
|
||
|
|
||
|
function cleanup {
|
||
|
rm -f $TFILE $TFILE2
|
||
|
}
|
||
|
|
||
|
trap cleanup EXIT
|
||
|
|
||
|
stest() {
|
||
|
if fcmp $TFILE $TFILE2; then
|
||
|
echo ": shuffling $TRUE_SIZE bytes"
|
||
|
$1 -s $TFILE
|
||
|
if fcmp $TFILE $TFILE2; then
|
||
|
echo "Failed: Shuffle did nothing"
|
||
|
exit 1
|
||
|
else
|
||
|
echo ": unshuffling $TRUE_SIZE bytes"
|
||
|
$1 -u $TFILE
|
||
|
if fcmp $TFILE $TFILE2; then
|
||
|
echo "OK"
|
||
|
else
|
||
|
echo "Failed: Unshuffle didn't reproduce original file"
|
||
|
exit 1
|
||
|
fi
|
||
|
fi
|
||
|
else
|
||
|
echo "Invalid init: Files weren't identical"
|
||
|
exit -1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
echo ">>> Initialising"
|
||
|
dd if=/dev/urandom of=$TFILE bs=$FSIZE count=$FCNT >> /dev/null 2>&1 || exit -1
|
||
|
cp $TFILE $TFILE2 || exit -1
|
||
|
|
||
|
if [[ -f "$1" ]]; then
|
||
|
echo ">>> Testing $1"
|
||
|
stest "$1" || exit 1
|
||
|
fi
|
||
|
|
||
|
if [[ -f "$2" ]]; then
|
||
|
echo ">>> Testing $2"
|
||
|
stest "$2" || exit 2
|
||
|
fi
|
||
|
|
||
|
echo "Passed."
|