From c61c0388f61ee69a13f093159e73e5d304f757d2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 9 May 2024 12:56:55 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ tests/test-dprintf-posix2.c | 19 ++++++++++++++++++- tests/test-dprintf-posix2.sh | 8 ++++++-- tests/test-fprintf-posix3.c | 18 +++++++++++++++++- tests/test-fprintf-posix3.sh | 6 +++++- 5 files changed, 54 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b54e43108..8329a83be1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-09 Bruno Haible + + 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. + 2024-05-09 Bruno Haible unistdio/*printf: Fix %n handling with module 'printf-with-n-directive'. 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 +/* 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 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 #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=$? -- 2.39.5