bug-gnulib
[Top][All Lists]
Advanced

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

Re: fprintf-posix on macOS


From: Bruno Haible
Subject: Re: fprintf-posix on macOS
Date: Thu, 03 Dec 2020 21:59:22 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-193-generic; KDE/5.18.0; x86_64; ; )

Martin Storsjö wrote:
> FAIL: test-fprintf-posix3.sh

This patch fixes it. It now produces a diagnostic
"Skipping test: cannot trust address space size on this platform"


2020-12-03  Bruno Haible  <bruno@clisp.org>

        fprintf-posix-tests: Avoid a test failure on macOS 10.13.
        Reported by Martin Storsjö <martin@martin.st> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00003.html>.
        * tests/test-fprintf-posix3.c: Skip the test on macOS.
        (main): Return a different exit code at each point. Allow 100 KB extra
        memory consumption.
        * tests/test-fprintf-posix3.sh: Update. Remove the "get_rusage_as()
        doesn't work" diagnostic.

diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c
index 67bcb92..5521839 100644
--- a/tests/test-fprintf-posix3.c
+++ b/tests/test-fprintf-posix3.c
@@ -20,6 +20,24 @@
 
 #include <stdio.h>
 
+#if defined __APPLE__ && defined __MACH__                            /* macOS 
*/
+
+/* On macOS 10.13, this test fails, because the address space size increases
+   by 10 MB to 42 MB during the test's execution.  But it's not a malloc
+   leak, as can be seen by running the 'leaks' program.  And it does not fail
+   if the test's output is redirected to /dev/null.  Probably piping a lot
+   of output to stdout, when not redirected to /dev/null, allocates 
intermediate
+   buffers in the virtual address space.  */
+
+int
+main ()
+{
+  fprintf (stderr, "Skipping test: cannot trust address space size on this 
platform\n");
+  return 78;
+}
+
+#else
+
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -84,7 +102,7 @@ main (int argc, char *argv[])
       if (memory == NULL)
         return 1;
       memset (memory, 17, MAX_ALLOC_TOTAL);
-      result = 78;
+      result = 80;
     }
   else
     {
@@ -98,14 +116,16 @@ main (int argc, char *argv[])
              but should not result in a permanent memory allocation.  */
           if (fprintf (stdout, "%011000d\n", 17) == -1
               && errno == ENOMEM)
-            return 1;
+            return 2;
         }
 
       result = 0;
     }
 
-  if (get_rusage_as () > initial_rusage_as + MAX_ALLOC_TOTAL)
-    return 1;
+  if (get_rusage_as () > initial_rusage_as + MAX_ALLOC_TOTAL + 100000)
+    return 3;
 
   return result;
 }
+
+#endif /* !macOS */
diff --git a/tests/test-fprintf-posix3.sh b/tests/test-fprintf-posix3.sh
index 351d375..96609c7 100755
--- a/tests/test-fprintf-posix3.sh
+++ b/tests/test-fprintf-posix3.sh
@@ -4,7 +4,7 @@
 
 (${CHECKER} ./test-fprintf-posix3${EXEEXT} 0
  result=$?
- if test $result != 77 && test $result != 78; then result=1; fi
+ if test $result != 77 && test $result != 78 && test $result != 80; then 
result=1; fi
  exit $result
 ) 2>/dev/null
 malloc_result=$?
@@ -12,6 +12,10 @@ if test $malloc_result = 77; then
   echo "Skipping test: no way to determine address space size"
   exit 77
 fi
+if test $malloc_result = 78; then
+  echo "Skipping test: cannot trust address space size on this platform"
+  exit 77
+fi
 
 ${CHECKER} ./test-fprintf-posix3${EXEEXT} 1 > /dev/null
 result=$?
@@ -23,9 +27,4 @@ if test $result != 0; then
   exit 1
 fi
 
-if test $malloc_result = 78; then
-  echo "Skipping test: get_rusage_as() doesn't work"
-  exit 77
-fi
-
 exit 0




reply via email to

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