From 82aa30c3066ec827f7a502e33b5098915be32540 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 23 Jul 2023 18:35:49 +0100 Subject: [PATCH] Add more verbose output and apply fixes suggested by shellcheck. --- ...ay_length_at_magnitude_boundary_-_Bytes.sh | 2 +- ...lay_length_at_magnitude_boundary_-_Rate.sh | 2 +- tests/Display_-_--average-rate.sh | 11 ++- tests/Display_-_--bytes.sh | 13 +++- tests/Display_-_--eta_-_plausible_values.sh | 19 ++++- .../Display_-_--fineta_-_plausible_values.sh | 18 ++++- tests/Display_-_--numeric.sh | 23 +++++- tests/Display_-_--numeric_--bytes.sh | 21 +++++- tests/Display_-_--numeric_--timer.sh | 29 +++++++- .../Display_-_--progress_-_basic_movement.sh | 13 +++- tests/Display_-_--quiet.sh | 12 ++- ...play_-_--rate_-_displayed_value_changes.sh | 13 +++- ...lay_-_--timer_-_displayed_value_changes.sh | 12 ++- tests/Integrity_-_Basic.sh | 2 +- tests/Integrity_-_Binary_data.sh | 15 ++-- tests/Integrity_-_From_bursty_source.sh | 25 ++++--- tests/Integrity_-_Large_file_support.sh | 73 ++++++++++--------- tests/Integrity_-_On_output_pipe_close.sh | 18 +++-- tests/Integrity_-_When_adjusted_remotely.sh | 41 ++++++----- tests/Transfer_-_--remote.sh | 5 +- tests/Transfer_-_--stop-at-size.sh | 12 +-- 21 files changed, 257 insertions(+), 122 deletions(-) diff --git a/tests/Bug_-_Display_length_at_magnitude_boundary_-_Bytes.sh b/tests/Bug_-_Display_length_at_magnitude_boundary_-_Bytes.sh index d8884fb..7ec0120 100644 --- a/tests/Bug_-_Display_length_at_magnitude_boundary_-_Bytes.sh +++ b/tests/Bug_-_Display_length_at_magnitude_boundary_-_Bytes.sh @@ -5,7 +5,7 @@ # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=586763 # Dummy assignments for "shellcheck". -testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp}" +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" # Transfer 1500kB of data in a bursty fashion. # diff --git a/tests/Bug_-_Display_length_at_magnitude_boundary_-_Rate.sh b/tests/Bug_-_Display_length_at_magnitude_boundary_-_Rate.sh index 2dda755..e9dc6c2 100644 --- a/tests/Bug_-_Display_length_at_magnitude_boundary_-_Rate.sh +++ b/tests/Bug_-_Display_length_at_magnitude_boundary_-_Rate.sh @@ -4,7 +4,7 @@ # but for rate, not bytes transferred. # Dummy assignments for "shellcheck". -testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp}" +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" # Transfer 1500kB of data in a bursty fashion. # diff --git a/tests/Display_-_--average-rate.sh b/tests/Display_-_--average-rate.sh index ee02c51..6eafe3a 100644 --- a/tests/Display_-_--average-rate.sh +++ b/tests/Display_-_--average-rate.sh @@ -3,6 +3,9 @@ # Check that the average transfer rate counter changes, but not more than it # should. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + # Transfer 210 bytes as 100 bytes, a 1 second gap, 110 bytes, and another 1 # second gap. # @@ -14,11 +17,15 @@ # Count the number of rates output that are below 80. # -NUM=$(tr '\r' '\n' < "${workFile1}" | tr -dc '0-9.\n' | sed '/^$/d' | awk '$1<80{print}' | wc -l | tr -d ' ') +lineCount=$(tr '\r' '\n' < "${workFile1}" | tr -dc '0-9.\n' | sed '/^$/d' | awk '$1<80{print}' | wc -l | tr -dc '0-9') # 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. # -test $NUM -lt 2 +test "${lineCount}" -lt 2 && exit 0 + +echo "average rate varied more than expected" +tr '\r' '\n' < "${workFile1}" +exit 1 # EOF diff --git a/tests/Display_-_--bytes.sh b/tests/Display_-_--bytes.sh index 9b549fc..b8d437f 100644 --- a/tests/Display_-_--bytes.sh +++ b/tests/Display_-_--bytes.sh @@ -2,9 +2,16 @@ # # Check that the byte counter counts. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + dd if=/dev/zero bs=100 count=1 2>/dev/null \ -| LANG=C "${testSubject}" -f -b >/dev/null 2>"${workFile1}" -NUM=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ') -test "$NUM" = "100B" +| "${testSubject}" -f -b >/dev/null 2>"${workFile1}" + +counterValue=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ') +test "${counterValue}" = "100B" && exit 0 + +echo "unexpected byte counter value: ${counterValue}" +exit 1 # EOF diff --git a/tests/Display_-_--eta_-_plausible_values.sh b/tests/Display_-_--eta_-_plausible_values.sh index e12aa08..29daed8 100644 --- a/tests/Display_-_--eta_-_plausible_values.sh +++ b/tests/Display_-_--eta_-_plausible_values.sh @@ -2,19 +2,32 @@ # # Check that the estimated time counter counts. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + dd if=/dev/zero bs=100 count=1 2>/dev/null \ | "${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' < "${workFile1}" | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' ') +valueCount=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -dc '0-9') # 3 or less - not OK, since it should have taken 4 seconds. # -test $NUM -gt 3 || exit 1 +if ! test "${valueCount}" -gt 3; then + echo "fewer than 4 ETA values seen" + tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sort | uniq + exit 1 +fi # 12 or more - not OK, since even on a heavily loaded system that's too long. # -test $NUM -lt 12 +if ! test "${valueCount}" -lt 12; then + echo "more than 11 ETA values seen" + tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sort | uniq + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--fineta_-_plausible_values.sh b/tests/Display_-_--fineta_-_plausible_values.sh index 783884a..41e7f46 100644 --- a/tests/Display_-_--fineta_-_plausible_values.sh +++ b/tests/Display_-_--fineta_-_plausible_values.sh @@ -2,19 +2,31 @@ # # Check that the estimated time counter can show the end time of day. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + dd if=/dev/zero bs=100 count=1 2>/dev/null \ | "${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' < "${workFile1}" | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -d ' ') +valueCount=$(tr '\r' '\n' < "${workFile1}" | tr -d ' ' | sed '/^$/d' | sort | uniq | wc -l | tr -dc '0-9') # There should be at least 1 line of output. # -test $NUM -gt 0 || exit 1 +if ! test "${valueCount}" -gt 0; then + echo "no output found" + exit 1 +fi # 8 or more different values - not OK. # -test $NUM -lt 8 +if ! test "${valueCount}" -lt 8; then + echo "more than 7 different values (${valueCount})" + tr '\r' '\n' < "${workFile1}" | sed '/^ *$/d' | sort | uniq + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--numeric.sh b/tests/Display_-_--numeric.sh index 79e504f..81f4bc7 100644 --- a/tests/Display_-_--numeric.sh +++ b/tests/Display_-_--numeric.sh @@ -2,17 +2,34 @@ # # Check that numeric output outputs some percentages. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + # Process 100 bytes at 100 bytes per second, updating every 0.1 seconds for # around 10 output lines. # dd if=/dev/zero bs=100 count=1 2>/dev/null \ | "${testSubject}" -s 100 -n -i 0.1 -L 100 >/dev/null 2>"${workFile1}" +lineCount=$(wc -l < "${workFile1}" | tr -dc '0-9') +finalLine=$(sed -n '$p' < "${workFile1}") + # The number of output lines should be >8 and <13, and the final percentage # should be 100. # -test $(wc -l < "${workFile1}") -gt 8 -test $(wc -l < "${workFile1}") -lt 13 -test $(sed -n '$p' < "${workFile1}") -eq 100 +if ! test "${lineCount}" -gt 8; then + echo "fewer than 9 output lines (${lineCount})" + exit 1 +fi +if ! test "${lineCount}" -lt 13; then + echo "more than 12 output lines (${lineCount})" + exit 1 +fi +if ! test "${finalLine}" = "100"; then + echo "final percentage was not 100 (${finalLine})" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--numeric_--bytes.sh b/tests/Display_-_--numeric_--bytes.sh index c072e40..ce6dee3 100644 --- a/tests/Display_-_--numeric_--bytes.sh +++ b/tests/Display_-_--numeric_--bytes.sh @@ -3,17 +3,32 @@ # Check that numeric output gives a byte count instead of a percentage when # used with -b. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + # Process 500 bytes at 500 bytes per second, updating every 0.1 seconds for # around 10 output lines. # dd if=/dev/zero bs=500 count=1 2>/dev/null \ | "${testSubject}" -s 500 -n -b -i 0.1 -L 500 >/dev/null 2>"${workFile1}" +lineCount=$(wc -l < "${workFile1}" | tr -dc '0-9') +finalLine=$(sed -n '$p' < "${workFile1}") + # The number of output lines should be >8 and <13, and the final byte count # should be 500. # -test $(wc -l < "${workFile1}") -gt 8 -test $(wc -l < "${workFile1}") -lt 13 -test $(sed -n '$p' < "${workFile1}") -eq 500 +if ! test "${lineCount}" -gt 8; then + echo "fewer than 9 output lines (${lineCount})" + exit 1 +fi +if ! test "${lineCount}" -lt 13; then + echo "more than 12 output lines (${lineCount})" + exit 1 +fi +if ! test "${finalLine}" = "500"; then + echo "final byte count was not 500 (${finalLine})" + exit 1 +fi # EOF diff --git a/tests/Display_-_--numeric_--timer.sh b/tests/Display_-_--numeric_--timer.sh index 36a502a..2efbcf7 100644 --- a/tests/Display_-_--numeric_--timer.sh +++ b/tests/Display_-_--numeric_--timer.sh @@ -2,19 +2,40 @@ # # Check that numeric output gives a timer when used with -t. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + # Process 100 bytes at 100 bytes per second, updating every 0.1 seconds for # around 10 output lines. # dd if=/dev/zero bs=100 count=1 2>/dev/null \ | "${testSubject}" -s 100 -n -t -i 0.1 -L 100 >/dev/null 2>"${workFile1}" +lineCount=$(wc -l < "${workFile1}" | tr -dc '0-9') +timesCount=$(tr ',' '.' < "${workFile1}" | awk '{print int(10*$1)}' | sort -n | uniq | wc -l | tr -dc '0-9') +finalPercentage=$(sed -n '$p' < "${workFile1}" | awk '{print $2}') + # 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 < "${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 +if ! test "${lineCount}" -gt 8; then + echo "fewer than 9 output lines (${lineCount})" + exit 1 +fi +if ! test "${lineCount}" -lt 13; then + echo "more than 12 output lines (${lineCount})" + exit 1 +fi +if ! test "${timesCount}" -gt 7; then + echo "fewer than 8 different elapsed times (${timesCount})" + exit 1 +fi +if ! test "${finalPercentage}" = "100"; then + echo "final percentage was not 100 (${finalPercentage})" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--progress_-_basic_movement.sh b/tests/Display_-_--progress_-_basic_movement.sh index fed00bf..1ff310f 100644 --- a/tests/Display_-_--progress_-_basic_movement.sh +++ b/tests/Display_-_--progress_-_basic_movement.sh @@ -2,12 +2,21 @@ # # Check that the progress bar moves when data is coming in. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + dd if=/dev/zero bs=100 count=1 2>/dev/null \ | "${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' < "${workFile1}" | sort | uniq -u | wc -l | tr -d ' ') -test $NUM -gt 2 +lineCount=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -dc '0-9') +if ! test "${lineCount}" -gt 2; then + echo "fewer than 3 different progress lines (${lineCount})" + tr '\r' '\n' < "${workFile1}" | sort | uniq -u + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--quiet.sh b/tests/Display_-_--quiet.sh index 06e611d..a90b1ca 100644 --- a/tests/Display_-_--quiet.sh +++ b/tests/Display_-_--quiet.sh @@ -2,8 +2,18 @@ # # Check that the -q option shuts everything up. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + dd if=/dev/zero bs=1000 count=5 2>/dev/null \ | "${testSubject}" -f -q -i 0.1 -L 5000 >/dev/null 2>"${workFile1}" -test ! -s "${workFile1}" + +if test -s "${workFile1}"; then + echo "output detected when there should be none" + cat "${workFile1}" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--rate_-_displayed_value_changes.sh b/tests/Display_-_--rate_-_displayed_value_changes.sh index 78ea7e2..a21e745 100644 --- a/tests/Display_-_--rate_-_displayed_value_changes.sh +++ b/tests/Display_-_--rate_-_displayed_value_changes.sh @@ -2,6 +2,9 @@ # # Check that the transfer rate counter changes. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + # Transfer 200 bytes as two 100-byte blocks with a 2-second gap between. # (dd if=/dev/zero bs=100 count=1 2>/dev/null; @@ -11,12 +14,18 @@ # Count the number of different rates output. # -NUM=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -d ' ') +rateCount=$(tr '\r' '\n' < "${workFile1}" | sort | uniq -u | wc -l | tr -dc '0-9') # 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 # bytes/sec for the average time reported at the end). # -test $NUM -gt 2 +if ! test "${rateCount}" -gt 2; then + echo "fewer than 3 different rates detected (${rateCount})" + tr '\r' '\n' < "${workFile1}" | sort | uniq -u + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Display_-_--timer_-_displayed_value_changes.sh b/tests/Display_-_--timer_-_displayed_value_changes.sh index 7700a50..7c38d7e 100644 --- a/tests/Display_-_--timer_-_displayed_value_changes.sh +++ b/tests/Display_-_--timer_-_displayed_value_changes.sh @@ -2,13 +2,21 @@ # # Check that the elapsed time counter does count up. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}" + # Transfer a zero amount of data, but take 3 seconds to do it. # (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 < "${workFile1}" | uniq -u | wc -l | tr -d ' ') -test $NUM -gt 1 +valueCount=$(sort < "${workFile1}" | uniq -u | wc -l | tr -dc '0-9') +if ! test "${valueCount}" -gt 1; then + echo "timer value did not change" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Integrity_-_Basic.sh b/tests/Integrity_-_Basic.sh index eb60d63..3524cff 100644 --- a/tests/Integrity_-_Basic.sh +++ b/tests/Integrity_-_Basic.sh @@ -6,7 +6,7 @@ testSubject="${testSubject:-false}" inputString="TESTING" -outputString=$(printf "${inputString}" | "${testSubject}" 2>/dev/null) || { echo "unexpected failure code"; exit 1; } +outputString=$(printf "%s" "${inputString}" | "${testSubject}" 2>/dev/null) || { echo "unexpected failure code"; exit 1; } test "${inputString}" = "${outputString}" && exit 0 echo "output did not match input" diff --git a/tests/Integrity_-_Binary_data.sh b/tests/Integrity_-_Binary_data.sh index 8dbf96b..071e6a9 100644 --- a/tests/Integrity_-_Binary_data.sh +++ b/tests/Integrity_-_Binary_data.sh @@ -3,24 +3,21 @@ # Transfer a large chunk of data through pv and check data correctness # afterwards. -rm -f "${workFile1}" "${workFile2}" 2>/dev/null - -# exit on non-zero return codes -set -e +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"; workFile2="${workFile2:-.tmp2}" # generate some data dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null -CKSUM1=$(cksum "${workFile1}" | awk '{print $1}') +inputChecksum=$(cksum "${workFile1}" | awk '{print $1}') # read through pv and test afterwards "${testSubject}" -B 100000 -q "${workFile1}" > "${workFile2}" -CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') +outputChecksum=$(cksum "${workFile2}" | awk '{print $1}') -test "x$CKSUM1" = "x$CKSUM2" +test "${inputChecksum}" = "${outputChecksum}" || exit 1 -# clean up -rm -f "${workFile1}" "${workFile2}" 2>/dev/null +exit 0 # EOF diff --git a/tests/Integrity_-_From_bursty_source.sh b/tests/Integrity_-_From_bursty_source.sh index 44c2266..9f8c42b 100644 --- a/tests/Integrity_-_From_bursty_source.sh +++ b/tests/Integrity_-_From_bursty_source.sh @@ -3,15 +3,13 @@ # Transfer a large chunk of data through pv using pipes, sending it in a # bursty fashion, and check data correctness afterwards. -rm -f "${workFile1}" "${workFile2}" 2>/dev/null - -# exit on non-zero return codes -set -e +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"; workFile2="${workFile2:-.tmp2}" # generate some data dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null -CKSUM1=$(cksum "${workFile1}" | awk '{print $1}') +inputChecksum=$(cksum "${workFile1}" | awk '{print $1}') # read through pv and test afterwards ( @@ -26,9 +24,12 @@ sleep 1 dd if="${workFile1}" bs=1024 skip=2048 ) 2>/dev/null | "${testSubject}" -q -L 2M | cat > "${workFile2}" -CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') +outputChecksum=$(cksum "${workFile2}" | awk '{print $1}') -test "x$CKSUM1" = "x$CKSUM2" +if ! test "${inputChecksum}" = "${outputChecksum}"; then + echo "checksum mismatch with dd | pv | cat" + exit 1 +fi # same again but with one less pipe ( @@ -43,11 +44,13 @@ sleep 1 dd if="${workFile1}" bs=1024 skip=2048 ) 2>/dev/null | "${testSubject}" -q -L 2M > "${workFile2}" -CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') +outputChecksum=$(cksum "${workFile2}" | awk '{print $1}') -test "x$CKSUM1" = "x$CKSUM2" +if ! test "${inputChecksum}" = "${outputChecksum}"; then + echo "checksum mismatch with dd | pv > file" + exit 1 +fi -# clean up -rm -f "${workFile1}" "${workFile2}" 2>/dev/null +exit 0 # EOF diff --git a/tests/Integrity_-_Large_file_support.sh b/tests/Integrity_-_Large_file_support.sh index 1175151..eb771e7 100644 --- a/tests/Integrity_-_Large_file_support.sh +++ b/tests/Integrity_-_Large_file_support.sh @@ -2,18 +2,21 @@ # # Make sure that files larger than 2GB are supported. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"; workFile2="${workFile2:-.tmp2}" + # Check there is enough free space for this test. -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}" +workFile1Dir="${workFile1%/*}" +workFile1FreeKiB=$(df -kP "${workFile1Dir}" | sed -n '$p' | awk '{print $(NF-2)}') +test -n "${workFile1FreeKiB}" || workFile1FreeKiB=0 +if ! test "${workFile1FreeKiB}" -gt 3300000 2>/dev/null; then + echo "test requires at least 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 > "${workFile1}" +true > "${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 @@ -21,59 +24,57 @@ 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 "${workFile1}" 2>/dev/null | awk '{print $5}') -test -n "${FILESIZE}" || FILESIZE=0 -if ! test "${FILESIZE}" -gt 3000000; then +# shellcheck disable=SC2012 +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" exit 2 fi # Transfer the file, and count how many bytes came through. -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' "${workFile2}" | tr -dc '0-9') -test -n "${COUNTED}" || COUNTED=0 -if ! test "${TRANSFERRED}" -eq "${FILESIZE}"; then - echo "transferred ${TRANSFERRED} of ${FILESIZE} bytes" +bytesTransferred=$("${testSubject}" -n -b "${workFile1}" 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9') +test -n "${bytesTransferred}" || bytesTransferred=0 +bytesReported=$(sed -n '$p' "${workFile2}" | tr -dc '0-9') +test -n "${bytesReported}" || bytesReported=0 +if ! test "${bytesTransferred}" -eq "${fileSize}"; then + echo "transferred ${bytesTransferred} of ${fileSize} bytes" exit 1 fi -if ! test "${COUNTED}" -eq "${FILESIZE}"; then - echo "counted ${TRANSFERRED} of ${FILESIZE} bytes" +if ! test "${bytesReported}" -eq "${fileSize}"; then + echo "counted ${bytesTransferred} of ${fileSize} bytes" exit 1 fi # Transfer the file from stdin, and count how many bytes came through. -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' "${workFile2}" | tr -dc '0-9') -test -n "${COUNTED}" || COUNTED=0 -if ! test "${TRANSFERRED}" -eq "${FILESIZE}"; then - echo "stdin - transferred ${TRANSFERRED} of ${FILESIZE} bytes" +bytesTransferred=$("${testSubject}" -n -b < "${workFile1}" 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9') +test -n "${bytesTransferred}" || bytesTransferred=0 +bytesReported=$(sed -n '$p' "${workFile2}" | tr -dc '0-9') +test -n "${bytesReported}" || bytesReported=0 +if ! test "${bytesTransferred}" -eq "${fileSize}"; then + echo "stdin - transferred ${bytesTransferred} of ${fileSize} bytes" exit 1 fi -if ! test "${COUNTED}" -eq "${FILESIZE}"; then - echo "stdin - counted ${TRANSFERRED} of ${FILESIZE} bytes" +if ! test "${bytesReported}" -eq "${fileSize}"; then + echo "stdin - counted ${bytesTransferred} of ${fileSize} bytes" exit 1 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=$("${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' "${workFile2}" | tr -dc '0-9') -test -n "${COUNTED}" || COUNTED=0 -if ! test "${TRANSFERRED}" -eq "${FILESIZE}"; then - echo "size read - transferred ${TRANSFERRED} of ${FILESIZE} bytes" +bytesTransferred=$("${testSubject}" -n -b -S -s "@${workFile1}" /dev/zero 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9') +test -n "${bytesTransferred}" || bytesTransferred=0 +bytesReported=$(sed -n '$p' "${workFile2}" | tr -dc '0-9') +test -n "${bytesReported}" || bytesReported=0 +if ! test "${bytesTransferred}" -eq "${fileSize}"; then + echo "size read - transferred ${bytesTransferred} of ${fileSize} bytes" exit 1 fi -if ! test "${COUNTED}" -eq "${FILESIZE}"; then - echo "size read - counted ${COUNTED} of ${FILESIZE} bytes" +if ! test "${bytesReported}" -eq "${fileSize}"; then + echo "size read - counted ${bytesReported} of ${fileSize} bytes" exit 1 fi -echo -n > "${workFile1}" -echo -n > "${workFile2}" - exit 0 # EOF diff --git a/tests/Integrity_-_On_output_pipe_close.sh b/tests/Integrity_-_On_output_pipe_close.sh index 0befe12..5dffd20 100644 --- a/tests/Integrity_-_On_output_pipe_close.sh +++ b/tests/Integrity_-_On_output_pipe_close.sh @@ -2,6 +2,9 @@ # # Check that there is no SIGPIPE or dropped data on bigger data transfers. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}" + # We nead GNU head. On some platforms it is named ghead instead of head. HEAD="head" for checkPath in $(echo "${PATH}" | tr ':' '\n') @@ -20,13 +23,18 @@ if ! echo | "${HEAD}" -c 10 >/dev/null 2>&1; then fi # Don't use dd. See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=324308 -COUNT1=100000000 +stopAtByteCount="100000000" #COUNT2=`"${testSubject}" -B 100000 -q /dev/zero | $HEAD -c $COUNT1 | wc -c | tr -d ' '` -# Remove \n to fix the test on AIX -COUNT2=$("${testSubject}" -B 100000 -q /dev/zero | "${HEAD}" -c $COUNT1 | tr -d '\n' | wc -c | tr -d ' ') +# We have to remove \n here, to fix the test on AIX. +bytesTransferred=$("${testSubject}" -B 100000 -q /dev/zero | "${HEAD}" -c "${stopAtByteCount}" | tr -d '\n' | wc -c | tr -dc '0-9') -#echo "[$COUNT1] [$COUNT2]" +if ! test "${stopAtByteCount}" = "${bytesTransferred}"; then + echo "number bytes transferred was not the expected value" + echo "transferred: ${bytesTransferred}" + echo "expected: ${stopAtByteCount}" + exit 1 +fi -test "x${COUNT1}" = "x${COUNT2}" +exit 0 # EOF diff --git a/tests/Integrity_-_When_adjusted_remotely.sh b/tests/Integrity_-_When_adjusted_remotely.sh index 17c5fd0..195cde9 100644 --- a/tests/Integrity_-_When_adjusted_remotely.sh +++ b/tests/Integrity_-_When_adjusted_remotely.sh @@ -3,17 +3,15 @@ # Try repeatedly messaging a transfer process, and make sure the data stays # intact. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.tmp1}"; workFile2="${workFile2:-.tmp2}"; workFile3="${workFile3:-.tmp3}"; workFile4="${workFile4:-.tmp4}" + # Do nothing if IPC is not supported. if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then echo "IPC is not supported on this platform" exit 2 fi -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="${workFile1}" bs=1024 count=10240 2>/dev/null @@ -23,19 +21,20 @@ echo FAIL > "${workFile3}" ( set +e sleep 2 -for x in 1 2 3; do - "${testSubject}" -R $(cat "${workFile4}") -apterb || exit 1 +for loopCount in 1 2 3; do + "${testSubject}" -R "$(cat "${workFile4}")" -apterb || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - "${testSubject}" -R $(cat "${workFile4}") -p || exit 1 + "${testSubject}" -R "$(cat "${workFile4}")" -p || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - "${testSubject}" -R $(cat "${workFile4}") -N "test" || exit 1 + "${testSubject}" -R "$(cat "${workFile4}")" -N "test" || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - "${testSubject}" -R $(cat "${workFile4}") -F "%e" || exit 1 + "${testSubject}" -R "$(cat "${workFile4}")" -F "%e" || exit 1 (usleep 200000 || sleep 1) 2>/dev/null - "${testSubject}" -R $(cat "${workFile4}") -N "." || exit 1 + "${testSubject}" -R "$(cat "${workFile4}")" -N "." || exit 1 (usleep 200000 || sleep 1) 2>/dev/null + echo "${loopCount}" >/dev/null # dummy for shellcheck done -"${testSubject}" -R $(cat "${workFile4}") -L 10M +"${testSubject}" -R "$(cat "${workFile4}")" -L 10M echo OK > "${workFile3}" ) & @@ -43,12 +42,20 @@ echo OK > "${workFile3}" "${testSubject}" -L 100k -i 0.1 -f -P "${workFile4}" "${workFile1}" > "${workFile2}" 2>/dev/null # Check our remote control calls ran OK. -BGSTATUS=$(cat "${workFile3}") -test "x$BGSTATUS" = "xOK" +backgroundStatus=$(cat "${workFile3}") +if ! test "${backgroundStatus}" = "OK"; then + echo "remote control calls failed" + exit 1 +fi # Check data integrity. -CKSUM1=$(cksum "${workFile1}" | awk '{print $1}') -CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') -test "x$CKSUM1" = "x$CKSUM2" +inputChecksum=$(cksum "${workFile1}" | awk '{print $1}') +outputChecksum=$(cksum "${workFile2}" | awk '{print $1}') +if ! test "${inputChecksum}" = "${outputChecksum}"; then + echo "input and output checksums differ" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Transfer_-_--remote.sh b/tests/Transfer_-_--remote.sh index 63e9315..efec0e2 100644 --- a/tests/Transfer_-_--remote.sh +++ b/tests/Transfer_-_--remote.sh @@ -10,9 +10,6 @@ fi 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="${workFile1}" bs=1024 count=10240 2>/dev/null @@ -27,6 +24,6 @@ sleep 2 # Make sure there is more than one length of line (excluding blank lines). line_lengths=$(tr '\r' '\n' < "${workFile3}" | awk '{print length($0)}' | grep -Fvx 0 | sort -n | uniq | wc -l) -test $line_lengths -gt 1 +test "${line_lengths}" -gt 1 # EOF diff --git a/tests/Transfer_-_--stop-at-size.sh b/tests/Transfer_-_--stop-at-size.sh index 404a2af..f59051c 100644 --- a/tests/Transfer_-_--stop-at-size.sh +++ b/tests/Transfer_-_--stop-at-size.sh @@ -2,8 +2,6 @@ # # Make sure -S stops at the given size. -rm -f "${workFile1}" "${workFile2}" 2>/dev/null - # exit on non-zero return codes set -e @@ -13,16 +11,12 @@ dd if=/dev/urandom of="${workFile1}" bs=1024 count=10 2>/dev/null # read through pv and test afterwards "${testSubject}" -S -s 5120 -q "${workFile1}" > "${workFile2}" -CKSUM2=$(cksum "${workFile2}" | awk '{print $1}') +outputChecksum=$(cksum "${workFile2}" | 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}') +inputChecksum=$(cksum "${workFile2}" | awk '{print $1}') -test "x$CKSUM1" = "x$CKSUM2" - -# clean up -rm -f "${workFile1}" "${workFile2}" 2>/dev/null +test "x${inputChecksum}" = "x${outputChecksum}" # EOF