maint: update all copyright year number ranges
[coreutils.git] / tests / dd / reblock.sh
blob8eb87128958df0af58e48316ca4b401a9eaeda98
1 #!/bin/sh
2 # test dd reblocking vs. bs=
4 # Copyright (C) 2008-2017 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 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ dd
22 # 2 short reads -> 1 full write + 1 partial write
23 cat <<\EOF > exp-reblock || framework_failure_
24 0+2 records in
25 1+1 records out
26 4 bytes copied
27 EOF
29 # 2 short reads -> 2 partial writes
30 cat <<\EOF > exp-no-reblock || framework_failure_
31 0+2 records in
32 0+2 records out
33 4 bytes copied
34 EOF
37 # Use a fifo rather than a pipe in the tests below
38 # so that the producer (printf subshell) will wait
39 # until the consumer (dd) opens the fifo therefore
40 # increasing the chance that dd will read the data
41 # from each printf separately.
42 mkfifo_or_skip_ dd.fifo
44 dd_reblock_1()
46 local delay="$1"
48 # ensure that dd reblocks when bs= is not specified
49 dd ibs=3 obs=3 if=dd.fifo > out 2> err&
50 (printf 'ab'; sleep $delay; printf 'cd') > dd.fifo
51 wait #for dd to complete
52 sed 's/,.*//' err > k && mv k err
53 compare exp-reblock err
56 retry_delay_ dd_reblock_1 .1 6 || fail=1
58 dd_reblock_2()
60 local delay="$1"
62 # Demonstrate that bs=N supersedes even following ibs= and obs= settings.
63 dd bs=3 ibs=1 obs=1 if=dd.fifo > out 2> err&
64 (printf 'ab'; sleep $delay; printf 'cd') > dd.fifo
65 wait #for dd to complete
66 sed 's/,.*//' err > k && mv k err
67 compare exp-no-reblock err
70 retry_delay_ dd_reblock_2 .1 6 || fail=1
72 Exit $fail