Files
pv/tests/Display_-_--rate_-_displayed_value_changes.test
T

33 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
#
# Check that the transfer rate counter changes.
# Allow all tests to be skipped, e.g. during a release build
test "${SKIP_ALL_TESTS}" = "1" && exit 77
true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
# 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;
sleep 2;
dd if=/dev/zero bs=100 count=1 2>/dev/null;
) | "${testSubject}" -f -i 0.5 -r >/dev/null 2>"${workFile1}"
# Count the number of different rates output.
#
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).
#
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