On 12/12/2013 01:34 PM, Bernhard Voelker wrote:
> On 12/11/2013 11:24 AM, Pádraig Brady wrote:
>>> The question is which of the tests hung?
>>> The input (i.e. skip) or the output (i.e. seek) tests?
>>
>> I think it was the last dd, though can't be sure as
>> the net connection died as I was debugging.
> 
> Sorry, I couldn't reproduce it either, and the test code
> looks good to me.  Could it have been a shell issue?

Probably a shell bug.
So what I've done is avoided the shell writing to the fifo.
Also I've added timeouts to be defensive.
Also I added a `wait` to avoid overlapping writers to the fifo.

I tested this test passes without delay on GNU/Linux, Solaris and FreeBSD.

The attached should hopefully be the last change before the release.

thanks,
Pádraig.
>From c6c10d0d0a1c03cb5fe592f2b499eb9923df02c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <[email protected]>
Date: Wed, 11 Dec 2013 04:36:08 +0000
Subject: [PATCH] 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.
---
 tests/dd/no-allocate.sh |   53 +++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/tests/dd/no-allocate.sh b/tests/dd/no-allocate.sh
index dd1a740..8823b88 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
-- 
1.7.7.6

Reply via email to