2008-12-17 11:30:03 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Exercise stdbuf functionality
|
|
|
|
|
|
2014-01-02 20:52:55 +01:00
|
|
|
# Copyright (C) 2009-2014 Free Software Foundation, Inc.
|
2008-12-17 11:30:03 +00:00
|
|
|
|
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2012-09-02 21:55:12 +02:00
|
|
|
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
2012-01-25 23:13:58 +00:00
|
|
|
print_ver_ stdbuf
|
2010-11-14 12:02:39 +01:00
|
|
|
|
2009-10-23 08:54:53 -06:00
|
|
|
getlimits_
|
|
|
|
|
require_built_ stdbuf
|
|
|
|
|
|
coreutils: keep lines within 80-column limits
* cfg.mk (LINE_LEN_MAX, FILTER_LONG_LINES): New macros.
(sc_long_lines): New rule.
* HACKING: Use shorter URLs to the same material.
* doc/Makefile.am, doc/coreutils.texi, m4/boottime.m4:
* man/help2man, man/stdbuf.x, src/Makefile.am, src/cat.c, src/copy.c:
* src/cp.c, src/dd.c, src/df.c, src/du.c, src/groups.c, src/install.c:
* src/ls.c, src/md5sum.c, src/mv.c, src/od.c, src/pinky.c, src/ptx.c:
* src/readlink.c, src/remove.c, src/rmdir.c, src/setuidgid.c:
* src/sort.c, src/tail.c, src/touch.c, tests/Coreutils.pm:
* tests/cp/existing-perm-race, tests/cp/perm, tests/cp/preserve-gid:
* tests/du/2g, tests/du/long-from-unreadable, tests/init.sh:
* tests/install/basic-1, tests/ls/nameless-uid:
* tests/ls/readdir-mountpoint-inode, tests/misc/chroot-credentials:
* tests/misc/cut, tests/misc/date, tests/misc/join, tests/misc/md5sum:
* tests/misc/sha1sum, tests/misc/sha224sum, tests/misc/sort:
* tests/misc/sort-continue, tests/misc/sort-files0-from:
* tests/misc/sort-rand, tests/misc/stdbuf, tests/misc/tr:
* tests/misc/uniq, tests/mv/atomic, tests/mv/part-fail:
* tests/mv/part-symlink, tests/mv/sticky-to-xpart, tests/pr/pr-tests:
* tests/rm/fail-2eperm, tests/rm/interactive-always:
Reformat to fit within 80 columns.
* doc/Makefile.am (BAD_POSIX_PERL): New macro.
* doc/coreutils.texi: Reword slightly, to make menus and
index lines shorter.
* src/md5sum.c: Redo --help output so that it fits within 79
columns, since that's a bit more portable and all the other --help
strings fit in 79 columns.
2010-12-28 12:28:48 -08:00
|
|
|
# stdbuf fails when the absolute top build dir name contains e.g.,
|
|
|
|
|
# space, TAB, NL
|
2009-08-20 18:27:07 +02:00
|
|
|
lf='
|
|
|
|
|
'
|
|
|
|
|
case $abs_top_builddir in
|
|
|
|
|
*[\\\"\#\$\&\'\`$lf\ \ ]*)
|
2011-06-14 16:22:41 +02:00
|
|
|
skip_ "unsafe absolute build directory name: $abs_top_builddir";;
|
2009-08-20 18:27:07 +02:00
|
|
|
esac
|
|
|
|
|
|
2008-12-17 11:30:03 +00:00
|
|
|
# Use a fifo rather than a pipe in the tests below
|
|
|
|
|
# so that the producer (uniq) will wait until the
|
|
|
|
|
# consumer (dd) opens the fifo therefore increasing
|
|
|
|
|
# the chance that dd will read the data from each
|
|
|
|
|
# write separately.
|
2011-05-10 08:14:16 +01:00
|
|
|
mkfifo_or_skip_ fifo
|
2008-12-17 11:30:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
# Verify input parameter checking
|
|
|
|
|
stdbuf -o1 true || fail=1 # verify size syntax
|
|
|
|
|
stdbuf -oK true || fail=1 # verify size syntax
|
|
|
|
|
stdbuf -o0 true || fail=1 # verify unbuffered syntax
|
|
|
|
|
stdbuf -oL true || fail=1 # verify line buffered syntax
|
2009-10-23 08:54:53 -06:00
|
|
|
stdbuf -ol true # Capital 'L' required
|
|
|
|
|
test $? = 125 || fail=1 # Internal error is a particular status
|
|
|
|
|
stdbuf -o$SIZE_OFLOW true # size too large
|
|
|
|
|
test $? = 125 || fail=1
|
|
|
|
|
stdbuf -iL true # line buffering stdin disallowed
|
|
|
|
|
test $? = 125 || fail=1
|
2013-06-22 03:37:51 +01:00
|
|
|
stdbuf true # a buffering mode must be specified
|
|
|
|
|
test $? = 125 || fail=1
|
2009-06-27 01:48:49 +01:00
|
|
|
stdbuf -i0 -o0 -e0 true || fail=1 #check all files
|
2009-10-23 08:54:53 -06:00
|
|
|
stdbuf -o1 . # invalid command
|
|
|
|
|
test $? = 126 || fail=1
|
2009-10-26 06:05:44 -06:00
|
|
|
stdbuf -o1 no_such # no such command
|
2009-10-23 08:54:53 -06:00
|
|
|
test $? = 127 || fail=1
|
2008-12-17 11:30:03 +00:00
|
|
|
|
|
|
|
|
# Ensure line buffering stdout takes effect
|
2010-07-05 08:53:10 +01:00
|
|
|
stdbuf_linebuffer()
|
|
|
|
|
{
|
|
|
|
|
local delay="$1"
|
|
|
|
|
|
|
|
|
|
printf '1\n' > exp
|
|
|
|
|
dd count=1 if=fifo > out 2> err &
|
|
|
|
|
(printf '1\n'; sleep $delay; printf '2\n') | stdbuf -oL uniq > fifo
|
|
|
|
|
wait # for dd to complete
|
2011-11-22 10:08:04 +01:00
|
|
|
compare exp out
|
2010-07-05 08:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retry_delay_ stdbuf_linebuffer .1 6 || fail=1
|
|
|
|
|
|
|
|
|
|
stdbuf_unbuffer()
|
|
|
|
|
{
|
|
|
|
|
local delay="$1"
|
|
|
|
|
|
|
|
|
|
# Ensure un buffering stdout takes effect
|
|
|
|
|
printf '1\n' > exp
|
|
|
|
|
dd count=1 if=fifo > out 2> err &
|
|
|
|
|
(printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o0 uniq > fifo
|
|
|
|
|
wait # for dd to complete
|
2011-11-22 10:08:04 +01:00
|
|
|
compare exp out
|
2010-07-05 08:53:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
retry_delay_ stdbuf_unbuffer .1 6 || fail=1
|
2008-12-17 11:30:03 +00:00
|
|
|
|
|
|
|
|
# Ensure un buffering stdin takes effect
|
|
|
|
|
# The following works for me, but is racy. I.E. we're depending
|
|
|
|
|
# on dd to run and close the fifo before the second write by uniq.
|
|
|
|
|
# If we add a sleep, then we're just testing -oL
|
|
|
|
|
# printf '3\n' > exp
|
|
|
|
|
# dd count=1 if=fifo > /dev/null 2> err &
|
|
|
|
|
# printf '1\n\2\n3\n' | (stdbuf -i0 -oL uniq > fifo; cat) > out
|
|
|
|
|
# wait # for dd to complete
|
2011-11-22 10:08:04 +01:00
|
|
|
# compare exp out || fail=1
|
2008-12-17 11:30:03 +00:00
|
|
|
# One could remove the need for dd (used to close the fifo to get uniq to quit
|
|
|
|
|
# early), if head -n1 read stdin char by char. Note uniq | head -c2 doesn't
|
|
|
|
|
# suffice due to the buffering implicit in the pipe. sed currently does read
|
2012-01-07 20:55:10 +01:00
|
|
|
# stdin char by char, so we can test with 'sed 1q'. However I'm wary about
|
2008-12-17 11:30:03 +00:00
|
|
|
# adding this dependency on a program outside of coreutils.
|
|
|
|
|
# printf '2\n' > exp
|
|
|
|
|
# printf '1\n2\n' | (stdbuf -i0 sed 1q >/dev/null; cat) > out
|
2011-11-22 10:08:04 +01:00
|
|
|
# compare exp out || fail=1
|
2008-12-17 11:30:03 +00:00
|
|
|
|
|
|
|
|
# Ensure block buffering stdout takes effect
|
|
|
|
|
# We don't currently test block buffering failures as
|
2011-04-09 23:23:01 +02:00
|
|
|
# this doesn't work on GLIBC-2.7 or GLIBC-2.9 at least.
|
2010-07-05 08:53:10 +01:00
|
|
|
# stdbuf_blockbuffer()
|
|
|
|
|
# {
|
|
|
|
|
# local delay="$1"
|
|
|
|
|
#
|
|
|
|
|
# printf '1\n2\n' > exp
|
|
|
|
|
# dd count=1 if=fifo > out 2> err &
|
|
|
|
|
# (printf '1\n'; sleep $delay; printf '2\n') | stdbuf -o4 uniq > fifo
|
|
|
|
|
# wait # for dd to complete
|
2011-11-22 10:08:04 +01:00
|
|
|
# compare exp out
|
2010-07-05 08:53:10 +01:00
|
|
|
# }
|
|
|
|
|
#
|
|
|
|
|
# retry_delay_ stdbuf_blockbuffer .1 6 || fail=1
|
2008-12-17 11:30:03 +00:00
|
|
|
|
|
|
|
|
Exit $fail
|