]> Savannah Git Hosting - gnulib.git/commitdiff
execinfo tests: Strengthen tests.
authorBruno Haible <bruno@clisp.org>
Sun, 12 May 2024 10:29:38 +0000 (12:29 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 12 May 2024 10:29:38 +0000 (12:29 +0200)
* tests/test-execinfo.c (test_backtrace): Add an argument. Check the
return value of backtrace(). Check that backtrace_symbols_fd is defined.
Check the return value of backtrace_symbols().
(main): Test also the case of a short buffer.
* modules/execinfo-tests (Makefile.am): Verify that LIB_EXECINFO is
defined.

ChangeLog
modules/execinfo-tests
tests/test-execinfo.c

index 3e5df0d22d8dc68017f544d274e0d027d70f754b..34d53eb4e114e37b16cdb38a7d069f4d08b9f1ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-05-12  Bruno Haible  <bruno@clisp.org>
+
+       execinfo tests: Strengthen tests.
+       * tests/test-execinfo.c (test_backtrace): Add an argument. Check the
+       return value of backtrace(). Check that backtrace_symbols_fd is defined.
+       Check the return value of backtrace_symbols().
+       (main): Test also the case of a short buffer.
+       * modules/execinfo-tests (Makefile.am): Verify that LIB_EXECINFO is
+       defined.
+
 2024-05-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        stdbit: don’t assume -DHAVE_CONFIG_H
index 191345cd5c76c640c7524cfc2b2b591add99cd96..5d6a28c69bd8923e25945ad4f8047c551635658f 100644 (file)
@@ -9,4 +9,4 @@ configure.ac:
 Makefile.am:
 TESTS += test-execinfo
 check_PROGRAMS += test-execinfo
-test_execinfo_LDADD = $(LDADD) $(LIB_EXECINFO)
+test_execinfo_LDADD = $(LDADD) @LIB_EXECINFO@
index af457c468ff8e8108f3feb422b220b3f068dcb38..5745306ed59c03011fe74ce1708010085aa624a2 100644 (file)
 #include "macros.h"
 
 static void
-test_backtrace (void)
+test_backtrace (int pass)
 {
   void *buffer[10];
-  char **symbols;
+  int max_size;
   int size;
+  char **symbols;
+
+  max_size = (pass == 0 ? SIZEOF (buffer) : 1);
+  size = backtrace (buffer, max_size);
+  ASSERT (size >= 0 && size <= max_size);
+
+  /* Print the backtrace to a file descriptor.  */
+  backtrace_symbols_fd (buffer, size, 1);
+  printf ("\n");
 
-  size = backtrace (buffer, SIZEOF (buffer));
   symbols = backtrace_symbols (buffer, size);
+  if (size > 0)
+    /* We have enough memory available.  */
+    ASSERT (symbols != NULL);
 
   /* Print the backtrace if possible.  */
-  if (0 < size && symbols != NULL)
+  if (symbols != NULL)
     {
       for (int i = 0; i < size; ++i)
         printf ("%s\n", symbols[i]);
@@ -48,7 +59,10 @@ test_backtrace (void)
 int
 main (void)
 {
-  test_backtrace ();
+  printf ("Full stack trace:\n"); fflush (stdout);
+  test_backtrace (0);
+  printf ("\nTruncated stack trace:\n"); fflush (stdout);
+  test_backtrace (1);
 
   return 0;
 }