From ddc0daea20280c3a06a910b72b14ffe3f624df71 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Wed, 4 Sep 2019 16:25:41 +0000 Subject: [PATCH] procstat/tests: Fix flakiness by waiting for program to start Some of the procstat tests start a program "while1" and examine the process using procstat, but did not wait properly for it to start (kill -0 will succeed immediately after the child process has been created). Instead, have "while1" write something when it starts, and use a fifo to wait for that. PR: 233587, 233588 Reviewed by: ngie MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D21519 --- usr.bin/procstat/tests/procstat_test.sh | 18 +++++------------- usr.bin/procstat/tests/while1.c | 5 +++-- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/usr.bin/procstat/tests/procstat_test.sh b/usr.bin/procstat/tests/procstat_test.sh index ba6aad045b76..b96c36bffce2 100755 --- a/usr.bin/procstat/tests/procstat_test.sh +++ b/usr.bin/procstat/tests/procstat_test.sh @@ -25,7 +25,6 @@ # $FreeBSD$ # -MAX_TRIES=20 PROG_PID= PROG_PATH=$(atf_get_srcdir)/while1 @@ -37,16 +36,13 @@ start_program() PROG_COMM=while1 PROG_PATH=$(atf_get_srcdir)/$PROG_COMM - $PROG_PATH $* & + mkfifo wait_for_start || atf_fail "mkfifo" + $PROG_PATH $* >wait_for_start & PROG_PID=$! - try=0 - while [ $try -lt $MAX_TRIES ] && ! kill -0 $PROG_PID; do - sleep 0.5 - : $(( try += 1 )) - done - if [ $try -ge $MAX_TRIES ]; then - atf_fail "Polled for program start $MAX_TRIES tries and failed" + if ! read dummy