maint: use standard spacing in shebang line in tests
[coreutils.git] / tests / dd / stats.sh
blobda2c2d25ff6f426f9acdb4406c8deb35b7bfa7d8
1 #!/bin/sh
2 # Check stats output for SIG{INFO,USR1} and status=progress
4 # Copyright (C) 2014-2015 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
21 require_trap_signame_
23 kill -l | grep 'INFO' && SIGINFO='INFO' || SIGINFO='USR1'
25 # This to avoid races in the USR1 case
26 # as the dd process will terminate by default until
27 # it has its handler enabled.
28 trap '' $SIGINFO
30 mkfifo_or_skip_ fifo
32 # Terminate any background processes
33 cleanup_()
35 kill $pid 2>/dev/null
36 kill $pid2 2>/dev/null
37 wait
40 for open in '' '1'; do
41 # Run dd with the fullblock iflag to avoid short reads
42 # which can be triggered by reception of signals
43 dd iflag=fullblock if=/dev/zero of=fifo count=50 bs=5000000 2>err & pid=$!
45 # Note if we sleep here we give dd a chance to exec and block on open.
46 # Otherwise we're probably testing SIG_IGN in the forked shell or early dd.
47 test "$open" && sleep .1
49 # dd will block on open until fifo is opened for reading.
50 # Timeout in case dd goes away erroneously which we check for below.
51 timeout 20 sh -c 'wc -c < fifo > nwritten' & pid2=$!
53 # Send lots of signals immediately to ensure dd not killed due
54 # to race setting handler, or blocking on open of fifo.
55 # Many signals also check that short reads are handled.
56 until ! kill -s $SIGINFO $pid 2>/dev/null; do
57 sleep .01
58 done
60 wait
62 # Ensure all data processed and at least last status written
63 grep '250000000 bytes .* copied' err || { cat err; fail=1; }
64 done
66 progress_output()
68 { sleep "$1"; echo 1; } | dd bs=1 status=progress of=/dev/null 2>err
69 # Progress output should be for "byte ... copied", while final is "bytes ..."
70 grep 'byte .* copied' err
72 retry_delay_ progress_output 1 4 || { cat err; fail=1; }
74 Exit $fail