tests: Avoid sleep when causing a write error
Cause a write error using a fifo and wait, rather than needing a sleep to wait for something to terminate. This is faster and avoids a potential test failure on a heavily loaded system. Using /dev/full would be simpler, but it is not portable enough (it tends not to be available in jails, even). Starting programs with stdout not open or only open for read/execute/search may have unexpected side effects. Reviewed by: ngie, des Differential Revision: https://reviews.freebsd.org/D57213
This commit is contained in:
@@ -75,14 +75,15 @@ stdout_body()
|
||||
{
|
||||
pwd=$(which pwd)
|
||||
[ -f "$pwd" ] || atf_skip "unable to distinguish binary from builtin"
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
# Give true(1) some time to exit.
|
||||
sleep 1
|
||||
$pwd 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
"$pwd" 2>stderr
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -68,13 +68,15 @@ stdout_head() {
|
||||
atf_set descr "Failure to write to stdout"
|
||||
}
|
||||
stdout_body() {
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
sleep 1
|
||||
echo " $a $b" | asa 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -136,13 +136,15 @@ bflag_body()
|
||||
# Helper for stdout test case
|
||||
atf_check_stdout()
|
||||
{
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
sleep 1
|
||||
cmp "$@" 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"2\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 2 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -306,13 +306,15 @@ stdout_head()
|
||||
}
|
||||
stdout_body()
|
||||
{
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
sleep 1
|
||||
du 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
Vendored
+7
-5
@@ -137,13 +137,15 @@ stdout_head()
|
||||
}
|
||||
stdout_body()
|
||||
{
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
sleep 1
|
||||
env 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -70,13 +70,15 @@ stdout_head()
|
||||
stdout_body()
|
||||
{
|
||||
local dir=$(atf_get_srcdir)
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
sleep 1
|
||||
ident "${dir}"/test.in 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -78,14 +78,15 @@ stdout_head()
|
||||
}
|
||||
stdout_body()
|
||||
{
|
||||
local dir=$(atf_get_srcdir)
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
sleep 1
|
||||
printenv 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -197,14 +197,15 @@ stdout_head() {
|
||||
atf_set descr "error writing to stdout"
|
||||
}
|
||||
stdout_body() {
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
# Give true(1) some time to exit.
|
||||
sleep 1
|
||||
echo a | uniq 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
@@ -66,14 +66,15 @@ stdout_head()
|
||||
}
|
||||
stdout_body()
|
||||
{
|
||||
(
|
||||
mkfifo fifo
|
||||
: <fifo &
|
||||
{
|
||||
wait
|
||||
trap "" PIPE
|
||||
# Give true(1) some time to exit.
|
||||
sleep 1
|
||||
yes 2>stderr
|
||||
echo $? >result
|
||||
) | true
|
||||
atf_check -o inline:"1\n" cat result
|
||||
result=$?
|
||||
} >fifo
|
||||
atf_check_equal 1 "$result"
|
||||
atf_check -o match:"stdout" cat stderr
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user