xref: /netbsd-src/tests/lib/libc/stdio/t_intr.sh (revision 0462042f3b0ebfe2a8f811c87688fadbedc7c189)
1*0462042fSgson# $NetBSD: t_intr.sh,v 1.7 2024/05/01 11:40:25 gson Exp $
299be3a9dSchristos#
399be3a9dSchristos# Copyright (c) 2021 The NetBSD Foundation, Inc.
499be3a9dSchristos# All rights reserved.
599be3a9dSchristos#
699be3a9dSchristos# This code is derived from software contributed to The NetBSD Foundation
799be3a9dSchristos# by Christos Zoulas.
899be3a9dSchristos#
999be3a9dSchristos# Redistribution and use in source and binary forms, with or without
1099be3a9dSchristos# modification, are permitted provided that the following conditions
1199be3a9dSchristos# are met:
1299be3a9dSchristos# 1. Redistributions of source code must retain the above copyright
1399be3a9dSchristos#    notice, this list of conditions and the following disclaimer.
1499be3a9dSchristos# 2. Redistributions in binary form must reproduce the above copyright
1599be3a9dSchristos#    notice, this list of conditions and the following disclaimer in the
1699be3a9dSchristos#    documentation and/or other materials provided with the distribution.
1799be3a9dSchristos#
1899be3a9dSchristos# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1999be3a9dSchristos# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2099be3a9dSchristos# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2199be3a9dSchristos# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2299be3a9dSchristos# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2399be3a9dSchristos# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2499be3a9dSchristos# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2599be3a9dSchristos# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2699be3a9dSchristos# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2799be3a9dSchristos# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2899be3a9dSchristos# POSSIBILITY OF SUCH DAMAGE.
2999be3a9dSchristos#
3099be3a9dSchristos
3199be3a9dSchristosDIR=$(atf_get_srcdir)
3299be3a9dSchristosMAX=10000000
3399be3a9dSchristosLMAX=1000000
3499be3a9dSchristosBSIZE=128000
3599be3a9dSchristosSSIZE=256000
3699be3a9dSchristosTMOUT=20
3799be3a9dSchristos
3899be3a9dSchristosh_test() {
39e417ffbfSgson	local avail=$( df -m . | awk '{if (int($4) > 0) print $4}' )
40*0462042fSgson	# The test data are stored in triplicate: numbers.in, numbers.out,
41*0462042fSgson	# and a temporary "stdout" file created by ATF.  Each line consists
42*0462042fSgson	# of up to 7 digits and a newline for a total of 8 bytes.
43*0462042fSgson	local need=$(( 3 * $MAX * 8 / 1000000 ))
44e417ffbfSgson	if [ $avail -lt $need ]; then
45e417ffbfSgson		atf_skip "not enough free space in working directory"
46e417ffbfSgson	fi
47e417ffbfSgson
4899be3a9dSchristos	"${DIR}/h_makenumbers" "$1" > numbers.in
4999be3a9dSchristos	"${DIR}/h_intr" \
50ad9a00f7Schristos	    -p "$2" -a ${SSIZE} -b ${BSIZE} -t ${TMOUT} \
5199be3a9dSchristos	    -c "dd of=numbers.out msgfmt=quiet" numbers.in
52984acdf0Srillig	atf_check -o "file:numbers.in" cat numbers.out
5399be3a9dSchristos}
5499be3a9dSchristos
5599be3a9dSchristosatf_test_case stdio_intr_ionbf
5699be3a9dSchristosstdio_intr_ionbf_head()
5799be3a9dSchristos{
5899be3a9dSchristos	atf_set "descr" "Checks stdio EINTR _IONBF"
5999be3a9dSchristos}
6099be3a9dSchristosstdio_intr_ionbf_body()
6199be3a9dSchristos{
6299be3a9dSchristos	h_test ${MAX} IONBF
6399be3a9dSchristos}
6499be3a9dSchristos
6599be3a9dSchristosatf_test_case stdio_intr_iolbf
6699be3a9dSchristosstdio_intr_iolbf_head()
6799be3a9dSchristos{
6899be3a9dSchristos	atf_set "descr" "Checks stdio EINTR _IOLBF"
6999be3a9dSchristos}
7099be3a9dSchristosstdio_intr_iolbf_body()
7199be3a9dSchristos{
7299be3a9dSchristos	h_test ${LMAX} IOLBF
7399be3a9dSchristos}
7499be3a9dSchristos
7599be3a9dSchristosatf_test_case stdio_intr_iofbf
7699be3a9dSchristosstdio_intr_iofbf_head()
7799be3a9dSchristos{
7899be3a9dSchristos	atf_set "descr" "Checks stdio EINTR _IOFBF"
7999be3a9dSchristos}
8099be3a9dSchristosstdio_intr_iofbf_body()
8199be3a9dSchristos{
82984acdf0Srillig	h_test ${LMAX} IOFBF
8399be3a9dSchristos}
8499be3a9dSchristos
8599be3a9dSchristosatf_init_test_cases()
8699be3a9dSchristos{
8799be3a9dSchristos	atf_add_test_case stdio_intr_ionbf
8899be3a9dSchristos	atf_add_test_case stdio_intr_iolbf
890e225f3bSrillig	# flappy test; see fflush.c 1.19 to 1.24
900e225f3bSrillig	#atf_add_test_case stdio_intr_iofbf
9199be3a9dSchristos}
92