summaryrefslogtreecommitdiff
path: root/tests/dd/no-allocate.sh
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2013-12-11 04:36:08 +0000
committerPádraig Brady <P@draigBrady.com>2013-12-13 02:29:03 +0000
commit41e9a094ad1fd49c8887da24f0fabf222272bfbe (patch)
tree445fc57642e1f00ddb5bb7ad4ecd712214c90a4f /tests/dd/no-allocate.sh
parent10ffe43d68f085995de5b95a8b301a9b7170eac2 (diff)
downloadcoreutils-41e9a094ad1fd49c8887da24f0fabf222272bfbe.tar.xz
tests: avoid unlikely deadlock in dd/no-allocate on some shells
* test/dd/no-allocate.sh: Use 'wait' to ensure we don't have multiple writers to the fifo, which was seen to trigger a very hard to reproduce deadlock with make -j20 on solaris. Also avoid writing to the fifo with the shell; instead using dd. (check_dd_seek_alloc): A new function refactored from the various cases, which are now constructed from function parameters.
Diffstat (limited to 'tests/dd/no-allocate.sh')
-rwxr-xr-xtests/dd/no-allocate.sh53
1 files changed, 35 insertions, 18 deletions
diff --git a/tests/dd/no-allocate.sh b/tests/dd/no-allocate.sh
index dd1a7408b..8823b8836 100755
--- a/tests/dd/no-allocate.sh
+++ b/tests/dd/no-allocate.sh
@@ -20,34 +20,51 @@
print_ver_ dd
require_ulimit_v_
-# count and skip is zero, we don't need to allocate memory
+# 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
+check_dd_seek_alloc() {
+ local file="$1"
+ local buf="$2"
+ test "$file" = 'in' && { dd_file=if; dd_op=skip; }
+ test "$file" = 'out' && { dd_file=of; dd_op=seek; }
+ test "$buf" = 'in' && { dd_buf=ibs; }
+ test "$buf" = 'out' && { dd_buf=obs; }
+ test "$buf" = 'both' && { dd_buf=bs; }
-# Use a fifo for which seek fails, but read does not
-if mkfifo tape; then
- # for non seekable output we need to allocate buffer when needed
- echo 1 > tape&
- (ulimit -v 20000; dd bs=30M skip=1 count=0 if=tape) && fail=1
-
- echo 1 > tape&
- (ulimit -v 20000; dd ibs=30M skip=1 count=0 if=tape) && fail=1
+ # Provide input to the "tape"
+ timeout 10 dd count=1 if=/dev/zero of=tape&
- echo 1 > tape&
- (ulimit -v 20000; dd obs=30M skip=1 count=0 if=tape) || fail=1
+ # Allocate buffer and read from the "tape"
+ (ulimit -v 20000; 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
+ test $ret = 124 && framework_failure_
- # for non seekable output we need to allocate buffer when needed
- echo 1 > tape&
- (ulimit -v 20000; dd bs=30M seek=1 count=0 of=tape) && fail=1
+ # This should happen without delay,
+ # and is used to ensure we've not multiple writers to the "tape"
+ wait
- echo 1 > tape&
- (ulimit -v 20000; dd obs=30M seek=1 count=0 of=tape) && fail=1
+ # We want the "tape" reader to fail iff allocating
+ # a large buffer corresponding to the file being read
+ case "$file$buf" in
+ inout|outin) test $ret = 0;;
+ *) test $ret != 0;;
+ esac
+}
- echo 1 > tape&
- (ulimit -v 20000; dd ibs=30M seek=1 count=0 of=tape) || fail=1
+# Use a fifo for which seek fails, but read does not.
+# For non seekable output we need to allocate a buffer
+# when simulating seeking with a read.
+if mkfifo tape; then
+ for file in 'in' 'out'; do
+ for buf in 'both' 'in' 'out'; do
+ check_dd_seek_alloc "$file" "$buf" || fail=1
+ done
+ done
fi
Exit $fail