]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: dd/reblock: Reduce chance of timing related failures
authorPádraig Brady <P@draigBrady.com>
Mon, 1 Dec 2008 01:08:02 +0000 (01:08 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 1 Dec 2008 01:20:18 +0000 (01:20 +0000)
* tests/dd/reblock: Change the IPC mechanism to the dd process
under test, from pipes to fifos. Also change the delay
between data writes to 0.2s for both tests.
This should increase the chance that the dd process
will read the data chunks separately.

tests/dd/reblock

index ef9e0361308f8a8863a1f6e2fa2f74a90e1afef9..7631acc192f505aac4fb3476957e9f5ec5d3bc6b 100755 (executable)
@@ -24,12 +24,14 @@ fi
 . $srcdir/lang-default
 . $srcdir/test-lib.sh
 
+# 2 short reads -> 1 full write + 1 partial write
 cat <<\EOF > exp-reblock || framework_failure
 0+2 records in
 1+1 records out
 4 bytes (4 B) copied
 EOF
 
+# 2 short reads -> 2 partial writes
 cat <<\EOF > exp-no-reblock || framework_failure
 0+2 records in
 0+2 records out
@@ -38,16 +40,24 @@ EOF
 
 fail=0
 
+# Use a fifo rather than a pipe in the tests below
+# so that the producer (printf subshell) will wait
+# until the consumer (dd) opens the fifo therefore
+# increasing the chance that dd will read the data
+# from each printf separately.
+mkfifo dd.fifo || framework_failure
+
 # ensure that dd reblocks when bs= is not specified
-(echo x; sleep .1; echo y) | dd ibs=3 obs=3 > out 2> err || fail=1
+dd ibs=3 obs=3 if=dd.fifo > out 2> err&
+(printf 'ab'; sleep .2; printf 'cd') > dd.fifo
+wait #for dd to complete
 sed 's/,.*//' err > k && mv k err
 compare err exp-reblock || fail=1
 
 # Demonstrate that bs=N supersedes even following ibs= and obs= settings.
-# Choosing a delay of 0.1 would result in an occasional lost race where
-# the consumer's first read would consume 3 bytes rather than the expected 2.
-# Not wanting to sleep a full second, I'll raise that to 0.3.
-(printf ab; sleep .3; printf cd) | dd bs=3 ibs=1 obs=1 > out 2> err || fail=1
+dd bs=3 ibs=1 obs=1 if=dd.fifo > out 2> err&
+(printf 'ab'; sleep .2; printf 'cd') > dd.fifo
+wait #for dd to complete
 sed 's/,.*//' err > k && mv k err
 compare err exp-no-reblock || fail=1