1#!/bin/sh 2# Test for proper detection of I/O errors in seq 3 4# Copyright (C) 2016-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_ seq 21 22if ! test -w /dev/full || ! test -c /dev/full; then 23 skip_ '/dev/full is required' 24fi 25 26# Run 'seq' with a timeout, preventing infinite-loop run. 27# expected returned codes: 28# 1 - seq detected an I/O error and exited with an error. 29# 124 - timed-out (seq likely infloop) 30# other - unexpected error 31timed_seq_fail() { timeout 10 seq "$@" >/dev/full 2>/dev/null; } 32 33 34# Test infinite sequence, using fast-path method (seq_fast). 35returns_ 1 timed_seq_fail 1 inf || fail=1 36 37# Test infinite sequence, using slow-path method (print_numbers). 38returns_ 1 timed_seq_fail 1.1 .1 inf || fail=1 39 40# Test non-infinite sequence, using slow-path method (print_numbers). 41# (despite being non-infinite, the entire sequence should take long time to 42# print. Thus, either an I/O error is detected immediately, or seq will 43# timeout). 44returns_ 1 timed_seq_fail 1 0.0001 99999999 || fail=1 45 46Exit $fail 47