diff options
author | Bruno Haible <bruno@clisp.org> | 2021-08-30 02:06:23 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-08-30 02:14:33 +0200 |
commit | f765c6881f9b237163aa0178df3da5540f282f87 (patch) | |
tree | 36901e978f6de8cfea1617bad8505f3c92730e5b | |
parent | 5d5eba1c0c43e4c9638cb857aa7f3c471ae0deba (diff) | |
download | gnulib-f765c6881f9b237163aa0178df3da5540f282f87.tar.gz |
spawn-pipe: Fix test failure when running under QEMU user-mode.
* tests/test-spawn-pipe-child.c: Include <stdbool.h>, <string.h>,
qemu.h.
(main): Under QEMU user-mode, allow fd 2 or fd 3 to be open.
* modules/spawn-pipe-tests (Files): Add qemu.h.
(Depends-on): Add stdbool.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | modules/spawn-pipe-tests | 2 | ||||
-rw-r--r-- | tests/test-spawn-pipe-child.c | 25 |
3 files changed, 30 insertions, 6 deletions
@@ -1,5 +1,14 @@ 2021-08-29 Bruno Haible <bruno@clisp.org> + spawn-pipe: Fix test failure when running under QEMU user-mode. + * tests/test-spawn-pipe-child.c: Include <stdbool.h>, <string.h>, + qemu.h. + (main): Under QEMU user-mode, allow fd 2 or fd 3 to be open. + * modules/spawn-pipe-tests (Files): Add qemu.h. + (Depends-on): Add stdbool. + +2021-08-29 Bruno Haible <bruno@clisp.org> + execute: Fix test failure when running under QEMU user-mode. * tests/test-execute-child.c: Include <stdbool.h>, qemu.h. (main): Under QEMU user-mode, allow fd 3 to be open. diff --git a/modules/spawn-pipe-tests b/modules/spawn-pipe-tests index a204031a61..64bcde2b59 100644 --- a/modules/spawn-pipe-tests +++ b/modules/spawn-pipe-tests @@ -6,11 +6,13 @@ tests/test-spawn-pipe-script.c tests/executable-script tests/executable-script.sh tests/executable-shell-script +tests/qemu.h tests/macros.h Depends-on: close msvc-inval +stdbool stdint configure.ac: diff --git a/tests/test-spawn-pipe-child.c b/tests/test-spawn-pipe-child.c index 9d4dd174b1..ee0ba9ad64 100644 --- a/tests/test-spawn-pipe-child.c +++ b/tests/test-spawn-pipe-child.c @@ -18,9 +18,11 @@ #include <errno.h> #include <fcntl.h> +#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> #if defined _WIN32 && ! defined __CYGWIN__ @@ -47,12 +49,17 @@ static FILE *myerr; #undef fdopen #undef fflush #undef fprintf +#undef open #undef read +#undef strcasestr +#undef strstr #undef write #if defined _WIN32 && !defined __CYGWIN__ # define fdopen _fdopen #endif +#include "qemu.h" + #if HAVE_MSVC_INVALID_PARAMETER_HANDLER static void __cdecl gl_msvc_invalid_parameter_handler (const wchar_t *expression, @@ -97,6 +104,10 @@ main (int argc, char *argv[]) _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler); #endif + /* QEMU 6.1 in user-mode passes an open fd, usually = 3, that references + /dev/urandom. We need to ignore this fd. */ + bool is_qemu = is_running_under_qemu_user (); + /* Read one byte from fd 0, and write its value plus one to fd 1. fd 2 should be closed iff the argument is 1. Check that no other file descriptors leaked. */ @@ -120,7 +131,8 @@ main (int argc, char *argv[]) was closed. Similarly on native Windows. Future POSIX will allow this, see <http://austingroupbugs.net/view.php?id=173>. */ #if !(defined __hpux || (defined _WIN32 && ! defined __CYGWIN__)) - ASSERT (! is_open (STDERR_FILENO)); + if (!is_qemu) + ASSERT (! is_open (STDERR_FILENO)); #endif break; default: @@ -129,11 +141,12 @@ main (int argc, char *argv[]) int fd; for (fd = 3; fd < 7; fd++) - { - errno = 0; - ASSERT (close (fd) == -1); - ASSERT (errno == EBADF); - } + if (!(is_qemu && fd == 3)) + { + errno = 0; + ASSERT (close (fd) == -1); + ASSERT (errno == EBADF); + } return 0; } |