]> Savannah Git Hosting - gnulib.git/commitdiff
dprintf-posix, fprintf-posix tests: Avoid test failures with ASAN.
authorBruno Haible <bruno@clisp.org>
Thu, 9 May 2024 10:56:55 +0000 (12:56 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 17 May 2024 23:30:33 +0000 (01:30 +0200)
* tests/test-dprintf-posix2.c (main): Skip the test if ASAN is enabled.
* tests/test-fprintf-posix3.c (main): Likewise.
* tests/test-dprintf-posix2.sh: Update.
* tests/test-fprintf-posix3.sh: Likewise.

ChangeLog
tests/test-dprintf-posix2.c
tests/test-dprintf-posix2.sh
tests/test-fprintf-posix3.c
tests/test-fprintf-posix3.sh

index 83dfc42a94f619fc8b4e9bc5fa79baf29098b00b..5d9c92533c9da1b5def50168ae68ef2cde45c00d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-05-09  Bruno Haible  <bruno@clisp.org>
+
+       dprintf-posix, fprintf-posix tests: Avoid test failures with ASAN.
+       * tests/test-dprintf-posix2.c (main): Skip the test if ASAN is enabled.
+       * tests/test-fprintf-posix3.c (main): Likewise.
+       * tests/test-dprintf-posix2.sh: Update.
+       * tests/test-fprintf-posix3.sh: Likewise.
+
 2024-05-08  Bruno Haible  <bruno@clisp.org>
 
        sigsegv, c-stack tests: Avoid test failures with ASAN.
index 24400467903a4299217a42b7898c38ff4b46eef8..3263072ebd2e696e52a2c26350fc6623c3d69c44 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of POSIX compatible dprintf() function.
-   Copyright (C) 2009-2023 Free Software Foundation, Inc.
+   Copyright (C) 2009-2024 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
 #include <stdio.h>
 
+/* Skip this test when an address sanitizer is in use, since it would fail.  */
+#ifndef __has_feature
+# define __has_feature(a) 0
+#endif
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+
+int
+main ()
+{
+  fprintf (stderr, "Skipping test: address sanitizer's malloc behaves differently\n");
+  return 80;
+}
+
+#else
+
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -92,7 +107,7 @@ main (int argc, char *argv[])
       if (memory == NULL)
         return 1;
       memset (memory, 17, MAX_ALLOC_TOTAL);
-      result = 80;
+      result = 81;
     }
   else
     {
@@ -117,3 +132,5 @@ main (int argc, char *argv[])
 
   return result;
 }
+
+#endif /* ! address sanitizer enabled */
index 7a548188f31a873e23bd0676ffc1128a43471467..12e25bc3182b3ee9ad081642eef78213249e77bd 100755 (executable)
@@ -4,7 +4,7 @@
 
 (${CHECKER} ./test-dprintf-posix2${EXEEXT} 0
  result=$?
- if test $result != 77 && test $result != 79 && test $result != 80; then result=1; fi
+ if test $result != 77 && test $result != 79 && test $result != 80 && test $result != 81; then result=1; fi
  exit $result
 ) 2>/dev/null
 malloc_result=$?
@@ -16,6 +16,10 @@ if test $malloc_result = 79; then
   echo "Skipping test: cannot trust address space size when running under QEMU"
   exit 77
 fi
+if test $malloc_result = 80; then
+  echo "Skipping test: address sanitizer's malloc behaves differently"
+  exit 77
+fi
 
 ${CHECKER} ./test-dprintf-posix2${EXEEXT} 1 > /dev/null
 result=$?
@@ -27,7 +31,7 @@ if test $result != 0; then
   exit 1
 fi
 
-if test $malloc_result = 80; then
+if test $malloc_result = 81; then
   echo "Skipping test: get_rusage_as() doesn't work"
   exit 77
 fi
index 330642d66ac3b324cdac5cc79deff7fb050a2d19..f2d31e71ac6252060e0386f78f95787f37d85aec 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of POSIX compatible fprintf() function.
-   Copyright (C) 2009-2023 Free Software Foundation, Inc.
+   Copyright (C) 2009-2024 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -38,6 +38,21 @@ main ()
 
 #else
 
+/* Skip this test when an address sanitizer is in use, since it would fail.  */
+#ifndef __has_feature
+# define __has_feature(a) 0
+#endif
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+
+int
+main ()
+{
+  fprintf (stderr, "Skipping test: address sanitizer's malloc behaves differently\n");
+  return 80;
+}
+
+#else
+
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -109,7 +124,7 @@ main (int argc, char *argv[])
       if (memory == NULL)
         return 1;
       memset (memory, 17, MAX_ALLOC_TOTAL);
-      result = 80;
+      result = 81;
     }
   else
     {
@@ -135,4 +150,5 @@ main (int argc, char *argv[])
   return result;
 }
 
+#endif /* ! address sanitizer enabled */
 #endif /* !macOS */
index a79273ee2e111b99d0332832363e4d6917bd9a9d..2fe1f27d4084ca0674fd889374de7d6114fd1f86 100755 (executable)
@@ -4,7 +4,7 @@
 
 (${CHECKER} ./test-fprintf-posix3${EXEEXT} 0
  result=$?
- if test $result != 77 && test $result != 78 && test $result != 79 && test $result != 80; then result=1; fi
+ if test $result != 77 && test $result != 78 && test $result != 79 && test $result != 80 && test $result != 81; then result=1; fi
  exit $result
 ) 2>/dev/null
 malloc_result=$?
@@ -20,6 +20,10 @@ if test $malloc_result = 79; then
   echo "Skipping test: cannot trust address space size when running under QEMU"
   exit 77
 fi
+if test $malloc_result = 80; then
+  echo "Skipping test: address sanitizer's malloc behaves differently"
+  exit 77
+fi
 
 ${CHECKER} ./test-fprintf-posix3${EXEEXT} 1 > /dev/null
 result=$?