diff options
-rw-r--r-- | cfg.mk | 6 | ||||
-rw-r--r-- | init.cfg | 36 | ||||
-rwxr-xr-x | tests/cp/link-heap.sh | 11 | ||||
-rwxr-xr-x | tests/dd/no-allocate.sh | 16 | ||||
-rwxr-xr-x | tests/misc/csplit-heap.sh | 9 | ||||
-rwxr-xr-x | tests/misc/cut-huge-range.sh | 12 | ||||
-rwxr-xr-x | tests/misc/head-c.sh | 6 | ||||
-rwxr-xr-x | tests/misc/printf-surprise.sh | 5 | ||||
-rwxr-xr-x | tests/rm/many-dir-entries-vs-OOM.sh | 30 | ||||
-rwxr-xr-x | tests/split/line-bytes.sh | 5 |
10 files changed, 83 insertions, 53 deletions
@@ -503,12 +503,12 @@ sc_some_programs_must_avoid_exit_failure: && { echo '$(ME): do not use EXIT_FAILURE in the above' \ 1>&2; exit 1; } || : -# Ensure that tests call the require_ulimit_v_ function if using ulimit -v +# Ensure that tests call the get_min_ulimit_v_ function if using ulimit -v sc_prohibit_test_ulimit_without_require_: - @(git grep -l require_ulimit_v_ $(srcdir)/tests; \ + @(git grep -l get_min_ulimit_v_ $(srcdir)/tests; \ git grep -l 'ulimit -v' $(srcdir)/tests) \ | sort | uniq -u | grep . && { echo "$(ME): the above test(s)"\ - " should match require_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || : + " should match get_min_ulimit_v_ with ulimit -v" 1>&2; exit 1; } || : # Ensure that tests call the cleanup_ function if using background processes sc_prohibit_test_background_without_cleanup_: @@ -144,24 +144,26 @@ require_openat_support_() fi } -require_ulimit_v_() -{ - local ulimit_works=yes - # Expect to be able to exec a program in 10MiB of virtual memory, - # (10MiB is usually plenty, but valgrind-wrapped date requires 19000KiB, - # so allow more in that case) - # but not in 20KiB. I chose "date". It must not be a shell built-in - # function, so you can't use echo, printf, true, etc. - # Of course, in coreutils, I could use $top_builddir/src/true, - # but this should be able to work for other projects, too. +# Determine the minimum required VM limit to run the given command. +# Output that value to stdout ... to be used by the caller. +# Return 0 in case of success, and a non-Zero value otherwise. +get_min_ulimit_v_() +{ local vm - case $(printenv LD_PRELOAD) in */valgrind/*) vm=22000;; *) vm=10000;; esac - - ( ulimit -v $vm; date ) > /dev/null 2>&1 || ulimit_works=no - ( ulimit -v 20; date ) > /dev/null 2>&1 && ulimit_works=no - - test $ulimit_works = no \ - && skip_ "this shell lacks ulimit support" + for v in $( seq 5000 5000 50000 ); do + if ( ulimit -v $v && "$@" ) >/dev/null; then + local vm_prev + prev_v=$v + for v in $( seq $(($prev_v-1000)) -1000 1000 ); do + ( ulimit -v $v && "$@" ) >/dev/null \ + || { echo $prev_v; return 0; } + prev_v=$v + done + fi + done + # The above did not find a working limit. Echo a very small number - just + # in case the caller does not handle the non-Zero return value. + echo 1; return 1 } require_readable_root_() diff --git a/tests/cp/link-heap.sh b/tests/cp/link-heap.sh index 901a92fc7..b65223a59 100755 --- a/tests/cp/link-heap.sh +++ b/tests/cp/link-heap.sh @@ -19,7 +19,12 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ cp expensive_ -require_ulimit_v_ + +# Determine basic amount of memory needed for 'cp -al'. +touch f || framework_failure_ +vm=$(get_min_ulimit_v_ cp -al f f2) \ + || skip_ "this shell lacks ulimit support" +rm f f2 || framework_failure_ a=$(printf %031d 0) b=$(printf %031d 1) @@ -31,7 +36,7 @@ cp -al $a $b || framework_failure_ mkdir e || framework_failure_ mv $a $b e || framework_failure_ -# Increased from 20000 to 22000 in 2012, for pre-F18 rawhide. -(ulimit -v 22000; cp -al e f) || fail=1 +# Allow cp(1) to use 4MiB more virtual memory than for the above trivial case. +(ulimit -v $(($vm+4000)) && cp -al e f) || fail=1 Exit $fail diff --git a/tests/dd/no-allocate.sh b/tests/dd/no-allocate.sh index 99e0542ac..d122e3544 100755 --- a/tests/dd/no-allocate.sh +++ b/tests/dd/no-allocate.sh @@ -18,12 +18,17 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ dd -require_ulimit_v_ + +# Determine basic amount of memory needed. +echo . > f || framework_failure_ +vm=$(get_min_ulimit_v_ dd if=f of=f2 status=none) \ + || skip_ "this shell lacks ulimit support" +rm -f f || framework_failure_ # count and skip are zero, we don't need to allocate memory -(ulimit -v 20000; dd bs=30M count=0) || fail=1 -(ulimit -v 20000; dd ibs=30M count=0) || fail=1 -(ulimit -v 20000; dd obs=30M count=0) || fail=1 +(ulimit -v $vm && dd bs=30M count=0) || fail=1 +(ulimit -v $vm && dd ibs=30M count=0) || fail=1 +(ulimit -v $vm && dd obs=30M count=0) || fail=1 check_dd_seek_alloc() { local file="$1" @@ -38,7 +43,8 @@ check_dd_seek_alloc() { timeout 10 dd count=1 if=/dev/zero of=tape& # Allocate buffer and read from the "tape" - (ulimit -v 20000; timeout 10 dd $dd_buf=30M $dd_op=1 count=0 $dd_file=tape) + (ulimit -v $(($vm+4000)) \ + && timeout 10 dd $dd_buf=30M $dd_op=1 count=0 $dd_file=tape) local ret=$? # Be defensive in case the tape reader is blocked for some reason diff --git a/tests/misc/csplit-heap.sh b/tests/misc/csplit-heap.sh index 9e51cb15f..0ffe70ad4 100755 --- a/tests/misc/csplit-heap.sh +++ b/tests/misc/csplit-heap.sh @@ -19,11 +19,14 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ csplit -require_ulimit_v_ +# Determine basic amount of memory needed. +{ echo y; echo n; } > f || framework_failure_ +vm=$(get_min_ulimit_v_ csplit -z f %n%1) \ + || skip_ "this shell lacks ulimit support" ( - ulimit -v 20000 - { yes | head -n2500000; echo n; } | csplit -z - %n%1 + ulimit -v $vm \ + && { yes | head -n2500000; echo n; } | csplit -z - %n%1 ) || fail=1 Exit $fail diff --git a/tests/misc/cut-huge-range.sh b/tests/misc/cut-huge-range.sh index 035d8d087..4df2fc066 100755 --- a/tests/misc/cut-huge-range.sh +++ b/tests/misc/cut-huge-range.sh @@ -18,9 +18,11 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ cut -require_ulimit_v_ getlimits_ +vm=$(get_min_ulimit_v_ cut -b1 /dev/null) \ + || skip_ "this shell lacks ulimit support" + # sed script to subtract one from the input. # Each input line should consist of a positive decimal number. # Each output line's number is one less than the input's. @@ -49,15 +51,15 @@ CUT_MAX=$(echo $SIZE_MAX | sed "$subtract_one") # From coreutils-8.10 through 8.20, this would make cut try to allocate # a 256MiB bit vector. With a 20MB limit on VM, the following would fail. -(ulimit -v 20000; : | cut -b$CUT_MAX- > err 2>&1) || fail=1 +(ulimit -v $vm && : | cut -b$CUT_MAX- > err 2>&1) || fail=1 # Up to and including coreutils-8.21, cut would allocate possibly needed # memory upfront. Subsequently extra memory is no longer needed. -(ulimit -v 20000; : | cut -b1-$CUT_MAX >> err 2>&1) || fail=1 +(ulimit -v $vm && : | cut -b1-$CUT_MAX >> err 2>&1) || fail=1 # Explicitly disallow values above CUT_MAX -(ulimit -v 20000; : | returns_ 1 cut -b$SIZE_MAX 2>/dev/null) || fail=1 -(ulimit -v 20000; : | returns_ 1 cut -b$SIZE_OFLOW 2>/dev/null) || fail=1 +(ulimit -v $vm && : | returns_ 1 cut -b$SIZE_MAX 2>/dev/null) || fail=1 +(ulimit -v $vm && : | returns_ 1 cut -b$SIZE_OFLOW 2>/dev/null) || fail=1 compare /dev/null err || fail=1 diff --git a/tests/misc/head-c.sh b/tests/misc/head-c.sh index a553a55bc..ab821ac61 100755 --- a/tests/misc/head-c.sh +++ b/tests/misc/head-c.sh @@ -18,9 +18,11 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ head -require_ulimit_v_ getlimits_ +vm=$(get_min_ulimit_v_ head -c1 /dev/null) \ + || skip_ "this shell lacks ulimit support" + # exercise the fix of 2001-08-18, based on test case from Ian Bruce echo abc > in || framework_failure_ (head -c1; head -c1) < in > out || fail=1 @@ -40,7 +42,7 @@ esac # Only allocate memory as needed. # Coreutils <= 8.21 would allocate memory up front # based on the value passed to -c -(ulimit -v 20000; head --bytes=-$SSIZE_MAX < /dev/null) || fail=1 +(ulimit -v $vm && head --bytes=-$SSIZE_MAX < /dev/null) || fail=1 # Make sure it works on funny files in /proc and /sys. diff --git a/tests/misc/printf-surprise.sh b/tests/misc/printf-surprise.sh index 20e6b0988..8480693fc 100755 --- a/tests/misc/printf-surprise.sh +++ b/tests/misc/printf-surprise.sh @@ -20,8 +20,9 @@ prog=printf . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ printf -require_ulimit_v_ +vm=$(get_min_ulimit_v_ env $prog %20f 0) \ + || skip_ "this shell lacks ulimit support" # Up to coreutils-6.9, "printf %.Nf 0" would encounter an ENOMEM internal # error from glibc's printf(3) function whenever N was large relative to @@ -60,7 +61,7 @@ head -c 10 fifo > out & pid=$! # Choosing the virtual memory limit, 11000 is enough, but 10000 is too # little and provokes a "memory exhausted" diagnostic on FreeBSD 9.0-p3. -( ulimit -v 15000; env $prog %20000000f 0 2>err-msg > fifo ) +( ulimit -v $vm && env $prog %20000000f 0 2>err-msg > fifo ) exit=$? # Map this longer, and rarer, diagnostic to the common one. diff --git a/tests/rm/many-dir-entries-vs-OOM.sh b/tests/rm/many-dir-entries-vs-OOM.sh index e9c95d5d5..8cc839bd1 100755 --- a/tests/rm/many-dir-entries-vs-OOM.sh +++ b/tests/rm/many-dir-entries-vs-OOM.sh @@ -19,21 +19,29 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ rm du chmod -require_ulimit_v_ - expensive_ +mkdir d2 \ + && touch d2/f || framework_failure_ + +# Restrict memory. Each of these coreutils-8.12 programs would fail +# with a diagnostic like "rm: fts_read failed: Cannot allocate memory". +vm=$(get_min_ulimit_v_ du -sh d2) \ + || skip_ "this shell lacks ulimit support" + # With many files in a single directory... -mkdir d && cd d || framework_failure_ -seq 200000|xargs touch || framework_failure_ +mkdir d || framework_failure_ +seq --format="d/%06g" 200000 | xargs touch || framework_failure_ -cd .. +# Allow 35MiB more memory as for the trivial case above. +(ulimit -v $(($vm + 35000)) && du -sh d) || fail=1 -# Restricted to 40MB, each of these coreutils-8.12 programs would fail -# with a diagnostic like "rm: fts_read failed: Cannot allocate memory". -ulimit -v 40000 -du -sh d || fail=1 -chmod -R 700 d || fail=1 -rm -rf d || fail=1 +vm=$(get_min_ulimit_v_ chmod -R 700 d2) \ + || skip_ "this shell lacks ulimit support" +(ulimit -v $(($vm + 35000)) && chmod -R 700 d) || fail=1 + +vm=$(get_min_ulimit_v_ rm -rf d2) \ + || skip_ "this shell lacks ulimit support" +(ulimit -v $(($vm + 35000)) && rm -rf d) || fail=1 Exit $fail diff --git a/tests/split/line-bytes.sh b/tests/split/line-bytes.sh index 6e2f13765..f2f0f8fd0 100755 --- a/tests/split/line-bytes.sh +++ b/tests/split/line-bytes.sh @@ -18,11 +18,12 @@ . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src print_ver_ split -require_ulimit_v_ +vm=$(get_min_ulimit_v_ split -C 'K' /dev/null) \ + || skip_ "this shell lacks ulimit support" # Ensure memory is not allocated up front -(ulimit -v 20000; split -C 'G' /dev/null) || fail=1 +(ulimit -v $vm && split -C 'G' /dev/null) || fail=1 # Ensure correct operation with various split and buffer size combinations |