]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: pr: add a test for bounded memory operation
authorCollin Funk <collin.funk1@gmail.com>
Sat, 15 Nov 2025 08:32:48 +0000 (00:32 -0800)
committerCollin Funk <collin.funk1@gmail.com>
Sat, 15 Nov 2025 19:34:21 +0000 (11:34 -0800)
* tests/pr/bounded-memory.sh: New file.
* tests/local.mk (all_tests): Add the test.

tests/local.mk
tests/pr/bounded-memory.sh [new file with mode: 0755]

index 8f58693afffaa19c3ef36ee7dde9a770d9084149..fd484476a8277419174e58fcadcf1d25d0947ca5 100644 (file)
@@ -277,6 +277,7 @@ all_tests =                                 \
   tests/od/od-float.sh                         \
   tests/misc/mktemp.pl                         \
   tests/misc/arch.sh                           \
+  tests/pr/bounded-memory.sh                   \
   tests/pr/pr-tests.pl                         \
   tests/pwd/pwd-option.sh                      \
   tests/chcon/chcon-fail.sh                    \
diff --git a/tests/pr/bounded-memory.sh b/tests/pr/bounded-memory.sh
new file mode 100755 (executable)
index 0000000..b5225a6
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+# Test that 'pr' can work on files larger than the systems memory.
+
+# Copyright (C) 2025 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_ pr
+
+vm=$(get_min_ulimit_v_ pr < /dev/null) ||
+  skip_ 'failed to determine memory limit'
+
+timeout 0.5 $SHELL -c \
+  "(ulimit -v $(($vm+6000)) \
+    && pr < /dev/zero > /dev/null 2>err)"
+ret=$?
+test -f err || skip_ 'shell ulimit failure'
+test $ret = 124 || {
+  fail=1
+  cat err
+  echo "pr used too much memory" >&2
+}
+
+Exit $fail