Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/regress/lib/libc/siginfo/sigchld more regression.



details:   https://anonhg.NetBSD.org/src/rev/9ccbd318f713
branches:  trunk
changeset: 551920:9ccbd318f713
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Sep 14 05:38:41 2003 +0000

description:
more regression.

diffstat:

 regress/lib/libc/siginfo/sigchld/Makefile  |   10 ++
 regress/lib/libc/siginfo/sigchld/sigchld.c |  117 +++++++++++++++++++++++++++++
 2 files changed, 127 insertions(+), 0 deletions(-)

diffs (135 lines):

diff -r ff67438ee847 -r 9ccbd318f713 regress/lib/libc/siginfo/sigchld/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/siginfo/sigchld/Makefile Sun Sep 14 05:38:41 2003 +0000
@@ -0,0 +1,10 @@
+#      $NetBSD: Makefile,v 1.1 2003/09/14 05:38:41 christos Exp $
+
+NOMAN=         # defined
+
+PROG=          sigchld
+
+regress: ${PROG}
+       ./${PROG}
+
+.include <bsd.prog.mk>
diff -r ff67438ee847 -r 9ccbd318f713 regress/lib/libc/siginfo/sigchld/sigchld.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/lib/libc/siginfo/sigchld/sigchld.c        Sun Sep 14 05:38:41 2003 +0000
@@ -0,0 +1,117 @@
+#include <assert.h>
+#include <signal.h>
+#include <stdio.h>
+#include <sys/ucontext.h>
+#include <sys/wait.h>
+
+pid_t child;
+int code;
+int status;
+
+void
+handler(int signo, siginfo_t *info, void *ptr)
+{
+#ifdef DEBUG
+       if (info != NULL) {
+               printf("si_signo=%d\n", info->si_signo);
+               printf("si_errno=%d\n", info->si_errno);
+               printf("si_code=%d\n", info->si_code);
+               printf("si_uid=%d\n", info->si_uid);
+               printf("si_pid=%d\n", info->si_pid);
+               printf("si_status=%d\n", info->si_status);
+               printf("si_utime=%d\n", info->si_utime);
+               printf("si_stime=%d\n", info->si_stime);
+       }
+#endif
+       assert(info->si_code == code);
+       assert(info->si_signo == SIGCHLD);
+       assert(info->si_uid == getuid());
+       assert(info->si_pid == child);
+       if (WIFEXITED(info->si_status))
+               assert(WEXITSTATUS(info->si_status) == status);
+       else if (WIFSTOPPED(info->si_status))
+               assert(WSTOPSIG(info->si_status) == status);
+       else if (WIFSIGNALED(info->si_status))
+               assert(WTERMSIG(info->si_status) == status);
+}
+
+static void
+sethandler(void (*action)(int, siginfo_t *, void *))
+{
+       struct sigaction sa;
+       sa.sa_flags = SA_SIGINFO;
+       sa.sa_sigaction = action;
+       sigemptyset(&sa.sa_mask);
+       sigaction(SIGCHLD, &sa, NULL);
+}
+
+
+static void
+runnormal()
+{
+       sigset_t set;
+       status = 25;
+       code = CLD_EXITED;
+
+       switch ((child = fork())) {
+       case 0:
+               sleep(1);
+               exit(status);
+       case -1:
+               err(1, "fork");
+       default:
+               sigemptyset(&set);
+               sigsuspend(&set);
+       }
+}
+
+static void
+rundump()
+{
+       sigset_t set;
+       status = SIGSEGV;
+       code = CLD_DUMPED;
+
+       switch ((child = fork())) {
+       case 0:
+               sleep(1);
+               *(long *)0x5a5a5a5a = 0;
+               break;
+       case -1:
+               err(1, "fork");
+       default:
+               sigemptyset(&set);
+               sigsuspend(&set);
+       }
+}
+
+static void
+runkill()
+{
+       sigset_t set;
+       status = SIGPIPE;
+       code = CLD_KILLED;
+
+       switch ((child = fork())) {
+       case 0:
+               sigemptyset(&set);
+               sigsuspend(&set);
+               break;
+       case -1:
+               err(1, "fork");
+       default:
+               kill(child, SIGPIPE);
+               sigemptyset(&set);
+               sigsuspend(&set);
+       }
+}
+int
+main(void)
+{
+       sethandler(handler);
+       runnormal();
+       rundump();
+       runkill();
+
+       return 0;
+}



Home | Main Index | Thread Index | Old Index