From 6a24d75022d20c1640c52c0e2ef29b0bcc19c27e Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 23 Jul 2023 18:45:53 +0100 Subject: [PATCH] Add more verbose output and apply fixes suggested by shellcheck. --- tests/Modifiers_-_--interval.sh | 13 +++++++++++-- tests/Transfer_-_--rate-limit.sh | 14 +++++++++++--- tests/Transfer_-_--remote.sh | 19 +++++++++++++------ tests/Transfer_-_--stop-at-size.sh | 11 ++++++++--- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/tests/Modifiers_-_--interval.sh b/tests/Modifiers_-_--interval.sh index 974a24e..ba2c9b5 100644 --- a/tests/Modifiers_-_--interval.sh +++ b/tests/Modifiers_-_--interval.sh @@ -2,11 +2,20 @@ # # Check that the update interval can be set. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}"; workFile1="${workFile1:-.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' < "${workFile1}" | wc -l | tr -d ' ') -test $NUM -gt 6 +lineCount=$(tr '\r' '\n' < "${workFile1}" | wc -l | tr -dc '0-9') +if ! test "${lineCount}" -gt 6; then + echo "fewer than 7 lines of output" + tr '\r' '\n' < "${workFile1}" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Transfer_-_--rate-limit.sh b/tests/Transfer_-_--rate-limit.sh index 1eb4fe4..6dbe2ee 100644 --- a/tests/Transfer_-_--rate-limit.sh +++ b/tests/Transfer_-_--rate-limit.sh @@ -2,12 +2,20 @@ # # A simple test of rate limiting. +# Dummy assignments for "shellcheck". +testSubject="${testSubject:-false}" + # Transfer 102 bytes at 100 bytes/sec. It should take at least 1 second. # -START=$(date +%S) +startTime=$(date +%S) dd if=/dev/zero bs=102 count=1 2>/dev/null | "${testSubject}" -L 100 2>/dev/null | cat >/dev/null -END=$(date +%S) +endTime=$(date +%S) -test $START -ne $END +if test "${startTime}" = "${endTime}"; then + echo "transfer took zero seconds" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Transfer_-_--remote.sh b/tests/Transfer_-_--remote.sh index efec0e2..a1f2e68 100644 --- a/tests/Transfer_-_--remote.sh +++ b/tests/Transfer_-_--remote.sh @@ -2,28 +2,35 @@ # # Try changing the format of a transfer remotely. +# 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 - # Generate an empty test file. dd if=/dev/zero of="${workFile1}" bs=1024 count=10240 2>/dev/null ( sleep 1 -"${testSubject}" -R $(cat "${workFile4}") -a +"${testSubject}" -R "$(cat "${workFile4}")" -a sleep 2 -"${testSubject}" -R $(cat "${workFile4}") -L 10M +"${testSubject}" -R "$(cat "${workFile4}")" -L 10M ) & "${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' < "${workFile3}" | awk '{print length($0)}' | grep -Fvx 0 | sort -n | uniq | wc -l) -test "${line_lengths}" -gt 1 +line_lengths=$(tr '\r' '\n' < "${workFile3}" | awk '{print length($0)}' | grep -Fvx 0 | sort -n | uniq | wc -l | tr -dc '0-9') + +if ! test "${line_lengths}" -gt 1; then + echo "only one line length seen - format change failed" + exit 1 +fi + +exit 0 # EOF diff --git a/tests/Transfer_-_--stop-at-size.sh b/tests/Transfer_-_--stop-at-size.sh index f59051c..cebf639 100644 --- a/tests/Transfer_-_--stop-at-size.sh +++ b/tests/Transfer_-_--stop-at-size.sh @@ -2,8 +2,8 @@ # # Make sure -S stops at the given size. -# 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=10 2>/dev/null @@ -17,6 +17,11 @@ outputChecksum=$(cksum "${workFile2}" | awk '{print $1}') dd if="${workFile1}" of="${workFile2}" bs=1024 count=5 2>/dev/null inputChecksum=$(cksum "${workFile2}" | awk '{print $1}') -test "x${inputChecksum}" = "x${outputChecksum}" +if ! test "${inputChecksum}" = "${outputChecksum}"; then + echo "input and output checksums differ" + exit 1 +fi + +exit 0 # EOF