From 0d45fa7b94bf8aa2d39791089af728708880482d Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 27 Nov 2020 15:56:39 +0000 Subject: [PATCH] added test target --- Makefile | 7 +++++++ test.sh | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 test.sh diff --git a/Makefile b/Makefile index 5a65e66..4edb20a 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,9 @@ release: | dirs $(PROJECT)-release .PHONY: debug debug: | dirs $(PROJECT)-debug +.PHONY: test +test: test-all + # Targets dirs: @@ -71,3 +74,7 @@ $(PROJECT)-debug: $(OBJ) clean: rm -rf obj rm -f $(PROJECT)-{release,debug} + +test-all: + @./test.sh ./$(PROJECT)-debug ./$(PROJECT)-release + diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..39b5a73 --- /dev/null +++ b/test.sh @@ -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."