]> Savannah Git Hosting - gnulib.git/commitdiff
posix_spawn* tests: Add support for native Windows.
authorBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 21:14:38 +0000 (22:14 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 24 Dec 2020 21:17:30 +0000 (22:17 +0100)
* tests/test-posix_spawn-open1.c (DATA_FILENAME): Treat native Windows
like Cygwin.
* tests/test-posix_spawn-dup2-stdin.c (main): Don't assume the signals
SIGHUP and SIGPIPE. On native Windows, don't call
posix_spawnattr_setsigmask.
* tests/test-posix_spawn-dup2-stdout.c (main): Likewise.
* tests/test-posix_spawn-fchdir.c (main): Likewise.
* tests/test-posix_spawn-chdir.c (test): Likewise. Accept the child
output from Cygwin's 'pwd' program.
* tests/test-posix_spawn-script.c (main): On native Windows, skip the
executable-shell-script part of the test.
* tests/test-posix_spawnp-script.c (main): Likewise.
* modules/posix_spawn-tests (Depends-on): Add freopen, waitpid.
(configure.ac): Don't define the POSIX_SPAWN_PORTED conditional.
(Makefile.am): Don't test the POSIX_SPAWN_PORTED conditional.
* modules/posix_spawnp-tests (Depends-on): Add  waitpid.
(configure.ac): Don't define the POSIX_SPAWN_PORTED conditional.
(Makefile.am): Don't test the POSIX_SPAWN_PORTED conditional.
* modules/posix_spawn_file_actions_addchdir-tests (Makefile.am): Don't
test the POSIX_SPAWN_PORTED conditional.
* modules/posix_spawn_file_actions_addfchdir-tests (configure.ac):
Define the POSIX_SPAWN_PORTED conditional here.

12 files changed:
ChangeLog
modules/posix_spawn-tests
modules/posix_spawn_file_actions_addchdir-tests
modules/posix_spawn_file_actions_addfchdir-tests
modules/posix_spawnp-tests
tests/test-posix_spawn-chdir.c
tests/test-posix_spawn-dup2-stdin.c
tests/test-posix_spawn-dup2-stdout.c
tests/test-posix_spawn-fchdir.c
tests/test-posix_spawn-open1.c
tests/test-posix_spawn-script.c
tests/test-posix_spawnp-script.c

index d93aa474aab96a994d36abb3ff22c9573aa274a4..b716a268a62e6030d6d177c5e7831b4f94a10f01 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2020-12-24  Bruno Haible  <bruno@clisp.org>
+
+       posix_spawn* tests: Add support for native Windows.
+       * tests/test-posix_spawn-open1.c (DATA_FILENAME): Treat native Windows
+       like Cygwin.
+       * tests/test-posix_spawn-dup2-stdin.c (main): Don't assume the signals
+       SIGHUP and SIGPIPE. On native Windows, don't call
+       posix_spawnattr_setsigmask.
+       * tests/test-posix_spawn-dup2-stdout.c (main): Likewise.
+       * tests/test-posix_spawn-fchdir.c (main): Likewise.
+       * tests/test-posix_spawn-chdir.c (test): Likewise. Accept the child
+       output from Cygwin's 'pwd' program.
+       * tests/test-posix_spawn-script.c (main): On native Windows, skip the
+       executable-shell-script part of the test.
+       * tests/test-posix_spawnp-script.c (main): Likewise.
+       * modules/posix_spawn-tests (Depends-on): Add freopen, waitpid.
+       (configure.ac): Don't define the POSIX_SPAWN_PORTED conditional.
+       (Makefile.am): Don't test the POSIX_SPAWN_PORTED conditional.
+       * modules/posix_spawnp-tests (Depends-on): Add  waitpid.
+       (configure.ac): Don't define the POSIX_SPAWN_PORTED conditional.
+       (Makefile.am): Don't test the POSIX_SPAWN_PORTED conditional.
+       * modules/posix_spawn_file_actions_addchdir-tests (Makefile.am): Don't
+       test the POSIX_SPAWN_PORTED conditional.
+       * modules/posix_spawn_file_actions_addfchdir-tests (configure.ac):
+       Define the POSIX_SPAWN_PORTED conditional here.
+
 2020-12-24  Bruno Haible  <bruno@clisp.org>
 
        sh-filename: Add support for native Windows.
index 06a843496740d30dfd7a86f23f49a253ffcabb07..ee505c0389d351a538ca771ddaffc7584bbc24c9 100644 (file)
@@ -18,19 +18,12 @@ unistd
 sys_wait
 environ
 fflush
+freopen
+waitpid
 
 configure.ac:
-AC_EGREP_CPP([notposix], [[
-#if defined _MSC_VER || defined __MINGW32__
-  notposix
-#endif
-  ]],
-  [posix_spawn_ported=no],
-  [posix_spawn_ported=yes])
-AM_CONDITIONAL([POSIX_SPAWN_PORTED], [test $posix_spawn_ported = yes])
 
 Makefile.am:
-if POSIX_SPAWN_PORTED
 TESTS += \
   test-posix_spawn-open1 \
   test-posix_spawn-open2 \
@@ -44,4 +37,3 @@ check_PROGRAMS += \
   test-posix_spawn-inherit1 \
   test-posix_spawn-script
 test_posix_spawn_script_CPPFLAGS = $(AM_CPPFLAGS) -DSRCDIR=\"$(srcdir)/\"
-endif
index 400c1f72ee7bccfb5b35f66369d0e3c13d0ddd7a..1c56b1c1d7c54f2698dcebb2f1507225a337aae8 100644 (file)
@@ -12,10 +12,9 @@ findprog
 configure.ac:
 
 Makefile.am:
-TESTS += test-posix_spawn_file_actions_addchdir
-check_PROGRAMS += test-posix_spawn_file_actions_addchdir
-
-if POSIX_SPAWN_PORTED
-TESTS += test-posix_spawn-chdir
-check_PROGRAMS += test-posix_spawn-chdir
-endif
+TESTS += \
+  test-posix_spawn_file_actions_addchdir \
+  test-posix_spawn-chdir
+check_PROGRAMS += \
+  test-posix_spawn_file_actions_addchdir \
+  test-posix_spawn-chdir
index 0d8c9903f7be0d36bc0525a68b0dcfd8b467a81a..45f42305721bea32de00fb3ef97537fa4d13fff3 100644 (file)
@@ -10,6 +10,14 @@ posix_spawnp-tests
 findprog
 
 configure.ac:
+AC_EGREP_CPP([notposix], [[
+#if defined _MSC_VER || defined __MINGW32__
+  notposix
+#endif
+  ]],
+  [posix_spawn_ported=no],
+  [posix_spawn_ported=yes])
+AM_CONDITIONAL([POSIX_SPAWN_PORTED], [test $posix_spawn_ported = yes])
 
 Makefile.am:
 TESTS += test-posix_spawn_file_actions_addfchdir
index 887569c60507d849565a391a3b782dd66df5d404..e84d89d0ed714bf50d75053dcead78addc865b8d 100644 (file)
@@ -26,19 +26,11 @@ dup
 environ
 sh-filename
 sigprocmask
+waitpid
 
 configure.ac:
-AC_EGREP_CPP([notposix], [[
-#if defined _MSC_VER || defined __MINGW32__
-  notposix
-#endif
-  ]],
-  [posix_spawn_ported=no],
-  [posix_spawn_ported=yes])
-AM_CONDITIONAL([POSIX_SPAWN_PORTED], [test $posix_spawn_ported = yes])
 
 Makefile.am:
-if POSIX_SPAWN_PORTED
 TESTS += \
   test-posix_spawn-dup2-stdout \
   test-posix_spawn-dup2-stdin \
@@ -63,4 +55,3 @@ test-posix_spawn-dup2-stdin.sh: test-posix_spawn-dup2-stdin.in.sh
 MOSTLYCLEANFILES += test-posix_spawn-dup2-stdin.sh test-posix_spawn-dup2-stdin.sh-t
 
 test_posix_spawnp_script_CPPFLAGS = $(AM_CPPFLAGS) -DSRCDIR=\"$(srcdir)/\"
-endif
index 91a5497ede2678480f2ddc7e6320fbe5120f49d0..62c60eeee271320454055ef7be89d6b85cbfe7e3 100644 (file)
@@ -64,6 +64,7 @@ test (const char *pwd_prog)
   int fd;
   FILE *fp;
   char line[80];
+  int line_len;
   int status;
   int exitstatus;
 
@@ -76,8 +77,12 @@ test (const char *pwd_prog)
   sigemptyset (&fatal_signal_set);
   sigaddset (&fatal_signal_set, SIGINT);
   sigaddset (&fatal_signal_set, SIGTERM);
+  #ifdef SIGHUP
   sigaddset (&fatal_signal_set, SIGHUP);
+  #endif
+  #ifdef SIGPIPE
   sigaddset (&fatal_signal_set, SIGPIPE);
+  #endif
   sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
   actions_allocated = false;
   attrs_allocated = false;
@@ -90,8 +95,13 @@ test (const char *pwd_prog)
           || (err = posix_spawn_file_actions_addchdir (&actions, "/")) != 0
           || (err = posix_spawnattr_init (&attrs)) != 0
           || (attrs_allocated = true,
+              #if defined _WIN32 && !defined __CYGWIN__
+              0
+              #else
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
-              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
+              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0
+              #endif
+             )
           || (err = posix_spawnp (&child, pwd_prog, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
@@ -108,22 +118,32 @@ test (const char *pwd_prog)
   sigprocmask (SIG_UNBLOCK, &fatal_signal_set, NULL);
   close (ifd[1]);
   fd = ifd[0];
-  fp = fdopen (fd, "r");
+  fp = fdopen (fd, "rb");
   if (fp == NULL)
     {
       fprintf (stderr, "fdopen() failed\n");
       exit (1);
     }
-  if (fread (line, 1, 80, fp) < 2)
+  line_len = fread (line, 1, 80, fp);
+  if (line_len < 2)
     {
       fprintf (stderr, "could not read expected output\n");
       exit (1);
     }
-  if (memcmp (line, "/\n", 2) != 0)
-    {
-      fprintf (stderr, "read output is not the expected output");
-      exit (1);
-    }
+  if (!(line_len == 2 && memcmp (line, "/\n", 2) == 0))
+#if defined _WIN32 && !defined __CYGWIN__
+    /* If the pwd program is Cygwin's pwd, its output in the root directory is
+       "/cygdrive/N", where N is a lowercase letter.  */
+    if (!(line_len > 11
+          && memcmp (line, "/cygdrive/", 10) == 0
+          && line[10] >= 'a' && line[10] <= 'z'
+          && ((line_len == 12 && line[11] == '\n')
+              || (line_len == 13 && line[11] == '\r' && line[12] == '\n'))))
+#endif
+      {
+        fprintf (stderr, "read output is not the expected output\n");
+        exit (1);
+      }
   fclose (fp);
   status = 0;
   while (waitpid (child, &status, 0) != child)
index 8af1e3fb8570f892b425ab8d332b8dc058688008..fe039bf46cd66ac1d23562e19f1ed14f29f8dbdf 100644 (file)
@@ -76,8 +76,12 @@ main ()
   sigemptyset (&fatal_signal_set);
   sigaddset (&fatal_signal_set, SIGINT);
   sigaddset (&fatal_signal_set, SIGTERM);
+  #ifdef SIGHUP
   sigaddset (&fatal_signal_set, SIGHUP);
+  #endif
+  #ifdef SIGPIPE
   sigaddset (&fatal_signal_set, SIGPIPE);
+  #endif
   sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
   actions_allocated = false;
   attrs_allocated = false;
@@ -88,8 +92,13 @@ main ()
           || (err = posix_spawn_file_actions_addclose (&actions, ofd[1])) != 0
           || (err = posix_spawnattr_init (&attrs)) != 0
           || (attrs_allocated = true,
+              #if defined _WIN32 && !defined __CYGWIN__
+              0
+              #else
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
-              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
+              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0
+              #endif
+             )
           || (err = posix_spawnp (&child, BOURNE_SHELL, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
index c67e143fb88c88b08093e644aa9f983b26fcb3fb..ce098449aa47552d98efae7a16233c4466923827 100644 (file)
@@ -98,8 +98,12 @@ main ()
   sigemptyset (&fatal_signal_set);
   sigaddset (&fatal_signal_set, SIGINT);
   sigaddset (&fatal_signal_set, SIGTERM);
+  #ifdef SIGHUP
   sigaddset (&fatal_signal_set, SIGHUP);
+  #endif
+  #ifdef SIGPIPE
   sigaddset (&fatal_signal_set, SIGPIPE);
+  #endif
   sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
   actions_allocated = false;
   attrs_allocated = false;
@@ -111,8 +115,13 @@ main ()
           || (err = posix_spawn_file_actions_addopen (&actions, STDIN_FILENO, "/dev/null", O_RDONLY, 0)) != 0
           || (err = posix_spawnattr_init (&attrs)) != 0
           || (attrs_allocated = true,
+              #if defined _WIN32 && !defined __CYGWIN__
+              0
+              #else
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
-              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
+              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0
+              #endif
+             )
           || (err = posix_spawnp (&child, BOURNE_SHELL, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
@@ -142,7 +151,7 @@ main ()
     }
   if (memcmp (line, "Halle Potta", 11) != 0)
     {
-      fprintf (stderr, "read output is not the expected output");
+      fprintf (stderr, "read output is not the expected output\n");
       exit (1);
     }
   fclose (fp);
index c5ca2a33a8a8a33f04eb44261e427970564d2d7d..3206ad54971c468b80ea808bb8ad75ccffced15d 100644 (file)
@@ -83,8 +83,12 @@ test (const char *pwd_prog)
   sigemptyset (&fatal_signal_set);
   sigaddset (&fatal_signal_set, SIGINT);
   sigaddset (&fatal_signal_set, SIGTERM);
+  #ifdef SIGHUP
   sigaddset (&fatal_signal_set, SIGHUP);
+  #endif
+  #ifdef SIGPIPE
   sigaddset (&fatal_signal_set, SIGPIPE);
+  #endif
   sigprocmask (SIG_BLOCK, &fatal_signal_set, NULL);
   actions_allocated = false;
   attrs_allocated = false;
@@ -97,8 +101,13 @@ test (const char *pwd_prog)
           || (err = posix_spawn_file_actions_addfchdir (&actions, rootfd)) != 0
           || (err = posix_spawnattr_init (&attrs)) != 0
           || (attrs_allocated = true,
+              #if defined _WIN32 && !defined __CYGWIN__
+              0
+              #else
               (err = posix_spawnattr_setsigmask (&attrs, &blocked_signals)) != 0
-              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0)
+              || (err = posix_spawnattr_setflags (&attrs, POSIX_SPAWN_SETSIGMASK)) != 0
+              #endif
+             )
           || (err = posix_spawnp (&child, pwd_prog, &actions, &attrs, argv, environ)) != 0))
     {
       if (actions_allocated)
@@ -128,7 +137,7 @@ test (const char *pwd_prog)
     }
   if (memcmp (line, "/\n", 2) != 0)
     {
-      fprintf (stderr, "read output is not the expected output");
+      fprintf (stderr, "read output is not the expected output\n");
       exit (1);
     }
   fclose (fp);
index e08c1135e38eb7f08eb437129436aa6867122671..648fc1d70fd89a1df8e4d64f04091e68753fdb69 100644 (file)
@@ -40,8 +40,9 @@ SIGNATURE_CHECK (posix_spawn, int, (pid_t *, char const *,
 
 #define CHILD_PROGRAM_FILENAME "test-posix_spawn-open1"
 #define DATA_FILENAME "t!#$%&'()*+,-;=?@[\\]^_`{|}~.tmp"
-/* On Cygwin, '*' '?' '\\' '|' cannot be used in file names.  */
-#if defined __CYGWIN__
+/* On Windows (including Cygwin), '*' '?' '\\' '|' cannot be used in file
+   names.  */
+#if defined _WIN32 || defined __CYGWIN__
 # undef DATA_FILENAME
 # define DATA_FILENAME "t!#$%&'()+,-;=@[]^_`{}~.tmp"
 #endif
index e17c3b84ff44be4a6786f351d4c8bd02fa505ee9..6fa8e486186fc79f1faf72d9cedb5f98bab7ac0f 100644 (file)
@@ -90,6 +90,12 @@ main ()
       }
   }
 
+#if defined _WIN32 && !defined __CYGWIN__
+  /* On native Windows, scripts - even with '#!' marker - are not executable.
+     Only .bat and .cmd files are.  */
+  fprintf (stderr, "Skipping test: scripts are not executable on this platform.\n");
+  return 77;
+#else
   {
     const char *prog_path = SRCDIR "executable-shell-script";
     const char *prog_argv[2] = { prog_path, NULL };
@@ -141,6 +147,7 @@ main ()
         return 1;
       }
   }
+#endif
 
   /* Clean up data file.  */
   unlink (DATA_FILENAME);
index b48e7914c3a1c7dae9c5749fd3028b30e5d02422..c2c3e5700df141cf9e60c692d1c9f9de4cca758d 100644 (file)
@@ -90,6 +90,12 @@ main ()
       }
   }
 
+#if defined _WIN32 && !defined __CYGWIN__
+  /* On native Windows, scripts - even with '#!' marker - are not executable.
+     Only .bat and .cmd files are.  */
+  fprintf (stderr, "Skipping test: scripts are not executable on this platform.\n");
+  return 77;
+#else
   {
     const char *prog_path = SRCDIR "executable-shell-script";
     const char *prog_argv[2] = { prog_path, NULL };
@@ -141,6 +147,7 @@ main ()
         return 1;
       }
   }
+#endif
 
   /* Clean up data file.  */
   unlink (DATA_FILENAME);