#!/bin/sh # # Check that watching a single file descriptor works as expected. # 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'}" true "${workFile2:?not set - call this from 'make check'}" true "${workFile3:?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. # We only start doing anything once the PV process below has started (the # workFile3 check). # NB we just export line to make shellcheck think it's used. true > "${workFile3}" ( while test -e "${workFile3}" && ! test -s "${workFile3}"; do sleep 0.1; done export line; sleep 1; read -r line; sleep 1; read -r line; sleep 1 ) <"${workFile1}" & pid=$! sleep 0.1 "${testSubject}" -P "${workFile3}" -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