From 4f58a3d751f8d9742383d4d9f439c805e4923ba7 Mon Sep 17 00:00:00 2001 From: Andrew Wood Date: Sun, 15 Dec 2024 13:36:14 +0000 Subject: [PATCH] Make background test processes wait for their subsequent foreground PV to start, to make a race condition less likely to trigger test failures on slower systems. --- tests/Integrity_-_When_adjusted_remotely.test | 5 ++++- tests/Memory_safety_-_Watchfd.test | 10 +++++++--- tests/Transfer_-_--remote.test | 5 ++++- tests/Watchfd_-_Multiple_descriptors.test | 11 ++++++++--- tests/Watchfd_-_Single_descriptor.test | 11 +++++++++-- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/Integrity_-_When_adjusted_remotely.test b/tests/Integrity_-_When_adjusted_remotely.test index f48a252..de92e5a 100755 --- a/tests/Integrity_-_When_adjusted_remotely.test +++ b/tests/Integrity_-_When_adjusted_remotely.test @@ -18,14 +18,17 @@ if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then exit 77 fi -# Generate some data. +# Generate 10MiB of data. dd if=/dev/urandom of="${workFile1}" bs=1024 count=10240 2>/dev/null # Run a few remote control commands in the background. # echo FAIL > "${workFile3}" +true > "${workFile4}" ( set +e +# Don't start doing anything until the main transfer process, started below, has begun. +while ! test -s "${workFile4}"; do sleep 0.1; done sleep 2 for loopCount in 1 2 3; do "${testSubject}" -R "$(cat "${workFile4}")" -apterb || exit 1 diff --git a/tests/Memory_safety_-_Watchfd.test b/tests/Memory_safety_-_Watchfd.test index d8d91b4..f5f1c4e 100755 --- a/tests/Memory_safety_-_Watchfd.test +++ b/tests/Memory_safety_-_Watchfd.test @@ -24,6 +24,7 @@ fi # Skip the test if "-d" does not work. sleep 2 & +pid=$! sleep 0.1 "${testSubject}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile1}" if grep -Fq ' -d: not available' "${workFile1}"; then @@ -34,17 +35,20 @@ fi # Check "--watchfd PID:FD". # See the "Watchfd" tests for more detail. seq 1 100 > "${workFile1}" +true > "${workFile3}" # shellcheck disable=SC2030 -(sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" & +(while ! test -s "${workFile3}"; do sleep 0.1; done; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" & pid=$! sleep 0.1 -{ runWithValgrind -d "${pid}:0" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1 +{ runWithValgrind -P "${workFile3}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1 # Check "--watchfd PID". seq 1 100 > "${workFile1}" seq 1 300 > "${workFile2}" +true > "${workFile3}" # shellcheck disable=SC2030 ( +while ! test -s "${workFile3}"; do sleep 0.1; done sleep 1 read -r line exec 9<"${workFile2}" @@ -59,6 +63,6 @@ sleep 1 ) <"${workFile1}" & pid=$! sleep 0.1 -{ runWithValgrind -d "${pid}" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1 +{ runWithValgrind -P "${workFile3}" -d "${pid}" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1 exit 0 diff --git a/tests/Transfer_-_--remote.test b/tests/Transfer_-_--remote.test index f11088a..93d52b3 100755 --- a/tests/Transfer_-_--remote.test +++ b/tests/Transfer_-_--remote.test @@ -17,10 +17,13 @@ if ! "${testSubject}" -h 2>/dev/null | grep -Eq "^ -R,"; then exit 77 fi -# Generate an empty test file. +# Generate a 10MiB test file of null bytes. dd if=/dev/zero of="${workFile1}" bs=1024 count=10240 2>/dev/null +true > "${workFile4}" ( +# Don't start doing anything until the main transfer process, started below, has begun. +while ! test -s "${workFile4}"; do sleep 0.1; done sleep 1 "${testSubject}" -R "$(cat "${workFile4}")" -a sleep 2 diff --git a/tests/Watchfd_-_Multiple_descriptors.test b/tests/Watchfd_-_Multiple_descriptors.test index 284a90d..fe8e27e 100755 --- a/tests/Watchfd_-_Multiple_descriptors.test +++ b/tests/Watchfd_-_Multiple_descriptors.test @@ -9,6 +9,7 @@ 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'}" +true "${workFile4:?not set - call this from 'make check'}" # Skip the test if "-d" is not available. if ! "${testSubject}" -h | grep -Fq ' -d'; then @@ -21,8 +22,12 @@ seq 1 300 > "${workFile2}" # Run a background process to perform a few reads from a file, opening a # second file after a moment. +# 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 -s "${workFile3}"; do sleep 0.1; done export line sleep 1 read -r line @@ -34,17 +39,17 @@ sleep 1 pid=$! sleep 0.1 -"${testSubject}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile3}" +"${testSubject}" -P "${workFile3}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile4}" # Skip the test if "-d" does not work. -if grep -Fq ' -d: not available' "${workFile3}"; then +if grep -Fq ' -d: not available' "${workFile4}"; then echo "no \`--watchfd' / \`-d' option on this platform" exit 77 fi # Process the output to make it easier to handle. # NB "ESC [ A" is "cursor up", we turn that into "-" and a newline. -tr '\r' '\n' < "${workFile3}" | sed 's/.\[A/-!/g' | tr '!' '\n' > "${workFile1}" +tr '\r' '\n' < "${workFile4}" | sed 's/.\[A/-!/g' | tr '!' '\n' > "${workFile1}" # We should see at least 2 file positions for fd 0. positionsReported="$(awk '/^ *0:/ {print $2}' < "${workFile1}" | sort -n | uniq)" diff --git a/tests/Watchfd_-_Single_descriptor.test b/tests/Watchfd_-_Single_descriptor.test index 44b5cfa..a27dcc4 100755 --- a/tests/Watchfd_-_Single_descriptor.test +++ b/tests/Watchfd_-_Single_descriptor.test @@ -8,6 +8,7 @@ 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 @@ -18,12 +19,18 @@ 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. -(export line; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" & +true > "${workFile3}" +( +while ! 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}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>"${workFile2}" +"${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