2 # Exercise stdbuf functionality
4 # Copyright (C) 2009-2010 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/>.
19 .
"${srcdir=.}/init.sh"; path_prepend_ ..
/src
25 # stdbuf fails when the absolute top build dir name contains e.g., space, TAB, NL
28 case $abs_top_builddir in
29 *[\\\"\
#\$\&\'\`$lf\ \ ]*)
30 skip_test_
"unsafe absolute build directory name: $abs_top_builddir";;
33 # Use a fifo rather than a pipe in the tests below
34 # so that the producer (uniq) will wait until the
35 # consumer (dd) opens the fifo therefore increasing
36 # the chance that dd will read the data from each
38 mkfifo fifo || framework_failure
41 # Verify input parameter checking
42 stdbuf
-o1 true || fail
=1 # verify size syntax
43 stdbuf
-oK true || fail
=1 # verify size syntax
44 stdbuf
-o0 true || fail
=1 # verify unbuffered syntax
45 stdbuf
-oL true || fail
=1 # verify line buffered syntax
46 stdbuf
-ol true
# Capital 'L' required
47 test $?
= 125 || fail
=1 # Internal error is a particular status
48 stdbuf
-o$SIZE_OFLOW true
# size too large
49 test $?
= 125 || fail
=1
50 stdbuf
-iL true
# line buffering stdin disallowed
51 test $?
= 125 || fail
=1
52 stdbuf
-i0 -o0 -e0 true || fail
=1 #check all files
53 stdbuf
-o1 .
# invalid command
54 test $?
= 126 || fail
=1
55 stdbuf
-o1 no_such
# no such command
56 test $?
= 127 || fail
=1
58 # Ensure line buffering stdout takes effect
64 dd count
=1 if=fifo
> out
2> err
&
65 (printf '1\n'; sleep $delay; printf '2\n') | stdbuf
-oL uniq > fifo
66 wait # for dd to complete
70 retry_delay_ stdbuf_linebuffer
.1 6 || fail
=1
76 # Ensure un buffering stdout takes effect
78 dd count
=1 if=fifo
> out
2> err
&
79 (printf '1\n'; sleep $delay; printf '2\n') | stdbuf
-o0 uniq > fifo
80 wait # for dd to complete
84 retry_delay_ stdbuf_unbuffer
.1 6 || fail
=1
86 # Ensure un buffering stdin takes effect
87 # The following works for me, but is racy. I.E. we're depending
88 # on dd to run and close the fifo before the second write by uniq.
89 # If we add a sleep, then we're just testing -oL
91 # dd count=1 if=fifo > /dev/null 2> err &
92 # printf '1\n\2\n3\n' | (stdbuf -i0 -oL uniq > fifo; cat) > out
93 # wait # for dd to complete
94 # compare out exp || fail=1
95 # One could remove the need for dd (used to close the fifo to get uniq to quit
96 # early), if head -n1 read stdin char by char. Note uniq | head -c2 doesn't
97 # suffice due to the buffering implicit in the pipe. sed currently does read
98 # stdin char by char, so we can test with `sed 1q`. However I'm wary about
99 # adding this dependency on a program outside of coreutils.
101 # printf '1\n2\n' | (stdbuf -i0 sed 1q >/dev/null; cat) > out
102 # compare out exp || fail=1
104 # Ensure block buffering stdout takes effect
105 # We don't currently test block buffering failures as
106 # this doesn't work on on GLIBC-2.7 or GLIBC-2.9 at least.
107 # stdbuf_blockbuffer()
111 # printf '1\n2\n' > exp
112 # dd count=1 if=fifo > out 2> err &
113 # (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o4 uniq > fifo
114 # wait # for dd to complete
118 # retry_delay_ stdbuf_blockbuffer .1 6 || fail=1