From 60d3d21057533e7a336f8504806f0faf41814b02 Mon Sep 17 00:00:00 2001 From: David Xu Date: Mon, 7 Nov 2005 14:10:33 +0000 Subject: [PATCH] Add sigqueue test code. --- tools/regression/sigqueue/Makefile | 5 ++ tools/regression/sigqueue/sigqtest1/Makefile | 8 +++ .../regression/sigqueue/sigqtest1/sigqtest1.c | 49 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tools/regression/sigqueue/Makefile create mode 100644 tools/regression/sigqueue/sigqtest1/Makefile create mode 100644 tools/regression/sigqueue/sigqtest1/sigqtest1.c diff --git a/tools/regression/sigqueue/Makefile b/tools/regression/sigqueue/Makefile new file mode 100644 index 000000000000..d3046c40d0dd --- /dev/null +++ b/tools/regression/sigqueue/Makefile @@ -0,0 +1,5 @@ +# $FreeBSD$ + +SUBDIR=sigqtest1 + +.include diff --git a/tools/regression/sigqueue/sigqtest1/Makefile b/tools/regression/sigqueue/sigqtest1/Makefile new file mode 100644 index 000000000000..08a140c5c894 --- /dev/null +++ b/tools/regression/sigqueue/sigqtest1/Makefile @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG=sigqtest1 +LDADD+= +NO_MAN= +DEBUG_FLAGS=-g + +.include diff --git a/tools/regression/sigqueue/sigqtest1/sigqtest1.c b/tools/regression/sigqueue/sigqtest1/sigqtest1.c new file mode 100644 index 000000000000..0f40021b4ab6 --- /dev/null +++ b/tools/regression/sigqueue/sigqtest1/sigqtest1.c @@ -0,0 +1,49 @@ +/* $FreeBSD$ */ +#include +#include +#include +#include + +int received; + +void handler(int sig, siginfo_t *si, void *ctx) +{ + if (si->si_code != SI_QUEUE) + errx(1, "si_code != SI_QUEUE"); + if (si->si_value.sival_int != received) + errx(1, "signal is out of order"); + received++; +} + +int main() +{ + struct sigaction sa; + union sigval val; + int ret; + int i; + sigset_t set; + + sa.sa_flags = SA_SIGINFO; + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = handler; + sigaction(SIGRTMIN, &sa, NULL); + sigemptyset(&set); + sigaddset(&set, SIGRTMIN); + sigprocmask(SIG_BLOCK, &set, NULL); + i = 0; + for (;;) { + val.sival_int = i; + ret = sigqueue(getpid(), SIGRTMIN, val); + if (ret == -1) { + if (errno != EAGAIN) { + errx(1, "errno != EAGAIN"); + } + break; + } + i++; + } + sigprocmask(SIG_UNBLOCK, &set, NULL); + if (received != i) + errx(1, "error, signal lost"); + printf("OK\n"); +}