Files
pv/tests/Watchfd_-_Single_descriptor.test
T

44 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
#
# Check that watching a single file descriptor works as expected.
true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
true "${workFile2:?not set - call this from 'make check'}"
# Skip the test if "-d" is not available.
if ! "${testSubject}" -h | grep -Fq ' -d'; then
echo "no \`--watchfd' / \`-d' option on this platform"
exit 77
fi
seq 1 100 > "${workFile1}"
# Run a background process to perform a few reads from a file.
# NB we just export line to make shellcheck think it's used.
(export line; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" &
pid=$!
sleep 0.1
"${testSubject}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>"${workFile2}"
# Skip the test if "-d" does not work.
if grep -Fq ' -d: not available' "${workFile2}"; then
echo "no \`--watchfd' / \`-d' option on this platform"
exit 77
fi
# There should be at least 2 different numbers starting the output lines.
positionsReported="$(tr '\r' '\n' < "${workFile2}" | awk '{print $1}' | sort -n | uniq)"
differentNumbers="$(printf "%s\n" "${positionsReported}" | grep -Ec .)"
if ! test "${differentNumbers}" -gt 1; then
printf "%s\n" "Expected at least 2 different numbers to be output"
printf "%s:\n%s\n" "Positions reported" "${positionsReported}"
printf "%s: %s\n" "Number of different values seen" "${differentNumbers}"
printf "%s\n" "Raw output:"
tr '\r' '\n' < "${workFile2}"
exit 1
fi
exit 0