From: Bruno Haible Date: Thu, 9 May 2024 10:56:55 +0000 (+0200) Subject: dprintf-posix, fprintf-posix tests: Avoid test failures with ASAN. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=83b9f6e907c1237a589a8a694384a9e6f3549059;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 83dfc42a94..5d9c92533c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-09 Bruno Haible + + 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 sigsegv, c-stack tests: Avoid test failures with ASAN. diff --git a/tests/test-dprintf-posix2.c b/tests/test-dprintf-posix2.c index 2440046790..3263072ebd 100644 --- a/tests/test-dprintf-posix2.c +++ b/tests/test-dprintf-posix2.c @@ -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 @@ -20,6 +20,21 @@ #include +/* 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 #include #include @@ -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 330642d66a..f2d31e71ac 100644 --- a/tests/test-fprintf-posix3.c +++ b/tests/test-fprintf-posix3.c @@ -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 #include #include @@ -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=$?