]> Savannah Git Hosting - gnulib.git/commitdiff
posix_spawn_file_actions_addfchdir: Avoid test failure under QEMU.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Aug 2021 23:56:46 +0000 (01:56 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Aug 2021 23:56:46 +0000 (01:56 +0200)
* tests/test-posix_spawn-fchdir.c: Include qemu.h.
(is_qemu): New variable.
(test): Under QEMU user-mode, don't expect that "pwd" produces the
result "/".
(main): Initialize is_qemu. Under QEMU user-mode, skip the relative file
name test.
* modules/posix_spawn_file_actions_addfchdir-tests (Files): Add qemu.h.
(Depends-on): Add stdbool.

ChangeLog
modules/posix_spawn_file_actions_addfchdir-tests
tests/test-posix_spawn-fchdir.c

index 88a396e09ee6c5ebee7ca4a02a73909eab2b32a9..511765e126babce8c0f9a66ef4113a23f0a1b870 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-08-29  Bruno Haible  <bruno@clisp.org>
+
+       posix_spawn_file_actions_addfchdir: Avoid test failure under QEMU.
+       * tests/test-posix_spawn-fchdir.c: Include qemu.h.
+       (is_qemu): New variable.
+       (test): Under QEMU user-mode, don't expect that "pwd" produces the
+       result "/".
+       (main): Initialize is_qemu. Under QEMU user-mode, skip the relative file
+       name test.
+       * modules/posix_spawn_file_actions_addfchdir-tests (Files): Add qemu.h.
+       (Depends-on): Add stdbool.
+
 2021-08-29  Bruno Haible  <bruno@clisp.org>
 
        getcwd tests: Avoid test failure when running under QEMU user-mode.
index 789a85d2e842f19cf2264bda6f31ffc6519f47af..903a30f859f3fe3ce47e54a044798a80eea99d9c 100644 (file)
@@ -2,12 +2,14 @@ Files:
 tests/test-posix_spawn_file_actions_addfchdir.c
 tests/test-posix_spawn-fchdir.c
 tests/signature.h
+tests/qemu.h
 tests/macros.h
 
 Depends-on:
 posix_spawn_file_actions_init
 posix_spawn_file_actions_destroy
 posix_spawnp-tests
+stdbool
 findprog
 
 configure.ac:
index 0f71374460ed710807c510fe0524d338212061a2..297a2de47d56c89a7ee40d65ad1570cfe548735c 100644 (file)
@@ -32,6 +32,9 @@
 #include <sys/wait.h>
 
 #include "findprog.h"
+#include "qemu.h"
+
+static bool is_qemu;
 
 static int
 fd_safer (int fd)
@@ -135,10 +138,17 @@ test (const char *pwd_prog)
       fprintf (stderr, "could not read expected output\n");
       exit (1);
     }
-  if (memcmp (line, "/\n", 2) != 0)
+  /* For a process running under QEMU user-mode, rootfd points to the directory
+     that is the value of the QEMU_LD_PREFIX environment variable or of the -L
+     command-line option, and the line produced by 'pwd' is that directory, not
+     "/".  */
+  if (!is_qemu)
     {
-      fprintf (stderr, "read output is not the expected output\n");
-      exit (1);
+      if (memcmp (line, "/\n", 2) != 0)
+        {
+          fprintf (stderr, "read output is not the expected output\n");
+          exit (1);
+        }
     }
   fclose (fp);
   status = 0;
@@ -160,19 +170,22 @@ test (const char *pwd_prog)
 int
 main ()
 {
+  is_qemu = is_running_under_qemu_user ();
+
   test ("pwd");
 
   /* Verify that if a program is given as a relative file name with at least one
      slash, it is interpreted w.r.t. the current directory after fchdir has been
      executed.  */
-  {
-    const char *abs_pwd_prog = find_in_path ("pwd");
-
-    if (abs_pwd_prog != NULL
-        && abs_pwd_prog[0] == '/'
-        && abs_pwd_prog[1] != '0' && abs_pwd_prog[1] != '/')
-      test (&abs_pwd_prog[1]);
-  }
+  if (!is_qemu)
+    {
+      const char *abs_pwd_prog = find_in_path ("pwd");
+
+      if (abs_pwd_prog != NULL
+          && abs_pwd_prog[0] == '/'
+          && abs_pwd_prog[1] != '0' && abs_pwd_prog[1] != '/')
+        test (&abs_pwd_prog[1]);
+    }
 
   return 0;
 }