summaryrefslogtreecommitdiff
path: root/tests/dd
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dd')
-rwxr-xr-xtests/dd/reblock20
1 files changed, 15 insertions, 5 deletions
diff --git a/tests/dd/reblock b/tests/dd/reblock
index ef9e03613..7631acc19 100755
--- a/tests/dd/reblock
+++ b/tests/dd/reblock
@@ -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