summaryrefslogtreecommitdiff
path: root/tests/tail-2/inotify-rotate.sh
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2015-07-04 17:13:50 +0300
committerIgor Pashev <pashev.igor@gmail.com>2015-07-04 17:13:50 +0300
commit71cd8e3a743046573744123777061b64881bf372 (patch)
tree82522befe647f4fff186a5630cad0cad33f8ef53 /tests/tail-2/inotify-rotate.sh
parentc18578632fd3c9e513e613a86ba2b7c4ebee6c45 (diff)
downloadcoreutils-upstream.tar.gz
Imported Upstream version 8.24upstream/8.24upstream
Diffstat (limited to 'tests/tail-2/inotify-rotate.sh')
-rwxr-xr-xtests/tail-2/inotify-rotate.sh73
1 files changed, 40 insertions, 33 deletions
diff --git a/tests/tail-2/inotify-rotate.sh b/tests/tail-2/inotify-rotate.sh
index 1c942cc3..638a3bbb 100755
--- a/tests/tail-2/inotify-rotate.sh
+++ b/tests/tail-2/inotify-rotate.sh
@@ -1,7 +1,7 @@
#!/bin/sh
# ensure that tail -F handles rotation
-# Copyright (C) 2009-2014 Free Software Foundation, Inc.
+# Copyright (C) 2009-2015 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,55 +16,62 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-if test "$VERBOSE" = yes; then
- set -x
- tail --version
-fi
-
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
-expensive_
+print_ver_ tail
+
+grep '^#define HAVE_INOTIFY 1' "$CONFIG_HEADER" >/dev/null \
+ || expensive_
+
+check_tail_output()
+{
+ local delay="$1"
+ grep "$tail_re" out > /dev/null ||
+ { sleep $delay; return 1; }
+}
+
+# Wait up to 25.5 seconds for grep REGEXP 'out' to succeed.
+grep_timeout() { tail_re="$1" retry_delay_ check_tail_output .1 8; }
-# Wait several seconds for grep REGEXP FILE to succeed.
-# Usage: grep_timeout REGEXP FILE
-grep_timeout()
+# Terminate any background tail process
+cleanup_() { kill $pid 2>/dev/null && wait $pid; }
+
+cleanup_fail()
{
- local j
- for j in $(seq 150); do
- grep $1 $2 > /dev/null && return 0
- sleep 0.1
- done
- return 1
+ cat out
+ warn_ $1
+ cleanup_
+ fail=1
}
-# For details, see
-# http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html
+# Speedup the non inotify case
+fastpoll='-s.1 --max-unchanged-stats=1'
# Perform at least this many iterations, because on multi-core systems
# the offending sequence of events can be surprisingly uncommon.
+# See: http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html
for i in $(seq 50); do
echo $i
- rm -rf k x out
+ rm -f k x out
+
# Normally less than a second is required here, but with heavy load
# and a lot of disk activity, even 20 seconds is insufficient, which
# leads to this timeout killing tail before the "ok" is written below.
>k && >x || framework_failure_ failed to initialize files
- timeout 40 tail -F k > out 2>&1 &
- pid=$!
- sleep .1
- echo b > k;
- # wait for b to appear in out
- grep_timeout b out || fail_ failed to find b in out
- while :; do grep b out > /dev/null && break; done
+ timeout 60 tail $fastpoll -F k > out 2>&1 & pid=$!
+
+ echo 'tailed' > k;
+ # wait for 'tailed' to appear in out
+ grep_timeout 'tailed' || { cleanup_fail 'failed to find "tailed"'; break; }
+
mv x k
# wait for tail to detect the rename
- grep_timeout tail: out || { cat out; fail_ failed to detect rename; }
+ grep_timeout 'tail:' || { cleanup_fail 'failed to detect rename'; break; }
+
echo ok >> k
- found=0
- # wait up to 10 seconds for "ok" to appear in out
- grep_timeout ok out && found=1
- kill $pid
- test $found = 0 && { cat out; fail_ failed to detect echoed '"ok"'; }
+ # wait for "ok" to appear in 'out'
+ grep_timeout 'ok' || { cleanup_fail 'failed to detect echoed ok'; break; }
+
+ cleanup_
done
-wait
Exit $fail