]> Savannah Git Hosting - gnulib.git/commitdiff
getcwd tests: Avoid test failure when running under QEMU user-mode.
authorBruno Haible <bruno@clisp.org>
Sun, 29 Aug 2021 23:44:03 +0000 (01:44 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 29 Aug 2021 23:44:03 +0000 (01:44 +0200)
* modules/getcwd-tests (Files): Add qemu.h.
(Depends-on): Add stdbool.
* tests/test-getcwd.c: Include qemu.h.
(test_long_name): Skip this test when running under QEMU user-mode.
(main): Consider return code 77 from test_long_name.

ChangeLog
modules/getcwd-tests
tests/test-getcwd.c

index ee933c9efaa6e2040fd513fe3393e5d4ca89e69a..88a396e09ee6c5ebee7ca4a02a73909eab2b32a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021-08-29  Bruno Haible  <bruno@clisp.org>
+
+       getcwd tests: Avoid test failure when running under QEMU user-mode.
+       * modules/getcwd-tests (Files): Add qemu.h.
+       (Depends-on): Add stdbool.
+       * tests/test-getcwd.c: Include qemu.h.
+       (test_long_name): Skip this test when running under QEMU user-mode.
+       (main): Consider return code 77 from test_long_name.
+
 2021-08-29  Paul Eggert  <eggert@cs.ucla.edu>
 
        base32, base64: treat negative sizes as overflows
index e5a7bd78b17a3ee066e340fe22b90649524166c5..c842c7711587fc69d19232642ce280915e7adaf5 100644 (file)
@@ -1,12 +1,14 @@
 Files:
-tests/test-getcwd.c
 tests/test-getcwd.sh
+tests/test-getcwd.c
+tests/qemu.h
 
 Depends-on:
 errno
 fcntl-h
 getcwd-lgpl
 pathmax
+stdbool
 sys_stat
 test-framework-sh
 
index 061c69eb12b8b3afe990b32c004f586d31574812..051d4f26a0a8c3e6e62ddd25239f633f9e62a7a0 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/stat.h>
 
 #include "pathmax.h"
+#include "qemu.h"
 #include "macros.h"
 
 #if !(HAVE_GETPAGESIZE || defined getpagesize)
@@ -138,6 +139,13 @@ test_long_name (void)
      this should be done in a compile test.  */
   return 0;
 #else
+  /* For a process running under QEMU user-mode, the "/" directory is not
+     really the root directory, but the value of the QEMU_LD_PREFIX environment
+     variable or of the -L command-line option.  This causes the logic from
+     glibc/sysdeps/posix/getcwd.c to fail.  In this case, skip the test.  */
+  if (is_running_under_qemu_user ())
+    return 77;
+
   char buf[PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1)
            + DIR_NAME_SIZE + BUF_SLOP];
   char *cwd = getcwd (buf, PATH_MAX);
@@ -256,5 +264,7 @@ test_long_name (void)
 int
 main (int argc, char **argv)
 {
-  return test_abort_bug () * 10 + test_long_name ();
+  int err1 = test_abort_bug ();
+  int err2 = test_long_name ();
+  return err1 * 10 + (err1 != 0 && err2 == 77 ? 0 : err2);
 }