Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Sep 2019 19:21:20 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r352491 - stable/12/usr.bin/procstat/tests
Message-ID:  <201909181921.x8IJLKSn026636@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Wed Sep 18 19:21:20 2019
New Revision: 352491
URL: https://svnweb.freebsd.org/changeset/base/352491

Log:
  MFC r351819: 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

Modified:
  stable/12/usr.bin/procstat/tests/procstat_test.sh
  stable/12/usr.bin/procstat/tests/while1.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/procstat/tests/procstat_test.sh
==============================================================================
--- stable/12/usr.bin/procstat/tests/procstat_test.sh	Wed Sep 18 17:21:34 2019	(r352490)
+++ stable/12/usr.bin/procstat/tests/procstat_test.sh	Wed Sep 18 19:21:20 2019	(r352491)
@@ -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 <wait_for_start; then
+		atf_fail "Program did not start properly"
 	fi
+	rm wait_for_start
 }
 
 atf_test_case binary_info

Modified: stable/12/usr.bin/procstat/tests/while1.c
==============================================================================
--- stable/12/usr.bin/procstat/tests/while1.c	Wed Sep 18 17:21:34 2019	(r352490)
+++ stable/12/usr.bin/procstat/tests/while1.c	Wed Sep 18 19:21:20 2019	(r352491)
@@ -33,7 +33,8 @@ int
 main(void)
 {
 
+	if (write(STDOUT_FILENO, "started\n", 8) != 8)
+		abort();
 	for (;;)
-		usleep(100);
-	exit(1);
+		pause();
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201909181921.x8IJLKSn026636>