]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: cat: extract checks for distinct read/write errors
authoroech3 <79379754+oech3@users.noreply.github.com>
Thu, 4 Jun 2026 11:15:40 +0000 (20:15 +0900)
committerPádraig Brady <P@draigBrady.com>
Mon, 13 Jul 2026 16:32:39 +0000 (17:32 +0100)
* tests/cat/splice.sh: Move read/error distinction test to ...
* tests/cat/cat-distinct-err.sh: ... here, and augment.
* tests/local.mk: Reference the new file.

tests/cat/cat-distinct-err.sh [new file with mode: 0755]
tests/cat/splice.sh
tests/local.mk

diff --git a/tests/cat/cat-distinct-err.sh b/tests/cat/cat-distinct-err.sh
new file mode 100755 (executable)
index 0000000..cf21be2
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Test that read/write errors are distinguished
+
+# Copyright (C) 2026 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 <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
+print_ver_ cat
+getlimits_
+uses_strace_
+
+# write error
+if test -w /dev/full && test -c /dev/full; then
+  echo "cat: write error: $ENOSPC" >exp || framework_failure_
+  echo 1 | returns_ 1 cat >/dev/full 2>err || fail=1
+  compare exp err || fail=1
+fi
+
+# read error
+if test -e /proc/self/mem &&
+   returns_ 1 dd if=/proc/self/mem bs=1 count=1; then
+  echo "cat: /proc/self/mem: $EIO" >exp || framework_failure_
+  returns_ 1 cat /proc/self/mem 2>err || fail=1
+  compare exp err || fail=1
+fi
+
+# Verify splice is called multiple times,
+# and doesn't just fall back after the first EINVAL.
+# This also implicitly handles systems without splice at all.
+strace -o splice_count -e splice cat /dev/zero | head -c1M >/dev/null
+splice_count=$(grep '^splice' splice_count | wc -l)
+
+# Test that splice errors are diagnosed.
+# Odd numbers are for input, even for output (since cat is not buffered)
+if test "$splice_count" -gt 1 &&
+   strace -o /dev/null -e inject=splice:error=EIO:when=3 true; then
+  for when in 3 4; do
+    test "$when" = 4 && efile='write error' || efile='/dev/zero'
+    printf 'cat: %s: %s\n' "$efile" "$EIO" > exp || framework_failure_
+    returns_ 1 timeout 10 strace -o /dev/null \
+      -e inject=splice:error=EIO:when=$when \
+      cat /dev/zero >/dev/null 2>err || fail=1
+    compare exp err || fail=1
+  done
+fi
+
+Exit $fail
index 55b96711bb5d15fc79fca078e0880a569c5a4200..f1636278ef71088ff9d50443e75660787c2af687 100755 (executable)
@@ -27,26 +27,6 @@ if timeout 10 true; then
   test $? = 124 || fail=1
 fi
 
-# Verify splice is called multiple times,
-# and doesn't just fall back after the first EINVAL.
-# This also implicitly handles systems without splice at all.
-strace -o splice_count -e splice cat /dev/zero | head -c1M >/dev/null
-splice_count=$(grep '^splice' splice_count | wc -l)
-
-# Test that splice errors are diagnosed.
-# Odd numbers are for input, even for output
-if test "$splice_count" -gt 1 &&
-   strace -o /dev/null -e inject=splice:error=EIO:when=3 true; then
-  for when in 3 4; do
-    test "$when" = 4 && efile='write error' || efile='/dev/zero'
-    printf 'cat: %s: %s\n' "$efile" "$EIO" > exp || framework_failure_
-    returns_ 1 timeout 10 strace -o /dev/null \
-      -e inject=splice:error=EIO:when=$when \
-      cat /dev/zero >/dev/null 2>err || fail=1
-    compare exp err || fail=1
-  done
-fi
-
 # Ensure we fallback to write() if there is an issue with (async) zero-copy
 zc_syscalls='io_uring_setup io_uring_enter io_uring_register memfd_create
              sendfile splice tee vmsplice'
index 0001534acf731ce71ef9a742d87a74c9f05e78ee..e2afbe134b9f01ee1cc8d940e524897b429bbe5b 100644 (file)
@@ -310,6 +310,7 @@ all_tests =                                 \
   tests/wc/wc-proc.sh                          \
   tests/wc/wc-sjis.sh                          \
   tests/wc/wc-total.sh                         \
+  tests/cat/cat-distinct-err.sh                        \
   tests/cat/cat-E.sh                           \
   tests/cat/cat-proc.sh                                \
   tests/cat/cat-buf.sh                         \