From b086ddf599eda5676ec5674c174cc9eaedf2e2de Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 23 Jul 2023 14:54:45 +0100 Subject: [PATCH] Rewrote most of run-test, and gave variables clearer names --- autoconf/scripts/run-test.sh | 168 ++++++++++++++++++++++++----------- tests/000-cat | 11 ++- tests/001-interval | 4 +- tests/002-rate | 2 +- tests/003-progress | 4 +- tests/004-timer | 4 +- tests/005-eta | 4 +- tests/006-fineta | 4 +- tests/007-ratecount | 4 +- tests/008-bytes | 4 +- tests/009-numeric | 8 +- tests/010-quiet | 4 +- tests/011-pipe | 16 ++-- tests/012-cksum | 12 +-- tests/013-averagerate | 4 +- tests/014-1m_boundary_1 | 6 +- tests/015-1m_boundary_2 | 8 +- tests/016-cksumpipe | 36 ++++---- tests/017-numeric-timer | 10 +-- tests/018-numeric-bytes | 8 +- tests/019-remote-format | 18 ++-- tests/020-remote-cksum | 34 +++---- tests/021-stop-at-size | 18 ++-- tests/022-large-file | 32 +++---- 24 files changed, 245 insertions(+), 178 deletions(-) diff --git a/autoconf/scripts/run-test.sh b/autoconf/scripts/run-test.sh index 580fda2..6be2052 100755 --- a/autoconf/scripts/run-test.sh +++ b/autoconf/scripts/run-test.sh @@ -1,73 +1,133 @@ #!/bin/sh # -# Run a test. Parameters are program name and source directory; if -# additional parameters are given, they are the tests to run, otherwise all -# tests are run. +# Parameters: testSubject sourcePath [testScript...] # -# Test scripts should exit 0 if the test passed. +# Run one or more test scripts. The ${testSubject} is the path of the test +# subject program, and the ${sourcePath} is the path to the top level of the +# source directory. If any ${testScript} parameters are given, they are the +# tests to run (each one being either the full path to a script, or the base +# filename of the script in the test directory). If no test scripts are +# listed, then all tests directly under "${sourcePath}/tests/" are run. # -# If a test exits with status 2, it is listed as being skipped. +# Test scripts should be written to exit 0 if the test passed, 2 if the test +# is to be skipped, or any other exit status to indicate failure. # # Anything output by a test script on stdout or stderr is captured and shown -# after the "OK"/"FAILED"/"skipped" status. +# after the "OK" / "FAILED" / "skipped" result description. +# +# The exit status of this script will be 1 if any test failed, 0 otherwise. +# A skipped test is not counted as a failure. # -PROG="$1" -SRCDIR="$2" +testSubject="$1" +sourcePath="$2" shift shift -TESTS="$*" +selectedTests="$*" -# Temporary working files +# Temporary working files, for the test scripts to use. +workFile1=$(mktemp 2>/dev/null) || workFile1="./.tmp1" +workFile2=$(mktemp 2>/dev/null) || workFile2="./.tmp2" +workFile3=$(mktemp 2>/dev/null) || workFile3="./.tmp3" +workFile4=$(mktemp 2>/dev/null) || workFile4="./.tmp4" + +# Clean up the temporary files on exit, in case we are interrupted. +trap 'rm -f "${workFile1}" "${workFile2}" "${workFile3}" "${workFile4}"' EXIT + +# Variables used by the test scripts. +export testSubject workFile1 workFile2 workFile3 workFile4 + +# If no tests were specified, list all test scripts under the source path. +test -n "${selectedTests}" || selectedTests=$(find "${sourcePath}/tests" -maxdepth 1 -type f | sort -n) + +# Initial pass to count the number of tests and find the length of the +# longest test name, to use when formatting the output. # -TMP1=$(mktemp 2>/dev/null) || TMP1=.tmp1 -TMP2=$(mktemp 2>/dev/null) || TMP2=.tmp2 -TMP3=$(mktemp 2>/dev/null) || TMP3=.tmp3 -TMP4=$(mktemp 2>/dev/null) || TMP4=.tmp4 +numberOfTests=0 +maxTestNameLength=0 +for testScript in ${selectedTests}; do + # Find the test script, make sure it exists. + test -f "${testScript}" || testScript="${sourcePath}/tests/${testScript}" + test -f "${testScript}" || testScript=$(find "${sourcePath}/tests" -maxdepth 1 -type f -name "${testScript}*" | sed -n '1p') + test -f "${testScript}" || continue -trap "rm -f ${TMP1} ${TMP2} ${TMP3} ${TMP4}" EXIT + numberOfTests=$((1+numberOfTests)) -export PROG TMP1 TMP2 TMP3 TMP4 # variables used by test scripts - -FAIL=0 - -test -n "$TESTS" || TESTS=$(ls "$SRCDIR/tests" | sort -n) - -MAXNAMESIZE=$(echo "$TESTS" | tr ' ' '\n' | sed 's,^.*/,,;s/-/ - /' | awk 'BEGIN{m=0} {n=length($0);if (n>m) m=n} END{print m}') -test -n "$MAXNAMESIZE" || MAXNAMESIZE=1 -test "$MAXNAMESIZE" -lt 10 && MAXNAMESIZE=10 -test "$MAXNAMESIZE" -gt 60 && MAXNAMESIZE=60 - -for SCRIPT in $TESTS; do - test -f "$SCRIPT" || SCRIPT="$SRCDIR/tests/$SCRIPT" - test -f "$SCRIPT" || SCRIPT=$(ls "$SRCDIR/tests/$SCRIPT"*) - test -f "$SCRIPT" || continue - - printf "%-${MAXNAMESIZE}.${MAXNAMESIZE}s " "$(echo "${SCRIPT}" | sed 's,^.*/,,;s/-/ - /')" - - TESTEXITSTATUS=0 - TESTOUTPUT="" - TESTOUTPUT=$(sh -e "$SCRIPT" 2>&1) - TESTEXITSTATUS=$? - - TESTRESULT="" - if test $TESTEXITSTATUS -eq 0; then - TESTRESULT="OK" - elif test $TESTEXITSTATUS -eq 2; then - TESTRESULT="skipped" - else - TESTRESULT="FAILED" - FAIL=1 - fi - - test -n "${TESTOUTPUT}" && TESTOUTPUT=" - ${TESTOUTPUT}" - - printf "%s%s\n" "${TESTRESULT}" "${TESTOUTPUT}" + testScriptLeaf="${testScript##*/}" + testName="$(echo "${testScriptLeaf}" | sed 's/-/ - /' | tr '_' ' ')" + testNameLength=${#testName} + test "${testNameLength}" -gt "${maxTestNameLength}" && maxTestNameLength="${testNameLength}" done -rm -f "$TMP1" "$TMP2" "$TMP3" "$TMP4" -trap "" EXIT +# Set a minimum and maximum test name length. +test "${maxTestNameLength}" -lt 10 && maxTestNameLength=10 +test "${maxTestNameLength}" -gt 60 && maxTestNameLength=60 -exit $FAIL +# Count the number of digits in the number of tests so we know how wide the +# column for the test count should be. +testCountWidth=${#numberOfTests} + +# The exit status - 0 means all tests that were run have passed, 1 means +# that at least one test failed. +overallExitStatus=0 + +# Run all of the selected test scripts, formatting the output. +# +testNumber=0 +for testScript in ${selectedTests}; do + # Find the test script, make sure it exists. + test -f "${testScript}" || testScript="${sourcePath}/tests/${testScript}" + test -f "${testScript}" || testScript=$(find "${sourcePath}/tests" -maxdepth 1 -type f -name "${testScript}*" | sed -n '1p') + test -f "${testScript}" || continue + + testNumber=$((1+testNumber)) + + testScriptLeaf="${testScript##*/}" + testName="$(echo "${testScriptLeaf}" | sed 's/-/ - /' | tr '_' ' ')" + printf "%${testCountWidth}d/%d: %-${maxTestNameLength}.${maxTestNameLength}s " "${testNumber}" "${numberOfTests}" "${testName}" + + # Run the test script, capturing the output and the exit status. + testExitStatus=0 + testOutput="" + testOutput=$(sh -e "${testScript}" 2>&1) + testExitStatus=$? + + # Work out what we're going to say about this test result. + testResultDescription="" + resultFormatCodes="" + if test ${testExitStatus} -eq 0; then + resultFormatCodes="setaf 2;bold" + testResultDescription="OK" + elif test ${testExitStatus} -eq 2; then + resultFormatCodes="setaf 3" + testResultDescription="skipped" + else + resultFormatCodes="setaf 1;bold" + testResultDescription="FAILED" + overallExitStatus=1 + fi + + # If there was any output from the test, prefix it with " - " to + # separate it from the test result description. + test -n "${testOutput}" && testOutput=" - ${testOutput}" + + # If stdout is not a terminal, don't use terminal format codes. + test -t 1 || resultFormatCodes="" + + # Show the description of the test result. + test -n "${resultFormatCodes}" && command -v tput >/dev/null 2>&1 && echo "${resultFormatCodes}" | tr ';' '\n' | tput -S 2>/dev/null + printf "%s" "${testResultDescription}" + test -n "${resultFormatCodes}" && command -v tput >/dev/null 2>&1 && tput sgr0 2>/dev/null + + # Show any output from the test, and start a new line. + printf "%s\n" "${testOutput}" +done + +# Clean up. +rm -f "${workFile1}" "${workFile2}" "${workFile3}" "${workFile4}" +trap '' EXIT + +# Exit with status 1 if any test failed outright, 0 otherwise. +exit ${overallExitStatus} # EOF diff --git a/tests/000-cat b/tests/000-cat index 068a270..eb60d63 100644 --- a/tests/000-cat +++ b/tests/000-cat @@ -2,7 +2,14 @@ # # Check that data can be just passed straight through. -VALUE=$(echo TESTING | $PROG 2>/dev/null) || exit 1 -test "$VALUE" = "TESTING" +# Dummy assignment for "shellcheck". +testSubject="${testSubject:-false}" + +inputString="TESTING" +outputString=$(printf "${inputString}" | "${testSubject}" 2>/dev/null) || { echo "unexpected failure code"; exit 1; } + +test "${inputString}" = "${outputString}" && exit 0 +echo "output did not match input" +exit 1 # EOF diff --git a/tests/001-interval b/tests/001-interval index c24fdc2..974a24e 100644 --- a/tests/001-interval +++ b/tests/001-interval @@ -2,11 +2,11 @@ # # Check that the update interval can be set. -sleep 1 | $PROG -f -i 0.1 >/dev/null 2>$TMP1 +sleep 1 | "${testSubject}" -f -i 0.1 >/dev/null 2>"${workFile1}" # There should be more than 6 lines of output. # -NUM=$(tr '\r' '\n' < $TMP1 | wc -l | tr -d ' ') +NUM=$(tr '\r' '\n' < "${workFile1}" | wc -l | tr -d ' ') test $NUM -gt 6 # EOF diff --git a/tests/002-rate b/tests/002-rate index 67ac07f..1eb4fe4 100644 --- a/tests/002-rate +++ b/tests/002-rate @@ -5,7 +5,7 @@ # Transfer 102 bytes at 100 bytes/sec. It should take at least 1 second. # START=$(date +%S) -dd if=/dev/zero bs=102 count=1 2>/dev/null | $PROG -L 100 2>/dev/null | cat >/dev/null +dd if=/dev/zero bs=102 count=1 2>/dev/null | "${testSubject}" -L 100 2>/dev/null | cat >/dev/null END=$(date +%S) test $START -ne $END diff --git a/tests/003-progress b/tests/003-progress index 2ea8d3e..fed00bf 100644 --- a/tests/003-progress +++ b/tests/003-progress @@ -3,11 +3,11 @@ # Check that the progress bar moves when data is coming in. dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| $PROG -f -p -i 0.1 -L 500 >/dev/null 2>$TMP1 +| "${testSubject}" -f -p -i 0.1 -L 500 >/dev/null 2>"${workFile1}" # There should be more than 2 different lines of output. # -NUM=$(tr '\r' '\n' < $TMP1 | sort | uniq -u | wc -l | tr -d ' ') +NUM=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -d ' ') test $NUM -gt 2 # EOF diff --git a/tests/004-timer b/tests/004-timer index e370eaa..7700a50 100644 --- a/tests/004-timer +++ b/tests/004-timer @@ -4,11 +4,11 @@ # Transfer a zero amount of data, but take 3 seconds to do it. # -(sleep 3 | $PROG -f -t >/dev/null) 2>&1 | tr '\r' '\n' > $TMP1 +(sleep 3 | "${testSubject}" -f -t >/dev/null) 2>&1 | tr '\r' '\n' > "${workFile1}" # Count the number of different timer values; it should be >1. # -NUM=$(sort < $TMP1 | uniq -u | wc -l | tr -d ' ') +NUM=$(sort < "${workFile1}" | uniq -u | wc -l | tr -d ' ') test $NUM -gt 1 # EOF diff --git a/tests/005-eta b/tests/005-eta index 5392425..e12aa08 100644 --- a/tests/005-eta +++ b/tests/005-eta @@ -3,11 +3,11 @@ # Check that the estimated time counter counts. dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| $PROG -f -e -s 100 -i 0.1 -L 25 >/dev/null 2>$TMP1 +| "${testSubject}" -f -e -s 100 -i 0.1 -L 25 >/dev/null 2>"${workFile1}" # Count the number of different ETA values there have been. # -NUM=$(tr '\r' '\n' < $TMP1 | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' ') +NUM=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' ') # 3 or less - not OK, since it should have taken 4 seconds. # diff --git a/tests/006-fineta b/tests/006-fineta index 8c3221d..783884a 100644 --- a/tests/006-fineta +++ b/tests/006-fineta @@ -3,11 +3,11 @@ # Check that the estimated time counter can show the end time of day. dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| $PROG -f -I -s 100 -i 0.1 -L 25 >/dev/null 2>$TMP1 +| "${testSubject}" -f -I -s 100 -i 0.1 -L 25 >/dev/null 2>"${workFile1}" # Count the number of different ETA values there have been. # -NUM=$(tr '\r' '\n' < $TMP1 | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' ') +NUM=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' ') # There should be at least 1 line of output. # diff --git a/tests/007-ratecount b/tests/007-ratecount index 5e3c448..78ea7e2 100644 --- a/tests/007-ratecount +++ b/tests/007-ratecount @@ -7,11 +7,11 @@ (dd if=/dev/zero bs=100 count=1 2>/dev/null; sleep 2; dd if=/dev/zero bs=100 count=1 2>/dev/null; -) | $PROG -f -i 0.5 -r >/dev/null 2>$TMP1 +) | "${testSubject}" -f -i 0.5 -r >/dev/null 2>"${workFile1}" # Count the number of different rates output. # -NUM=$(tr '\r' '\n' < $TMP1 | sort | uniq -u | wc -l | tr -d ' ') +NUM=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -d ' ') # There should be more than 2 different rates counted (around 100 bytes/sec # for the each block, 0 bytes/sec for the gap in the middle, and around 50 diff --git a/tests/008-bytes b/tests/008-bytes index 03fc482..9b549fc 100644 --- a/tests/008-bytes +++ b/tests/008-bytes @@ -3,8 +3,8 @@ # Check that the byte counter counts. dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| LANG=C $PROG -f -b >/dev/null 2>$TMP1 -NUM=$(tr '\r' '\n' < $TMP1 | tr -d ' ') +| LANG=C "${testSubject}" -f -b >/dev/null 2>"${workFile1}" +NUM=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ') test "$NUM" = "100B" # EOF diff --git a/tests/009-numeric b/tests/009-numeric index 656e3b8..79e504f 100644 --- a/tests/009-numeric +++ b/tests/009-numeric @@ -6,13 +6,13 @@ # around 10 output lines. # dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| $PROG -s 100 -n -i 0.1 -L 100 >/dev/null 2>$TMP1 +| "${testSubject}" -s 100 -n -i 0.1 -L 100 >/dev/null 2>"${workFile1}" # The number of output lines should be >8 and <13, and the final percentage # should be 100. # -test $(wc -l < $TMP1) -gt 8 -test $(wc -l < $TMP1) -lt 13 -test $(sed -n '$p' < $TMP1) -eq 100 +test $(wc -l < "${workFile1}") -gt 8 +test $(wc -l < "${workFile1}") -lt 13 +test $(sed -n '$p' < "${workFile1}") -eq 100 # EOF diff --git a/tests/010-quiet b/tests/010-quiet index a75da36..06e611d 100644 --- a/tests/010-quiet +++ b/tests/010-quiet @@ -3,7 +3,7 @@ # Check that the -q option shuts everything up. dd if=/dev/zero bs=1000 count=5 2>/dev/null \ -| $PROG -f -q -i 0.1 -L 5000 >/dev/null 2>$TMP1 -test ! -s $TMP1 +| "${testSubject}" -f -q -i 0.1 -L 5000 >/dev/null 2>"${workFile1}" +test ! -s "${workFile1}" # EOF diff --git a/tests/011-pipe b/tests/011-pipe index a7183f5..0befe12 100644 --- a/tests/011-pipe +++ b/tests/011-pipe @@ -3,30 +3,30 @@ # Check that there is no SIGPIPE or dropped data on bigger data transfers. # We nead GNU head. On some platforms it is named ghead instead of head. -HEAD=head -for p in $(echo $PATH | tr ':' '\n') +HEAD="head" +for checkPath in $(echo "${PATH}" | tr ':' '\n') do - if test -x $p/ghead + if test -x "${checkPath}/ghead" then - HEAD=$p/ghead + HEAD="${checkPath}/ghead" break fi done # Check that it really is GNU head, and skip the test if not. -if ! echo | $HEAD -c 10 >/dev/null 2>&1; then +if ! echo | "${HEAD}" -c 10 >/dev/null 2>&1; then echo "GNU \`head' is required" exit 2 fi # Don't use dd. See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=324308 COUNT1=100000000 -#COUNT2=`$PROG -B 100000 -q /dev/zero | $HEAD -c $COUNT1 | wc -c | tr -d ' '` +#COUNT2=`"${testSubject}" -B 100000 -q /dev/zero | $HEAD -c $COUNT1 | wc -c | tr -d ' '` # Remove \n to fix the test on AIX -COUNT2=$($PROG -B 100000 -q /dev/zero | $HEAD -c $COUNT1 | tr -d '\n' | wc -c | tr -d ' ') +COUNT2=$("${testSubject}" -B 100000 -q /dev/zero | "${HEAD}" -c $COUNT1 | tr -d '\n' | wc -c | tr -d ' ') #echo "[$COUNT1] [$COUNT2]" -test "x$COUNT1" = "x$COUNT2" +test "x${COUNT1}" = "x${COUNT2}" # EOF diff --git a/tests/012-cksum b/tests/012-cksum index 49be101..8dbf96b 100644 --- a/tests/012-cksum +++ b/tests/012-cksum @@ -3,24 +3,24 @@ # Transfer a large chunk of data through pv and check data correctness # afterwards. -rm -f $TMP1 $TMP2 2>/dev/null +rm -f "${workFile1}" "${workFile2}" 2>/dev/null # exit on non-zero return codes set -e # generate some data -dd if=/dev/urandom of=$TMP1 bs=1024 count=10240 2>/dev/null +dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null -CKSUM1=$(cksum $TMP1 | awk '{print $1}') +CKSUM1=$(cksum "${workFile1}" | awk '{print $1}') # read through pv and test afterwards -$PROG -B 100000 -q $TMP1 > $TMP2 +"${testSubject}" -B 100000 -q "${workFile1}" > "${workFile2}" -CKSUM2=$(cksum $TMP2 | awk '{print $1}') +CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') test "x$CKSUM1" = "x$CKSUM2" # clean up -rm -f $TMP1 $TMP2 2>/dev/null +rm -f "${workFile1}" "${workFile2}" 2>/dev/null # EOF diff --git a/tests/013-averagerate b/tests/013-averagerate index 8fb5e2f..ee02c51 100644 --- a/tests/013-averagerate +++ b/tests/013-averagerate @@ -10,11 +10,11 @@ sleep 1; dd if=/dev/zero bs=110 count=1 2>/dev/null; sleep 1; -) | $PROG -f -i 0.5 -a >/dev/null 2>$TMP1 +) | "${testSubject}" -f -i 0.5 -a >/dev/null 2>"${workFile1}" # Count the number of rates output that are below 80. # -NUM=$(tr '\r' '\n' < $TMP1 | tr -dc '0-9.\n' | sed '/^$/d' | awk '$1<80{print}' | wc -l | tr -d ' ') +NUM=$(tr '\r' '\n' < "${workFile1}" | tr -dc '0-9.\n' | sed '/^$/d' | awk '$1<80{print}' | wc -l | tr -d ' ') # Nearly all of the output rates should be above 80 since the average rate # will always be around 100 bytes per second, except for pauses. diff --git a/tests/014-1m_boundary_1 b/tests/014-1m_boundary_1 index fc68fb2..73ddf12 100644 --- a/tests/014-1m_boundary_1 +++ b/tests/014-1m_boundary_1 @@ -12,14 +12,14 @@ sleep 1; dd if=/dev/zero bs=1k count=500; sleep 1; -) 2>/dev/null | ($PROG -btef -s 1500k >/dev/null) 2>$TMP1 +) 2>/dev/null | ("${testSubject}" -btef -s 1500k >/dev/null) 2>"${workFile1}" # Count how many different line lengths we've seen. # -NUM=$(tr '\r' '\n' < $TMP1 | awk '{x=length($0);if(x>0)print length($0)}' | sort | uniq | wc -l) +NUM=$(tr '\r' '\n' < "${workFile1}" | awk '{x=length($0);if(x>0)print length($0)}' | sort | uniq | wc -l) # There should only be one length (not counting 0). # -test $NUM -eq 1 || { echo; tr '\r' '\n' < $TMP1; exit 1; } +test $NUM -eq 1 || { echo; tr '\r' '\n' < "${workFile1}"; exit 1; } # EOF diff --git a/tests/015-1m_boundary_2 b/tests/015-1m_boundary_2 index 8de6d1d..e0aaeec 100644 --- a/tests/015-1m_boundary_2 +++ b/tests/015-1m_boundary_2 @@ -1,6 +1,6 @@ #!/bin/sh # -# Same as test 13 (1mboundary) but for rate, not bytes transferred. +# Same as test (1m_boundary_1) but for rate, not bytes transferred. # Transfer 1500kB of data in a bursty fashion. # @@ -12,14 +12,14 @@ sleep 1; dd if=/dev/zero bs=1k count=500; sleep 1; -) 2>/dev/null | ($PROG -rtef -s 1500k >/dev/null) 2>$TMP1 +) 2>/dev/null | ("${testSubject}" -rtef -s 1500k >/dev/null) 2>"${workFile1}" # Count how many different line lengths we've seen. # -NUM=$(tr '\r' '\n' < $TMP1 | awk '{x=length($0);if(x>0)print length($0)}' | sort | uniq | wc -l) +NUM=$(tr '\r' '\n' < "${workFile1}" | awk '{x=length($0);if(x>0)print length($0)}' | sort | uniq | wc -l) # There should only be one length (not counting 0). # -test $NUM -eq 1 || { echo; tr '\r' '\n' < $TMP1; exit 1; } +test $NUM -eq 1 || { echo; tr '\r' '\n' < "${workFile1}"; exit 1; } # EOF diff --git a/tests/016-cksumpipe b/tests/016-cksumpipe index d676148..44c2266 100644 --- a/tests/016-cksumpipe +++ b/tests/016-cksumpipe @@ -3,51 +3,51 @@ # Transfer a large chunk of data through pv using pipes, sending it in a # bursty fashion, and check data correctness afterwards. -rm -f $TMP1 $TMP2 2>/dev/null +rm -f "${workFile1}" "${workFile2}" 2>/dev/null # exit on non-zero return codes set -e # generate some data -dd if=/dev/urandom of=$TMP1 bs=1024 count=10240 2>/dev/null +dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null -CKSUM1=$(cksum $TMP1 | awk '{print $1}') +CKSUM1=$(cksum "${workFile1}" | awk '{print $1}') # read through pv and test afterwards ( -dd if=$TMP1 bs=1 count=9000 +dd if="${workFile1}" bs=1 count=9000 sleep 1 -dd if=$TMP1 bs=1 skip=9000 count=1240 +dd if="${workFile1}" bs=1 skip=9000 count=1240 sleep 1 -dd if=$TMP1 bs=1024 skip=10 count=1014 +dd if="${workFile1}" bs=1024 skip=10 count=1014 sleep 1 -dd if=$TMP1 bs=1024 skip=1024 count=1024 +dd if="${workFile1}" bs=1024 skip=1024 count=1024 sleep 1 -dd if=$TMP1 bs=1024 skip=2048 -) 2>/dev/null | $PROG -q -L 2M | cat > $TMP2 +dd if="${workFile1}" bs=1024 skip=2048 +) 2>/dev/null | "${testSubject}" -q -L 2M | cat > "${workFile2}" -CKSUM2=$(cksum $TMP2 | awk '{print $1}') +CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') test "x$CKSUM1" = "x$CKSUM2" # same again but with one less pipe ( -dd if=$TMP1 bs=1 count=9000 +dd if="${workFile1}" bs=1 count=9000 sleep 1 -dd if=$TMP1 bs=1 skip=9000 count=1240 +dd if="${workFile1}" bs=1 skip=9000 count=1240 sleep 1 -dd if=$TMP1 bs=1024 skip=10 count=1014 +dd if="${workFile1}" bs=1024 skip=10 count=1014 sleep 1 -dd if=$TMP1 bs=1024 skip=1024 count=1024 +dd if="${workFile1}" bs=1024 skip=1024 count=1024 sleep 1 -dd if=$TMP1 bs=1024 skip=2048 -) 2>/dev/null | $PROG -q -L 2M > $TMP2 +dd if="${workFile1}" bs=1024 skip=2048 +) 2>/dev/null | "${testSubject}" -q -L 2M > "${workFile2}" -CKSUM2=$(cksum $TMP2 | awk '{print $1}') +CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') test "x$CKSUM1" = "x$CKSUM2" # clean up -rm -f $TMP1 $TMP2 2>/dev/null +rm -f "${workFile1}" "${workFile2}" 2>/dev/null # EOF diff --git a/tests/017-numeric-timer b/tests/017-numeric-timer index 9d8f08b..36a502a 100644 --- a/tests/017-numeric-timer +++ b/tests/017-numeric-timer @@ -6,15 +6,15 @@ # around 10 output lines. # dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| $PROG -s 100 -n -t -i 0.1 -L 100 >/dev/null 2>$TMP1 +| "${testSubject}" -s 100 -n -t -i 0.1 -L 100 >/dev/null 2>"${workFile1}" # The number of output lines should be >8 and <13, and the number of # different elapsed times should be at least 7. The last percentage should # be 100. # -test $(wc -l < $TMP1) -gt 8 -test $(wc -l < $TMP1) -lt 13 -test $(tr , . < "$TMP1" | awk '{print int(10*$1)}' | sort -n | uniq | wc -l) -gt 7 -test $(sed -n '$p' < $TMP1 | awk '{print $2}') -eq 100 +test $(wc -l < "${workFile1}") -gt 8 +test $(wc -l < "${workFile1}") -lt 13 +test $(tr , . < ""${workFile1}"" | awk '{print int(10*$1)}' | sort -n | uniq | wc -l) -gt 7 +test $(sed -n '$p' < "${workFile1}" | awk '{print $2}') -eq 100 # EOF diff --git a/tests/018-numeric-bytes b/tests/018-numeric-bytes index 9d4e6fd..c072e40 100644 --- a/tests/018-numeric-bytes +++ b/tests/018-numeric-bytes @@ -7,13 +7,13 @@ # around 10 output lines. # dd if=/dev/zero bs=500 count=1 2>/dev/null \ -| $PROG -s 500 -n -b -i 0.1 -L 500 >/dev/null 2>$TMP1 +| "${testSubject}" -s 500 -n -b -i 0.1 -L 500 >/dev/null 2>"${workFile1}" # The number of output lines should be >8 and <13, and the final byte count # should be 500. # -test $(wc -l < $TMP1) -gt 8 -test $(wc -l < $TMP1) -lt 13 -test $(sed -n '$p' < $TMP1) -eq 500 +test $(wc -l < "${workFile1}") -gt 8 +test $(wc -l < "${workFile1}") -lt 13 +test $(sed -n '$p' < "${workFile1}") -eq 500 # EOF diff --git a/tests/019-remote-format b/tests/019-remote-format index f301ed2..63e9315 100644 --- a/tests/019-remote-format +++ b/tests/019-remote-format @@ -3,30 +3,30 @@ # Try changing the format of a transfer remotely. # Do nothing if IPC is not supported. -if ! $PROG -h | grep -Eq "^ -R,"; then - echo "SKIPPED" | tr "\n" ' ' - exit 0 +if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then + echo "IPC is not supported on this platform" + exit 2 fi -rm -f $TMP1 $TMP2 $TMP3 $TMP4 2>/dev/null +rm -f "${workFile1}" "${workFile2}" "${workFile3}" "${workFile4}" 2>/dev/null # Exit on non-zero return codes. set -e # Generate an empty test file. -dd if=/dev/zero of=$TMP1 bs=1024 count=10240 2>/dev/null +dd if=/dev/zero of="${workFile1}" bs=1024 count=10240 2>/dev/null ( sleep 1 -$PROG -R $(cat $TMP4) -a +"${testSubject}" -R $(cat "${workFile4}") -a sleep 2 -$PROG -R $(cat $TMP4) -L 10M +"${testSubject}" -R $(cat "${workFile4}") -L 10M ) & -$PROG -L 2M -f -P $TMP4 $TMP1 > $TMP2 2>$TMP3 +"${testSubject}" -L 2M -f -P "${workFile4}" "${workFile1}" > "${workFile2}" 2>"${workFile3}" # Make sure there is more than one length of line (excluding blank lines). -line_lengths=$(tr '\r' '\n' < "$TMP3" | awk '{print length($0)}' | grep -Fvx 0 | sort -n | uniq | wc -l) +line_lengths=$(tr '\r' '\n' < "${workFile3}" | awk '{print length($0)}' | grep -Fvx 0 | sort -n | uniq | wc -l) test $line_lengths -gt 1 # EOF diff --git a/tests/020-remote-cksum b/tests/020-remote-cksum index c98999d..17c5fd0 100644 --- a/tests/020-remote-cksum +++ b/tests/020-remote-cksum @@ -4,51 +4,51 @@ # intact. # Do nothing if IPC is not supported. -if ! $PROG -h | grep -Eq "^ -R,"; then - echo "SKIPPED" | tr "\n" ' ' - exit 0 +if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then + echo "IPC is not supported on this platform" + exit 2 fi -rm -f $TMP1 $TMP2 $TMP3 $TMP4 2>/dev/null +rm -f "${workFile1}" "${workFile2}" "${workFile3}" "${workFile4}" 2>/dev/null # Exit on non-zero return codes. set -e # Generate some data. -dd if=/dev/urandom of=$TMP1 bs=1024 count=10240 2>/dev/null +dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null # Run a few remote control commands in the background. # -echo FAIL > $TMP3 +echo FAIL > "${workFile3}" ( set +e sleep 2 for x in 1 2 3; do - $PROG -R $(cat $TMP4) -apterb || exit 1 + "${testSubject}" -R $(cat "${workFile4}") -apterb || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - $PROG -R $(cat $TMP4) -p || exit 1 + "${testSubject}" -R $(cat "${workFile4}") -p || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - $PROG -R $(cat $TMP4) -N "test" || exit 1 + "${testSubject}" -R $(cat "${workFile4}") -N "test" || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - $PROG -R $(cat $TMP4) -F "%e" || exit 1 + "${testSubject}" -R $(cat "${workFile4}") -F "%e" || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - $PROG -R $(cat $TMP4) -N "." || exit 1 + "${testSubject}" -R $(cat "${workFile4}") -N "." || exit 1 (usleep 200000 || sleep 1) 2>/dev/null done -$PROG -R $(cat $TMP4) -L 10M -echo OK > $TMP3 +"${testSubject}" -R $(cat "${workFile4}") -L 10M +echo OK > "${workFile3}" ) & # Run our data transfer. -$PROG -L 100k -i 0.1 -f -P $TMP4 $TMP1 > $TMP2 2>/dev/null +"${testSubject}" -L 100k -i 0.1 -f -P "${workFile4}" "${workFile1}" > "${workFile2}" 2>/dev/null # Check our remote control calls ran OK. -BGSTATUS=$(cat $TMP3) +BGSTATUS=$(cat "${workFile3}") test "x$BGSTATUS" = "xOK" # Check data integrity. -CKSUM1=$(cksum $TMP1 | awk '{print $1}') -CKSUM2=$(cksum $TMP2 | awk '{print $1}') +CKSUM1=$(cksum "${workFile1}" | awk '{print $1}') +CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') test "x$CKSUM1" = "x$CKSUM2" # EOF diff --git a/tests/021-stop-at-size b/tests/021-stop-at-size index edfb6b5..404a2af 100644 --- a/tests/021-stop-at-size +++ b/tests/021-stop-at-size @@ -2,27 +2,27 @@ # # Make sure -S stops at the given size. -rm -f $TMP1 $TMP2 2>/dev/null +rm -f "${workFile1}" "${workFile2}" 2>/dev/null # exit on non-zero return codes set -e # generate some data -dd if=/dev/urandom of=$TMP1 bs=1024 count=10 2>/dev/null +dd if=/dev/urandom of="${workFile1}" bs=1024 count=10 2>/dev/null # read through pv and test afterwards -$PROG -S -s 5120 -q $TMP1 > $TMP2 +"${testSubject}" -S -s 5120 -q "${workFile1}" > "${workFile2}" -CKSUM2=$(cksum $TMP2 | awk '{print $1}') +CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') -# take the first 5120 bytes of TMP1 and cksum them -rm -f $TMP2 -dd if=$TMP1 of=$TMP2 bs=1024 count=5 2>/dev/null -CKSUM1=$(cksum $TMP2 | awk '{print $1}') +# take the first 5120 bytes of workFile1 and cksum them +rm -f "${workFile2}" +dd if="${workFile1}" of="${workFile2}" bs=1024 count=5 2>/dev/null +CKSUM1=$(cksum "${workFile2}" | awk '{print $1}') test "x$CKSUM1" = "x$CKSUM2" # clean up -rm -f $TMP1 $TMP2 2>/dev/null +rm -f "${workFile1}" "${workFile2}" 2>/dev/null # EOF diff --git a/tests/022-large-file b/tests/022-large-file index 485f587..1175151 100644 --- a/tests/022-large-file +++ b/tests/022-large-file @@ -3,25 +3,25 @@ # Make sure that files larger than 2GB are supported. # Check there is enough free space for this test. -TMP1DIR="${TMP1%/*}" -TMP1SPACEKB=$(df -kP "${TMP1DIR}" | sed -n '$p' | awk '{print $(NF-2)}') -test -n "${TMP1SPACEKB}" || TMP1SPACEKB=0 -if ! test "${TMP1SPACEKB}" -gt 3300000 2>/dev/null; then - echo "need >3GB free on ${TMP1DIR}" +workFile1DIR="${workFile1%/*}" +workFile1SPACEKB=$(df -kP "${workFile1DIR}" | sed -n '$p' | awk '{print $(NF-2)}') +test -n "${workFile1SPACEKB}" || workFile1SPACEKB=0 +if ! test "${workFile1SPACEKB}" -gt 3300000 2>/dev/null; then + echo "need >3GB free on ${workFile1DIR}" exit 2 fi # Generate a 3GB sparse file - we don't really need 3GB of free space unless # sparse files are not supported. -echo -n > "${TMP1}" -if ! dd if="/dev/zero" of="${TMP1}" count=1 bs=1048576 seek=3072 2>/dev/null; then +echo -n > "${workFile1}" +if ! dd if="/dev/zero" of="${workFile1}" count=1 bs=1048576 seek=3072 2>/dev/null; then echo "failed to create 3GB specimen file" exit 2 fi # NB the "stat" command is not portable - BSD stat(1) has a different syntax # to GNU stat(1) - so we have to parse the output of ls(1). -FILESIZE=$(ls -nl "${TMP1}" 2>/dev/null | awk '{print $5}') +FILESIZE=$(ls -nl "${workFile1}" 2>/dev/null | awk '{print $5}') test -n "${FILESIZE}" || FILESIZE=0 if ! test "${FILESIZE}" -gt 3000000; then echo "failed to validate specimen file size" @@ -29,9 +29,9 @@ if ! test "${FILESIZE}" -gt 3000000; then fi # Transfer the file, and count how many bytes came through. -TRANSFERRED=$("${PROG}" -n -b "${TMP1}" 2>"${TMP2}" | wc -c 2>/dev/null | tr -dc '0-9') +TRANSFERRED=$("${testSubject}" -n -b "${workFile1}" 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9') test -n "${TRANSFERRED}" || TRANSFERRED=0 -COUNTED=$(sed -n '$p' "${TMP2}" | tr -dc '0-9') +COUNTED=$(sed -n '$p' "${workFile2}" | tr -dc '0-9') test -n "${COUNTED}" || COUNTED=0 if ! test "${TRANSFERRED}" -eq "${FILESIZE}"; then echo "transferred ${TRANSFERRED} of ${FILESIZE} bytes" @@ -43,9 +43,9 @@ if ! test "${COUNTED}" -eq "${FILESIZE}"; then fi # Transfer the file from stdin, and count how many bytes came through. -TRANSFERRED=$("${PROG}" -n -b < "${TMP1}" 2>"${TMP2}" | wc -c 2>/dev/null | tr -dc '0-9') +TRANSFERRED=$("${testSubject}" -n -b < "${workFile1}" 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9') test -n "${TRANSFERRED}" || TRANSFERRED=0 -COUNTED=$(sed -n '$p' "${TMP2}" | tr -dc '0-9') +COUNTED=$(sed -n '$p' "${workFile2}" | tr -dc '0-9') test -n "${COUNTED}" || COUNTED=0 if ! test "${TRANSFERRED}" -eq "${FILESIZE}"; then echo "stdin - transferred ${TRANSFERRED} of ${FILESIZE} bytes" @@ -58,9 +58,9 @@ fi # Use the file as a size value and transfer its size of bytes from dev/zero, # and count how many bytes came through. -TRANSFERRED=$("${PROG}" -n -b -S -s "@${TMP1}" /dev/zero 2>"${TMP2}" | wc -c 2>/dev/null | tr -dc '0-9') +TRANSFERRED=$("${testSubject}" -n -b -S -s "@${workFile1}" /dev/zero 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9') test -n "${TRANSFERRED}" || TRANSFERRED=0 -COUNTED=$(sed -n '$p' "${TMP2}" | tr -dc '0-9') +COUNTED=$(sed -n '$p' "${workFile2}" | tr -dc '0-9') test -n "${COUNTED}" || COUNTED=0 if ! test "${TRANSFERRED}" -eq "${FILESIZE}"; then echo "size read - transferred ${TRANSFERRED} of ${FILESIZE} bytes" @@ -71,8 +71,8 @@ if ! test "${COUNTED}" -eq "${FILESIZE}"; then exit 1 fi -echo -n > "${TMP1}" -echo -n > "${TMP2}" +echo -n > "${workFile1}" +echo -n > "${workFile2}" exit 0