Author: jilles
Date: Wed Sep  4 16:25:41 2019
New Revision: 351819
URL: https://svnweb.freebsd.org/changeset/base/351819

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

Modified:
  head/usr.bin/procstat/tests/procstat_test.sh
  head/usr.bin/procstat/tests/while1.c

Modified: head/usr.bin/procstat/tests/procstat_test.sh
==============================================================================
--- head/usr.bin/procstat/tests/procstat_test.sh        Wed Sep  4 15:55:44 
2019        (r351818)
+++ head/usr.bin/procstat/tests/procstat_test.sh        Wed Sep  4 16:25:41 
2019        (r351819)
@@ -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
@@ -78,8 +74,6 @@ command_line_arguments_head()
 }
 command_line_arguments_body()
 {
-       atf_skip "https://bugs.freebsd.org/233587";
-
        arguments="my arguments"
 
        start_program $arguments
@@ -104,8 +98,6 @@ environment_head()
 }
 environment_body()
 {
-       atf_skip "https://bugs.freebsd.org/233588";
-
        var="MY_VARIABLE=foo"
        eval "export $var"
 

Modified: head/usr.bin/procstat/tests/while1.c
==============================================================================
--- head/usr.bin/procstat/tests/while1.c        Wed Sep  4 15:55:44 2019        
(r351818)
+++ head/usr.bin/procstat/tests/while1.c        Wed Sep  4 16:25:41 2019        
(r351819)
@@ -33,7 +33,8 @@ int
 main(void)
 {
 
+       if (write(STDOUT_FILENO, "started\n", 8) != 8)
+               abort();
        for (;;)
-               usleep(100);
-       exit(1);
+               pause();
 }
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to