1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/bin/sh
#
# Check that numeric output gives a byte count instead of a percentage when
# used with -b.
# 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'}"
# 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 >6 and <13, and the final byte count
# should be 500.
#
if ! test "${lineCount}" -gt 6; then
echo "fewer than 7 output lines (${lineCount}):"
cat "${workFile1}"
exit 1
fi
if ! test "${lineCount}" -lt 13; then
echo "more than 12 output lines (${lineCount}):"
cat "${workFile1}"
exit 1
fi
if ! test "${finalLine}" = "500"; then
echo "final byte count was not 500 (${finalLine}):"
cat "${workFile1}"
exit 1
fi
|