With the clang17 address sanitizer and UB sanitizer, I'm seeing these two test failures:
FAIL: test-dprintf-posix2.sh FAIL: test-fprintf-posix3.sh The cause is that the malloc (10000000) call returns NULL. The test cannot work in this circumstance. 2024-05-09 Bruno Haible <br...@clisp.org> dprintf-posix, fprintf-posix: 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. diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c index 8eb8643762..3263072ebd 100644 --- a/tests/test-dprintf-posix2.c +++ b/tests/test-dprintf-posix2.c @@ -20,6 +20,21 @@ #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 */ diff --git a/tests/test-dprintf-posix2.sh b/tests/test-dprintf-posix2.sh index 7a548188f3..12e25bc318 100755 --- a/tests/test-dprintf-posix2.sh +++ b/tests/test-dprintf-posix2.sh @@ -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 diff --git a/tests/test-fprintf-posix3.c b/tests/test-fprintf-posix3.c index 3a2ba7f926..f2d31e71ac 100644 --- a/tests/test-fprintf-posix3.c +++ b/tests/test-fprintf-posix3.c @@ -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 */ diff --git a/tests/test-fprintf-posix3.sh b/tests/test-fprintf-posix3.sh index a79273ee2e..2fe1f27d40 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 && 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=$?