summaryrefslogtreecommitdiff
path: root/tests/misc
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2015-05-01 05:26:38 +0100
committerPádraig Brady <P@draigBrady.com>2015-05-11 23:02:16 +0100
commit9069f4ec850364e778c51bfa6f1ab761be67caec (patch)
tree3a05bcfa1d13c50992281bb786d99e07658f4664 /tests/misc
parentfe02153e6475ae52f90cfccae1d1ba24baf35f9c (diff)
downloadcoreutils-9069f4ec850364e778c51bfa6f1ab761be67caec.tar.xz
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.
Diffstat (limited to 'tests/misc')
-rwxr-xr-xtests/misc/cat-buf.sh6
-rwxr-xr-xtests/misc/help-version.sh7
-rwxr-xr-xtests/misc/printf-surprise.sh5
-rwxr-xr-xtests/misc/sort-compress-proc.sh5
-rwxr-xr-xtests/misc/sort-spinlock-abuse.sh5
-rwxr-xr-xtests/misc/stdbuf.sh11
-rwxr-xr-xtests/misc/tac-continue.sh10
-rwxr-xr-xtests/misc/timeout-group.sh9
8 files changed, 41 insertions, 17 deletions
diff --git a/tests/misc/cat-buf.sh b/tests/misc/cat-buf.sh
index 68be86e1a..31382481a 100755
--- a/tests/misc/cat-buf.sh
+++ b/tests/misc/cat-buf.sh
@@ -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
}
diff --git a/tests/misc/help-version.sh b/tests/misc/help-version.sh
index 64d6e1642..e0dd721f9 100755
--- a/tests/misc/help-version.sh
+++ b/tests/misc/help-version.sh
@@ -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"; }
diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh
index 0af64482d..20e6b0988 100755
--- a/tests/misc/printf-surprise.sh
+++ b/tests/misc/printf-surprise.sh
@@ -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.
diff --git a/tests/misc/sort-compress-proc.sh b/tests/misc/sort-compress-proc.sh
index a191a3c51..4ad42d514 100755
--- a/tests/misc/sort-compress-proc.sh
+++ b/tests/misc/sort-compress-proc.sh
@@ -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
diff --git a/tests/misc/sort-spinlock-abuse.sh b/tests/misc/sort-spinlock-abuse.sh
index 31c5aa200..e81abf801 100755
--- a/tests/misc/sort-spinlock-abuse.sh
+++ b/tests/misc/sort-spinlock-abuse.sh
@@ -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:
diff --git a/tests/misc/stdbuf.sh b/tests/misc/stdbuf.sh
index bb1d40ca5..428d4a2f1 100755
--- a/tests/misc/stdbuf.sh
+++ b/tests/misc/stdbuf.sh
@@ -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
}
diff --git a/tests/misc/tac-continue.sh b/tests/misc/tac-continue.sh
index 9078cd58d..1389072b4 100755
--- a/tests/misc/tac-continue.sh
+++ b/tests/misc/tac-continue.sh
@@ -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
diff --git a/tests/misc/timeout-group.sh b/tests/misc/timeout-group.sh
index 77682920b..054c5aec6 100755
--- a/tests/misc/timeout-group.sh
+++ b/tests/misc/timeout-group.sh
@@ -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