I've pushed a basic test for execinfo. Since BSD needs to link to
-lexecinfo unlike glibc. Should catch any bugs that occur there or if
another system adds it as a library.

Collin
From 06ff525438b5df5c83664535908c02ae398f6e3f Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sat, 11 May 2024 20:46:12 -0700
Subject: [PATCH] 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.
---
 ChangeLog              |  8 +++++++
 modules/execinfo-tests | 12 ++++++++++
 tests/test-execinfo.c  | 54 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 modules/execinfo-tests
 create mode 100644 tests/test-execinfo.c

diff --git a/ChangeLog b/ChangeLog
index 9ccd92700e..a159f518dc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-05-11  Collin Funk  <collin.fu...@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  <br...@clisp.org>
 
 	Continue to use spaces for indentation, not tabs.
diff --git a/modules/execinfo-tests b/modules/execinfo-tests
new file mode 100644
index 0000000000..191345cd5c
--- /dev/null
+++ b/modules/execinfo-tests
@@ -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
index 0000000000..af457c468f
--- /dev/null
+++ b/tests/test-execinfo.c
@@ -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.fu...@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;
+}
-- 
2.45.0

Reply via email to