a837798f3d3f12cb4a052d32fabd42de9e4a5289
[platform/upstream/coreutils.git] / tests / tail-2 / assert
1 #!/bin/sh
2 # This test fails with tail from textutils-2.0.
3 # It would get something like this:
4 #   tail: tail.c:718: recheck: Assertion `valid_file_spec (f)' failed.
5 #   Aborted
6 # due to a race condition in which a dev/inode pair is reused.
7
8 if test "$VERBOSE" = yes; then
9   set -x
10   tail --version
11 fi
12
13 tmp=tail-assert.$$
14 pwd=`pwd`
15 trap "cd $pwd; rm -rf $tmp" 0 1 2 3 15
16
17 test_failure=0
18 mkdir $tmp || test_failure=1
19 cd $tmp || test_failure=1
20
21 if test $test_failure = 1; then
22   echo 'failure in testing framework'
23   exit 1
24 fi
25
26 ok='ok ok ok'
27
28 touch a foo
29 tail --follow=name a foo > err 2>&1 &
30 tail_pid=$!
31 # Arrange for the tail process to die after 12 seconds.
32 (sleep 12; kill $tail_pid) &
33
34 echo sleeping for 7 seconds...
35
36 # Give the backgrounded `tail' a chance to start before removing foo.
37 # Otherwise, without --retry, tail wouldn't try to open `foo' again.
38 sleep 1
39
40 rm -f foo
41 sleep 6
42 echo $ok > f
43 mv f foo
44
45 # echo waiting....
46 wait
47
48 case "`cat err`" in
49   *$ok) fail=0;;
50   *) fail=1;;
51 esac
52
53 test $fail = 1 && cat err
54
55 exit $fail