maint: reorganize latest NEWS
[coreutils/ericb.git] / tests / dd / reblock
blob9c9b0f85f2e19170654821b4d61d9faa0bd826d4
1 #!/bin/sh
2 # test dd reblocking vs. bs=
4 # Copyright (C) 2008-2010 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 if test "$VERBOSE" = yes; then
20 set -x
21 dd --version
24 . $srcdir/test-lib.sh
26 # 2 short reads -> 1 full write + 1 partial write
27 cat <<\EOF > exp-reblock || framework_failure
28 0+2 records in
29 1+1 records out
30 4 bytes (4 B) copied
31 EOF
33 # 2 short reads -> 2 partial writes
34 cat <<\EOF > exp-no-reblock || framework_failure
35 0+2 records in
36 0+2 records out
37 4 bytes (4 B) copied
38 EOF
41 # Use a fifo rather than a pipe in the tests below
42 # so that the producer (printf subshell) will wait
43 # until the consumer (dd) opens the fifo therefore
44 # increasing the chance that dd will read the data
45 # from each printf separately.
46 mkfifo dd.fifo || framework_failure
48 dd_reblock_1()
50 local delay="$1"
52 # ensure that dd reblocks when bs= is not specified
53 dd ibs=3 obs=3 if=dd.fifo > out 2> err&
54 (printf 'ab'; sleep $delay; printf 'cd') > dd.fifo
55 wait #for dd to complete
56 sed 's/,.*//' err > k && mv k err
57 compare err exp-reblock
60 retry_delay_ dd_reblock_1 .1 6 || fail=1
62 dd_reblock_2()
64 local delay="$1"
66 # Demonstrate that bs=N supersedes even following ibs= and obs= settings.
67 dd bs=3 ibs=1 obs=1 if=dd.fifo > out 2> err&
68 (printf 'ab'; sleep $delay; printf 'cd') > dd.fifo
69 wait #for dd to complete
70 sed 's/,.*//' err > k && mv k err
71 compare err exp-no-reblock
74 retry_delay_ dd_reblock_2 .1 6 || fail=1
76 Exit $fail