From 1baf5e2a66516cbc706eeb23f2451862a7ab0f89 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 25 Nov 2009 18:26:35 +0100 Subject: [PATCH] test-pread: cover failure with ESPIPE and EINVAL * tests/test-pread.c (main): Test for failure, too. * tests/test-pread.sh: Invoke with stdin on a pipe. Suggested by Eric Blake. --- ChangeLog | 5 +++++ tests/test-pread.c | 16 ++++++++++++++++ tests/test-pread.sh | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 2e5f9fbe61..2ec9906c43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-11-25 Jim Meyering + test-pread: cover failure with ESPIPE and EINVAL + * tests/test-pread.c (main): Test for failure, too. + * tests/test-pread.sh: Invoke with stdin on a pipe. + Suggested by Eric Blake. + pread: improvement and fix * modules/pread (Depends-on): Depend on lseek, for portability to e.g., mingw. Suggested by Eric Blake. diff --git a/tests/test-pread.c b/tests/test-pread.c index cf4179f32f..fd5db8e8a1 100644 --- a/tests/test-pread.c +++ b/tests/test-pread.c @@ -24,6 +24,7 @@ #include #include #include +#include #define ASSERT(expr) \ do \ @@ -72,7 +73,22 @@ main (void) } } + { + /* Invalid offset must evoke failure with EINVAL. */ + char byte; + ASSERT (pread (fd, &byte, 1, (off_t) -1) == -1); + ASSERT (errno == EINVAL); + } + ASSERT (close (fd) == 0); + { + char byte; + /* Trying to operate on a pipe must evoke failure with ESPIPE. + This assumes that stdin is a pipe, and hence not seekable. */ + ASSERT (pread (STDIN_FILENO, &byte, 1, 1) == -1); + ASSERT (errno == ESPIPE); + } + return 0; } diff --git a/tests/test-pread.sh b/tests/test-pread.sh index 98971a4c58..5ab88eb6ff 100755 --- a/tests/test-pread.sh +++ b/tests/test-pread.sh @@ -3,6 +3,6 @@ . $srcdir/init.sh --set-path=. fail=0; -test-pread || fail=1 +echo abc | test-pread || fail=1 Exit $fail -- 2.30.2