# Determine basic amount of memory needed.
echo . > f || framework_failure_
-vm=$(get_min_ulimit_v_ dd if=f of=f2 status=none) \
+vm=$(get_min_ulimit_v_ timeout 10 dd if=f of=f2 status=none) \
|| skip_ "this shell lacks ulimit support"
-rm -f f || framework_failure_
+rm f f2 || framework_failure_
# count and skip are zero, we don't need to allocate memory
(ulimit -v $vm && dd bs=30M count=0) || fail=1
timeout 10 dd count=1 if=/dev/zero of=tape&
# Allocate buffer and read from the "tape"
- (ulimit -v $(($vm+4000)) \
- && timeout 10 dd $dd_buf=30M $dd_op=1 count=0 $dd_file=tape)
+ (ulimit -v $vm \
+ && 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
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.
+# a 256MiB bit vector.
(ulimit -v $vm && : | cut -b$CUT_MAX- > err 2>&1) || fail=1
# Up to and including coreutils-8.21, cut would allocate possibly needed
# Only allocate memory as needed.
# Coreutils <= 8.21 would allocate memory up front
# based on the value passed to -c
-(ulimit -v $vm && head --bytes=-$SSIZE_MAX < /dev/null) || fail=1
+(ulimit -v $(($vm+1000)) && head --bytes=-$SSIZE_MAX < /dev/null) || fail=1
# Make sure it works on funny files in /proc and /sys.
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.
+# Trigger large mem allocation failure
( ulimit -v $vm && env $prog %20000000f 0 2>err-msg > fifo )
exit=$?