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