aboutsummaryrefslogtreecommitdiff
path: root/tests/tcg/multiarch
diff options
context:
space:
mode:
authorIlya Leoshkevich <iii@linux.ibm.com>2024-10-30 00:17:48 +0100
committerRichard Henderson <richard.henderson@linaro.org>2024-11-05 10:36:08 +0000
commit6f58b090328f5b47ee688c77542bf20d521239a2 (patch)
treee2158b9c515cdc0791484f59ac28e557ef5a6fa1 /tests/tcg/multiarch
parentc107521e0ee9ea1744f674a79d02d3d5ea2ba98c (diff)
downloadqemu-6f58b090328f5b47ee688c77542bf20d521239a2.zip
qemu-6f58b090328f5b47ee688c77542bf20d521239a2.tar.gz
qemu-6f58b090328f5b47ee688c77542bf20d521239a2.tar.bz2
tests/tcg: Add SIGRTMIN/SIGRTMAX test
Test the lowest and the highest real-time signals. This requires configuring the real-time signal mapping, and therefore some knowledge about the host. To this end, pass the emulator path in the QEMU environment variable to all tests (this should not disturb the existing ones), and assume that all hosts have signals 36-39 available. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Message-ID: <20241029232211.206766-3-iii@linux.ibm.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tests/tcg/multiarch')
-rw-r--r--tests/tcg/multiarch/linux/linux-sigrtminmax.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/tests/tcg/multiarch/linux/linux-sigrtminmax.c b/tests/tcg/multiarch/linux/linux-sigrtminmax.c
new file mode 100644
index 0000000..a7059aa
--- /dev/null
+++ b/tests/tcg/multiarch/linux/linux-sigrtminmax.c
@@ -0,0 +1,74 @@
+/*
+ * Test the lowest and the highest real-time signals.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include <assert.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/* For hexagon and microblaze. */
+#ifndef __SIGRTMIN
+#define __SIGRTMIN 32
+#endif
+
+extern char **environ;
+
+static bool seen_sigrtmin, seen_sigrtmax;
+
+static void handle_signal(int sig)
+{
+ if (sig == SIGRTMIN) {
+ seen_sigrtmin = true;
+ } else if (sig == SIGRTMAX) {
+ seen_sigrtmax = true;
+ } else {
+ _exit(1);
+ }
+}
+
+int main(int argc, char **argv)
+{
+ char *qemu = getenv("QEMU");
+ struct sigaction act;
+
+ assert(qemu);
+
+ if (!getenv("QEMU_RTSIG_MAP")) {
+ char **new_argv = malloc((argc + 2) + sizeof(char *));
+ int tsig1, hsig1, count1, tsig2, hsig2, count2;
+ char rt_sigmap[64];
+
+ /* Re-exec with a mapping that includes SIGRTMIN and SIGRTMAX. */
+ new_argv[0] = qemu;
+ memcpy(&new_argv[1], argv, (argc + 1) * sizeof(char *));
+ tsig1 = __SIGRTMIN;
+ /* The host must have a few signals starting from this one. */
+ hsig1 = 36;
+ count1 = SIGRTMIN - __SIGRTMIN + 1;
+ tsig2 = SIGRTMAX;
+ hsig2 = hsig1 + count1;
+ count2 = 1;
+ snprintf(rt_sigmap, sizeof(rt_sigmap), "%d %d %d,%d %d %d",
+ tsig1, hsig1, count1, tsig2, hsig2, count2);
+ setenv("QEMU_RTSIG_MAP", rt_sigmap, 0);
+ assert(execve(new_argv[0], new_argv, environ) == 0);
+ return EXIT_FAILURE;
+ }
+
+ memset(&act, 0, sizeof(act));
+ act.sa_handler = handle_signal;
+ assert(sigaction(SIGRTMIN, &act, NULL) == 0);
+ assert(sigaction(SIGRTMAX, &act, NULL) == 0);
+
+ assert(kill(getpid(), SIGRTMIN) == 0);
+ assert(seen_sigrtmin);
+ assert(kill(getpid(), SIGRTMAX) == 0);
+ assert(seen_sigrtmax);
+
+ return EXIT_SUCCESS;
+}