diff options
author | Bruno Haible <bruno@clisp.org> | 2020-12-24 22:14:38 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-12-24 22:17:30 +0100 |
commit | 8cf7746a2b5c5fe50e8369951619a87ecb3786bd (patch) | |
tree | dfa579efe442004b0398067464f4dbae287962d7 /tests/test-posix_spawn-chdir.c | |
parent | c9ed8d9a58bae5a90fc1410232354cf8e27e2e3c (diff) | |
download | gnulib-8cf7746a2b5c5fe50e8369951619a87ecb3786bd.tar.gz |
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.
Diffstat (limited to 'tests/test-posix_spawn-chdir.c')
-rw-r--r-- | tests/test-posix_spawn-chdir.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/tests/test-posix_spawn-chdir.c b/tests/test-posix_spawn-chdir.c index 91a5497ede..62c60eeee2 100644 --- a/tests/test-posix_spawn-chdir.c +++ b/tests/test-posix_spawn-chdir.c @@ -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) |