aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2023-07-28 09:10:27 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2023-07-28 09:10:27 +0000
commitdf1ea5887326103f0cc1445ab42fce528b474030 (patch)
treeb478cf9a5ba0869803268ca6176a600122a35f62
parent4281dab8bc11b3b2f3b58be5e0f67806329bddae (diff)
downloadsrc-df1ea5887326103f0cc1445ab42fce528b474030.tar.gz
src-df1ea5887326103f0cc1445ab42fce528b474030.zip
tests: Test libexecinfo backtrace call througth signal trampoline
It should fails on Aarch64 until https://reviews.llvm.org/D155066 is not merged. Reviewed by: Differential Revision: https://reviews.freebsd.org/D41129
-rw-r--r--lib/libexecinfo/tests/Makefile3
-rw-r--r--lib/libexecinfo/tests/sigtramp_test.c75
2 files changed, 78 insertions, 0 deletions
diff --git a/lib/libexecinfo/tests/Makefile b/lib/libexecinfo/tests/Makefile
index da34964c5005..7b90029fe354 100644
--- a/lib/libexecinfo/tests/Makefile
+++ b/lib/libexecinfo/tests/Makefile
@@ -14,7 +14,10 @@ STRIP=
# so that doesn't seem useful.
NETBSD_ATF_TESTS_C+= backtrace_test
+ATF_TESTS_C+= sigtramp_test
+
LIBADD.backtrace_test+= execinfo
+LIBADD.sigtramp_test+= execinfo
.include <netbsd-tests.test.mk>
diff --git a/lib/libexecinfo/tests/sigtramp_test.c b/lib/libexecinfo/tests/sigtramp_test.c
new file mode 100644
index 000000000000..cd3b3cc418de
--- /dev/null
+++ b/lib/libexecinfo/tests/sigtramp_test.c
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2023 Dmitry Chagin <dchagin@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/wait.h>
+
+#include <execinfo.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <atf-c.h>
+
+#define BT_FUNCTIONS 10
+
+void handler(int);
+
+__noinline void
+handler(int signum __unused)
+{
+ void *addresses[BT_FUNCTIONS];
+ char **symbols;
+ size_t n, i, match;
+
+ n = backtrace(addresses, nitems(addresses));
+ ATF_REQUIRE(n > 1);
+ symbols = backtrace_symbols(addresses, n);
+ ATF_REQUIRE(symbols != NULL);
+
+ match = -1;
+ for (i = 0; i < n; i++) {
+ printf("%zu: %p, %s\n", i, addresses[i], symbols[i]);
+ if (strstr(symbols[i], "<main+") != NULL)
+ match = i;
+ }
+ ATF_REQUIRE(match > 0);
+ printf("match at %zu, symbols %zu\n", match, n);
+
+}
+
+ATF_TC_WITHOUT_HEAD(test_backtrace_sigtramp);
+ATF_TC_BODY(test_backtrace_sigtramp, tc)
+{
+ struct sigaction act;
+ pid_t child;
+ int status;
+
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = handler;
+ sigemptyset(&act.sa_mask);
+ sigaction(SIGUSR1, &act, NULL);
+
+ child = fork();
+ ATF_REQUIRE(child != -1);
+
+ if (child == 0) {
+ kill(getppid(), SIGUSR1);
+ _exit(0);
+ } else
+ wait(&status);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, test_backtrace_sigtramp);
+
+ return (atf_no_error());
+}