tests: avoid false failure in tail inotify test
[coreutils.git] / tests / tail-2 / assert.sh
blobc5f370323a881ba1d8b7e217ff323c9b573633ee
1 #!/bin/sh
2 # Test for assertion failure in "test".
4 # Copyright (C) 1999-2016 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # This test fails with tail from textutils-2.0.
21 # It would get something like this:
22 # tail: tail.c:718: recheck: Assertion 'valid_file_spec (f)' failed.
23 # Aborted
24 # due to a race condition in which a dev/inode pair is reused.
26 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
27 print_ver_ tail
29 check_tail_output()
31 local delay="$1"
32 grep "$tail_re" out ||
33 { sleep $delay; return 1; }
36 # Terminate any background tail process
37 cleanup_() { kill $pid 2>/dev/null && wait $pid; }
39 # Speedup the non inotify case
40 fastpoll='-s.1 --max-unchanged-stats=1'
42 for mode in '' '---disable-inotify'; do
43 rm -f a foo out
44 touch a foo || framework_failure_
46 tail $mode --follow=name $fastpoll a foo > out 2>&1 & pid=$!
48 # Wait up to 12.7s for tail to start.
49 echo x > a || framework_failure_
50 tail_re='^x$' retry_delay_ check_tail_output .1 7 ||
51 { cat out; fail=1; break; }
53 # Wait 12.7s for this diagnostic:
54 # tail: foo: No such file or directory
55 rm foo || framework_failure_
56 tail_re='No such file' retry_delay_ check_tail_output .1 7 ||
57 { cat out; fail=1; break; }
59 # Wait up to 12.7s for tail to notice new foo file
60 ok='ok ok ok'
61 echo "$ok" > foo || framework_failure_
62 tail_re="^$ok$" retry_delay_ check_tail_output .1 7 ||
63 { echo "$0: foo: unexpected delay?"; cat out; fail=1; break; }
65 cleanup_
66 done
68 Exit $fail