added test target

progress
Avril 4 years ago
parent d5dd86ed24
commit 0d45fa7b94
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -42,6 +42,9 @@ release: | dirs $(PROJECT)-release
.PHONY: debug .PHONY: debug
debug: | dirs $(PROJECT)-debug debug: | dirs $(PROJECT)-debug
.PHONY: test
test: test-all
# Targets # Targets
dirs: dirs:
@ -71,3 +74,7 @@ $(PROJECT)-debug: $(OBJ)
clean: clean:
rm -rf obj rm -rf obj
rm -f $(PROJECT)-{release,debug} rm -f $(PROJECT)-{release,debug}
test-all:
@./test.sh ./$(PROJECT)-debug ./$(PROJECT)-release

@ -0,0 +1,54 @@
#!/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."
Loading…
Cancel
Save