.
[coreutils.git] / tests / tail-2 / tail-n0f
blob3e78fb2ff6a93498eed70403f046e236585abfba
1 #!/bin/sh
2 # Make sure that `tail -n0 -f' and `tail -c0 -f' sleep
3 # rather than doing what amounted to a busy-wait.
4 # This bug was fixed for 5.0.91
5 # It skips the test if your system lacks a /proc/$pid/status
6 # file, or if its contents don't look right.
8 if test "$VERBOSE" = yes; then
9 set -x
10 tail --version
13 sleep 2 &
14 pid=$!
15 sleep .5
16 grep '^State:[ ]*[S]' /proc/$pid/status > /dev/null 2>&1 || \
18 echo "$0:/proc/$pid/status: missing or 'different': skipping this test" 1>&2
19 (exit 77); exit 77
21 kill $pid
23 pwd=`pwd`
24 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
25 trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0
26 trap '(exit $?); exit $?' 1 2 13 15
28 framework_failure=0
29 mkdir -p $tmp || framework_failure=1
30 cd $tmp || framework_failure=1
31 touch empty || framework_failure=1
32 echo anything > nonempty || framework_failure=1
34 if test $framework_failure = 1; then
35 echo "$0: failure in testing framework" 1>&2
36 (exit 1); exit 1
39 fail=0
41 for file in empty nonempty; do
42 for c_or_n in c n; do
43 tail --sleep=4 -${c_or_n} 0 -f $file &
44 pid=$!
45 sleep .5
46 set _ `sed -n '/^State:[ ]*\([^ ]\)/s//\1/p' /proc/$pid/status`
47 shift # Remove the leading `_'.
48 state=$1
49 case $state in
50 S*) ;;
51 *) echo $0: process in unexpected state: $state 1>&2; fail=1 ;;
52 esac
53 kill $pid
54 done
55 done
57 (exit $fail); exit $fail