Sometimes a test has several failures on a certain platform (e.g. the test-c32is* tests). In order to display all failed ASSERTs, not just the first one, so far I hand-edited tests/macros.h.
But this approach does not work with CI builds, because - it's not easy to hand-edit a file, - it's also not possible to use gdb. As a mitigation, I'm introducing a CONTINUE_AFTER_ASSERT macro that, when defined, will let the test progress after an ASSERT failure. Of course the test should still be failing, then, even though abort() may not be called. The following two patches achieve this. It's a small complication for writing new unit tests, but not a heavy one, because it's trivial to change return 0; to return test_exit_status; (It's not a requirement that the test continues properly after an ASSERT failure. It's OK if the test crashes through undefined behaviour, such as a NULL pointer access.) 2024-05-18 Bruno Haible <br...@clisp.org> abort-debug: Integrate with CONTINUE_AFTER_ASSERT. * lib/stdlib.in.h (_gl_pre_abort): New declaration. * lib/abort-debug.c (_gl_pre_abort): New function. * tests/macros.h (ASSERT, ASSERT_NO_STDIO): If CONTINUE_AFTER_ASSERT is 1 and the assertion fails, invoke _gl_pre_abort. 2024-05-18 Bruno Haible <br...@clisp.org> tests: Support showing all assertion failures, not just the first one. * tests/macros.h (CONTINUE_AFTER_ASSERT): New macro. (test_exit_status): New variable. (ASSERT, ASSERT_NO_STDIO): If CONTINUE_AFTER_ASSERT is 1, set test_exit_status instead of aborting. * tests/**/test-*.{c,h,cc} (main): Instead of exiting with exit code 0, exit with exit code test_exit_status. * tests/test-spawn-pipe-child.c: Undefine CONTINUE_AFTER_ASSERT. * tests/uninorm/test-nf*.c: Include macros.h. * tests/uninorm/test-u32-nf*-big.c: Likewise. * tests/random*.c: Define NO_MAIN_HERE.
0001-tests-Support-showing-all-assertion-failures-not-jus.patch.gz
Description: application/gzip
>From 036cabf60010269a92e82272c52fbbd37c8fe59f Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 18 May 2024 22:53:28 +0200 Subject: [PATCH 2/2] abort-debug: Integrate with CONTINUE_AFTER_ASSERT. * lib/stdlib.in.h (_gl_pre_abort): New declaration. * lib/abort-debug.c (_gl_pre_abort): New function. * tests/macros.h (ASSERT, ASSERT_NO_STDIO): If CONTINUE_AFTER_ASSERT is 1 and the assertion fails, invoke _gl_pre_abort. --- ChangeLog | 8 ++++++++ lib/abort-debug.c | 13 +++++++++++++ lib/stdlib.in.h | 8 ++++++++ tests/macros.h | 10 ++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c119e32014..7de9b90f6d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-05-18 Bruno Haible <br...@clisp.org> + + abort-debug: Integrate with CONTINUE_AFTER_ASSERT. + * lib/stdlib.in.h (_gl_pre_abort): New declaration. + * lib/abort-debug.c (_gl_pre_abort): New function. + * tests/macros.h (ASSERT, ASSERT_NO_STDIO): If CONTINUE_AFTER_ASSERT + is 1 and the assertion fails, invoke _gl_pre_abort. + 2024-05-18 Bruno Haible <br...@clisp.org> tests: Support showing all assertion failures, not just the first one. diff --git a/lib/abort-debug.c b/lib/abort-debug.c index 2ca8f81169..ca4dbc7291 100644 --- a/lib/abort-debug.c +++ b/lib/abort-debug.c @@ -55,6 +55,19 @@ print_stack_trace (FILE *stream) #endif +void +_gl_pre_abort (void) +{ +#if HAVE_EXECINFO_H + print_stack_trace (stderr); +#endif +} + +/* rpl_abort (); + is equivalent to + _gl_pre_abort (); + original abort (); // i.e. raise (SIGABRT); + */ void rpl_abort (void) { diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 1888d3ee31..ef9fde30eb 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -231,6 +231,14 @@ _GL_CXXALIAS_SYS (abort, void, (void)); _GL_CXXALIASWARN (abort); # endif #endif +#if @GNULIB_ABORT_DEBUG@ && @REPLACE_ABORT@ +_GL_EXTERN_C void _gl_pre_abort (void); +#else +# if !GNULIB_defined_gl_pre_abort +# define _gl_pre_abort() /* nothing */ +# define GNULIB_defined_gl_pre_abort 1 +# endif +#endif #if @GNULIB_FREE_POSIX@ diff --git a/tests/macros.h b/tests/macros.h index d60de6fd3e..144905e031 100644 --- a/tests/macros.h +++ b/tests/macros.h @@ -81,7 +81,10 @@ int volatile test_exit_status = EXIT_SUCCESS; __FILE__, __LINE__, #expr); \ fflush (ASSERT_STREAM); \ if (CONTINUE_AFTER_ASSERT) \ - test_exit_status = EXIT_FAILURE; \ + { \ + _gl_pre_abort (); \ + test_exit_status = EXIT_FAILURE; \ + } \ else \ abort (); \ } \ @@ -102,7 +105,10 @@ int volatile test_exit_status = EXIT_SUCCESS; WRITE_TO_STDERR (#expr); \ WRITE_TO_STDERR ("' failed\n"); \ if (CONTINUE_AFTER_ASSERT) \ - test_exit_status = EXIT_FAILURE; \ + { \ + _gl_pre_abort (); \ + test_exit_status = EXIT_FAILURE; \ + } \ else \ abort (); \ } \ -- 2.34.1