build: update to latest gnulib
[coreutils.git] / tests / dd / stats.sh
blobe906c7486d0cc94bace1a750f68e5d92251b1f4a
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
22 env kill -l | grep '^INFO$' && SIGINFO='INFO' || SIGINFO='USR1'
24 # This to avoid races in the USR1 case
25 # as the dd process will terminate by default until
26 # it has its handler enabled.
27 trap '' $SIGINFO
29 mkfifo_or_skip_ fifo
31 # Terminate any background processes
32 cleanup_()
34 kill $pid 2>/dev/null
35 kill $pid2 2>/dev/null
36 wait
39 for open in '' '1'; do
40 # Run dd with the fullblock iflag to avoid short reads
41 # which can be triggered by reception of signals
42 dd iflag=fullblock if=/dev/zero of=fifo count=100 bs=5000000 2>err & pid=$!
44 # Note if we sleep here we give dd a chance to exec and block on open.
45 # Otherwise we're probably testing SIG_IGN in the forked shell or early dd.
46 test "$open" && sleep .1
48 # dd will block on open until fifo is opened for reading.
49 # Timeout in case dd goes away erroneously which we check for below.
50 timeout 10 sh -c 'wc -c < fifo > nwritten' & pid2=$!
52 # Send lots of signals immediately to ensure dd not killed due
53 # to race setting handler, or blocking on open of fifo.
54 # Many signals also check that short reads are handled.
55 until ! kill -s $SIGINFO $pid 2>/dev/null; do
56 sleep .01
57 done
59 wait
61 # Ensure all data processed and at least last status written
62 grep '500000000 bytes .* copied' err || { cat err; fail=1; }
63 done
65 progress_output()
67 { sleep "$1"; echo 1; } | dd bs=1 status=progress of=/dev/null 2>err
68 # Progress output should be for "byte ... copied", while final is "bytes ..."
69 grep 'byte .* copied' err
71 retry_delay_ progress_output 1 4 || { cat err; fail=1; }
73 Exit $fail