077c9d
commit 114f792eaea2505cd8aee02d330aad37238da6a5
077c9d
Author: Stefan Liebler <stli@linux.ibm.com>
077c9d
Date:   Fri Feb 1 11:03:35 2019 +0100
077c9d
077c9d
    posix/tst-spawn: Fix racy tests in spawned processes.
077c9d
    
077c9d
    From time to time I get fails in tst-spawn like:
077c9d
    tst-spawn.c:111: numeric comparison failure
077c9d
       left: 0 (0x0); from: xlseek (fd2, 0, SEEK_CUR)
077c9d
      right: 28 (0x1c); from: strlen (fd2string)
077c9d
    error: 1 test failures
077c9d
    tst-spawn.c:252: numeric comparison failure
077c9d
       left: 1 (0x1); from: WEXITSTATUS (status)
077c9d
      right: 0 (0x0); from: 0
077c9d
    error: 1 test failures
077c9d
    
077c9d
    It turned out, that a child process is testing it's open file descriptors
077c9d
    with e.g. a sequence of testing the current position, setting the position
077c9d
    to zero and reading a specific amount of bytes.
077c9d
    
077c9d
    Unfortunately starting with commit 2a69f853c03034c2e383e0f9c35b5402ce8b5473
077c9d
    the test is spawning a second child process which is sharing some of the
077c9d
    file descriptors.  If the test sequence as mentioned above is running in parallel
077c9d
    it leads to test failures.
077c9d
    
077c9d
    As the second call of posix_spawn shall test a NULL pid argument,
077c9d
    this patch is just moving the waitpid of the first child
077c9d
    before the posix_spawn of the second child.
077c9d
    
077c9d
    ChangeLog:
077c9d
    
077c9d
            * posix/tst-spawn do_test(): Move waitpid before posix_spawn.
077c9d
077c9d
diff --git a/posix/tst-spawn.c b/posix/tst-spawn.c
077c9d
index eea5addbf3..9aa7e621e6 100644
077c9d
--- a/posix/tst-spawn.c
077c9d
+++ b/posix/tst-spawn.c
077c9d
@@ -237,6 +237,12 @@ do_test (int argc, char *argv[])
077c9d
   TEST_COMPARE (posix_spawn (&pid, argv[1], &actions, NULL, spargv, environ),
077c9d
 		0);
077c9d
 
077c9d
+  /* Wait for the children.  */
077c9d
+  TEST_COMPARE (xwaitpid (pid, &status, 0), pid);
077c9d
+  TEST_VERIFY (WIFEXITED (status));
077c9d
+  TEST_VERIFY (!WIFSIGNALED (status));
077c9d
+  TEST_COMPARE (WEXITSTATUS (status), 0);
077c9d
+
077c9d
   /* Same test but with a NULL pid argument.  */
077c9d
   TEST_COMPARE (posix_spawn (NULL, argv[1], &actions, NULL, spargv, environ),
077c9d
 		0);
077c9d
@@ -246,11 +252,6 @@ do_test (int argc, char *argv[])
077c9d
   free (name3_copy);
077c9d
 
077c9d
   /* Wait for the children.  */
077c9d
-  TEST_COMPARE (xwaitpid (pid, &status, 0), pid);
077c9d
-  TEST_VERIFY (WIFEXITED (status));
077c9d
-  TEST_VERIFY (!WIFSIGNALED (status));
077c9d
-  TEST_COMPARE (WEXITSTATUS (status), 0);
077c9d
-
077c9d
   xwaitpid (-1, &status, 0);
077c9d
   TEST_VERIFY (WIFEXITED (status));
077c9d
   TEST_VERIFY (!WIFSIGNALED (status));