From 974ab3dd887985e3aa347f3c6521f819296396a0 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sat, 16 Feb 2013 14:42:43 +0000 Subject: Imported Upstream version 8.21 --- tests/tail-2/F-vs-missing | 64 ----------------------------- tests/tail-2/F-vs-missing.sh | 64 +++++++++++++++++++++++++++++ tests/tail-2/F-vs-rename | 75 ---------------------------------- tests/tail-2/F-vs-rename.sh | 75 ++++++++++++++++++++++++++++++++++ tests/tail-2/append-only | 43 -------------------- tests/tail-2/append-only.sh | 43 ++++++++++++++++++++ tests/tail-2/assert | 61 ---------------------------- tests/tail-2/assert-2 | 49 ----------------------- tests/tail-2/assert-2.sh | 49 +++++++++++++++++++++++ tests/tail-2/assert.sh | 61 ++++++++++++++++++++++++++++ tests/tail-2/big-4gb | 50 ----------------------- tests/tail-2/big-4gb.sh | 50 +++++++++++++++++++++++ tests/tail-2/flush-initial | 40 ------------------- tests/tail-2/flush-initial.sh | 40 +++++++++++++++++++ tests/tail-2/follow-name | 36 ----------------- tests/tail-2/follow-name.sh | 36 +++++++++++++++++ tests/tail-2/follow-stdin | 36 ----------------- tests/tail-2/follow-stdin.sh | 36 +++++++++++++++++ tests/tail-2/infloop-1 | 45 --------------------- tests/tail-2/infloop-1.sh | 45 +++++++++++++++++++++ tests/tail-2/inotify-hash-abuse | 63 ----------------------------- tests/tail-2/inotify-hash-abuse.sh | 63 +++++++++++++++++++++++++++++ tests/tail-2/inotify-hash-abuse2 | 39 ------------------ tests/tail-2/inotify-hash-abuse2.sh | 39 ++++++++++++++++++ tests/tail-2/inotify-race | 69 -------------------------------- tests/tail-2/inotify-race.sh | 69 ++++++++++++++++++++++++++++++++ tests/tail-2/inotify-rotate | 68 ------------------------------- tests/tail-2/inotify-rotate.sh | 70 ++++++++++++++++++++++++++++++++ tests/tail-2/pid | 51 ----------------------- tests/tail-2/pid.sh | 51 +++++++++++++++++++++++ tests/tail-2/pipe-f | 27 ------------- tests/tail-2/pipe-f.sh | 27 +++++++++++++ tests/tail-2/pipe-f2 | 43 -------------------- tests/tail-2/pipe-f2.sh | 43 ++++++++++++++++++++ tests/tail-2/proc-ksyms | 28 ------------- tests/tail-2/proc-ksyms.sh | 28 +++++++++++++ tests/tail-2/start-middle | 33 --------------- tests/tail-2/start-middle.sh | 33 +++++++++++++++ tests/tail-2/tail-n0f | 55 ------------------------- tests/tail-2/tail-n0f.sh | 55 +++++++++++++++++++++++++ tests/tail-2/wait | 80 ------------------------------------- tests/tail-2/wait.sh | 80 +++++++++++++++++++++++++++++++++++++ 42 files changed, 1057 insertions(+), 1055 deletions(-) delete mode 100755 tests/tail-2/F-vs-missing create mode 100755 tests/tail-2/F-vs-missing.sh delete mode 100755 tests/tail-2/F-vs-rename create mode 100755 tests/tail-2/F-vs-rename.sh delete mode 100755 tests/tail-2/append-only create mode 100755 tests/tail-2/append-only.sh delete mode 100755 tests/tail-2/assert delete mode 100755 tests/tail-2/assert-2 create mode 100755 tests/tail-2/assert-2.sh create mode 100755 tests/tail-2/assert.sh delete mode 100755 tests/tail-2/big-4gb create mode 100755 tests/tail-2/big-4gb.sh delete mode 100755 tests/tail-2/flush-initial create mode 100755 tests/tail-2/flush-initial.sh delete mode 100755 tests/tail-2/follow-name create mode 100755 tests/tail-2/follow-name.sh delete mode 100755 tests/tail-2/follow-stdin create mode 100755 tests/tail-2/follow-stdin.sh delete mode 100755 tests/tail-2/infloop-1 create mode 100755 tests/tail-2/infloop-1.sh delete mode 100755 tests/tail-2/inotify-hash-abuse create mode 100755 tests/tail-2/inotify-hash-abuse.sh delete mode 100755 tests/tail-2/inotify-hash-abuse2 create mode 100755 tests/tail-2/inotify-hash-abuse2.sh delete mode 100755 tests/tail-2/inotify-race create mode 100755 tests/tail-2/inotify-race.sh delete mode 100755 tests/tail-2/inotify-rotate create mode 100755 tests/tail-2/inotify-rotate.sh delete mode 100755 tests/tail-2/pid create mode 100755 tests/tail-2/pid.sh delete mode 100755 tests/tail-2/pipe-f create mode 100755 tests/tail-2/pipe-f.sh delete mode 100755 tests/tail-2/pipe-f2 create mode 100755 tests/tail-2/pipe-f2.sh delete mode 100755 tests/tail-2/proc-ksyms create mode 100755 tests/tail-2/proc-ksyms.sh delete mode 100755 tests/tail-2/start-middle create mode 100755 tests/tail-2/start-middle.sh delete mode 100755 tests/tail-2/tail-n0f create mode 100755 tests/tail-2/tail-n0f.sh delete mode 100755 tests/tail-2/wait create mode 100755 tests/tail-2/wait.sh (limited to 'tests/tail-2') diff --git a/tests/tail-2/F-vs-missing b/tests/tail-2/F-vs-missing deleted file mode 100755 index fbdb5331..00000000 --- a/tests/tail-2/F-vs-missing +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/sh -# demonstrate that tail -F works for currently missing dirs -# Before coreutils-8.6, tail -F missing/file would not -# notice any subsequent availability of the missing/file. - -# Copyright (C) 2010-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -debug='---disable-inotify' -debug= -tail $debug -F -s.1 missing/file > out 2>&1 & pid=$! - -check_tail_output() -{ - local delay="$1" - grep "$tail_re" out > /dev/null || - { sleep $delay; return 1; } -} - -# Wait up to 6.3s for tail to start with diagnostic: -# tail: cannot open 'missing/file' for reading: No such file or directory -tail_re='cannot open' retry_delay_ check_tail_output .1 7 || fail=1 - -mkdir missing || fail=1 -(cd missing && echo x > file) - -# Wait up to 6.3s for this to appear in the output: -# "tail: '...' has appeared; following end of new file" -tail_re='has appeared' retry_delay_ check_tail_output .1 7 || - { echo "$0: file: unexpected delay?"; cat out; fail=1; } - -kill -HUP $pid - -cleanup() -{ - local delay="$1" - rm -rf missing || - { sleep $delay; return 1; } -} - -# Try repeatedly to remove the temporary directory. -# This is normally unnecessary, because the containing directory will -# be removed by code from init.sh. However, when this particular test -# is run on an NFS-mounted volume, sometimes init.sh's cleanup code -# fails because the directory is not yet really empty, perhaps because -# the tail process (reading missing/file) is not yet killed. -retry_delay_ cleanup .1 6 - -Exit $fail diff --git a/tests/tail-2/F-vs-missing.sh b/tests/tail-2/F-vs-missing.sh new file mode 100755 index 00000000..0f744042 --- /dev/null +++ b/tests/tail-2/F-vs-missing.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# demonstrate that tail -F works for currently missing dirs +# Before coreutils-8.6, tail -F missing/file would not +# notice any subsequent availability of the missing/file. + +# Copyright (C) 2010-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +debug='---disable-inotify' +debug= +tail $debug -F -s.1 missing/file > out 2>&1 & pid=$! + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out > /dev/null || + { sleep $delay; return 1; } +} + +# Wait up to 6.3s for tail to start with diagnostic: +# tail: cannot open 'missing/file' for reading: No such file or directory +tail_re='cannot open' retry_delay_ check_tail_output .1 7 || fail=1 + +mkdir missing || fail=1 +(cd missing && echo x > file) + +# Wait up to 6.3s for this to appear in the output: +# "tail: '...' has appeared; following end of new file" +tail_re='has appeared' retry_delay_ check_tail_output .1 7 || + { echo "$0: file: unexpected delay?"; cat out; fail=1; } + +kill -HUP $pid + +cleanup() +{ + local delay="$1" + rm -rf missing || + { sleep $delay; return 1; } +} + +# Try repeatedly to remove the temporary directory. +# This is normally unnecessary, because the containing directory will +# be removed by code from init.sh. However, when this particular test +# is run on an NFS-mounted volume, sometimes init.sh's cleanup code +# fails because the directory is not yet really empty, perhaps because +# the tail process (reading missing/file) is not yet killed. +retry_delay_ cleanup .1 6 + +Exit $fail diff --git a/tests/tail-2/F-vs-rename b/tests/tail-2/F-vs-rename deleted file mode 100755 index 53bc00dd..00000000 --- a/tests/tail-2/F-vs-rename +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/sh -# demonstrate that tail -F works when renaming the tailed files -# Before coreutils-8.3, tail -F a b would stop tracking additions to b -# after "mv a b". - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -touch a b || framework_failure_ - -debug='---disable-inotify' -debug= -tail $debug -F -s.1 a b > out 2>&1 & pid=$! - -check_tail_output() -{ - local delay="$1" - grep "$tail_re" out > /dev/null || - { sleep $delay; return 1; } -} - -# Wait up to 6.3s for tail to start -echo x > a -tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1 - -mv a b || fail=1 - -# Wait 6.3s for this diagnostic: -# tail: 'a' has become inaccessible: No such file or directory -tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || fail=1 - -echo x > a -# Wait up to 6.3s for this to appear in the output: -# "tail: '...' has appeared; following end of new file" -tail_re='has appeared' retry_delay_ check_tail_output .1 7 || - { echo "$0: a: unexpected delay?"; cat out; fail=1; } - -echo y >> b -# Wait up to 6.3s for "y" to appear in the output: -tail_f_vs_rename_2() { - local delay="$1" - tr '\n' @ < out | grep '@@==> b <==@y@$' > /dev/null || - { sleep $delay; return 1; } -} -retry_delay_ tail_f_vs_rename_2 .1 7 || - { echo "$0: b: unexpected delay?"; cat out; fail=1; } - -echo z >> a -# Wait up to 6.3s for "z" to appear in the output: -tail_f_vs_rename_3() { - local delay="$1" - tr '\n' @ < out | grep '@@==> a <==@z@$' > /dev/null || - { sleep $delay; return 1; } -} -retry_delay_ tail_f_vs_rename_3 .1 7 || - { echo "$0: a: unexpected delay?"; cat out; fail=1; } - -kill -HUP $pid - -Exit $fail diff --git a/tests/tail-2/F-vs-rename.sh b/tests/tail-2/F-vs-rename.sh new file mode 100755 index 00000000..4f3ad5eb --- /dev/null +++ b/tests/tail-2/F-vs-rename.sh @@ -0,0 +1,75 @@ +#!/bin/sh +# demonstrate that tail -F works when renaming the tailed files +# Before coreutils-8.3, tail -F a b would stop tracking additions to b +# after "mv a b". + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +touch a b || framework_failure_ + +debug='---disable-inotify' +debug= +tail $debug -F -s.1 a b > out 2>&1 & pid=$! + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out > /dev/null || + { sleep $delay; return 1; } +} + +# Wait up to 6.3s for tail to start +echo x > a +tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1 + +mv a b || fail=1 + +# Wait 6.3s for this diagnostic: +# tail: 'a' has become inaccessible: No such file or directory +tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || fail=1 + +echo x > a +# Wait up to 6.3s for this to appear in the output: +# "tail: '...' has appeared; following end of new file" +tail_re='has appeared' retry_delay_ check_tail_output .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } + +echo y >> b +# Wait up to 6.3s for "y" to appear in the output: +tail_f_vs_rename_2() { + local delay="$1" + tr '\n' @ < out | grep '@@==> b <==@y@$' > /dev/null || + { sleep $delay; return 1; } +} +retry_delay_ tail_f_vs_rename_2 .1 7 || + { echo "$0: b: unexpected delay?"; cat out; fail=1; } + +echo z >> a +# Wait up to 6.3s for "z" to appear in the output: +tail_f_vs_rename_3() { + local delay="$1" + tr '\n' @ < out | grep '@@==> a <==@z@$' > /dev/null || + { sleep $delay; return 1; } +} +retry_delay_ tail_f_vs_rename_3 .1 7 || + { echo "$0: a: unexpected delay?"; cat out; fail=1; } + +kill -HUP $pid + +Exit $fail diff --git a/tests/tail-2/append-only b/tests/tail-2/append-only deleted file mode 100755 index c79bb7b2..00000000 --- a/tests/tail-2/append-only +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# Ensure that tail -f works on an append-only file -# Requires root access to do chattr +a, as well as an ext[23] or xfs file system - -# Copyright (C) 2006-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail -require_root_ - -chattr_a_works=1 -touch f -chattr +a f 2>/dev/null || chattr_a_works=0 -( echo x > f ) 2>/dev/null && chattr_a_works=0 -echo x >> f || chattr_a_works=0 - -if test $chattr_a_works = 0; then - skip_ "chattr +a doesn't work on this file system" -fi - - -for inotify in ---disable-inotify ''; do - sleep 1 & - pid=$! - tail --pid=$pid -f $inotify f || fail=1 -done - -chattr -a f 2>/dev/null - -Exit $fail diff --git a/tests/tail-2/append-only.sh b/tests/tail-2/append-only.sh new file mode 100755 index 00000000..93d0b323 --- /dev/null +++ b/tests/tail-2/append-only.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Ensure that tail -f works on an append-only file +# Requires root access to do chattr +a, as well as an ext[23] or xfs file system + +# Copyright (C) 2006-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail +require_root_ + +chattr_a_works=1 +touch f +chattr +a f 2>/dev/null || chattr_a_works=0 +( echo x > f ) 2>/dev/null && chattr_a_works=0 +echo x >> f || chattr_a_works=0 + +if test $chattr_a_works = 0; then + skip_ "chattr +a doesn't work on this file system" +fi + + +for inotify in ---disable-inotify ''; do + sleep 1 & + pid=$! + tail --pid=$pid -f $inotify f || fail=1 +done + +chattr -a f 2>/dev/null + +Exit $fail diff --git a/tests/tail-2/assert b/tests/tail-2/assert deleted file mode 100755 index 043e2593..00000000 --- a/tests/tail-2/assert +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh -# Test for assertion failure in "test". - -# Copyright (C) 1999-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -# This test fails with tail from textutils-2.0. -# It would get something like this: -# tail: tail.c:718: recheck: Assertion 'valid_file_spec (f)' failed. -# Aborted -# due to a race condition in which a dev/inode pair is reused. - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -# Not "expensive" per se, but sleeping for so long is annoying. -very_expensive_ - -ok='ok ok ok' - -touch a foo -tail --follow=name a foo > err 2>&1 & -tail_pid=$! -# Arrange for the tail process to die after 12 seconds. -(sleep 12; kill $tail_pid) & - -echo sleeping for 7 seconds... - -# Give the backgrounded 'tail' a chance to start before removing foo. -# Otherwise, without --retry, tail wouldn't try to open 'foo' again. -sleep 1 - -rm -f foo -sleep 6 -echo $ok > f -mv f foo - -# echo waiting.... -wait - -case "$(cat err)" in - *$ok) ;; - *) fail=1;; -esac - -test $fail = 1 && cat err - -Exit $fail diff --git a/tests/tail-2/assert-2 b/tests/tail-2/assert-2 deleted file mode 100755 index d94d3d8e..00000000 --- a/tests/tail-2/assert-2 +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# This variant of 'assert' would get a UMR reliably in 2.0.9. -# Due to a race condition in the test, the 'assert' script would get -# the UMR on Solaris only some of the time, and not at all on Linux/GNU. - -# Copyright (C) 2000-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -# Not "expensive" per se, but sleeping for so long is annoying. -very_expensive_ - -ok='ok ok ok' - -touch a -tail --follow=name a foo > err 2>&1 & -tail_pid=$! -# Arrange for the tail process to die after 12 seconds. -(sleep 12; kill $tail_pid) & -echo $ok > f -echo sleeping for 7 seconds... -sleep 7 -mv f foo - -# echo waiting.... -wait - -case "$(cat err)" in - *$ok) ;; - *) fail=1;; -esac - -test $fail = 1 && cat err - -Exit $fail diff --git a/tests/tail-2/assert-2.sh b/tests/tail-2/assert-2.sh new file mode 100755 index 00000000..13cb3e02 --- /dev/null +++ b/tests/tail-2/assert-2.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# This variant of 'assert' would get a UMR reliably in 2.0.9. +# Due to a race condition in the test, the 'assert' script would get +# the UMR on Solaris only some of the time, and not at all on Linux/GNU. + +# Copyright (C) 2000-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +# Not "expensive" per se, but sleeping for so long is annoying. +very_expensive_ + +ok='ok ok ok' + +touch a +tail --follow=name a foo > err 2>&1 & +tail_pid=$! +# Arrange for the tail process to die after 12 seconds. +(sleep 12; kill $tail_pid) & +echo $ok > f +echo sleeping for 7 seconds... +sleep 7 +mv f foo + +# echo waiting.... +wait + +case "$(cat err)" in + *$ok) ;; + *) fail=1;; +esac + +test $fail = 1 && cat err + +Exit $fail diff --git a/tests/tail-2/assert.sh b/tests/tail-2/assert.sh new file mode 100755 index 00000000..ee7cec8c --- /dev/null +++ b/tests/tail-2/assert.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# Test for assertion failure in "test". + +# Copyright (C) 1999-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# This test fails with tail from textutils-2.0. +# It would get something like this: +# tail: tail.c:718: recheck: Assertion 'valid_file_spec (f)' failed. +# Aborted +# due to a race condition in which a dev/inode pair is reused. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +# Not "expensive" per se, but sleeping for so long is annoying. +very_expensive_ + +ok='ok ok ok' + +touch a foo +tail --follow=name a foo > err 2>&1 & +tail_pid=$! +# Arrange for the tail process to die after 12 seconds. +(sleep 12; kill $tail_pid) & + +echo sleeping for 7 seconds... + +# Give the backgrounded 'tail' a chance to start before removing foo. +# Otherwise, without --retry, tail wouldn't try to open 'foo' again. +sleep 1 + +rm -f foo +sleep 6 +echo $ok > f +mv f foo + +# echo waiting.... +wait + +case "$(cat err)" in + *$ok) ;; + *) fail=1;; +esac + +test $fail = 1 && cat err + +Exit $fail diff --git a/tests/tail-2/big-4gb b/tests/tail-2/big-4gb deleted file mode 100755 index 8ace3183..00000000 --- a/tests/tail-2/big-4gb +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh -# Demonstrate a bug in 'tail -cN' when operating on files of size 4G and larger -# Fixed in coreutils-4.5.2. - -# Copyright (C) 2002-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail -expensive_ - -# Create a file of size exactly 4GB (2^32) with 8 bytes -# at the beginning and another set of 8 bytes at the end. -# The rest will be NUL bytes. On most modern systems, the following -# creates a file that takes up only a few KB. Here, du -sh says 16K. -echo abcdefgh | tr -d '\n' > big || framework_failure_ -echo 87654321 | tr -d '\n' > tmp || framework_failure_ -# Seek 4GB - 8 -dd bs=1 seek=4294967288 if=tmp of=big 2> err || dd_failed=1 -if test "$dd_failed" = 1; then - cat err 1>&2 - skip_ \ -'cannot create a file large enough for this test, -possibly because this system does not support large files; -Consider rerunning this test on a different file system.' -fi - - -tail -c1 big > out || fail=1 -# Append a newline. -echo >> out -cat <<\EOF > exp -1 -EOF - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/tail-2/big-4gb.sh b/tests/tail-2/big-4gb.sh new file mode 100755 index 00000000..4e7463c6 --- /dev/null +++ b/tests/tail-2/big-4gb.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# Demonstrate a bug in 'tail -cN' when operating on files of size 4G and larger +# Fixed in coreutils-4.5.2. + +# Copyright (C) 2002-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail +expensive_ + +# Create a file of size exactly 4GB (2^32) with 8 bytes +# at the beginning and another set of 8 bytes at the end. +# The rest will be NUL bytes. On most modern systems, the following +# creates a file that takes up only a few KB. Here, du -sh says 16K. +echo abcdefgh | tr -d '\n' > big || framework_failure_ +echo 87654321 | tr -d '\n' > tmp || framework_failure_ +# Seek 4GB - 8 +dd bs=1 seek=4294967288 if=tmp of=big 2> err || dd_failed=1 +if test "$dd_failed" = 1; then + cat err 1>&2 + skip_ \ +'cannot create a file large enough for this test, +possibly because this system does not support large files; +Consider rerunning this test on a different file system.' +fi + + +tail -c1 big > out || fail=1 +# Append a newline. +echo >> out +cat <<\EOF > exp +1 +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/tail-2/flush-initial b/tests/tail-2/flush-initial deleted file mode 100755 index bf68ce76..00000000 --- a/tests/tail-2/flush-initial +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# inotify-based tail -f didn't flush its initial output before blocking - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -echo line > in || fail=1 -# Output should be buffered since we're writing to file -# so we're depending on the flush to write out -tail -f in > out & -tail_pid=$! - -# Wait for 1.5s for the file to be flushed. -tail_flush() -{ - local delay="$1" - - test -s out || - { sleep "$delay"; return 1; } -} -retry_delay_ tail_flush .1 5 || fail=1 - -kill $tail_pid - -Exit $fail diff --git a/tests/tail-2/flush-initial.sh b/tests/tail-2/flush-initial.sh new file mode 100755 index 00000000..c9f7f4e7 --- /dev/null +++ b/tests/tail-2/flush-initial.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# inotify-based tail -f didn't flush its initial output before blocking + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +echo line > in || fail=1 +# Output should be buffered since we're writing to file +# so we're depending on the flush to write out +tail -f in > out & +tail_pid=$! + +# Wait for 1.5s for the file to be flushed. +tail_flush() +{ + local delay="$1" + + test -s out || + { sleep "$delay"; return 1; } +} +retry_delay_ tail_flush .1 5 || fail=1 + +kill $tail_pid + +Exit $fail diff --git a/tests/tail-2/follow-name b/tests/tail-2/follow-name deleted file mode 100755 index 2ab1c011..00000000 --- a/tests/tail-2/follow-name +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# ensure that --follow=name does not imply --retry - -# Copyright (C) 2011-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -cat <<\EOF > exp || framework_failure_ -tail: cannot open 'no-such' for reading: No such file or directory -tail: no files remaining -EOF - -timeout 10 tail --follow=name no-such > out 2> err -test $? = 1 || fail=1 - -# Remove an inconsequential inotify warning so -# we can compare against the above error -sed '/inotify cannot be used/d' err > k && mv k err - -compare exp err || fail=1 - -Exit $fail diff --git a/tests/tail-2/follow-name.sh b/tests/tail-2/follow-name.sh new file mode 100755 index 00000000..ba480fee --- /dev/null +++ b/tests/tail-2/follow-name.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# ensure that --follow=name does not imply --retry + +# Copyright (C) 2011-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +cat <<\EOF > exp || framework_failure_ +tail: cannot open 'no-such' for reading: No such file or directory +tail: no files remaining +EOF + +timeout 10 tail --follow=name no-such > out 2> err +test $? = 1 || fail=1 + +# Remove an inconsequential inotify warning so +# we can compare against the above error +sed '/inotify cannot be used/d' err > k && mv k err + +compare exp err || fail=1 + +Exit $fail diff --git a/tests/tail-2/follow-stdin b/tests/tail-2/follow-stdin deleted file mode 100755 index ee0d1ae8..00000000 --- a/tests/tail-2/follow-stdin +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# tail -f - would fail with the initial inotify implementation - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -echo line > exp || framework_failure_ -echo line > in || framework_failure_ - -timeout 1 tail -f < in > out 2> err - -# tail from coreutils-7.5 would fail -test $? = 124 || fail=1 - -# Ensure there was no error output. -test -s err && fail=1 - -# Ensure there was -compare exp out || fail=1 - -Exit $fail diff --git a/tests/tail-2/follow-stdin.sh b/tests/tail-2/follow-stdin.sh new file mode 100755 index 00000000..b2ccba35 --- /dev/null +++ b/tests/tail-2/follow-stdin.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# tail -f - would fail with the initial inotify implementation + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +echo line > exp || framework_failure_ +echo line > in || framework_failure_ + +timeout 1 tail -f < in > out 2> err + +# tail from coreutils-7.5 would fail +test $? = 124 || fail=1 + +# Ensure there was no error output. +test -s err && fail=1 + +# Ensure there was +compare exp out || fail=1 + +Exit $fail diff --git a/tests/tail-2/infloop-1 b/tests/tail-2/infloop-1 deleted file mode 100755 index 3f45f774..00000000 --- a/tests/tail-2/infloop-1 +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# This test would fail with tail from pre-1.22i textutils. - -# Copyright (C) 1999-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -yes > t & -yes_pid=$! -while :; do - test -s t && break - sleep .1 -done -tail -n 1 t & -tail_pid=$! -kill $yes_pid - -# This test is racy, and can fail under unusual circumstances. -# On a very busy system, tail will fail to notice that $yes_pid is gone. -# Then the following kill will succeed and cause this test to fail. - -# Wait for up to 3 seconds for tail to detect the death of $yes_pid. -for i in $(seq 30); do - kill -0 $tail_pid || break - echo sleep 0.1s - sleep .1 -done - -kill $tail_pid && fail=1 || : - -Exit $fail diff --git a/tests/tail-2/infloop-1.sh b/tests/tail-2/infloop-1.sh new file mode 100755 index 00000000..a4afb675 --- /dev/null +++ b/tests/tail-2/infloop-1.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# This test would fail with tail from pre-1.22i textutils. + +# Copyright (C) 1999-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +yes > t & +yes_pid=$! +while :; do + test -s t && break + sleep .1 +done +tail -n 1 t & +tail_pid=$! +kill $yes_pid + +# This test is racy, and can fail under unusual circumstances. +# On a very busy system, tail will fail to notice that $yes_pid is gone. +# Then the following kill will succeed and cause this test to fail. + +# Wait for up to 3 seconds for tail to detect the death of $yes_pid. +for i in $(seq 30); do + kill -0 $tail_pid || break + echo sleep 0.1s + sleep .1 +done + +kill $tail_pid && fail=1 || : + +Exit $fail diff --git a/tests/tail-2/inotify-hash-abuse b/tests/tail-2/inotify-hash-abuse deleted file mode 100755 index deec76d1..00000000 --- a/tests/tail-2/inotify-hash-abuse +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/sh -# Exercise an abort-inducing flaw in inotify-enabled tail -F. - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -# 9 is a magic number, related to internal details of tail.c and hash.c -n=9 -seq $n | xargs touch || framework_failure_ - -debug='---disable-inotify' -debug= -tail $debug -s.1 -qF $(seq $n) > out 2>&1 & pid=$! - -check_tail_output() -{ - local delay="$1" - grep "$tail_re" out > /dev/null || - { sleep $delay; return 1; } -} - -# Wait up to 6.3s for tail to start -echo x > $n -tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1 - -mv 1 f || fail=1 - -# Wait 6.3s for this diagnostic: -# tail: '1' has become inaccessible: No such file or directory -tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || fail=1 - -# Trigger the bug. Before the fix, this would provoke the abort. -echo a > 1 || fail=1 - -# Wait up to 2s for the buggy tail to die, -# or for the "tail: '1' has appeared; following end of new file" output -for i in $(seq 10); do - kill -0 $pid || break - grep 'has appeared;' out > /dev/null && break - sleep .2 -done - -# Kill the working tail, or fail if it has already aborted -kill $pid || fail=1 - -cat out - -Exit $fail diff --git a/tests/tail-2/inotify-hash-abuse.sh b/tests/tail-2/inotify-hash-abuse.sh new file mode 100755 index 00000000..b9c7f108 --- /dev/null +++ b/tests/tail-2/inotify-hash-abuse.sh @@ -0,0 +1,63 @@ +#!/bin/sh +# Exercise an abort-inducing flaw in inotify-enabled tail -F. + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +# 9 is a magic number, related to internal details of tail.c and hash.c +n=9 +seq $n | xargs touch || framework_failure_ + +debug='---disable-inotify' +debug= +tail $debug -s.1 -qF $(seq $n) > out 2>&1 & pid=$! + +check_tail_output() +{ + local delay="$1" + grep "$tail_re" out > /dev/null || + { sleep $delay; return 1; } +} + +# Wait up to 6.3s for tail to start +echo x > $n +tail_re='^x$' retry_delay_ check_tail_output .1 7 || fail=1 + +mv 1 f || fail=1 + +# Wait 6.3s for this diagnostic: +# tail: '1' has become inaccessible: No such file or directory +tail_re='inaccessible' retry_delay_ check_tail_output .1 7 || fail=1 + +# Trigger the bug. Before the fix, this would provoke the abort. +echo a > 1 || fail=1 + +# Wait up to 2s for the buggy tail to die, +# or for the "tail: '1' has appeared; following end of new file" output +for i in $(seq 10); do + kill -0 $pid || break + grep 'has appeared;' out > /dev/null && break + sleep .2 +done + +# Kill the working tail, or fail if it has already aborted +kill $pid || fail=1 + +cat out + +Exit $fail diff --git a/tests/tail-2/inotify-hash-abuse2 b/tests/tail-2/inotify-hash-abuse2 deleted file mode 100755 index eb192a65..00000000 --- a/tests/tail-2/inotify-hash-abuse2 +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh -# Exercise an abort-inducing flaw in inotify-enabled tail -F. -# Like inotify-hash-abuse, but without a hard-coded "9". - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -touch f || framework_failure_ - -debug='---disable-inotify -s .001' -debug= -tail $debug -F f & pid=$! -cleanup_() { kill $pid; } - -for i in $(seq 200); do - kill -0 $pid || break; - mv f g - touch f -done - -# Kill the working tail, or fail if it has already aborted -kill $pid || fail=1 - -Exit $fail diff --git a/tests/tail-2/inotify-hash-abuse2.sh b/tests/tail-2/inotify-hash-abuse2.sh new file mode 100755 index 00000000..7dbefdd3 --- /dev/null +++ b/tests/tail-2/inotify-hash-abuse2.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Exercise an abort-inducing flaw in inotify-enabled tail -F. +# Like inotify-hash-abuse, but without a hard-coded "9". + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +touch f || framework_failure_ + +debug='---disable-inotify -s .001' +debug= +tail $debug -F f & pid=$! +cleanup_() { kill $pid; } + +for i in $(seq 200); do + kill -0 $pid || break; + mv f g + touch f +done + +# Kill the working tail, or fail if it has already aborted +kill $pid || fail=1 + +Exit $fail diff --git a/tests/tail-2/inotify-race b/tests/tail-2/inotify-race deleted file mode 100755 index ab25f67d..00000000 --- a/tests/tail-2/inotify-race +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh -# Ensure that tail does not ignore data that is appended to a tailed-forever -# file between tail's initial read-to-EOF, and when the inotify watches -# are established in tail_forever_inotify. That data could be ignored -# indefinitely if no *other* data is appended, but it would be printed as -# soon as any additional appended data is detected. - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -# Don't run this test by default because sometimes it's skipped as noted below. -# Also gdb has a bug in Debian's gdb-6.8-3 at least that causes it to not -# cleanup and exit correctly when it receives a SIGTERM, thus hanging the test. -very_expensive_ - -touch file || framework_failure_ -touch tail.out || framework_failure_ - -( timeout 10s gdb --version ) > gdb.out 2>&1 -case $(cat gdb.out) in - *'GNU gdb'*) ;; - *) skip_ "can't run gdb";; -esac - -# See if gdb works and -# tail_forever_inotify is compiled and not inlined -timeout 10s gdb -nx --batch-silent \ - --eval-command='break tail_forever_inotify' \ - --eval-command='run -f file' \ - --eval-command='quit' \ - tail < /dev/null > gdb.out 2>&1 - -# FIXME: The above is seen to _intermittently_ fail with: -# warning: .dynamic section for "/lib/libc.so.6" is not at the expected address -# warning: difference appears to be caused by prelink, adjusting expectations -test -s gdb.out && { cat gdb.out; skip_ "can't set breakpoints in tail"; } - -# Run "tail -f file", stopping to append a line just before -# inotify initialization, and then continue. Before the fix, -# that just-appended line would never be output. -timeout 10s gdb -nx --batch-silent \ - --eval-command='break tail_forever_inotify' \ - --eval-command='run -f file >> tail.out' \ - --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 --pid=$pid -f tail.out | (read; kill $pid) - -test -s tail.out || fail=1 - -Exit $fail diff --git a/tests/tail-2/inotify-race.sh b/tests/tail-2/inotify-race.sh new file mode 100755 index 00000000..cc0f61b3 --- /dev/null +++ b/tests/tail-2/inotify-race.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# Ensure that tail does not ignore data that is appended to a tailed-forever +# file between tail's initial read-to-EOF, and when the inotify watches +# are established in tail_forever_inotify. That data could be ignored +# indefinitely if no *other* data is appended, but it would be printed as +# soon as any additional appended data is detected. + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +# Don't run this test by default because sometimes it's skipped as noted below. +# Also gdb has a bug in Debian's gdb-6.8-3 at least that causes it to not +# cleanup and exit correctly when it receives a SIGTERM, thus hanging the test. +very_expensive_ + +touch file || framework_failure_ +touch tail.out || framework_failure_ + +( timeout 10s gdb --version ) > gdb.out 2>&1 +case $(cat gdb.out) in + *'GNU gdb'*) ;; + *) skip_ "can't run gdb";; +esac + +# See if gdb works and +# tail_forever_inotify is compiled and not inlined +timeout 10s gdb -nx --batch-silent \ + --eval-command='break tail_forever_inotify' \ + --eval-command='run -f file' \ + --eval-command='quit' \ + tail < /dev/null > gdb.out 2>&1 + +# FIXME: The above is seen to _intermittently_ fail with: +# warning: .dynamic section for "/lib/libc.so.6" is not at the expected address +# warning: difference appears to be caused by prelink, adjusting expectations +test -s gdb.out && { cat gdb.out; skip_ "can't set breakpoints in tail"; } + +# Run "tail -f file", stopping to append a line just before +# inotify initialization, and then continue. Before the fix, +# that just-appended line would never be output. +timeout 10s gdb -nx --batch-silent \ + --eval-command='break tail_forever_inotify' \ + --eval-command='run -f file >> tail.out' \ + --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 --pid=$pid -f tail.out | (read; kill $pid) + +test -s tail.out || fail=1 + +Exit $fail diff --git a/tests/tail-2/inotify-rotate b/tests/tail-2/inotify-rotate deleted file mode 100755 index 311633a8..00000000 --- a/tests/tail-2/inotify-rotate +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/sh -# ensure that tail -F handles rotation - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -if test "$VERBOSE" = yes; then - set -x - tail --version -fi - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -expensive_ - -# Wait several seconds for grep REGEXP FILE to succeed. -# Usage: grep_timeout REGEXP FILE -grep_timeout() -{ - local j - for j in $(seq 150); do - grep $1 $2 > /dev/null && return 0 - sleep 0.1 - done - return 1 -} - -# For details, see -# http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html - -# Perform at least this many iterations, because on multi-core systems -# the offending sequence of events can be surprisingly uncommon. -for i in $(seq 50); do - echo $i - rm -rf 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 && 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 - mv x k - # wait for tail to detect the rename - grep_timeout tail: out || { cat out; fail_ failed to detect rename; } - 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"'; } -done - -Exit $fail diff --git a/tests/tail-2/inotify-rotate.sh b/tests/tail-2/inotify-rotate.sh new file mode 100755 index 00000000..4a16202d --- /dev/null +++ b/tests/tail-2/inotify-rotate.sh @@ -0,0 +1,70 @@ +#!/bin/sh +# ensure that tail -F handles rotation + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +if test "$VERBOSE" = yes; then + set -x + tail --version +fi + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +expensive_ + +# Wait several seconds for grep REGEXP FILE to succeed. +# Usage: grep_timeout REGEXP FILE +grep_timeout() +{ + local j + for j in $(seq 150); do + grep $1 $2 > /dev/null && return 0 + sleep 0.1 + done + return 1 +} + +# For details, see +# http://lists.gnu.org/archive/html/bug-coreutils/2009-11/msg00213.html + +# Perform at least this many iterations, because on multi-core systems +# the offending sequence of events can be surprisingly uncommon. +for i in $(seq 50); do + echo $i + rm -rf 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 + mv x k + # wait for tail to detect the rename + grep_timeout tail: out || { cat out; fail_ failed to detect rename; } + 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"'; } +done + +wait +Exit $fail diff --git a/tests/tail-2/pid b/tests/tail-2/pid deleted file mode 100755 index 0a26f8d3..00000000 --- a/tests/tail-2/pid +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -# Test the --pid option of tail. - -# Copyright (C) 2003-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail -getlimits_ - -touch empty here || framework_failure_ - - -for inotify in ---disable-inotify ''; do - # Use tail itself to create a background process to monitor, - # which will auto exit when "here" is removed. - tail -f $inotify here & - bg_pid=$! - - # Ensure that tail --pid=PID does not exit when PID is alive. - timeout 1 tail -f -s.1 --pid=$bg_pid $inotify here - test $? = 124 || fail=1 - - # Cleanup background process - kill $bg_pid - - # Ensure that tail --pid=PID exits with success status when PID is dead. - # Use an unlikely-to-be-live PID - timeout 10 tail -f -s.1 --pid=$PID_T_MAX $inotify empty - ret=$? - test $ret = 124 && skip_ "pid $PID_T_MAX present or tail too slow" - test $ret = 0 || fail=1 - - # Ensure tail doesn't wait for data when PID is dead - timeout 10 tail -f -s10 --pid=$PID_T_MAX $inotify empty - test $? = 124 && fail=1 -done - -Exit $fail diff --git a/tests/tail-2/pid.sh b/tests/tail-2/pid.sh new file mode 100755 index 00000000..19e6a18b --- /dev/null +++ b/tests/tail-2/pid.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# Test the --pid option of tail. + +# Copyright (C) 2003-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail +getlimits_ + +touch empty here || framework_failure_ + + +for inotify in ---disable-inotify ''; do + # Use tail itself to create a background process to monitor, + # which will auto exit when "here" is removed. + tail -f $inotify here & + bg_pid=$! + + # Ensure that tail --pid=PID does not exit when PID is alive. + timeout 1 tail -f -s.1 --pid=$bg_pid $inotify here + test $? = 124 || fail=1 + + # Cleanup background process + kill $bg_pid + + # Ensure that tail --pid=PID exits with success status when PID is dead. + # Use an unlikely-to-be-live PID + timeout 10 tail -f -s.1 --pid=$PID_T_MAX $inotify empty + ret=$? + test $ret = 124 && skip_ "pid $PID_T_MAX present or tail too slow" + test $ret = 0 || fail=1 + + # Ensure tail doesn't wait for data when PID is dead + timeout 10 tail -f -s10 --pid=$PID_T_MAX $inotify empty + test $? = 124 && fail=1 +done + +Exit $fail diff --git a/tests/tail-2/pipe-f b/tests/tail-2/pipe-f deleted file mode 100755 index e3d8a70b..00000000 --- a/tests/tail-2/pipe-f +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# ensure that :|tail -f doesn't hang, per POSIX - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -echo foo | timeout 10 tail -f -c3 > out || fail=1 -echo oo > exp || fail=1 - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/tail-2/pipe-f.sh b/tests/tail-2/pipe-f.sh new file mode 100755 index 00000000..e0cf3c6d --- /dev/null +++ b/tests/tail-2/pipe-f.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# ensure that :|tail -f doesn't hang, per POSIX + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +echo foo | timeout 10 tail -f -c3 > out || fail=1 +echo oo > exp || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/tail-2/pipe-f2 b/tests/tail-2/pipe-f2 deleted file mode 100755 index fffd43a1..00000000 --- a/tests/tail-2/pipe-f2 +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# Ensure that "tail -f fifo" tails indefinitely. - -# Copyright (C) 2009-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -mkfifo_or_skip_ fifo - -echo 1 > fifo & -echo 1 > exp || framework_failure_ - -timeout 10 tail -f fifo > out & pid=$! - -check_tail_output() -{ - local n_sec="$1" - test -s out || { sleep $n_sec; return 1; } -} - -# Wait 6.3s for tail to write something. -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 - -Exit $fail diff --git a/tests/tail-2/pipe-f2.sh b/tests/tail-2/pipe-f2.sh new file mode 100755 index 00000000..63091e39 --- /dev/null +++ b/tests/tail-2/pipe-f2.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Ensure that "tail -f fifo" tails indefinitely. + +# Copyright (C) 2009-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +mkfifo_or_skip_ fifo + +echo 1 > fifo & +echo 1 > exp || framework_failure_ + +timeout 10 tail -f fifo > out & pid=$! + +check_tail_output() +{ + local n_sec="$1" + test -s out || { sleep $n_sec; return 1; } +} + +# Wait 6.3s for tail to write something. +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 + +Exit $fail diff --git a/tests/tail-2/proc-ksyms b/tests/tail-2/proc-ksyms deleted file mode 100755 index ad446d35..00000000 --- a/tests/tail-2/proc-ksyms +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# Prior to textutils-2.0.17, 'tail /proc/ksyms' would segfault on Linux. - -# Copyright (C) 2001-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - - -ksyms=/proc/ksyms -if test -r $ksyms; then - tail $ksyms > /dev/null || fail=1 -fi - -Exit $fail diff --git a/tests/tail-2/proc-ksyms.sh b/tests/tail-2/proc-ksyms.sh new file mode 100755 index 00000000..243bb9b9 --- /dev/null +++ b/tests/tail-2/proc-ksyms.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# Prior to textutils-2.0.17, 'tail /proc/ksyms' would segfault on Linux. + +# Copyright (C) 2001-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + + +ksyms=/proc/ksyms +if test -r $ksyms; then + tail $ksyms > /dev/null || fail=1 +fi + +Exit $fail diff --git a/tests/tail-2/start-middle b/tests/tail-2/start-middle deleted file mode 100755 index 5b40de45..00000000 --- a/tests/tail-2/start-middle +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# Verify that tail works even when it's reading from a file -# that is not at its beginning. Based on a report from John Roll. - -# Copyright (C) 2001-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -(echo 1; echo 2) > k || framework_failure_ - - -sh -c 'read x; tail' < k > out || fail=1 -cat < exp -2 -EOF - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/tail-2/start-middle.sh b/tests/tail-2/start-middle.sh new file mode 100755 index 00000000..67d5b1a9 --- /dev/null +++ b/tests/tail-2/start-middle.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Verify that tail works even when it's reading from a file +# that is not at its beginning. Based on a report from John Roll. + +# Copyright (C) 2001-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +(echo 1; echo 2) > k || framework_failure_ + + +sh -c 'read x; tail' < k > out || fail=1 +cat < exp +2 +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/tail-2/tail-n0f b/tests/tail-2/tail-n0f deleted file mode 100755 index 2b2147a7..00000000 --- a/tests/tail-2/tail-n0f +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -# Make sure that 'tail -n0 -f' and 'tail -c0 -f' sleep -# rather than doing what amounted to a busy-wait. - -# Copyright (C) 2003-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# This bug was fixed for 5.0.91 -# It skips the test if your system lacks a /proc/$pid/status -# file, or if its contents don't look right. - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -require_proc_pid_status_ - -touch empty || framework_failure_ -echo anything > nonempty || framework_failure_ - - -for inotify in ---disable-inotify ''; do - for file in empty nonempty; do - for c_or_n in c n; do - tail --sleep=4 -${c_or_n} 0 -f $inotify $file & - pid=$! - tail_sleeping() - { - local delay="$1"; sleep $delay - state=$(get_process_status_ $pid) - case $state in - S*) ;; - *) return 1;; - esac - } - # 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 - done - done -done - -Exit $fail diff --git a/tests/tail-2/tail-n0f.sh b/tests/tail-2/tail-n0f.sh new file mode 100755 index 00000000..a8d37597 --- /dev/null +++ b/tests/tail-2/tail-n0f.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Make sure that 'tail -n0 -f' and 'tail -c0 -f' sleep +# rather than doing what amounted to a busy-wait. + +# Copyright (C) 2003-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This bug was fixed for 5.0.91 +# It skips the test if your system lacks a /proc/$pid/status +# file, or if its contents don't look right. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +require_proc_pid_status_ + +touch empty || framework_failure_ +echo anything > nonempty || framework_failure_ + + +for inotify in ---disable-inotify ''; do + for file in empty nonempty; do + for c_or_n in c n; do + tail --sleep=4 -${c_or_n} 0 -f $inotify $file & + pid=$! + tail_sleeping() + { + local delay="$1"; sleep $delay + state=$(get_process_status_ $pid) + case $state in + S*) ;; + *) return 1;; + esac + } + # 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 + done + done +done + +Exit $fail diff --git a/tests/tail-2/wait b/tests/tail-2/wait deleted file mode 100755 index 587b4495..00000000 --- a/tests/tail-2/wait +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/sh -# Make sure that 'tail -f' returns immediately if a file doesn't exist -# while 'tail -F' waits for it to appear. - -# Copyright (C) 2003-2012 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ tail - -touch here || framework_failure_ -{ touch unreadable && chmod a-r unreadable; } || framework_failure_ - - -for inotify in ---disable-inotify ''; do - timeout 10 tail -s0.1 -f $inotify not_here - test $? = 124 && fail=1 - - if test ! -r unreadable; then # can't test this when root - timeout 10 tail -s0.1 -f $inotify unreadable - test $? = 124 && fail=1 - fi - - timeout 1 tail -s0.1 -f $inotify here 2>tail.err - test $? = 124 || fail=1 - - # 'tail -F' must wait in any case. - - timeout 1 tail -s0.1 -F $inotify here 2>>tail.err - test $? = 124 || fail=1 - - if test ! -r unreadable; then # can't test this when root - timeout 1 tail -s0.1 -F $inotify unreadable - test $? = 124 || fail=1 - fi - - timeout 1 tail -s0.1 -F $inotify not_here - test $? = 124 || fail=1 - - grep -Ev 'inotify (resources exhausted|cannot be used)' tail.err > x - mv x tail.err - test -s tail.err && fail=1 - :>tail.err - - tail_F() - { - local delay="$1" - - touch k || framework_failure_ - tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out & - pid=$! - sleep $delay - mv k l - sleep $delay - touch k - mv k l - sleep $delay - echo NO >> l - sleep $delay - kill $pid - rm -f k l - - test ! -s tail.out - } - retry_delay_ tail_F .1 4 || fail=1 -done - -Exit $fail diff --git a/tests/tail-2/wait.sh b/tests/tail-2/wait.sh new file mode 100755 index 00000000..529b9459 --- /dev/null +++ b/tests/tail-2/wait.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# Make sure that 'tail -f' returns immediately if a file doesn't exist +# while 'tail -F' waits for it to appear. + +# Copyright (C) 2003-2013 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail + +touch here || framework_failure_ +{ touch unreadable && chmod a-r unreadable; } || framework_failure_ + + +for inotify in ---disable-inotify ''; do + timeout 10 tail -s0.1 -f $inotify not_here + test $? = 124 && fail=1 + + if test ! -r unreadable; then # can't test this when root + timeout 10 tail -s0.1 -f $inotify unreadable + test $? = 124 && fail=1 + fi + + timeout 1 tail -s0.1 -f $inotify here 2>tail.err + test $? = 124 || fail=1 + + # 'tail -F' must wait in any case. + + timeout 1 tail -s0.1 -F $inotify here 2>>tail.err + test $? = 124 || fail=1 + + if test ! -r unreadable; then # can't test this when root + timeout 1 tail -s0.1 -F $inotify unreadable + test $? = 124 || fail=1 + fi + + timeout 1 tail -s0.1 -F $inotify not_here + test $? = 124 || fail=1 + + grep -Ev 'inotify (resources exhausted|cannot be used)' tail.err > x + mv x tail.err + test -s tail.err && fail=1 + :>tail.err + + tail_F() + { + local delay="$1" + + touch k || framework_failure_ + tail -s.1 --max-unchanged-stats=2 -F $inotify k > tail.out & + pid=$! + sleep $delay + mv k l + sleep $delay + touch k + mv k l + sleep $delay + echo NO >> l + sleep $delay + kill $pid + rm -f k l + + test ! -s tail.out + } + retry_delay_ tail_F .1 4 || fail=1 +done + +Exit $fail -- cgit v1.2.3