]> Savannah Git Hosting - gnulib.git/commitdiff
execinfo: Add tests.
authorCollin Funk <collin.funk1@gmail.com>
Sun, 12 May 2024 03:46:12 +0000 (20:46 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Sun, 12 May 2024 03:46:12 +0000 (20:46 -0700)
* modules/execinfo-tests: New file.
* tests/test-execinfo.c (test_backtrace): New function. Simply test that
the symbols defined in execinfo.h can be used.
(main): Use it.

ChangeLog
modules/execinfo-tests [new file with mode: 0644]
tests/test-execinfo.c [new file with mode: 0644]

index 9ccd92700e00571df5ac37b1da0e8b0fa97fa1ea..a159f518dcadd7a2da421bfe769b705a10aaebbf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-05-11  Collin Funk  <collin.funk1@gmail.com>
+
+       execinfo: Add tests.
+       * modules/execinfo-tests: New file.
+       * tests/test-execinfo.c (test_backtrace): New function. Simply test that
+       the symbols defined in execinfo.h can be used.
+       (main): Use it.
+
 2024-05-11  Bruno Haible  <bruno@clisp.org>
 
        Continue to use spaces for indentation, not tabs.
diff --git a/modules/execinfo-tests b/modules/execinfo-tests
new file mode 100644 (file)
index 0000000..191345c
--- /dev/null
@@ -0,0 +1,12 @@
+Files:
+tests/test-execinfo.c
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-execinfo
+check_PROGRAMS += test-execinfo
+test_execinfo_LDADD = $(LDADD) $(LIB_EXECINFO)
diff --git a/tests/test-execinfo.c b/tests/test-execinfo.c
new file mode 100644 (file)
index 0000000..af457c4
--- /dev/null
@@ -0,0 +1,54 @@
+/* Test that execinfo.h defines stub functions.
+   Copyright (C) 2024 Free Software Foundation, Inc.
+
+   This file is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation, either version 3 of the License,
+   or (at your option) any later version.
+
+   This file is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Collin Funk <collin.funk1@gmail.com>, 2024.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <execinfo.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "macros.h"
+
+static void
+test_backtrace (void)
+{
+  void *buffer[10];
+  char **symbols;
+  int size;
+
+  size = backtrace (buffer, SIZEOF (buffer));
+  symbols = backtrace_symbols (buffer, size);
+
+  /* Print the backtrace if possible.  */
+  if (0 < size && symbols != NULL)
+    {
+      for (int i = 0; i < size; ++i)
+        printf ("%s\n", symbols[i]);
+      free (symbols);
+    }
+}
+
+int
+main (void)
+{
+  test_backtrace ();
+
+  return 0;
+}