bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gettext-0.22.4 gettext-tools/gnulib-tests/test-execute.sh test case


From: Bruno Haible
Subject: Re: gettext-0.22.4 gettext-tools/gnulib-tests/test-execute.sh test case 17/18/19 bug
Date: Fri, 26 Jan 2024 01:18:25 +0100

[CCing bug-gnulib, since these unit tests live in Gnulib. The original report
is at <https://lists.gnu.org/archive/html/bug-gettext/2024-01/msg00006.html>.]

Guangyu Li wrote:
> Hi devs, I found a test bug on macOSX Sonoma (M2 chip) with clang 14.0.0.
> The cause seems to be the unexpected fd returned by 'open' from the new
> macos kernel. The obtained file descriptor was 11, failing the fd < 10
> assertion below. This bug affects test-execute-main.c and
> test-execute-child.c in case 17-19. When the range check and dup2 arg are
> both adjusted accordingly (e.g. < 20 and dup2 to 20), all those three can
> pass. Hope this helps!
> 
> 
> ============================================================================
> Testsuite summary for gettext-tools 0.22.4
> ============================================================================
> # TOTAL: 393
> # PASS:  357
> # SKIP:  35
> # XFAIL: 0
> # FAIL:  1
> # XPASS: 0
> # ERROR: 0
> 
> 
> FAIL: test-execute.sh
> =====================
> 
> test-execute-main: test-execute-child subprocess failed
> ../../../gettext-tools/gnulib-tests/test-execute-main.c:366: assertion 'fd
> >= 0 && fd < 10' failed
> ../../../gettext-tools/gnulib-tests/test-execute.sh: line 4: 58735 Abort
> trap: 6           ${CHECKER} ./test-execute-main${EXEEXT}
> ./test-execute-child${EXEEXT} $i
> test-execute.sh: test case 17 failed
> ../../../gettext-tools/gnulib-tests/test-execute-main.c:391: assertion 'fd
> >= 0 && fd < 10' failed
> ../../../gettext-tools/gnulib-tests/test-execute.sh: line 4: 58789 Abort
> trap: 6           ${CHECKER} ./test-execute-main${EXEEXT}
> ./test-execute-child${EXEEXT} $i
> test-execute.sh: test case 18 failed
> ../../../gettext-tools/gnulib-tests/test-execute-main.c:423: assertion
> 'fd_in >= 0 && fd_in < 10' failed
> ../../../gettext-tools/gnulib-tests/test-execute.sh: line 4: 58840 Abort
> trap: 6           ${CHECKER} ./test-execute-main${EXEEXT}
> ./test-execute-child${EXEEXT} $i
> test-execute.sh: test case 19 failed
> FAIL test-execute.sh (exit status: 1)

Thanks for the report! Indeed, if on this platform the file descriptors
0 .. 10 are all already taken, and
  fd = open (BASE ".tmp", O_RDONLY)
is 11, the unit tests need to use file descriptors that are higher than that.

Using 20 instead of 10 is, however, not portable, because according to
https://stackoverflow.com/questions/77883284/
on IRIX only 20 file descriptors may be available. But 15 instead of 10
should be OK. I'm therefore committing this workaround:


2024-01-25  Bruno Haible  <bruno@clisp.org>

        execute tests: Avoid test failure on macOS 14.
        Reported by Guangyu Li <gl343@cornell.edu> in
        <https://lists.gnu.org/archive/html/bug-gettext/2024-01/msg00006.html>.
        * tests/test-execute-main.c (main): In the tests 17, 18, 19, 20, use the
        file descriptors 15, 16 instead of 10, 11, respectively.
        * tests/test-execute-child.c (main): Likewise.

diff --git a/tests/test-execute-child.c b/tests/test-execute-child.c
index e5d0599fdf..7660c7cc18 100644
--- a/tests/test-execute-child.c
+++ b/tests/test-execute-child.c
@@ -199,14 +199,14 @@ main (int argc, char *argv[])
          including the file position.  */
       {
         char buf[6];
-        int n = read (10, buf, sizeof (buf));
+        int n = read (15, buf, sizeof (buf));
         return !(n == 4 && memcmp (buf, "obar", 4) == 0);
       }
     case 18:
       /* Check that file descriptors >= 3, open for writing, can be inherited,
          including the file position.  */
       {
-        int n = write (10, "bar", 3);
+        int n = write (15, "bar", 3);
         return !(n == 3);
       }
     case 19:
@@ -217,9 +217,9 @@ main (int argc, char *argv[])
          isatty() property, part 2 (character devices).  */
       {
         #if defined _WIN32 && ! defined __CYGWIN__
-        return 4 + 2 * (_isatty (10) != 0) + (_isatty (11) != 0);
+        return 4 + 2 * (_isatty (15) != 0) + (_isatty (16) != 0);
         #else
-        return 4 + 2 * (isatty (10) != 0) + (isatty (11) != 0);
+        return 4 + 2 * (isatty (15) != 0) + (isatty (16) != 0);
         #endif
       }
     case 21:
diff --git a/tests/test-execute-main.c b/tests/test-execute-main.c
index 15623ecf73..67c00ee6f3 100644
--- a/tests/test-execute-main.c
+++ b/tests/test-execute-main.c
@@ -82,7 +82,8 @@ main (int argc, char *argv[])
            - with GNU make, when invoked as 'make -j N' with j > 1,
            - in some versions of the KDE desktop environment,
            - on NetBSD,
-           - in MacPorts with the "trace mode" enabled.
+           - in MacPorts with the "trace mode" enabled,
+           - on macOS 14.
        */
       #if HAVE_CLOSE_RANGE
       if (close_range (3, 20 - 1, 0) < 0)
@@ -363,11 +364,11 @@ main (int argc, char *argv[])
         ASSERT (fclose (fp) == 0);
 
         int fd = open (BASE ".tmp", O_RDONLY);
-        ASSERT (fd >= 0 && fd < 10);
+        ASSERT (fd >= 0 && fd < 15);
 
-        ASSERT (dup2 (fd, 10) >= 0);
+        ASSERT (dup2 (fd, 15) >= 0);
         close (fd);
-        fd = 10;
+        fd = 15;
 
         char buf[2];
         ASSERT (read (fd, buf, sizeof (buf)) == sizeof (buf));
@@ -388,11 +389,11 @@ main (int argc, char *argv[])
            including the file position.  */
         remove (BASE ".tmp");
         int fd = open (BASE ".tmp", O_RDWR | O_CREAT | O_TRUNC, 0600);
-        ASSERT (fd >= 0 && fd < 10);
+        ASSERT (fd >= 0 && fd < 15);
 
-        ASSERT (dup2 (fd, 10) >= 0);
+        ASSERT (dup2 (fd, 15) >= 0);
         close (fd);
-        fd = 10;
+        fd = 15;
 
         ASSERT (write (fd, "Foo", 3) == 3);
         /* The file position is now 3.  */
@@ -420,26 +421,26 @@ main (int argc, char *argv[])
         ASSERT (fclose (fp) == 0);
 
         int fd_in = open (BASE ".tmp", O_RDONLY);
-        ASSERT (fd_in >= 0 && fd_in < 10);
+        ASSERT (fd_in >= 0 && fd_in < 15);
 
         int fd_out = open (BASE ".tmp", O_WRONLY | O_APPEND);
-        ASSERT (fd_out >= 0 && fd_out < 10);
+        ASSERT (fd_out >= 0 && fd_out < 15);
 
-        ASSERT (dup2 (fd_in, 10) >= 0);
+        ASSERT (dup2 (fd_in, 15) >= 0);
         close (fd_in);
-        fd_in = 10;
+        fd_in = 15;
 
-        ASSERT (dup2 (fd_out, 11) >= 0);
+        ASSERT (dup2 (fd_out, 16) >= 0);
         close (fd_out);
-        fd_out = 11;
+        fd_out = 16;
 
         const char *prog_argv[3] = { prog_path, "19", NULL };
         int ret = execute (progname, prog_argv[0], prog_argv, NULL,
                            false, false, false, false, true, false, NULL);
         #if defined _WIN32 && ! defined __CYGWIN__
-        ASSERT (ret == 4 + 2 * (_isatty (10) != 0) + (_isatty (11) != 0));
+        ASSERT (ret == 4 + 2 * (_isatty (15) != 0) + (_isatty (16) != 0));
         #else
-        ASSERT (ret == 4 + 2 * (isatty (10) != 0) + (isatty (11) != 0));
+        ASSERT (ret == 4 + 2 * (isatty (15) != 0) + (isatty (16) != 0));
         #endif
 
         close (fd_in);
@@ -451,19 +452,19 @@ main (int argc, char *argv[])
       {
         /* Check that file descriptors >= 3, when inherited, preserve their
            isatty() property, part 2 (character devices).  */
-        ASSERT (dup2 (STDIN_FILENO, 10) >= 0);
-        int fd_in = 10;
+        ASSERT (dup2 (STDIN_FILENO, 15) >= 0);
+        int fd_in = 15;
 
-        ASSERT (dup2 (STDOUT_FILENO, 11) >= 0);
-        int fd_out = 11;
+        ASSERT (dup2 (STDOUT_FILENO, 16) >= 0);
+        int fd_out = 16;
 
         const char *prog_argv[3] = { prog_path, "20", NULL };
         int ret = execute (progname, prog_argv[0], prog_argv, NULL,
                            false, false, false, false, true, false, NULL);
         #if defined _WIN32 && ! defined __CYGWIN__
-        ASSERT (ret == 4 + 2 * (_isatty (10) != 0) + (_isatty (11) != 0));
+        ASSERT (ret == 4 + 2 * (_isatty (15) != 0) + (_isatty (16) != 0));
         #else
-        ASSERT (ret == 4 + 2 * (isatty (10) != 0) + (isatty (11) != 0));
+        ASSERT (ret == 4 + 2 * (isatty (15) != 0) + (isatty (16) != 0));
         #endif
 
         close (fd_in);






reply via email to

[Prev in Thread] Current Thread [Next in Thread]