tests: avoid false failure in tail inotify test
[coreutils.git] / tests / dd / stats.sh
blobf87d2dab290e6dd82de693daa93da3024ceb8179
1 #!/bin/sh
2 # Check stats output for SIG{INFO,USR1} and status=progress
4 # Copyright (C) 2014-2016 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 > err || framework_failure_
43 # Run dd with the fullblock iflag to avoid short reads
44 # which can be triggered by reception of signals
45 dd iflag=fullblock if=/dev/zero of=fifo count=50 bs=5000000 2>err & pid=$!
47 # Note if we sleep here we give dd a chance to exec and block on open.
48 # Otherwise we're probably testing SIG_IGN in the forked shell or early dd.
49 test "$open" && sleep .1
51 # dd will block on open until fifo is opened for reading.
52 # Timeout in case dd goes away erroneously which we check for below.
53 timeout 20 sh -c 'wc -c < fifo > nwritten' & pid2=$!
55 # Send lots of signals immediately to ensure dd not killed due
56 # to race setting handler, or blocking on open of fifo.
57 # Many signals also check that short reads are handled.
58 until ! kill -s $SIGINFO $pid 2>/dev/null; do
59 sleep .01
60 done
62 wait
64 # Ensure all data processed and at least last status written
65 grep '250000000 bytes (250 MB, 238 MiB) copied' err || { cat err; fail=1; }
66 done
68 progress_output()
70 { sleep $1; echo 1; } | dd bs=1 status=progress of=/dev/null 2>err
71 # Progress output should be for "byte copied", while final is "bytes ..."
72 grep 'byte copied' err
74 retry_delay_ progress_output 1 4 || { cat err; fail=1; }
76 Exit $fail