mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
tests: cleanup background processes upon interruption
Reap background processes so that: - Stray processes aren't left on the system - Files aren't held open causing deletion issues on NFS - Partitions used to run the tests from can be unmounted * tests/tail-2/F-vs-missing.sh: Add the `kill && wait` of the background $pid(s) to cleanup_(). * tests/tail-2/F-vs-rename.sh: Likewise. * tests/tail-2/f-vs-rename.sh: Likewise. * tests/tail-2/append-only.sh: Likewise. * tests/tail-2/assert-2.sh: Likewise. * tests/tail-2/assert.sh: Likewise. * tests/tail-2/flush-initial.sh: Likewise. * tests/tail-2/inotify-hash-abuse.sh: Likewise. * tests/tail-2/inotify-hash-abuse2.sh: Likewise. * tests/tail-2/inotify-race.sh: Likewise. * tests/tail-2/inotify-rotate-resources.sh: Likewise. * tests/tail-2/inotify-rotate.sh: Likewise. * tests/tail-2/pid.sh: Likewise. * tests/tail-2/pipe-f2.sh: Likewise. * tests/tail-2/retry.sh: Likewise. * tests/tail-2/symlink.sh: Likewise. * tests/tail-2/tail-n0f.sh: Likewise. * tests/tail-2/wait.sh: Likewise. * tests/cp/existing-perm-race.sh: Likewise. * tests/cp/file-perm-race.sh: Likewise. * tests/cp/parent-perm-race.sh: Likewise. * tests/cp/sparse-to-pipe.sh: Likewise. * tests/dd/stats.sh: Likewise. * tests/du/move-dir-while-traversing.sh: Likewise. * tests/misc/cat-buf.sh: Likewise. * tests/misc/help-version.sh: Likewise. * tests/misc/printf-surprise.sh: Likewise. * tests/misc/sort-compress-proc.sh: Likewise. * tests/misc/sort-spinlock-abuse.sh: Likewise. * tests/misc/stdbuf.sh: Likewise. * tests/misc/tac-continue.sh: Likewise. * tests/misc/timeout-group.sh: Likewise. * tests/mv/i-3.sh: Likewise. * tests/rm/dangling-symlink.sh: Likewise. * tests/rm/isatty.sh: Likewise. * cfg.mk (sc_prohibit_test_background_without_cleanup_): A new syntax-check to ensure cleanup_() is defined when background tasks are created in a test.
This commit is contained in:
1 parent
fe02153e64
commit
9069f4ec85
36 files changed
+188
-96
No files matched your search
@@ -487,6 +487,13 @@ sc_prohibit_test_ulimit_without_require_:
|
||||
| sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
|
||||
" should match require_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || :
|
||||
|
||||
# Ensure that tests call the cleanup_ function if using background processes
|
||||
sc_prohibit_test_background_without_cleanup_:
|
||||
@(git grep -El '( &$$|&[^&]*=\$$!)' tests; \
|
||||
git grep -l 'cleanup_()' tests | sed p) \
|
||||
| sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\
|
||||
" should use cleanup_ for background processes" 1>&2; exit 1; } || :
|
||||
|
||||
# Ensure that tests call the print_ver_ function for programs which are
|
||||
# actually used in that test.
|
||||
sc_prohibit_test_calls_print_ver_with_irrelevant_argument:
|
||||
|
||||
@@ -37,10 +37,12 @@ chgrp $g1 fifo &&
|
||||
chgrp $g2 fifo-copy &&
|
||||
chmod g+r fifo-copy || framework-failure
|
||||
|
||||
# Terminate any background cp process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Copy a fifo's contents. That way, we can examine the
|
||||
# destination permissions before they're finalized.
|
||||
cp -p --copy-contents fifo fifo-copy &
|
||||
cp_pid=$!
|
||||
cp -p --copy-contents fifo fifo-copy & pid=$!
|
||||
|
||||
(
|
||||
# Now 'cp' is reading the fifo. Wait for the destination file to
|
||||
@@ -77,7 +79,7 @@ case $mode in
|
||||
*) fail=1;;
|
||||
esac
|
||||
|
||||
wait $cp_pid || fail=1
|
||||
wait $pid || fail=1
|
||||
|
||||
# Check that the final mode and group are right.
|
||||
ls -l -n fifo-copy >ls.out &&
|
||||
|
||||
@@ -25,10 +25,12 @@ require_local_dir_
|
||||
umask 022
|
||||
mkfifo_or_skip_ fifo
|
||||
|
||||
# Terminate any background cp process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Copy a fifo's contents. That way, we can examine the
|
||||
# destination permissions before they're finalized.
|
||||
cp -p --copy-contents fifo fifo-copy &
|
||||
cp_pid=$!
|
||||
cp -p --copy-contents fifo fifo-copy & pid=$!
|
||||
|
||||
(
|
||||
# Now 'cp' is reading the fifo. Wait for the destination file to
|
||||
@@ -51,6 +53,6 @@ case $(cat ls.out) in
|
||||
*) fail=1;;
|
||||
esac
|
||||
|
||||
wait $cp_pid || fail=1
|
||||
wait $pid || fail=1
|
||||
|
||||
Exit $fail
|
||||
@@ -26,6 +26,8 @@ umask 002
|
||||
mkdir mode ownership d || framework_failure_
|
||||
chmod g+s d 2>/dev/null # The cp test is valid either way.
|
||||
|
||||
# Terminate any background cp process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
for attr in mode ownership
|
||||
do
|
||||
@@ -33,8 +35,7 @@ do
|
||||
|
||||
# Copy a fifo's contents. That way, we can examine d/$attr's
|
||||
# state while cp is running.
|
||||
cp --preserve=$attr -R --copy-contents --parents $attr d &
|
||||
cp_pid=$!
|
||||
cp --preserve=$attr -R --copy-contents --parents $attr d & pid=$!
|
||||
|
||||
(
|
||||
# Now 'cp' is reading the fifo.
|
||||
@@ -58,7 +59,7 @@ do
|
||||
fail=1;;
|
||||
esac
|
||||
|
||||
wait $cp_pid || fail=1
|
||||
wait $pid || fail=1
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
@@ -21,14 +21,17 @@ print_ver_ cp
|
||||
|
||||
require_sparse_support_
|
||||
|
||||
# Terminate any background cp process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
mkfifo_or_skip_ pipe
|
||||
timeout 10 cat pipe > copy &
|
||||
timeout 10 cat pipe > copy & pid=$!
|
||||
|
||||
truncate -s1M sparse || framework_failure_
|
||||
cp sparse pipe || fail=1
|
||||
|
||||
# Ensure that the cat has completed before comparing.
|
||||
wait
|
||||
wait $pid
|
||||
|
||||
cmp sparse copy || fail=1
|
||||
|
||||
|
||||
+9
-1
@@ -28,6 +28,14 @@ trap '' $SIGINFO
|
||||
|
||||
mkfifo_or_skip_ fifo
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_()
|
||||
{
|
||||
kill $pid 2>/dev/null
|
||||
kill $pid2 2>/dev/null
|
||||
wait
|
||||
}
|
||||
|
||||
for open in '' '1'; do
|
||||
# Run dd with the fullblock iflag to avoid short reads
|
||||
# which can be triggered by reception of signals
|
||||
@@ -39,7 +47,7 @@ for open in '' '1'; do
|
||||
|
||||
# dd will block on open until fifo is opened for reading.
|
||||
# Timeout in case dd goes away erroneously which we check for below.
|
||||
timeout 10 sh -c 'wc -c < fifo > nwritten' &
|
||||
timeout 10 sh -c 'wc -c < fifo > nwritten' & pid2=$!
|
||||
|
||||
# Send lots of signals immediately to ensure dd not killed due
|
||||
# to race setting handler, or blocking on open of fifo.
|
||||
|
||||
@@ -71,10 +71,13 @@ for i in $(seq 50); do
|
||||
mkdir -p $t/3/a/b/c/$i/$long || framework_failure_
|
||||
done
|
||||
|
||||
# Terminate any background cp process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Prohibit suspension, which could otherwise cause a timeout-induced FP failure.
|
||||
trap '' TSTP
|
||||
|
||||
timeout 6 ./inotify-watch-for-dir-access.py $t/3/a/b > start-msg &
|
||||
timeout 6 ./inotify-watch-for-dir-access.py $t/3/a/b > start-msg & pid=$!
|
||||
|
||||
# Wait for the watcher to start...
|
||||
nonempty() { test -s start-msg || { sleep $1; return 1; }; }
|
||||
|
||||
@@ -26,6 +26,8 @@ print_ver_ cat
|
||||
# write separately.
|
||||
mkfifo_or_skip_ fifo
|
||||
|
||||
# Terminate any background cp process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
echo 1 > exp
|
||||
|
||||
@@ -33,9 +35,9 @@ cat_buf_1()
|
||||
{
|
||||
local delay="$1"
|
||||
|
||||
dd count=1 if=fifo > out &
|
||||
dd count=1 if=fifo > out & pid=$!
|
||||
(echo 1; sleep $delay; echo 2) | cat -v > fifo
|
||||
wait # for dd to complete
|
||||
wait $pid
|
||||
compare exp out
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ export SHELL
|
||||
|
||||
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
expected_failure_status_chroot=125
|
||||
expected_failure_status_env=125
|
||||
expected_failure_status_nice=125
|
||||
@@ -216,8 +219,8 @@ id_setup () { args=-u; }
|
||||
|
||||
# Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
|
||||
kill_setup () {
|
||||
env sleep 31.5 &
|
||||
args=$!
|
||||
env sleep 10m & pid=$!
|
||||
args=$pid
|
||||
}
|
||||
|
||||
link_setup () { args="$tmp_in link-target"; }
|
||||
|
||||
@@ -53,7 +53,10 @@ mkfifo_or_skip_ fifo
|
||||
# http://bugs.debian.org/481543#77
|
||||
export MALLOC_PERTURB_=0
|
||||
|
||||
head -c 10 fifo > out &
|
||||
# Terminate any background process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
head -c 10 fifo > out & pid=$!
|
||||
|
||||
# Choosing the virtual memory limit, 11000 is enough, but 10000 is too
|
||||
# little and provokes a "memory exhausted" diagnostic on FreeBSD 9.0-p3.
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
print_ver_ sort
|
||||
expensive_
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
SORT_FAILURE=2
|
||||
|
||||
seq -w 2000 > exp || fail=1
|
||||
@@ -63,7 +66,7 @@ done
|
||||
# Ignore a random child process created before 'sort' was exec'ed.
|
||||
# This bug was also present in coreutils 8.7.
|
||||
#
|
||||
( (sleep 1; exec false) &
|
||||
( (sleep 1; exec false) & pid=$!
|
||||
PRE_COMPRESS='test -f ok || sleep 2'
|
||||
POST_COMPRESS='touch ok'
|
||||
exec sort --compress-program=./compress -S 1k in >out
|
||||
|
||||
@@ -29,13 +29,16 @@ very_expensive_
|
||||
grep '^#define HAVE_PTHREAD_T 1' "$CONFIG_HEADER" > /dev/null ||
|
||||
skip_ 'requires pthreads'
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
seq 100000 > in || framework_failure_
|
||||
mkfifo_or_skip_ fifo
|
||||
|
||||
# Arrange for sort to require 8.0+ seconds of wall-clock time,
|
||||
# while actually using far less than 1 second of CPU time.
|
||||
(for i in $(seq 80); do read line; echo $i; sleep .1; done
|
||||
cat > /dev/null) < fifo &
|
||||
cat > /dev/null) < fifo & pid=$!
|
||||
|
||||
# However, under heavy load, it can easily take more than
|
||||
# one second of CPU time, so set a permissive limit:
|
||||
|
||||
@@ -58,15 +58,18 @@ test $? = 126 || fail=1
|
||||
stdbuf -o1 no_such # no such command
|
||||
test $? = 127 || fail=1
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Ensure line buffering stdout takes effect
|
||||
stdbuf_linebuffer()
|
||||
{
|
||||
local delay="$1"
|
||||
|
||||
printf '1\n' > exp
|
||||
dd count=1 if=fifo > out 2> err &
|
||||
dd count=1 if=fifo > out 2> err & pid=$!
|
||||
(printf '1\n'; sleep $delay; printf '2\n') | stdbuf -oL uniq > fifo
|
||||
wait # for dd to complete
|
||||
wait $pid
|
||||
compare exp out
|
||||
}
|
||||
|
||||
@@ -78,9 +81,9 @@ stdbuf_unbuffer()
|
||||
|
||||
# Ensure un buffering stdout takes effect
|
||||
printf '1\n' > exp
|
||||
dd count=1 if=fifo > out 2> err &
|
||||
dd count=1 if=fifo > out 2> err & pid=$!
|
||||
(printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o0 uniq > fifo
|
||||
wait # for dd to complete
|
||||
wait $pid
|
||||
compare exp out
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,13 @@ if ! test -d "$FULL_PARTITION_TMPDIR"; then
|
||||
fi
|
||||
|
||||
fp_tmp="$FULL_PARTITION_TMPDIR/tac-cont-$$"
|
||||
cleanup_() { rm -f "$fp_tmp"; }
|
||||
cleanup_()
|
||||
{
|
||||
# Terminate any background process
|
||||
# and remove tmp dir
|
||||
rm -f "$fp_tmp"
|
||||
kill $pid 2>/dev/null && wait $pid
|
||||
}
|
||||
|
||||
# Make sure we can create an empty file there (i.e., no shortage of inodes).
|
||||
if ! touch $fp_tmp; then
|
||||
@@ -54,7 +60,7 @@ seq 5 > in
|
||||
# Give tac a fifo command line argument.
|
||||
# This makes it try to create a temporary file in $TMPDIR.
|
||||
mkfifo_or_skip_ fifo
|
||||
seq 1000 > fifo &
|
||||
seq 1000 > fifo & pid=$!
|
||||
TMPDIR=$FULL_PARTITION_TMPDIR tac fifo in >out 2>err && fail=1
|
||||
|
||||
cat <<\EOF > exp || fail=1
|
||||
|
||||
@@ -57,15 +57,17 @@ check_timeout_cmd_running()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Start above script in its own group.
|
||||
# We could use timeout for this, but that assumes an implementation.
|
||||
setsid ./group.sh &
|
||||
setsid ./group.sh & pid=$!
|
||||
# Wait 6.3s for timeout.cmd to start
|
||||
retry_delay_ check_timeout_cmd_running .1 6 || fail=1
|
||||
# Simulate a Ctrl-C to the group to test timely exit
|
||||
# Note dash doesn't support signalling groups (a leading -)
|
||||
env kill -INT -- -$!
|
||||
env kill -INT -- -$pid
|
||||
wait
|
||||
test -e int.received || fail=1
|
||||
|
||||
@@ -82,8 +84,7 @@ start=$(date +%s)
|
||||
# Note the first timeout must send a signal that
|
||||
# the second is handling for it to be propagated to the command.
|
||||
# SIGINT, SIGTERM, SIGALRM etc. are implicit.
|
||||
timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20&
|
||||
pid=$!
|
||||
timeout -sALRM 30 timeout -sINT 25 ./timeout.cmd 20 & pid=$!
|
||||
# Wait 6.3s for timeout.cmd to start
|
||||
retry_delay_ check_timeout_cmd_running .1 6 || fail=1
|
||||
kill -ALRM $pid # trigger the alarm of the first timeout command
|
||||
|
||||
+4
-1
@@ -39,6 +39,9 @@ tty=$(readlink -f /dev/stdin)
|
||||
test -r "$tty" 2>&1 \
|
||||
|| skip_ '/dev/stdin is not readable'
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
mv f g < $tty > out 2>&1 & pid=$!
|
||||
|
||||
# Test for the expected prompt; sleep upon non-match.
|
||||
@@ -54,7 +57,7 @@ check_overwrite_prompt()
|
||||
# Wait for up to 12.7 seconds for the expected prompt.
|
||||
retry_delay_ check_overwrite_prompt .1 7 || { fail=1; cat out; }
|
||||
|
||||
kill $pid
|
||||
cleanup_
|
||||
|
||||
mv -f h i > out 2>&1 || fail=1
|
||||
test -f i || fail=1
|
||||
|
||||
@@ -25,9 +25,10 @@ print_ver_ rm
|
||||
ln -s no-file dangle
|
||||
ln -s / symlink
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
rm ---presume-input-tty dangle symlink &
|
||||
pid=$!
|
||||
rm ---presume-input-tty dangle symlink & pid=$!
|
||||
# The buggy rm (fileutils-4.1.9) would hang here, waiting for input.
|
||||
|
||||
# Wait up to 3.1s for rm to remove the files
|
||||
@@ -40,6 +41,6 @@ check_files_removed() {
|
||||
}
|
||||
retry_delay_ check_files_removed .1 5 || fail=1
|
||||
|
||||
kill $pid > /dev/null 2>&1
|
||||
cleanup_
|
||||
|
||||
Exit $fail
|
||||
+5
-3
@@ -25,10 +25,12 @@ skip_if_root_
|
||||
ls /dev/stdin >/dev/null 2>&1 \
|
||||
|| skip_ 'there is no /dev/stdin file'
|
||||
|
||||
# Terminate any background processes
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
touch f
|
||||
chmod 0 f
|
||||
rm ---presume-input-tty f > out 2>&1 &
|
||||
pid=$!
|
||||
rm ---presume-input-tty f > out 2>&1 & pid=$!
|
||||
|
||||
# Wait a second, to give a buggy rm (as in fileutils-4.0.40)
|
||||
# enough time to remove the file.
|
||||
@@ -37,7 +39,7 @@ sleep 1
|
||||
# The file must still exist.
|
||||
test -f f || fail=1
|
||||
|
||||
kill $pid > /dev/null 2>&1
|
||||
cleanup_
|
||||
|
||||
# Note the trailing 'x' -- so I don't have to have a trailing
|
||||
# blank in this file :-)
|
||||
|
||||
@@ -28,6 +28,9 @@ check_tail_output()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -49,9 +52,7 @@ for mode in '' '---disable-inotify'; do
|
||||
tail_re='has appeared' retry_delay_ check_tail_output .1 7 ||
|
||||
{ echo "$0: file: unexpected delay?"; cat out; fail=1; }
|
||||
|
||||
kill $pid
|
||||
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ check_tail_output()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -74,9 +77,7 @@ for mode in '' '---disable-inotify'; do
|
||||
retry_delay_ tail_f_vs_rename_3 .1 7 ||
|
||||
{ echo "$0: a: unexpected delay?"; cat out; fail=1; }
|
||||
|
||||
kill $pid
|
||||
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
@@ -21,6 +21,9 @@
|
||||
print_ver_ tail
|
||||
require_root_
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
chattr_a_works=1
|
||||
touch f
|
||||
chattr +a f 2>/dev/null || chattr_a_works=0
|
||||
@@ -35,6 +38,7 @@ fi
|
||||
for mode in '' '---disable-inotify'; do
|
||||
sleep 1 & pid=$!
|
||||
tail --pid=$pid -f $mode f || fail=1
|
||||
cleanup_
|
||||
done
|
||||
|
||||
chattr -a f 2>/dev/null
|
||||
|
||||
@@ -28,10 +28,12 @@ check_tail_output()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
|
||||
for mode in '' '---disable-inotify'; do
|
||||
rm -f a foo out
|
||||
touch a || framework_failure_
|
||||
@@ -41,16 +43,15 @@ for mode in '' '---disable-inotify'; do
|
||||
# Wait up to 12.7s for tail to start.
|
||||
echo x > a || framework_failure_
|
||||
tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
|
||||
{ cat out; fail=1; }
|
||||
{ cat out; fail=1; break; }
|
||||
|
||||
# Wait up to 12.7s for tail to notice new foo file
|
||||
ok='ok ok ok'
|
||||
echo "$ok" > foo || framework_failure_
|
||||
tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
|
||||
{ echo "$0: foo: unexpected delay?"; cat out; fail=1; }
|
||||
{ echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
|
||||
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
@@ -33,10 +33,12 @@ check_tail_output()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
|
||||
for mode in '' '---disable-inotify'; do
|
||||
rm -f a foo out
|
||||
touch a foo || framework_failure_
|
||||
@@ -46,22 +48,21 @@ for mode in '' '---disable-inotify'; do
|
||||
# Wait up to 12.7s for tail to start.
|
||||
echo x > a || framework_failure_
|
||||
tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
|
||||
{ cat out; fail=1; }
|
||||
{ cat out; fail=1; break; }
|
||||
|
||||
# Wait 12.7s for this diagnostic:
|
||||
# tail: foo: No such file or directory
|
||||
rm foo || framework_failure_
|
||||
tail_re='No such file' retry_delay_ check_tail_output .1 7 ||
|
||||
{ cat out; fail=1; }
|
||||
{ cat out; fail=1; break; }
|
||||
|
||||
# Wait up to 12.7s for tail to notice new foo file
|
||||
ok='ok ok ok'
|
||||
echo "$ok" > foo || framework_failure_
|
||||
tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
|
||||
{ echo "$0: foo: unexpected delay?"; cat out; fail=1; }
|
||||
{ echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
|
||||
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
@@ -28,6 +28,9 @@ check_tail_output()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -47,9 +50,7 @@ for mode in '' '---disable-inotify'; do
|
||||
# Wait up to 12.7s for "y" to appear in the output:
|
||||
tail_re='^y$' retry_delay_ check_tail_output .1 7 || { cat out; fail=1; }
|
||||
|
||||
kill $pid
|
||||
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
@@ -22,10 +22,13 @@ print_ver_ tail
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
echo line > in || framework_failure_
|
||||
# Output should be buffered since we're writing to file
|
||||
# so we're depending on the flush to write out
|
||||
tail $fastpoll -f in > out & tail_pid=$!
|
||||
tail $fastpoll -f in > out & pid=$!
|
||||
|
||||
# Wait for 3.1s for the file to be flushed.
|
||||
tail_flush()
|
||||
@@ -37,8 +40,6 @@ tail_flush()
|
||||
}
|
||||
retry_delay_ tail_flush .1 5 || fail=1
|
||||
|
||||
kill $tail_pid
|
||||
|
||||
wait $tail_pid
|
||||
cleanup_
|
||||
|
||||
Exit $fail
|
||||
@@ -30,6 +30,9 @@ check_tail_output()
|
||||
{ sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -58,10 +61,10 @@ for mode in '' '---disable-inotify'; do
|
||||
tail_re='has appeared' retry_delay_ check_tail_output .1 6 ||
|
||||
{ cat out; fail=1; }
|
||||
|
||||
# Kill the working tail, or fail if it has already aborted
|
||||
kill $pid || fail=1
|
||||
# Double check that tail hasn't aborted
|
||||
kill -0 $pid || fail=1
|
||||
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
||||
print_ver_ tail
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -34,10 +37,10 @@ for mode in '' '---disable-inotify'; do
|
||||
touch f
|
||||
done
|
||||
|
||||
# Kill the working tail, or fail if it has already aborted
|
||||
kill $pid || fail=1
|
||||
# Ensure tail hasn't aborted
|
||||
kill -0 $pid || fail=1
|
||||
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
Exit $fail
|
||||
@@ -23,6 +23,12 @@
|
||||
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
||||
print_ver_ tail
|
||||
|
||||
# Terminate any background gdb/tail process
|
||||
cleanup_() {
|
||||
kill $pid 2>/dev/null && wait $pid
|
||||
kill $sleep 2>/dev/null && wait $sleep
|
||||
}
|
||||
|
||||
touch file || framework_failure_
|
||||
touch tail.out || framework_failure_
|
||||
|
||||
@@ -75,8 +81,7 @@ gdb -nx --batch-silent \
|
||||
--eval-command='shell echo never-seen-with-tail-7.5 >> file' \
|
||||
--eval-command='continue' \
|
||||
--eval-command='quit' \
|
||||
tail < /dev/null > /dev/null 2>&1 &
|
||||
pid=$!
|
||||
tail < /dev/null > /dev/null 2>&1 & pid=$!
|
||||
|
||||
tail --pid=$pid -f tail.out | (read; kill $pid)
|
||||
|
||||
|
||||
@@ -48,13 +48,17 @@ cleanup_fail()
|
||||
fail=1
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
# Normally less than a second is required here, but with heavy load
|
||||
# and a lot of disk activity, even 20 seconds per grep_timeout is insufficient,
|
||||
# which leads to this timeout (used as a safety net for cleanup)
|
||||
# killing tail before processing is completed.
|
||||
touch k || framework_failure_
|
||||
|
||||
# Note the timeout guard isn't strictly necessary here,
|
||||
# however without it strace will ignore SIGTERM.
|
||||
# strace does always honor SIGTERM with the -I2 option,
|
||||
# though that's not available on RHEL6 for example.
|
||||
timeout 180 strace -e inotify_rm_watch -o strace.out \
|
||||
tail -F $fastpoll k >> out 2>&1 & pid=$!
|
||||
|
||||
@@ -92,7 +96,7 @@ for i in $(seq 2); do
|
||||
done
|
||||
|
||||
test "$reverted_to_polling_" = 1 && skip_ 'inotify resources already depleted'
|
||||
kill $pid
|
||||
wait $pid
|
||||
|
||||
cleanup_
|
||||
|
||||
Exit $fail
|
||||
@@ -32,11 +32,14 @@ check_tail_output()
|
||||
# Wait up to 25.5 seconds for grep REGEXP 'out' to succeed.
|
||||
grep_timeout() { tail_re="$1" retry_delay_ check_tail_output .1 8; }
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
cleanup_fail()
|
||||
{
|
||||
cat out
|
||||
warn_ $1
|
||||
kill $pid
|
||||
cleanup_
|
||||
fail=1
|
||||
}
|
||||
|
||||
@@ -68,8 +71,7 @@ for i in $(seq 50); do
|
||||
# wait for "ok" to appear in 'out'
|
||||
grep_timeout 'ok' || { cleanup_fail 'failed to detect echoed ok'; break; }
|
||||
|
||||
kill $pid
|
||||
cleanup_
|
||||
done
|
||||
|
||||
wait
|
||||
Exit $fail
|
||||
+3
-3
@@ -22,6 +22,8 @@ getlimits_
|
||||
|
||||
touch empty here || framework_failure_
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
for mode in '' '---disable-inotify'; do
|
||||
# Use tail itself to create a background process to monitor,
|
||||
@@ -32,9 +34,7 @@ for mode in '' '---disable-inotify'; do
|
||||
timeout 1 tail -f -s.1 --pid=$pid $mode here
|
||||
test $? = 124 || fail=1
|
||||
|
||||
# Cleanup background process
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
|
||||
# Ensure that tail --pid=PID exits with success status when PID is dead.
|
||||
# Use an unlikely-to-be-live PID
|
||||
|
||||
@@ -24,6 +24,9 @@ mkfifo_or_skip_ fifo
|
||||
echo 1 > fifo &
|
||||
echo 1 > exp || framework_failure_
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -40,9 +43,9 @@ retry_delay_ check_tail_output .1 7 || fail=1
|
||||
|
||||
compare exp out || fail=1
|
||||
|
||||
# Kill the still-running tail, or fail if it's gone.
|
||||
kill $pid || fail=1
|
||||
# Ensure tail is still running
|
||||
kill -0 $pid || fail=1
|
||||
|
||||
wait $pid
|
||||
cleanup_
|
||||
|
||||
Exit $fail
|
||||
@@ -36,6 +36,9 @@ wait4lines_ ()
|
||||
[ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# Speedup the non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -62,8 +65,7 @@ retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; }
|
||||
echo "X" > missing || framework_failure_
|
||||
# Wait for the expected output.
|
||||
retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; }
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
# Expect 3 lines in the output file.
|
||||
[ "$(countlines_)" = 3 ] || { fail=1; cat out; }
|
||||
grep -F 'cannot open' out || { fail=1; cat out; }
|
||||
@@ -80,8 +82,7 @@ retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; }
|
||||
echo "X" > missing || framework_failure_
|
||||
# Wait for the expected output.
|
||||
retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; }
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
# Expect 4 lines in the output file.
|
||||
[ "$(countlines_)" = 4 ] || { fail=1; cat out; }
|
||||
grep -F 'retry only effective for the initial open' out \
|
||||
|
||||
@@ -36,6 +36,9 @@ wait4lines_ ()
|
||||
[ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; }
|
||||
}
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# speedup non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -50,8 +53,7 @@ retry_delay_ wait4lines_ .1 6 1 || { cat out; fail=1; }
|
||||
echo "X" > target || framework_failure_
|
||||
# Wait for the expected output.
|
||||
retry_delay_ wait4lines_ .1 6 3 || { cat out; fail=1; }
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
# Expect 3 lines in the output file.
|
||||
[ "$(countlines_)" = 3 ] || { fail=1; cat out; }
|
||||
grep -F 'cannot open' out || { fail=1; cat out; }
|
||||
@@ -74,8 +76,7 @@ retry_delay_ wait4lines_ .1 6 2 || { cat out; fail=1; }
|
||||
echo "X2" > target2 || framework_failure_
|
||||
# Wait for the expected output.
|
||||
retry_delay_ wait4lines_ .1 6 4 || { cat out; fail=1; }
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
# Expect 4 lines in the output file.
|
||||
[ "$(countlines_)" = 4 ] || { fail=1; cat out; }
|
||||
grep -F 'become inacce' out || { fail=1; cat out; }
|
||||
|
||||
@@ -35,6 +35,9 @@ chmod 0 unreadable || framework_failure_
|
||||
tail -c0 unreadable || fail=1
|
||||
tail -n0 unreadable || fail=1
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
for mode in '' '---disable-inotify'; do
|
||||
for file in empty nonempty; do
|
||||
for c_or_n in c n; do
|
||||
@@ -51,8 +54,7 @@ for mode in '' '---disable-inotify'; do
|
||||
# Wait up to 1.5s for tail to sleep
|
||||
retry_delay_ tail_sleeping .1 4 ||
|
||||
{ echo $0: process in unexpected state: $state >&2; fail=1; }
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
@@ -23,6 +23,9 @@ print_ver_ tail
|
||||
touch here || framework_failure_
|
||||
{ touch unreadable && chmod a-r unreadable; } || framework_failure_
|
||||
|
||||
# Terminate any background tail process
|
||||
cleanup_() { kill $pid 2>/dev/null && wait $pid; }
|
||||
|
||||
# speedup non inotify case
|
||||
fastpoll='-s.1 --max-unchanged-stats=1'
|
||||
|
||||
@@ -72,8 +75,7 @@ for mode in '' '---disable-inotify'; do
|
||||
sleep $delay
|
||||
echo NO >> l
|
||||
sleep $delay
|
||||
kill $pid
|
||||
wait $pid
|
||||
cleanup_
|
||||
rm -f k l
|
||||
|
||||
test -s tail.out
|
||||
|
||||
Reference in new issue
Block a user