From d071aa2e1f0284a019d3c713611547d42e59b596 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 9 May 2024 01:41:52 +0200 Subject: [PATCH] sigsegv, c-stack tests: Avoid test failures with ASAN. * tests/test-sigsegv-catch-stackoverflow1.c (HAVE_STACK_OVERFLOW_RECOVERY): Undefine if ASAN is enabled. * tests/test-sigsegv-catch-stackoverflow2.c (HAVE_STACK_OVERFLOW_RECOVERY): Likewise. * tests/test-c-stack.c (main): Skip the test if ASAN is enabled. --- ChangeLog | 9 +++++++++ tests/test-c-stack.c | 23 ++++++++++++++++++++--- tests/test-sigsegv-catch-stackoverflow1.c | 8 ++++++++ tests/test-sigsegv-catch-stackoverflow2.c | 10 +++++++++- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f47dcf75ee..83dfc42a94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2024-05-08 Bruno Haible + + sigsegv, c-stack tests: Avoid test failures with ASAN. + * tests/test-sigsegv-catch-stackoverflow1.c + (HAVE_STACK_OVERFLOW_RECOVERY): Undefine if ASAN is enabled. + * tests/test-sigsegv-catch-stackoverflow2.c + (HAVE_STACK_OVERFLOW_RECOVERY): Likewise. + * tests/test-c-stack.c (main): Skip the test if ASAN is enabled. + 2024-05-08 Bruno Haible argp: Fix test failure with clang's ASAN. diff --git a/tests/test-c-stack.c b/tests/test-c-stack.c index 2f689d9183..d21b8dad7b 100644 --- a/tests/test-c-stack.c +++ b/tests/test-c-stack.c @@ -1,5 +1,5 @@ /* Test of c-stack module. - Copyright (C) 2002, 2004, 2006, 2008-2023 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2006, 2008-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 @@ -30,6 +30,21 @@ #include "macros.h" +/* Skip this test when an address sanitizer is in use. */ +#ifndef __has_feature +# define __has_feature(a) 0 +#endif +#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) + +int +main (int argc, char **argv) +{ + fputs ("skipping test: address sanitizer in use\n", stderr); + return 77; +} + +#else + static volatile int * recurse_1 (volatile int n, volatile int *p) { @@ -48,7 +63,7 @@ recurse (volatile int n) int main (int argc, char **argv) { -#if HAVE_SETRLIMIT && defined RLIMIT_STACK +# if HAVE_SETRLIMIT && defined RLIMIT_STACK /* Before starting the endless recursion, try to be friendly to the user's machine. On some Linux 2.2.x systems, there is no stack limit for user processes at all. We don't want to kill such @@ -56,7 +71,7 @@ main (int argc, char **argv) struct rlimit rl; rl.rlim_cur = rl.rlim_max = 0x100000; /* 1 MB */ setrlimit (RLIMIT_STACK, &rl); -#endif +# endif if (c_stack_action (NULL) == 0) { @@ -71,3 +86,5 @@ main (int argc, char **argv) perror ("c_stack_action"); return 77; } + +#endif diff --git a/tests/test-sigsegv-catch-stackoverflow1.c b/tests/test-sigsegv-catch-stackoverflow1.c index 46b120686c..7e58bbb762 100644 --- a/tests/test-sigsegv-catch-stackoverflow1.c +++ b/tests/test-sigsegv-catch-stackoverflow1.c @@ -24,6 +24,14 @@ #include #include +/* Skip this test when an address sanitizer is in use. */ +#ifndef __has_feature +# define __has_feature(a) 0 +#endif +#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +# undef HAVE_STACK_OVERFLOW_RECOVERY +#endif + #if HAVE_STACK_OVERFLOW_RECOVERY # if defined _WIN32 && !defined __CYGWIN__ diff --git a/tests/test-sigsegv-catch-stackoverflow2.c b/tests/test-sigsegv-catch-stackoverflow2.c index f6dc32626f..60f7eb0cfb 100644 --- a/tests/test-sigsegv-catch-stackoverflow2.c +++ b/tests/test-sigsegv-catch-stackoverflow2.c @@ -1,5 +1,5 @@ /* Test that stack overflow and SIGSEGV are correctly distinguished. - Copyright (C) 2002-2023 Free Software Foundation, Inc. + Copyright (C) 2002-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 @@ -25,6 +25,14 @@ #include #include +/* Skip this test when an address sanitizer is in use. */ +#ifndef __has_feature +# define __has_feature(a) 0 +#endif +#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer) +# undef HAVE_STACK_OVERFLOW_RECOVERY +#endif + #if HAVE_STACK_OVERFLOW_RECOVERY && HAVE_SIGSEGV_RECOVERY # if defined _WIN32 && !defined __CYGWIN__ -- 2.39.5