summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2008-12-17 11:30:03 +0000
committerPádraig Brady <P@draigBrady.com>2009-06-17 14:54:29 +0100
commita5a2a406f8d65f0e852d9ed7fbfb630c6b81dd7f (patch)
treed6ec40e289bbe748eb05f5e6cb9e8d376d79f446 /tests
parentff6fe3d17d9294f2494b4535a320bc9bfc86cc49 (diff)
downloadcoreutils-a5a2a406f8d65f0e852d9ed7fbfb630c6b81dd7f.tar.xz
stdbuf: A new program to run a command with modified stdio buffering
* AUTHORS: Register as the author. * NEWS: Mention this change. * README: Add stdbuf command to list. * configure.ac: Only enable on ELF systems with GCC. * cfg.mk (sc_system_h_headers): Use VC_LIST_EXCEPT rather than VC_LIST, so we can add an exception, if needed. * .x-sc_system_h_headers: New file. Exempt libstdbuf.c. * Makefile.am (syntax_check_exceptions): Add .x-sc_system_h_headers. * doc/coreutils.texi (stdbuf invocation): Add stdbuf info. * man/.gitignore: Ignore generated manpage. * src/.gitignore: Ignore stdbuf and libstdbuf.so binaries. * man/Makefile.am (stdbuf.1): Add dependency. * man/stdbuf.x: New file with example usage. * po/POTFILES.in: Reference new command and shared library sources. * src/Makefile.am (build_if_possible__progs): Add stdbuf and libstdbuf, (pkglib_PROGRAMS): Reference optional shared lib, (libstdbuf_so_LDADD): Ensure we don't link with non PIC libcoreutils.a. (libstdbuf_so_LDFLAGS): Add -shared GCC option, (libstdbuf_so_CFLAGS): Add -fPIC GCC option. (check-README): Exclude libstbuf. (check-AUTHORS): ditto. (sc_tight_scope): Exclude functions starting with __. * src/libstdbuf.c: The LD_PRELOAD shared library to control buffering. * src/stdbuf.c: New file to setup env variables before execing command. * tests/Makefile.am: Reference new test file. * tests/misc/help-version: Set expected exit codes. * tests/misc/invalid-opt: ditto. * tests/misc/stdbuf: Add 9 tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/misc/help-version2
-rwxr-xr-xtests/misc/invalid-opt1
-rwxr-xr-xtests/misc/stdbuf86
4 files changed, 90 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 24f54baef..59737a05d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -217,6 +217,7 @@ TESTS = \
misc/split-l \
misc/stat-fmt \
misc/stat-printf \
+ misc/stdbuf \
misc/stty \
misc/stty-invalid \
misc/stty-row-col \
diff --git a/tests/misc/help-version b/tests/misc/help-version
index ee7460058..983148b87 100755
--- a/tests/misc/help-version
+++ b/tests/misc/help-version
@@ -28,6 +28,7 @@ export SHELL
. $srcdir/test-lib.sh
expected_failure_status_nohup=127
+expected_failure_status_stdbuf=125
expected_failure_status_timeout=125
expected_failure_status_printenv=2
expected_failure_status_tty=3
@@ -148,6 +149,7 @@ printf_args=foo
seq_args=10
sleep_args=0
su_args=--version
+stdbuf_args="-oL true"
timeout_args=--version
# I'd rather not run sync, since it spins up disks that I've
diff --git a/tests/misc/invalid-opt b/tests/misc/invalid-opt
index cbd41cae1..9af2dd24c 100755
--- a/tests/misc/invalid-opt
+++ b/tests/misc/invalid-opt
@@ -32,6 +32,7 @@ my %exit_status =
expr => 0,
nohup => 127,
sort => 2,
+ stdbuf => 125,
test => 0,
timeout => 125,
true => 0,
diff --git a/tests/misc/stdbuf b/tests/misc/stdbuf
new file mode 100755
index 000000000..6f79e771f
--- /dev/null
+++ b/tests/misc/stdbuf
@@ -0,0 +1,86 @@
+#!/bin/sh
+# Exercise stdbuf functionality
+
+# Copyright (C) 2009 Free Software Foundation, Inc.
+
+# 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/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ stdbuf --version
+fi
+
+. $srcdir/test-lib.sh
+getlimits_
+
+# 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.
+mkfifo fifo || framework_failure
+
+fail=0
+
+# 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
+stdbuf -ol true && fail=1 # Capital 'L' required
+stdbuf -o$SIZE_OFLOW true && fail=1 # size too large
+stdbuf -iL true && fail=1 # line buffering stdin disallowed
+
+# Ensure line buffering stdout takes effect
+printf '1\n' > exp
+dd count=1 if=fifo > out 2> err &
+(printf '1\n'; sleep .2; printf '2\n') | stdbuf -oL uniq > fifo
+wait # for dd to complete
+compare out exp || fail=1
+
+# Ensure un buffering stdout takes effect
+printf '1\n' > exp
+dd count=1 if=fifo > out 2> err &
+(printf '1\n'; sleep .2; printf '2\n') | stdbuf -o0 uniq > fifo
+wait # for dd to complete
+compare out exp || fail=1
+
+# 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
+ # compare out exp || fail=1
+# 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
+# stdin char by char, so we can test with `sed 1q`. However I'm wary about
+# 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
+ # compare out exp || fail=1
+
+# Ensure block buffering stdout takes effect
+# We don't currently test block buffering failures as
+# this doesn't work on on GLIBC-2.7 or GLIBC-2.9 at least.
+ # printf '1\n2\n' > exp
+ # dd count=1 if=fifo > out 2> err &
+ # (printf '1\n'; sleep .2; printf '2\n') | stdbuf -o4 uniq > fifo
+ # wait # for dd to complete
+ # compare out exp || fail=1
+
+Exit $fail