git: 73e0d6b44038 - main - tests: Avoid sleep when causing a write error
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 03 Jun 2026 22:10:52 UTC
The branch main has been updated by jilles:
URL: https://cgit.FreeBSD.org/src/commit/?id=73e0d6b44038d1c7764c5013a54ae17a8f680a69
commit 73e0d6b44038d1c7764c5013a54ae17a8f680a69
Author: Jilles Tjoelker <jilles@FreeBSD.org>
AuthorDate: 2026-06-03 22:10:08 +0000
Commit: Jilles Tjoelker <jilles@FreeBSD.org>
CommitDate: 2026-06-03 22:10:08 +0000
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
---
bin/pwd/tests/pwd_test.sh | 15 ++++++++-------
usr.bin/asa/tests/asa_test.sh | 12 +++++++-----
usr.bin/cmp/tests/cmp_test2.sh | 12 +++++++-----
usr.bin/du/tests/du_test.sh | 12 +++++++-----
usr.bin/env/tests/env_test.sh | 12 +++++++-----
usr.bin/ident/tests/ident_test.sh | 12 +++++++-----
usr.bin/printenv/tests/printenv_test.sh | 13 +++++++------
usr.bin/uniq/tests/uniq_test.sh | 13 +++++++------
usr.bin/yes/tests/yes_test.sh | 13 +++++++------
9 files changed, 64 insertions(+), 50 deletions(-)
diff --git a/bin/pwd/tests/pwd_test.sh b/bin/pwd/tests/pwd_test.sh
index a8805582cc4d..db062b253a0d 100644
--- a/bin/pwd/tests/pwd_test.sh
+++ b/bin/pwd/tests/pwd_test.sh
@@ -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
}
diff --git a/usr.bin/asa/tests/asa_test.sh b/usr.bin/asa/tests/asa_test.sh
index 2b8fecb12d98..d6cb9f404318 100644
--- a/usr.bin/asa/tests/asa_test.sh
+++ b/usr.bin/asa/tests/asa_test.sh
@@ -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
}
diff --git a/usr.bin/cmp/tests/cmp_test2.sh b/usr.bin/cmp/tests/cmp_test2.sh
index bca8fc18a6b8..b148e77b62b2 100755
--- a/usr.bin/cmp/tests/cmp_test2.sh
+++ b/usr.bin/cmp/tests/cmp_test2.sh
@@ -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
}
diff --git a/usr.bin/du/tests/du_test.sh b/usr.bin/du/tests/du_test.sh
index 16accdcb42a1..5b298785c058 100755
--- a/usr.bin/du/tests/du_test.sh
+++ b/usr.bin/du/tests/du_test.sh
@@ -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
}
diff --git a/usr.bin/env/tests/env_test.sh b/usr.bin/env/tests/env_test.sh
index 3210361eb223..ed1d82f38281 100644
--- a/usr.bin/env/tests/env_test.sh
+++ b/usr.bin/env/tests/env_test.sh
@@ -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
}
diff --git a/usr.bin/ident/tests/ident_test.sh b/usr.bin/ident/tests/ident_test.sh
index 9dcc45a1625f..2fae2fe8d1e1 100755
--- a/usr.bin/ident/tests/ident_test.sh
+++ b/usr.bin/ident/tests/ident_test.sh
@@ -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
}
diff --git a/usr.bin/printenv/tests/printenv_test.sh b/usr.bin/printenv/tests/printenv_test.sh
index 83535a555b17..8a9650819d82 100644
--- a/usr.bin/printenv/tests/printenv_test.sh
+++ b/usr.bin/printenv/tests/printenv_test.sh
@@ -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
}
diff --git a/usr.bin/uniq/tests/uniq_test.sh b/usr.bin/uniq/tests/uniq_test.sh
index fc143632bdd2..46233640b5de 100755
--- a/usr.bin/uniq/tests/uniq_test.sh
+++ b/usr.bin/uniq/tests/uniq_test.sh
@@ -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
}
diff --git a/usr.bin/yes/tests/yes_test.sh b/usr.bin/yes/tests/yes_test.sh
index 797ac5f6ac9f..5f2f4566d01a 100644
--- a/usr.bin/yes/tests/yes_test.sh
+++ b/usr.bin/yes/tests/yes_test.sh
@@ -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
}