]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: avoid $SHELL -c "ulimit ..." pattern
authorPádraig Brady <P@draigBrady.com>
Wed, 15 Apr 2026 14:08:27 +0000 (15:08 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Apr 2026 14:08:27 +0000 (15:08 +0100)
As described in commit v9.10-283-g5cb0cca3b
avoid using ulimit with $SHELL -c, and explict
invocation of the shell like that can require lots of memory,
often due to loading the locale archive.
* tests/basenc/bounded-memory.sh: Avoid $SHELL -c with ulimit.
* tests/cut/bounded-memory.sh: Likewise.
* tests/expand/bounded-memory.sh Likewise.
* tests/pr/bounded-memory.sh Likewise.
* tests/unexpand/bounded-memory.sh Likewise.
* tests/fold/fold-zero-width.sh: Bring the ulimit bound
down to the standard 6M over the determined limit.

tests/basenc/bounded-memory.sh
tests/cut/bounded-memory.sh
tests/expand/bounded-memory.sh
tests/fold/fold-zero-width.sh
tests/pr/bounded-memory.sh
tests/unexpand/bounded-memory.sh

index 166d547947c72cf7b876c937eeacd942f619db2c..a34f7d3e3aa1e3b7d9e61f884b294a0880e87940 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ basenc
 
-vm=$(get_min_ulimit_v_ basenc --base64 /dev/null) ||
+vm=$(get_min_ulimit_v_ timeout 10 basenc --base64 /dev/null) ||
   skip_ 'failed to determine memory limit'
 
 # Check all except for --base58.
 for algorithm in '--base64' '--base64url' '--base32' '--base32hex' '--base16' \
                  '--base2msbf' '--base2lsbf' '--z85'; do
-  timeout 0.5 $SHELL -c \
-    "(ulimit -v $(($vm+6000)) \
-      && basenc $algorithm </dev/zero >/dev/null 2>err)"
+  (ulimit -v $(($vm+6000)) \
+    && timeout 0.5 basenc $algorithm </dev/zero >/dev/null 2>err)
   ret=$?
-  test -f err || skip_ 'shell ulimit failure'
   test $ret = 124 || {
     fail=1
     cat err
index 4c60145635444af143de11857cf0f8ea7533926e..5c0018a745ca7368222fde40203cf27be62f8a27 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ cut
 
-vm=$(get_min_ulimit_v_ cut -b1 /dev/null) ||
+vm=$(get_min_ulimit_v_ timeout 10 cut -b1 /dev/null) ||
   skip_ 'failed to determine memory limit'
 
 # There is no way to implement '-s -f1' without allocating unbounded memory.
 # Check the rest.
 for opts in '-c1' '-b1' '-s -f2' '-f1'; do
-  timeout 0.5 $SHELL -c \
-    "(ulimit -v $(($vm+6000)) \
-      && cut $opts </dev/zero >/dev/null 2>err)"
+  (ulimit -v $(($vm+6000)) \
+    && timeout 0.5 cut $opts </dev/zero >/dev/null 2>err)
   ret=$?
-  test -f err || skip_ 'shell ulimit failure'
   test $ret = 124 || {
     fail=1
     cat err
index 8b72e7f38e345b255eecf2d8775728a3ab318acb..76cde9c656958aa8c9c7b26fd0fc6bbd51a59530 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ expand
 
-vm=$(get_min_ulimit_v_ expand /dev/null) ||
+vm=$(get_min_ulimit_v_ timeout 10 expand /dev/null) ||
   skip_ 'failed to determine memory limit'
 
-timeout 0.5 $SHELL -c \
-  "(ulimit -v $(($vm+6000)) \
-    && expand </dev/zero >/dev/null 2>err)"
+(ulimit -v $(($vm+6000)) \
+  && timeout 0.5 expand </dev/zero >/dev/null 2>err)
 ret=$?
-test -f err || skip_ 'shell ulimit failure'
 test $ret = 124 || {
   fail=1
   cat err
index 933d09ca138a100c09df58c0e3121f9291858e2a..1bec0ef34a8f36043996c25bb78e0900b4db8805 100755 (executable)
@@ -58,7 +58,7 @@ vm=$(get_min_ulimit_v_ timeout 10 fold /dev/null) && {
   # \303 results in EILSEQ on input
   for c in '\n' '\0' '\303'; do
     tr '\0' "$c" < /dev/zero |
-     (ulimit -v $(($vm+12000)) && timeout 10 fold 2>err >/dev/full)
+     (ulimit -v $(($vm+6000)) && timeout 10 fold 2>err >/dev/full)
     ret=$?
     { test $ret = 124 || ! grep "$ENOSPC" err >/dev/null; } &&
      { fail=1; cat err; echo "fold didn't diagnose ENOSPC" >&2; }
index 90c265743e5304ebf3b8b1584455c34b84683a12..42083e92a4ceaf6793200795fca45c85f28682df 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ pr
 
-vm=$(get_min_ulimit_v_ pr < /dev/null) ||
+vm=$(get_min_ulimit_v_ timeout 10 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)"
+(ulimit -v $(($vm+6000)) \
+ && timeout 0.5 pr < /dev/zero > /dev/null 2>err)
 ret=$?
-test -f err || skip_ 'shell ulimit failure'
 test $ret = 124 || {
   fail=1
   cat err
index db3d365b4cbf2e94eea562089468e696b39f2f18..d16f6c6b187c9a605275053753dfedcc0aeaac5d 100755 (executable)
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ unexpand
 
-vm=$(get_min_ulimit_v_ unexpand /dev/null) ||
+vm=$(get_min_ulimit_v_ timeout 10 unexpand /dev/null) ||
   skip_ 'failed to determine memory limit'
 
-timeout 0.5 $SHELL -c \
-  "(ulimit -v $(($vm+6000)) \
-    && unexpand </dev/zero >/dev/null 2>err)"
+(ulimit -v $(($vm+6000)) \
+ && timeout 0.5 unexpand </dev/zero >/dev/null 2>err)
 ret=$?
-test -f err || skip_ 'shell ulimit failure'
 test $ret = 124 || {
   fail=1
   cat err