1#!/bin/sh 2# Check stats output for SIG{INFO,USR1} and status=progress 3 4# Copyright (C) 2014-2023 Free Software Foundation, Inc. 5 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. 10 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. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ dd 21require_trap_signame_ 22 23kill -l | grep 'INFO' && SIGINFO='INFO' || SIGINFO='USR1' 24 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. 28trap '' $SIGINFO 29 30mkfifo_or_skip_ fifo 31 32# Terminate any background processes 33cleanup_() 34{ 35 kill $pid 2>/dev/null 36 kill $pid2 2>/dev/null 37 wait 38} 39 40for open in '' '1'; do 41 > err || framework_failure_ 42 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=$! 46 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 50 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 60 sh -c 'wc -c < fifo > nwritten' & pid2=$! 54 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 61 62 wait 63 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; } 66done 67 68progress_output() 69{ 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 73} 74retry_delay_ progress_output 1 4 || { cat err; fail=1; } 75 76Exit $fail 77