summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2020-09-16 14:14:42 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2020-09-16 14:14:42 +0000
commit5794373a035745bbb6746fdd821a9d91b1606b36 (patch)
treee484321085962a7cebd60b8a760dedad6c30c6ad /regress/sys
parent066599f72b90b9602c1baabd2f7d762dfbf14d02 (diff)
Remove tests that are now under signal/
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/kern/sig-stop/Makefile5
-rw-r--r--regress/sys/kern/sig-stop/sig-stop.c57
-rw-r--r--regress/sys/kern/siginfo-fault/Makefile6
-rw-r--r--regress/sys/kern/siginfo-fault/siginfo-fault.c175
-rw-r--r--regress/sys/kern/sigio/Makefile36
-rw-r--r--regress/sys/kern/sigio/common.h61
-rw-r--r--regress/sys/kern/sigio/main.c73
-rw-r--r--regress/sys/kern/sigio/sigio_common.c255
-rw-r--r--regress/sys/kern/sigio/sigio_pipe.c78
-rw-r--r--regress/sys/kern/sigio/sigio_socket.c144
-rw-r--r--regress/sys/kern/sigio/util.c135
-rw-r--r--regress/sys/kern/signal-stress/Makefile5
-rw-r--r--regress/sys/kern/signal-stress/signal-stress.c176
-rw-r--r--regress/sys/kern/sigpending/Makefile5
-rw-r--r--regress/sys/kern/sigpending/sigpending.c25
-rw-r--r--regress/sys/kern/sigprof/Makefile7
-rw-r--r--regress/sys/kern/sigprof/sigprof.c132
-rw-r--r--regress/sys/kern/sigpthread/LICENSE15
-rw-r--r--regress/sys/kern/sigpthread/Makefile447
-rw-r--r--regress/sys/kern/sigpthread/README27
-rw-r--r--regress/sys/kern/sigpthread/sigpthread.c282
-rw-r--r--regress/sys/kern/sigsuspend/Makefile5
-rw-r--r--regress/sys/kern/sigsuspend/sigsuspend.c129
23 files changed, 0 insertions, 2280 deletions
diff --git a/regress/sys/kern/sig-stop/Makefile b/regress/sys/kern/sig-stop/Makefile
deleted file mode 100644
index c148c65071f..00000000000
--- a/regress/sys/kern/sig-stop/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-# $OpenBSD: Makefile,v 1.1 2007/04/29 20:10:24 art Exp $
-
-PROG= sig-stop
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/sig-stop/sig-stop.c b/regress/sys/kern/sig-stop/sig-stop.c
deleted file mode 100644
index 278fc1cb69a..00000000000
--- a/regress/sys/kern/sig-stop/sig-stop.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* $OpenBSD: sig-stop.c,v 1.1 2007/04/29 20:10:24 art Exp $ */
-/*
- * Written by Artur Grabowski <art@openbsd.org> 2007 Public Domain.
- */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <time.h>
-#include <err.h>
-#include <signal.h>
-
-int
-main(int argc, char **argv)
-{
- struct timespec ts;
- pid_t child;
- int status;
- int count;
- int toggle = 0;
-
- switch((child = fork())) {
- case -1:
- err(1, "fork");
- case 0:
- ts.tv_sec = 0;
- ts.tv_nsec = 1000;
- for (count = 0; count < 100; count++) {
- nanosleep(&ts, NULL);
- }
- exit(0);
- default:
- break;
- }
-
- ts.tv_sec = 1;
- ts.tv_nsec = 0;
- nanosleep(&ts, NULL);
-
- do {
- toggle ^= 1;
- if (kill(child, toggle ? SIGSTOP : SIGCONT)) {
- if (wait(&status) < 0)
- err(1, "wait");
- break;
- }
- } while(waitpid(child, &status, WCONTINUED|WUNTRACED) > 0 &&
- (toggle ? WIFSTOPPED(status) : WIFCONTINUED(status)));
-
- if (!WIFEXITED(status))
- err(1, "bad status: %d\n", status);
-
- return 0;
-}
diff --git a/regress/sys/kern/siginfo-fault/Makefile b/regress/sys/kern/siginfo-fault/Makefile
deleted file mode 100644
index 938648b44d2..00000000000
--- a/regress/sys/kern/siginfo-fault/Makefile
+++ /dev/null
@@ -1,6 +0,0 @@
-# $OpenBSD: Makefile,v 1.2 2017/07/13 00:29:14 bluhm Exp $
-
-PROG= siginfo-fault
-CFLAGS= -Wall
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/siginfo-fault/siginfo-fault.c b/regress/sys/kern/siginfo-fault/siginfo-fault.c
deleted file mode 100644
index e56d3155e0e..00000000000
--- a/regress/sys/kern/siginfo-fault/siginfo-fault.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/* $OpenBSD: siginfo-fault.c,v 1.6 2017/07/22 16:12:27 kettenis Exp $ */
-/*
- * Copyright (c) 2014 Google Inc.
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/mman.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-/*
- * Some architectures deliver an imprecise fault address.
- */
-#ifdef __sparc64__
-#define EXPADDR_MASK ~(3UL)
-#else
-#define EXPADDR_MASK ~(0UL)
-#endif
-
-#define CHECK_EQ(a, b) assert((a) == (b))
-#define CHECK_NE(a, b) assert((a) != (b))
-#define CHECK_LE(a, b) assert((a) <= (b))
-#define FAIL() assert(0)
-
-static jmp_buf env;
-static volatile int gotsigno;
-static volatile siginfo_t gotsi;
-
-static void
-sigsegv(int signo, siginfo_t *si, void *ctx)
-{
- gotsigno = signo;
- gotsi = *si;
- siglongjmp(env, 1);
-}
-
-static const char *
-strsigcode(int signum, int sigcode)
-{
- switch (signum) {
- case SIGSEGV:
- switch (sigcode) {
- case SEGV_MAPERR:
- return "address not mapped to object";
- case SEGV_ACCERR:
- return "invalid permissions";
- }
- break;
- case SIGBUS:
- switch (sigcode) {
- case BUS_ADRALN:
- return "invalid address alignment";
- case BUS_ADRERR:
- return "non-existent physical address";
- case BUS_OBJERR:
- return "object specific hardware error";
- }
- break;
- }
- return "unknown";
-}
-
-static int
-checksig(const char *name, int expsigno, int expcode, volatile char *expaddr)
-{
- int fail = 0;
- char str1[NL_TEXTMAX], str2[NL_TEXTMAX];
-
- expaddr = (char *)((uintptr_t)expaddr & EXPADDR_MASK);
-
- if (expsigno != gotsigno) {
- strlcpy(str1, strsignal(expsigno), sizeof(str1));
- strlcpy(str2, strsignal(gotsigno), sizeof(str2));
- fprintf(stderr, "%s signo: expect %d (%s), actual %d (%s)\n",
- name, expsigno, str1, gotsigno, str2);
- ++fail;
- }
- if (expsigno != gotsi.si_signo) {
- strlcpy(str1, strsignal(expsigno), sizeof(str1));
- strlcpy(str2, strsignal(gotsi.si_signo), sizeof(str2));
- fprintf(stderr, "%s si_signo: expect %d (%s), actual %d (%s)\n",
- name, expsigno, str1, gotsi.si_signo, str2);
- ++fail;
- }
- if (expcode != gotsi.si_code) {
- fprintf(stderr, "%s si_code: expect %d (%s), actual %d (%s)\n",
- name, expcode, strsigcode(expsigno, expcode),
- gotsi.si_code, strsigcode(gotsigno, gotsi.si_code));
- ++fail;
- }
- if (expaddr != gotsi.si_addr) {
- fprintf(stderr, "%s si_addr: expect %p, actual %p\n",
- name, expaddr, gotsi.si_addr);
- ++fail;
- }
- return (fail);
-}
-
-int
-main()
-{
- int fail = 0;
- long pagesize = sysconf(_SC_PAGESIZE);
- CHECK_NE(-1, pagesize);
-
- const struct sigaction sa = {
- .sa_sigaction = sigsegv,
- .sa_flags = SA_SIGINFO,
- };
- CHECK_EQ(0, sigaction(SIGSEGV, &sa, NULL));
- CHECK_EQ(0, sigaction(SIGBUS, &sa, NULL));
-
- volatile char *p;
- CHECK_NE(MAP_FAILED, (p = mmap(NULL, pagesize, PROT_NONE,
- MAP_PRIVATE|MAP_ANON, -1, 0)));
-
- CHECK_EQ(0, mprotect((void *)p, pagesize, PROT_READ));
- if (sigsetjmp(env, 1) == 0) {
- p[0] = 1;
- FAIL();
- }
- fail += checksig("mprotect read", SIGSEGV, SEGV_ACCERR, p);
-
- CHECK_EQ(0, mprotect((void *)p, pagesize, PROT_NONE));
- if (sigsetjmp(env, 1) == 0) {
- (void)p[1];
- FAIL();
- }
- fail += checksig("mprotect none", SIGSEGV, SEGV_ACCERR, p + 1);
-
- CHECK_EQ(0, munmap((void *)p, pagesize));
- if (sigsetjmp(env, 1) == 0) {
- (void)p[2];
- FAIL();
- }
- fail += checksig("munmap", SIGSEGV, SEGV_MAPERR, p + 2);
-
- char filename[] = "/tmp/siginfo-fault.XXXXXXXX";
- int fd;
- CHECK_LE(0, (fd = mkstemp(filename)));
- CHECK_EQ(0, unlink(filename));
- CHECK_EQ(0, ftruncate(fd, 0)); /* just in case */
- CHECK_NE(MAP_FAILED, (p = mmap(NULL, pagesize, PROT_READ|PROT_WRITE,
- MAP_SHARED, fd, 0)));
- CHECK_EQ(0, close(fd));
-
- if (sigsetjmp(env, 1) == 0) {
- p[3] = 1;
- FAIL();
- }
- fail += checksig("mmap file", SIGBUS, BUS_OBJERR, p + 3);
-
- return (fail);
-}
diff --git a/regress/sys/kern/sigio/Makefile b/regress/sys/kern/sigio/Makefile
deleted file mode 100644
index 4e7c56ac33f..00000000000
--- a/regress/sys/kern/sigio/Makefile
+++ /dev/null
@@ -1,36 +0,0 @@
-# $OpenBSD: Makefile,v 1.4 2018/11/22 07:12:44 anton Exp $
-
-PROG= sigio_test
-SRCS= main.c sigio_common.c sigio_pipe.c sigio_socket.c util.c
-
-WARNINGS= yes
-
-TESTS+= pipe_badpgid
-TESTS+= pipe_badsession
-TESTS+= pipe_cansigio
-TESTS+= pipe_getown
-TESTS+= pipe_read
-#TESTS+= pipe_write
-TESTS+= socket_badpgid
-TESTS+= socket_badsession
-TESTS+= socket_cansigio
-TESTS+= socket_getown
-TESTS+= socket_inherit
-TESTS+= socket_read
-TESTS+= socket_write
-
-TESTS_ROOT+= pipe_cansigio
-TESTS_ROOT+= socket_cansigio
-
-.for t in ${TESTS}
-run-regress-${t}: ${PROG}
-.if !empty(TESTS_ROOT:M${t})
- ${SUDO} ./${PROG} ${t}
-REGRESS_ROOT_TARGETS += run-regress-${t}
-.else
- ./${PROG} ${t}
-.endif
-REGRESS_TARGETS += run-regress-${t}
-.endfor
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/sigio/common.h b/regress/sys/kern/sigio/common.h
deleted file mode 100644
index aafc18e6658..00000000000
--- a/regress/sys/kern/sigio/common.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* $OpenBSD: common.h,v 1.3 2018/11/19 12:55:18 visa Exp $ */
-
-/*
- * Copyright (c) 2018 Visa Hankala
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#define SIGIO_REGRESS_USER "nobody"
-
-/*
- * Wait until signal signum arrives, or fail if a timeout occurs first.
- */
-#define expect_signal(signum) \
- expect_signal_impl(signum, #signum, __FILE__, __LINE__)
-
-/*
- * Fail if signal signum is pending.
- */
-#define reject_signal(signum) \
- reject_signal_impl(signum, #signum, __FILE__, __LINE__)
-
-void expect_signal_impl(int, const char *, const char *, int);
-void reject_signal_impl(int, const char *, const char *, int);
-
-int test_common_badpgid(int);
-int test_common_badsession(int);
-int test_common_cansigio(int *);
-int test_common_getown(int);
-int test_common_read(int *);
-int test_common_write(int *);
-int test_pipe_badpgid(void);
-int test_pipe_badsession(void);
-int test_pipe_cansigio(void);
-int test_pipe_getown(void);
-int test_pipe_read(void);
-int test_pipe_write(void);
-int test_socket_badpgid(void);
-int test_socket_badsession(void);
-int test_socket_cansigio(void);
-int test_socket_getown(void);
-int test_socket_inherit(void);
-int test_socket_read(void);
-int test_socket_write(void);
-
-void test_init(void);
-void test_barrier(int);
-int test_fork(pid_t *, int *);
-int test_wait(pid_t, int);
-#define PARENT 1
-#define CHILD 0
diff --git a/regress/sys/kern/sigio/main.c b/regress/sys/kern/sigio/main.c
deleted file mode 100644
index 54da5aaa1c1..00000000000
--- a/regress/sys/kern/sigio/main.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/* $OpenBSD: main.c,v 1.3 2018/11/19 12:55:18 visa Exp $ */
-
-/*
- * Copyright (c) 2018 Visa Hankala
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <err.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-
-static struct {
- const char *t_name;
- int (*t_func)(void);
-} tests[] = {
- { "pipe_badpgid", test_pipe_badpgid },
- { "pipe_badsession", test_pipe_badsession },
- { "pipe_cansigio", test_pipe_cansigio },
- { "pipe_getown", test_pipe_getown },
- { "pipe_read", test_pipe_read },
- { "pipe_write", test_pipe_write },
- { "socket_badpgid", test_socket_badpgid },
- { "socket_badsession", test_socket_badsession },
- { "socket_cansigio", test_socket_cansigio },
- { "socket_getown", test_socket_getown },
- { "socket_inherit", test_socket_inherit },
- { "socket_read", test_socket_read },
- { "socket_write", test_socket_write },
- { NULL, NULL }
-};
-
-int
-main(int argc, char *argv[])
-{
- const char *t_name;
- int (*t_func)(void) = NULL;
- int i;
-
- if (argc < 2) {
- fprintf(stderr, "usage: %s testname\n", getprogname());
- exit(1);
- }
- t_name = argv[1];
-
- for (i = 0; tests[i].t_name != NULL; i++) {
- if (strcmp(tests[i].t_name, t_name) == 0) {
- t_func = tests[i].t_func;
- break;
- }
- }
- if (t_func == NULL)
- errx(1, "unknown test: %s", t_name);
-
- test_init();
-
- return t_func();
-}
diff --git a/regress/sys/kern/sigio/sigio_common.c b/regress/sys/kern/sigio/sigio_common.c
deleted file mode 100644
index b7e81f0a875..00000000000
--- a/regress/sys/kern/sigio/sigio_common.c
+++ /dev/null
@@ -1,255 +0,0 @@
-/* $OpenBSD: sigio_common.c,v 1.3 2018/11/13 16:27:22 visa Exp $ */
-
-/*
- * Copyright (c) 2018 Visa Hankala
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/ioctl.h>
-#include <sys/limits.h>
-#include <assert.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include "common.h"
-
-static char buf[1024];
-
-int
-test_common_badpgid(int fd)
-{
- int pgid;
-
- /* ID of non-existent process */
- pgid = 1000000;
- errno = 0;
- assert(fcntl(fd, F_SETOWN, pgid) == -1);
- assert(errno == ESRCH);
- errno = 0;
- assert(ioctl(fd, FIOSETOWN, &pgid) == -1);
- assert(errno == ESRCH);
-
- /* ID of non-existent process group */
- pgid = -1000000;
- errno = 0;
- assert(fcntl(fd, F_SETOWN, pgid) == -1);
- assert(errno == ESRCH);
- errno = 0;
- assert(ioctl(fd, FIOSETOWN, &pgid) == -1);
- assert(errno == ESRCH);
-
- return 0;
-}
-
-int
-test_common_badsession(int fd)
-{
- int arg, sfd;
- pid_t pid, ppid;
-
- /* Ensure this process has its own process group. */
- assert(setpgid(0, 0) == 0);
-
- ppid = getpid();
- if (test_fork(&pid, &sfd) == PARENT) {
- test_barrier(sfd);
- } else {
- assert(setsid() != -1);
- errno = 0;
- assert(fcntl(fd, F_SETOWN, ppid) == -1);
- assert(errno == EPERM);
- errno = 0;
- assert(fcntl(fd, F_SETOWN, -ppid) == -1);
- assert(errno == EPERM);
- arg = ppid;
- errno = 0;
- assert(ioctl(fd, FIOSETOWN, &arg) == -1);
- assert(errno == EPERM);
- arg = -ppid;
- errno = 0;
- assert(ioctl(fd, FIOSETOWN, &arg) == -1);
- assert(errno == EPERM);
- test_barrier(sfd);
- }
- return test_wait(pid, sfd);
-}
-
-/*
- * Test that signal is not delivered if there is a privilege mismatch.
- */
-int
-test_common_cansigio(int *fds)
-{
- struct passwd *pw;
- int flags, sfd;
- pid_t pid, ppid;
-
- assert((pw = getpwnam(SIGIO_REGRESS_USER)) != NULL);
- assert(pw->pw_uid != getuid());
-
- flags = fcntl(fds[0], F_GETFL);
- assert(fcntl(fds[0], F_SETFL, flags | O_ASYNC) == 0);
-
- ppid = getpid();
- if (test_fork(&pid, &sfd) == PARENT) {
- /* Privilege mismatch prevents signal sending. */
- reject_signal(SIGIO);
- test_barrier(sfd);
- test_barrier(sfd);
- reject_signal(SIGIO);
- assert(read(fds[0], buf, 1) == 1);
-
- test_barrier(sfd);
- assert(setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == 0);
-
- /* Privileges allow signal sending. */
- reject_signal(SIGIO);
- test_barrier(sfd);
- test_barrier(sfd);
- expect_signal(SIGIO);
- assert(read(fds[0], buf, 1) == 1);
- } else {
- assert(setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == 0);
- assert(fcntl(fds[0], F_SETOWN, ppid) == 0);
-
- test_barrier(sfd);
- assert(write(fds[1], buf, 1) == 1);
- test_barrier(sfd);
-
- test_barrier(sfd);
-
- test_barrier(sfd);
- assert(write(fds[1], buf, 1) == 1);
- test_barrier(sfd);
- }
- return test_wait(pid, sfd);
-}
-
-/*
- * Test that fcntl(fd, F_GETOWN) and ioctl(fd, FIOGETOWN, &arg) reflect
- * successful fcntl(fd, F_SETOWN, arg) and ioctl(fd, FIOSETOWN, &arg).
- */
-int
-test_common_getown(int fd)
-{
- int pgid;
-
- assert(fcntl(fd, F_GETOWN) == 0);
-
- pgid = getpid();
- assert(fcntl(fd, F_SETOWN, pgid) == 0);
- assert(fcntl(fd, F_GETOWN) == pgid);
-
- pgid = -getpgrp();
- assert(fcntl(fd, F_SETOWN, pgid) == 0);
- assert(fcntl(fd, F_GETOWN) == pgid);
-
- assert(fcntl(fd, F_SETOWN, 0) == 0);
- assert(fcntl(fd, F_GETOWN) == 0);
-
- pgid = INT_MIN;
- assert(ioctl(fd, FIOGETOWN, &pgid) == 0);
- assert(pgid == 0);
-
- pgid = getpid();
- assert(ioctl(fd, FIOSETOWN, &pgid) == 0);
- pgid = INT_MIN;
- assert(ioctl(fd, FIOGETOWN, &pgid) == 0);
- assert(pgid == getpid());
-
- pgid = -getpgrp();
- assert(ioctl(fd, FIOSETOWN, &pgid) == 0);
- pgid = INT_MIN;
- assert(ioctl(fd, FIOGETOWN, &pgid) == 0);
- assert(pgid == -getpgrp());
-
- pgid = 0;
- assert(ioctl(fd, FIOSETOWN, &pgid) == 0);
- pgid = INT_MIN;
- assert(ioctl(fd, FIOGETOWN, &pgid) == 0);
- assert(pgid == 0);
-
- return 0;
-}
-
-/*
- * Test that SIGIO gets triggered when data becomes available for reading.
- */
-int
-test_common_read(int *fds)
-{
- int flags, sfd;
- pid_t pid;
-
- flags = fcntl(fds[0], F_GETFL);
- assert(fcntl(fds[0], F_SETFL, flags | O_ASYNC) == 0);
-
- assert(fcntl(fds[0], F_SETOWN, getpid()) == 0);
-
- if (test_fork(&pid, &sfd) == PARENT) {
- reject_signal(SIGIO);
- test_barrier(sfd);
- test_barrier(sfd);
- expect_signal(SIGIO);
- assert(read(fds[0], buf, 1) == 1);
- } else {
- test_barrier(sfd);
- assert(write(fds[1], buf, 1) == 1);
- test_barrier(sfd);
- }
- return test_wait(pid, sfd);
-}
-
-/*
- * Test that SIGIO gets triggered when buffer space becomes available
- * for writing.
- */
-int
-test_common_write(int *fds)
-{
- ssize_t n;
- int flags, sfd;
- pid_t pid;
-
- flags = fcntl(fds[0], F_GETFL);
- assert(fcntl(fds[0], F_SETFL, flags | O_ASYNC | O_NONBLOCK) == 0);
- flags = fcntl(fds[1], F_GETFL);
- assert(fcntl(fds[1], F_SETFL, flags | O_NONBLOCK) == 0);
-
- assert(fcntl(fds[0], F_SETOWN, getpid()) == 0);
-
- if (test_fork(&pid, &sfd) == PARENT) {
- while ((n = write(fds[0], buf, sizeof(buf))) > 0)
- continue;
- assert(n == -1);
- assert(errno == EWOULDBLOCK);
- reject_signal(SIGIO);
-
- test_barrier(sfd);
- test_barrier(sfd);
- expect_signal(SIGIO);
- assert(write(fds[0], buf, 1) == 1);
- } else {
- test_barrier(sfd);
- while ((n = read(fds[1], buf, sizeof(buf))) > 0)
- continue;
- assert(n == -1);
- assert(errno == EWOULDBLOCK);
- test_barrier(sfd);
- }
- return test_wait(pid, sfd);
-}
diff --git a/regress/sys/kern/sigio/sigio_pipe.c b/regress/sys/kern/sigio/sigio_pipe.c
deleted file mode 100644
index 7ba09211ca9..00000000000
--- a/regress/sys/kern/sigio/sigio_pipe.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/* $OpenBSD: sigio_pipe.c,v 1.2 2018/11/13 13:05:42 visa Exp $ */
-
-/*
- * Copyright (c) 2018 Visa Hankala
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <assert.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
-
-#include "common.h"
-
-int
-test_pipe_badpgid(void)
-{
- int fds[2];
-
- assert(pipe(fds) == 0);
- return test_common_badpgid(fds[0]);
-}
-
-int
-test_pipe_badsession(void)
-{
- int fds[2];
-
- assert(pipe(fds) == 0);
- return test_common_badsession(fds[0]);
-}
-
-int
-test_pipe_cansigio(void)
-{
- int fds[2];
-
- assert(pipe(fds) == 0);
- return test_common_cansigio(fds);
-}
-
-int
-test_pipe_getown(void)
-{
- int fds[2];
-
- assert(pipe(fds) == 0);
- return test_common_getown(fds[0]);
-}
-
-int
-test_pipe_read(void)
-{
- int fds[2];
-
- assert(pipe(fds) == 0);
- return test_common_read(fds);
-}
-
-int
-test_pipe_write(void)
-{
- int fds[2];
-
- assert(pipe(fds) == 0);
- return test_common_write(fds);
-}
diff --git a/regress/sys/kern/sigio/sigio_socket.c b/regress/sys/kern/sigio/sigio_socket.c
deleted file mode 100644
index 4e7daa4dc86..00000000000
--- a/regress/sys/kern/sigio/sigio_socket.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/* $OpenBSD: sigio_socket.c,v 1.1 2018/11/19 12:55:18 visa Exp $ */
-
-/*
- * Copyright (c) 2018 Visa Hankala
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <assert.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-
-int
-test_socket_badpgid(void)
-{
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
- return test_common_badpgid(fds[0]);
-}
-
-int
-test_socket_badsession(void)
-{
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
- return test_common_badsession(fds[0]);
-}
-
-int
-test_socket_cansigio(void)
-{
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
- return test_common_cansigio(fds);
-}
-
-int
-test_socket_getown(void)
-{
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
- return test_common_getown(fds[0]);
-}
-
-/*
- * Test that the parent socket's signal target gets assigned to the socket
- * of an accepted connection.
- */
-int
-test_socket_inherit(void)
-{
- struct sockaddr_in inaddr;
- socklen_t inaddrlen;
- pid_t pid;
- int cli, flags, sfd, sock;
-
- sock = socket(AF_INET, SOCK_STREAM, 0);
- assert(sock != -1);
-
- memset(&inaddr, 0, sizeof(inaddr));
- inaddr.sin_len = sizeof(inaddr);
- inaddr.sin_family = AF_INET;
- inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- assert(bind(sock, (struct sockaddr *)&inaddr, sizeof(inaddr)) == 0);
- assert(listen(sock, 1) == 0);
-
- flags = fcntl(sock, F_GETFL);
- assert(fcntl(sock, F_SETFL, flags | O_ASYNC) == 0);
-
- if (test_fork(&pid, &sfd) == PARENT) {
- inaddrlen = sizeof(inaddr);
- cli = accept(sock, (struct sockaddr *)&inaddr, &inaddrlen);
- assert(cli != -1);
- assert(fcntl(cli, F_GETOWN) == 0);
- close(cli);
-
- assert(fcntl(sock, F_SETOWN, getpid()) == 0);
- test_barrier(sfd);
-
- inaddrlen = sizeof(inaddr);
- cli = accept(sock, (struct sockaddr *)&inaddr, &inaddrlen);
- assert(cli != -1);
- assert(fcntl(cli, F_GETOWN) == getpid());
- close(cli);
- } else {
- inaddrlen = sizeof(inaddr);
- assert(getsockname(sock, (struct sockaddr *)&inaddr,
- &inaddrlen) == 0);
-
- cli = socket(AF_INET, SOCK_STREAM, 0);
- assert(cli != -1);
- assert(connect(cli, (struct sockaddr *)&inaddr, sizeof(inaddr))
- == 0);
- close(cli);
-
- test_barrier(sfd);
-
- cli = socket(AF_INET, SOCK_STREAM, 0);
- assert(cli != -1);
- assert(connect(cli, (struct sockaddr *)&inaddr, sizeof(inaddr))
- == 0);
- close(cli);
- }
- return test_wait(pid, sfd);
-}
-
-int
-test_socket_read(void)
-{
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
- return test_common_read(fds);
-}
-
-int
-test_socket_write(void)
-{
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
- return test_common_write(fds);
-}
diff --git a/regress/sys/kern/sigio/util.c b/regress/sys/kern/sigio/util.c
deleted file mode 100644
index a323a62cfc6..00000000000
--- a/regress/sys/kern/sigio/util.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/* $OpenBSD: util.c,v 1.1 2018/11/12 16:50:28 visa Exp $ */
-
-/*
- * Copyright (c) 2018 Visa Hankala
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <assert.h>
-#include <errno.h>
-#include <poll.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-
-static void
-signal_handler(int signum)
-{
-}
-
-void
-expect_signal_impl(int signum, const char *signame, const char *file, int line)
-{
- sigset_t sigmask;
- struct timespec tmo;
- int ret;
-
- tmo.tv_sec = 5;
- tmo.tv_nsec = 0;
- sigprocmask(0, NULL, &sigmask);
- sigdelset(&sigmask, signum);
- ret = ppoll(NULL, 0, &tmo, &sigmask);
- if (ret == 0) {
- fprintf(stderr, "%s:%d: signal %s timeout\n",
- file, line, signame);
- _exit(1);
- }
- if (ret != -1) {
- fprintf(stderr, "%s: poll: unexpected return value: %d\n",
- __func__, ret);
- _exit(1);
- }
-}
-
-void
-reject_signal_impl(int signum, const char *signame, const char *file, int line)
-{
- sigset_t sigmask;
-
- if (sigpending(&sigmask) != 0) {
- fprintf(stderr, "%s: sigpending: %s\n", __func__,
- strerror(errno));
- _exit(1);
- }
- if (sigismember(&sigmask, signum)) {
- fprintf(stderr, "%s:%d: signal %s not expected\n", file, line,
- signame);
- _exit(1);
- }
-}
-
-void
-test_init(void)
-{
- sigset_t mask;
-
- sigemptyset(&mask);
- sigaddset(&mask, SIGCHLD);
- sigaddset(&mask, SIGIO);
- sigaddset(&mask, SIGURG);
- sigprocmask(SIG_BLOCK, &mask, NULL);
- signal(SIGCHLD, signal_handler);
- signal(SIGIO, signal_handler);
- signal(SIGURG, signal_handler);
-
- alarm(10);
-}
-
-void
-test_barrier(int sfd)
-{
- char b = 0;
-
- assert(write(sfd, &b, 1) == 1);
- assert(read(sfd, &b, 1) == 1);
-}
-
-int
-test_fork(pid_t *ppid, int *psfd)
-{
- pid_t pid;
- int fds[2];
-
- assert(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
-
- pid = fork();
- assert(pid != -1);
- *ppid = pid;
- if (pid == 0) {
- close(fds[0]);
- *psfd = fds[1];
- return CHILD;
- } else {
- close(fds[1]);
- *psfd = fds[0];
- return PARENT;
- }
-}
-
-int
-test_wait(pid_t pid, int sfd)
-{
- int status;
-
- close(sfd);
- if (pid == 0)
- _exit(0);
- assert(waitpid(pid, &status, 0) == pid);
- return 0;
-}
diff --git a/regress/sys/kern/signal-stress/Makefile b/regress/sys/kern/signal-stress/Makefile
deleted file mode 100644
index 84b8773055f..00000000000
--- a/regress/sys/kern/signal-stress/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-# $OpenBSD: Makefile,v 1.1 2004/08/05 02:58:35 art Exp $
-
-PROG= signal-stress
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/signal-stress/signal-stress.c b/regress/sys/kern/signal-stress/signal-stress.c
deleted file mode 100644
index 61aa23bcd66..00000000000
--- a/regress/sys/kern/signal-stress/signal-stress.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/* $OpenBSD: signal-stress.c,v 1.3 2008/04/13 00:22:17 djm Exp $ */
-/*
- * Written by Artur Grabowski <art@openbsd.org> 2004 Public Domain.
- */
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/wait.h>
-
-#include <signal.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <err.h>
-
-int nprocs, nsigs;
-pid_t *pids;
-pid_t next, prev;
-sig_atomic_t usr1, usr2;
-
-void
-sighand(int sig)
-{
- if (sig == SIGUSR1 && ++usr1 <= nsigs) {
- if (kill(next, sig))
- _exit(1);
- }
- if (sig == SIGUSR2 && ++usr2 <= nsigs) {
- if (kill(prev, sig))
- _exit(1);
- }
-}
-
-void
-do_child(void)
-{
- int i;
-
- /*
- * Step 1 - suspend and wait for SIGCONT so that all siblings have
- * been started before the next step.
- */
- raise(SIGSTOP);
-
- /* Find our neighbours. */
- for (i = 0; i < nprocs; i++) {
- if (pids[i] != getpid())
- continue;
- if (i + 1 == nprocs)
- next = pids[0];
- else
- next = pids[i + 1];
- if (i == 0)
- prev = pids[nprocs - 1];
- else
- prev = pids[i - 1];
- }
-
- signal(SIGUSR1, sighand);
- signal(SIGUSR2, sighand);
-
- /* Step 2 - wait again until everyone is ready. */
- raise(SIGSTOP);
-
- while (usr1 < nsigs || usr2 < nsigs)
- pause();
-
- /* Step 3 - wait again until everyone is ready. */
- raise(SIGSTOP);
-}
-
-void
-wait_stopped(pid_t pid)
-{
- int status;
-
- if (waitpid(pid, &status, WUNTRACED) != pid)
- err(1, "waitpid");
- if (!WIFSTOPPED(status))
- errx(1, "child %d not stopped", pid);
-}
-
-void
-cleanup(void)
-{
- int i;
-
- for (i = 0; i < nprocs; i++)
- kill(pids[i], 9);
-}
-
-void
-alrmhand(int sig)
-{
- cleanup();
- _exit(1);
-}
-
-int
-main()
-{
- int i;
- pid_t pid;
-
- nprocs = 35;
-
- nsigs = 1000;
-
- if ((pids = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_SHARED, -1, 0)) == MAP_FAILED)
- err(1, "mmap");
-
- for (i = 0; i < nprocs; i++) {
- switch((pid = fork())) {
- case 0:
- do_child();
- _exit(0);
- case -1:
- err(1, "fork");
- }
- pids[i] = pid;
- }
-
- atexit(cleanup);
- signal(SIGALRM, alrmhand);
- alarm(120); /* Die after two minutes. */
-
- /* Step 1. Wait until all children have went to sleep */
- for (i = 0; i < nprocs; i++)
- wait_stopped(pids[i]);
- /* And wake them */
- for (i = 0; i < nprocs; i++)
- kill(pids[i], SIGCONT);
-
- /* Step 2. Repeat. */
- for (i = 0; i < nprocs; i++)
- wait_stopped(pids[i]);
- for (i = 0; i < nprocs; i++)
- kill(pids[i], SIGCONT);
-
- /*
- * Now all children are ready for action.
- * Send the first signals and wait until they all exit.
- */
- kill(pids[arc4random_uniform(nprocs)], SIGUSR1);
- kill(pids[arc4random_uniform(nprocs)], SIGUSR2);
-
- /*
- * The signal game is running, now insert noise in the process.
- */
- for (i = 0; i < nprocs; i++) {
- pid_t pid = pids[arc4random_uniform(nprocs)];
- kill(pid, SIGSTOP);
- wait_stopped(pid);
- kill(pid, SIGCONT);
- }
-
-
- /* Step 3. Repeat. */
- for (i = 0; i < nprocs; i++)
- wait_stopped(pids[i]);
- for (i = 0; i < nprocs; i++)
- kill(pids[i], SIGCONT);
-
- /* Wait for everyone to finish. */
- for (i = 0; i < nprocs; i++) {
- int status;
-
- if (waitpid(pids[i], &status, WUNTRACED) != pids[i])
- err(1, "waitpid");
- if (!WIFEXITED(status))
- errx(1, "child %d not stopped (%d)", pids[i], status);
- if (WEXITSTATUS(status) != 0)
- warnx("child %d status: %d", i, status);
- }
-
- return (0);
-}
diff --git a/regress/sys/kern/sigpending/Makefile b/regress/sys/kern/sigpending/Makefile
deleted file mode 100644
index 1fbff8fec5a..00000000000
--- a/regress/sys/kern/sigpending/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-# $OpenBSD: Makefile,v 1.1 2012/06/29 00:21:55 matthew Exp $
-
-PROG= sigpending
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/sigpending/sigpending.c b/regress/sys/kern/sigpending/sigpending.c
deleted file mode 100644
index 140f9c6a221..00000000000
--- a/regress/sys/kern/sigpending/sigpending.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* $OpenBSD: sigpending.c,v 1.3 2012/06/29 00:34:39 matthew Exp $ */
-/*
- * Written by Matthew Dempsky, 2012.
- * Public domain.
- */
-
-#include <assert.h>
-#include <signal.h>
-#include <stddef.h>
-
-int
-main()
-{
- sigset_t set;
-
- assert(sigemptyset(&set) == 0);
- assert(sigaddset(&set, SIGUSR1) == 0);
- assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
- assert(raise(SIGUSR1) == 0);
- assert(sigemptyset(&set) == 0);
- assert(sigpending(&set) == 0);
- assert(sigismember(&set, SIGUSR1) == 1);
-
- return (0);
-}
diff --git a/regress/sys/kern/sigprof/Makefile b/regress/sys/kern/sigprof/Makefile
deleted file mode 100644
index e0c4f3b9a62..00000000000
--- a/regress/sys/kern/sigprof/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-# $OpenBSD: Makefile,v 1.2 2019/05/12 17:44:25 bluhm Exp $
-
-PROG= sigprof
-LDADD= -lpthread
-DPADD= ${LIBPTHREAD}
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/sigprof/sigprof.c b/regress/sys/kern/sigprof/sigprof.c
deleted file mode 100644
index 9848c96580e..00000000000
--- a/regress/sys/kern/sigprof/sigprof.c
+++ /dev/null
@@ -1,132 +0,0 @@
-/* $OpenBSD: sigprof.c,v 1.1 2013/10/07 15:52:18 jsing Exp $ */
-/*
- * Copyright (c) 2013 Joel Sing <jsing@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-/*
- * Test that profiling signals are delivered to the thread whose execution
- * consumed the CPU time and resulted in the profiling timer expiring.
- * Inspired by a problem report test case from Russ Cox <rsc@golang.org>.
- */
-
-#include <err.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-
-#define NTHREADS 4
-#define NSIGNALS 100
-#define NSIGTOTAL (NTHREADS * NSIGNALS)
-#define NMINSIG ((NSIGNALS * 75) / 100)
-
-void handler(int);
-void *spinloop(void *);
-
-pthread_t threads[NTHREADS + 1];
-int sigcount[NTHREADS + 1];
-volatile int sigtotal;
-volatile int done;
-
-void
-handler(int sig)
-{
- pthread_t self;
- int i;
-
- /*
- * pthread_self() is not required to be async-signal-safe, however
- * the OpenBSD implementation currently is.
- */
- self = pthread_self();
-
- for (i = 0; i <= NTHREADS; i++)
- if (threads[i] == self)
- sigcount[i]++;
-
- if (++sigtotal >= NSIGTOTAL)
- done = 1;
-}
-
-void *
-spinloop(void *arg)
-{
- while (!done)
- ;
-
- pthread_exit(NULL);
-}
-
-int
-main(int argc, char **argv)
-{
- struct sigaction sa;
- struct itimerval it;
- int i;
-
- bzero(&sa, sizeof(sa));
- sa.sa_handler = handler;
- sa.sa_flags = SA_RESTART;
- sigfillset(&sa.sa_mask);
- sigaction(SIGPROF, &sa, 0);
-
- threads[0] = pthread_self();
- for (i = 1; i <= NTHREADS; i++)
- if (pthread_create(&threads[i], NULL, spinloop, NULL) != 0)
- err(1, "pthread_create");
-
- bzero(&it, sizeof(it));
- it.it_interval.tv_usec = 10000;
- it.it_value = it.it_interval;
- setitimer(ITIMER_PROF, &it, NULL);
-
- for (i = 1; i <= NTHREADS; i++)
- if (pthread_join(threads[i], NULL) != 0)
- err(1, "pthread_join");
-
- bzero(&it, sizeof(it));
- setitimer(ITIMER_PROF, &it, NULL);
-
- fprintf(stderr, "total profiling signals: %d\n", sigtotal);
- fprintf(stderr, "minimum signals per thread: %d\n", NMINSIG);
- fprintf(stderr, "main thread - %d\n", sigcount[0]);
- for (i = 1; i <= NTHREADS; i++)
- fprintf(stderr, "thread %d - %d\n", i, sigcount[i]);
-
- if (sigtotal < NSIGTOTAL)
- errx(1, "insufficient profiling signals (%d < %d)",
- sigtotal, NSIGTOTAL);
-
- /*
- * The main thread is effectively sleeping and should have received
- * almost no profiling signals. Allow a small tolerance.
- */
- if (sigcount[0] > ((NSIGNALS * 10) / 100))
- errx(1, "main thread received too many signals (%d)",
- sigcount[0]);
-
- /*
- * Ensure that the kernel delivered the profiling signals to the
- * thread that consumed the CPU time. In an ideal world each thread
- * would have received equal CPU time and an equal number of signals.
- * In the less than ideal world we'll just settle for a percentage.
- */
- for (i = 1; i <= NTHREADS; i++)
- if (sigcount[i] < NMINSIG)
- errx(1, "thread %d received only %d signals (%d < %d)",
- i, sigcount[i], sigcount[i], NMINSIG);
-
- return 0;
-}
diff --git a/regress/sys/kern/sigpthread/LICENSE b/regress/sys/kern/sigpthread/LICENSE
deleted file mode 100644
index 897cd3e6996..00000000000
--- a/regress/sys/kern/sigpthread/LICENSE
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
diff --git a/regress/sys/kern/sigpthread/Makefile b/regress/sys/kern/sigpthread/Makefile
deleted file mode 100644
index 3fd78ee80a4..00000000000
--- a/regress/sys/kern/sigpthread/Makefile
+++ /dev/null
@@ -1,447 +0,0 @@
-# $OpenBSD: Makefile,v 1.1 2019/05/13 19:40:22 bluhm Exp $
-
-PROG = sigpthread
-WARNINGS = yes
-LDADD = -lpthread
-DPADD = ${LIBPTHREAD}
-CLEANFILES += out
-
-# first test signal delivery while they are blocked
-
-.for t in 0 1 2
-
-REGRESS_TARGETS += run-block-thread-3-unblock-$t
-run-block-thread-3-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # suspend threads until signaled
- # unblock thread $t
- # handle signal
- ./sigpthread -b -t 3 -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-main-unblock-$t
-run-block-thread-3-sleep-main-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # suspend threads until signaled
- # sleep in main thread, signal should be received while suspended
- # kill process
- # unblock thread $t
- # handle signal
- ./sigpthread -b -s -t 3 -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-unblock-$t-sleep-thread
-run-block-thread-3-sleep-thread-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # sleep in threads, signal should be pending when suspending
- # suspend threads until signaled
- # unblock thread $t
- # handle signal
- ./sigpthread -b -S -t 3 -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-unblock-unblock-$t
-run-block-thread-3-sleep-unblock-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # suspend threads until signaled
- # sleep in thread $t, others should be exited when unblocking
- # unblock thread $t
- # handle signal
- ./sigpthread -b -t 3 -U -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-unblock-$t
-run-block-thread-3-kill-$t-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # suspend threads until signaled
- # unblock thread $t
- # handle signal
- ./sigpthread -b -k $t -t 3 -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-main-kill-$t-unblock-$t
-run-block-thread-3-sleep-main-kill-$t-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # suspend threads until signaled
- # sleep in main thread, signal should be received while suspended
- # kill thread $t
- # unblock thread $t
- # handle signal
- ./sigpthread -b -k $t -s -t 3 -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-sleep-thread-unblock-$t
-run-block-thread-3-kill-$t-sleep-thread-unblock-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # sleep in threads, signal should be pending when suspending
- # suspend threads until signaled
- # unblock thread $t
- # handle signal
- ./sigpthread -b -k $t -S -t 3 -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-unblock-$t-sleep-unblock
-run-block-thread-3-kill-$t-unblock-$t-sleep-unblock:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # suspend threads until signaled
- # sleep in thread $t, others should be exited when unblocking
- # unblock thread $t
- # handle signal
- ./sigpthread -b -k $t -t 3 -U -u $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t
-run-block-thread-3-kill-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # suspend threads until signaled
- # unblock all threads
- # handle signal
- ./sigpthread -b -k $t -t 3 >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-main-kill-$t
-run-block-thread-3-sleep-main-kill-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # suspend threads until signaled
- # sleep in main thread, signal should be received while suspended
- # kill thread $t
- # unblock all threads
- # handle signal
- ./sigpthread -b -k $t -s -t 3 >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-sleep-thread
-run-block-thread-3-kill-$t-sleep-thread:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # sleep in threads, signal should be pending when suspending
- # suspend threads until signaled
- # unblock all threads
- # handle signal
- ./sigpthread -b -k $t -S -t 3 >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-sleep-unblock
-run-block-thread-3-kill-$t-sleep-unblock:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # suspend threads until signaled
- # sleep in all threads
- # unblock all threads
- # handle signal
- ./sigpthread -b -k $t -t 3 -U >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-.endfor
-
-REGRESS_TARGETS += run-block-thread-3
-run-block-thread-3:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # suspend threads until signaled
- # unblock all threads
- # handle signal
- ./sigpthread -b -t 3 >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-main
-run-block-thread-3-sleep-main:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # suspend threads until signaled
- # sleep in main thread, signal should be received while suspended
- # kill process
- # unblock all threads
- # handle signal
- ./sigpthread -b -s -t 3 >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-thread
-run-block-thread-3-sleep-thread:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # sleep in threads, signal should be pending when suspending
- # suspend threads until signaled
- # unblock all threads
- # handle signal
- ./sigpthread -b -S -t 3 >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-unblock
-run-block-thread-3-sleep-unblock:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # suspend threads until signaled
- # sleep in all threads
- # unblock all threads
- # handle signal
- ./sigpthread -b -t 3 -U >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-# check what happens if signals are not blocked but delivered immediately
-
-.for t in 0 1 2
-
-REGRESS_TARGETS += run-thread-3-kill-$t
-run-thread-3-kill-$t:
- @echo '\n======== $@ ========'
- # run 3 threads
- # kill thread $t
- # handle signal
- # suspend threads until signaled
- ./sigpthread -k $t -t 3 >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-thread-3-sleep-main-kill-$t
-run-thread-3-sleep-main-kill-$t:
- @echo '\n======== $@ ========'
- # run 3 threads
- # suspend threads until signaled
- # sleep in main thread, signal should be received while suspended
- # kill thread $t
- # handle signal
- ./sigpthread -k $t -s -t 3 >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-thread-3-kill-$t-sleep-thread
-run-thread-3-kill-$t-sleep-thread:
- @echo '\n======== $@ ========'
- # run 3 threads
- # kill thread $t
- # sleep in threads, signal should be received while sleeping
- # handle signal
- # suspend threads until signaled
- ./sigpthread -k $t -S -t 3 >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-thread-3-kill-$t-sleep-unblock
-run-thread-3-kill-$t-sleep-unblock:
- @echo '\n======== $@ ========'
- # run 3 threads
- # kill thread $t
- # handle signal
- # suspend threads until signaled
- # sleep in all threads
- ./sigpthread -k $t -t 3 -U >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-.endfor
-
-REGRESS_TARGETS += run-thread-3
-run-thread-3:
- @echo '\n======== $@ ========'
- # run 3 threads
- # kill process
- # handle signal
- # suspend threads until signaled
- ./sigpthread -t 3 >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-thread-3-sleep-main
-run-thread-3-sleep-main:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # suspend threads until signaled
- # sleep in main thread, signal should be received while suspended
- # kill process
- # handle signal
- ./sigpthread -s -t 3 >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-thread-3-sleep-thread
-run-thread-3-sleep-thread:
- @echo '\n======== $@ ========'
- # run 3 threads
- # kill process
- # sleep in threads, signal should be received while sleeping
- # handle signal
- # suspend threads until signaled
- ./sigpthread -S -t 3 >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-thread-3-sleep-unblock
-run-thread-3-sleep-unblock:
- @echo '\n======== $@ ========'
- # run 3 threads
- # kill process
- # handle signal
- # suspend threads until signaled
- # sleep in all threads
- ./sigpthread -t 3 -U >out
- grep 'signal [0-2]' out
- test `wc -l <out` = 1
-
-# signals are blocked and received by sigwait
-
-.for t in 0 1 2
-
-REGRESS_TARGETS += run-block-thread-3-waiter-$t
-run-block-thread-3-waiter-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # wait for signal in thread $t
- # suspend threads until signaled
- ./sigpthread -b -t 3 -w $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-main-waiter-$t
-run-block-thread-3-sleep-main-waiter-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # wait for signal in thread $t
- # suspend threads until signaled
- # sleep in main thread, signal should be received while waiting
- # kill process
- ./sigpthread -b -s -t 3 -w $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-waiter-$t-sleep-thread
-run-block-thread-3-sleep-thread-waiter-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill process
- # sleep in threads, signal should be pending when waiting
- # wait for signal in thread $t
- # suspend threads until signaled
- ./sigpthread -b -S -t 3 -w $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-waiter-$t
-run-block-thread-3-kill-$t-waiter-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # wait for signal in thread $t
- # suspend threads until signaled
- ./sigpthread -b -k $t -t 3 -w $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-sleep-main-kill-$t-waiter-$t
-run-block-thread-3-sleep-main-kill-$t-waiter-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # wait for signal in thread $t
- # suspend threads until signaled
- # sleep in main thread, signal should be received while waiting
- # kill thread $t
- ./sigpthread -b -k $t -s -t 3 -w $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-3-kill-$t-sleep-thread-waiter-$t
-run-block-thread-3-kill-$t-sleep-thread-waiter-$t:
- @echo '\n======== $@ ========'
- # block signal
- # run 3 threads
- # kill thread $t
- # sleep in threads, signal should be pending when waiting
- # wait for signal in thread $t
- # suspend threads until signaled
- ./sigpthread -b -k $t -S -t 3 -w $t >out
- grep 'signal $t' out
- test `wc -l <out` = 1
-
-.endfor
-
-# simple tests with much more threads
-
-REGRESS_TARGETS += run-block-thread-100-unblock-23
-run-block-thread-100-unblock-23:
- @echo '\n======== $@ ========'
- # block signal
- # run 100 threads
- # kill process
- # suspend threads until signaled
- # unblock thread 23
- # handle signal
- ./sigpthread -b -t 100 -u 23 >out
- grep 'signal 23' out
- test `wc -l <out` = 1
-
-REGRESS_TARGETS += run-block-thread-100-waiter-42
-run-block-thread-100-waiter-42:
- @echo '\n======== $@ ========'
- # block signal
- # run 100 threads
- # kill process
- # wait for signal in thread 42
- # suspend threads until signaled
- ./sigpthread -b -t 100 -w 42 >out
- grep 'signal 42' out
- test `wc -l <out` = 1
-
-${REGRESS_TARGETS}: ${PROG}
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/sigpthread/README b/regress/sys/kern/sigpthread/README
deleted file mode 100644
index ec286ce8fda..00000000000
--- a/regress/sys/kern/sigpthread/README
+++ /dev/null
@@ -1,27 +0,0 @@
-Test the interaction of signals with multiple posix threads.
-
-Signal SIGUSR1 is used for thread coordination, SIGUSR2 to test
-signal delivery. First SIGUSR1 and SIGUSR2 get blocked. Then a
-given number of threads are created, the main thread is also counted
-as a thread.
-
-Signal SIGUSR2 is send to the process with kill(2), but it is not
-delivered yet as it is blocked in all threads. Meanwhile the threads
-wait for SIGUSR1 in sigsuspend(2). This enforces that SIGUSR2 is
-marked as pending at the process. To continue, SIGUSR1 is sent to
-all threads and they wake up. Only one thread is configured to
-handle SIGUSR2, this one unblocks it with pthread_sigmask(3). The
-signal should be delivered immediately, the handler records it.
-
-The test is considered successful if the thread that unblocks SIGUSR2
-actually handles it.
-
-To test different race conditions, sleeps can be inserted. If the
-kill(2) is delayed, SIGUSR2 hits the threads when they are in
-sigsuspend(2). If the sleep is before sigsuspend(2), the threads
-are in nanosleep(2). The unblocking pthread_sigmask(3) can be
-delayed so that the other threads have been joined already.
-
-It is also possible to avoid blocking the signals and check which
-handler catches it. Alternatively sigwait(3) can be used to test
-signal reception.
diff --git a/regress/sys/kern/sigpthread/sigpthread.c b/regress/sys/kern/sigpthread/sigpthread.c
deleted file mode 100644
index d158ae1532d..00000000000
--- a/regress/sys/kern/sigpthread/sigpthread.c
+++ /dev/null
@@ -1,282 +0,0 @@
-/* $OpenBSD: sigpthread.c,v 1.1 2019/05/13 19:40:22 bluhm Exp $ */
-/*
- * Copyright (c) 2019 Alexander Bluhm <bluhm@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <err.h>
-#include <errno.h>
-#include <limits.h>
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-void __dead usage(void);
-void handler(int);
-void *runner(void *);
-
-void __dead
-usage(void)
-{
- fprintf(stderr, "sigpthread [-bSsU] [-k kill] -t threads [-u unblock] "
- "[-w waiter]\n"
- " -b block signal to make it pending\n"
- " -k kill thread to kill, else process\n"
- " -S sleep in each thread before suspend\n"
- " -s sleep in main before kill\n"
- " -t threads number of threads to run\n"
- " -U sleep in thread before unblock\n"
- " -u unblock thread to unblock, else unblock all\n"
- " -w waiter use sigwait in thread\n"
- );
- exit(1);
-}
-
-int blocksignal = 0;
-int threadmax, threadunblock = -1, threadwaiter = -1;
-int sleepthread, sleepmain, sleepunblock;
-sigset_t set, oset;
-pthread_t *threads;
-volatile sig_atomic_t *signaled;
-
-int
-main(int argc, char *argv[])
-{
- struct sigaction act;
- int ch, ret, tnum, threadkill = -1;
- long arg;
- void *val;
- const char *errstr;
-
- while ((ch = getopt(argc, argv, "bk:Sst:Uu:w:")) != -1) {
- switch (ch) {
- case 'b':
- blocksignal = 1;
- break;
- case 'k':
- threadkill = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL)
- errx(1, "thread to kill is %s: %s",
- errstr, optarg);
- break;
- case 'S':
- sleepthread = 1;
- break;
- case 's':
- sleepmain = 1;
- break;
- case 't':
- threadmax = strtonum(optarg, 1, INT_MAX, &errstr);
- if (errstr != NULL)
- errx(1, "number of threads is %s: %s",
- errstr, optarg);
- break;
- case 'U':
- sleepunblock = 1;
- break;
- case 'u':
- threadunblock = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL)
- errx(1, "thread to unblock is %s: %s",
- errstr, optarg);
- break;
- case 'w':
- threadwaiter = strtonum(optarg, 0, INT_MAX, &errstr);
- if (errstr != NULL)
- errx(1, "thread to wait is %s: %s",
- errstr, optarg);
- break;
- default:
- usage();
- }
- }
- argc -= optind;
- argv += optind;
- if (argc != 0)
- errx(1, "more arguments than expected");
- if (threadmax == 0)
- errx(1, "number of threads required");
- if (threadkill >= threadmax)
- errx(1, "thread to kill greater than number of threads");
- if (threadunblock >= threadmax)
- errx(1, "thread to unblock greater than number of threads");
- if (threadwaiter >= threadmax)
- errx(1, "thread to wait greater than number of threads");
- if (!blocksignal && threadunblock >= 0)
- errx(1, "do not unblock thread without blocked signals");
- if (!blocksignal && threadwaiter >= 0)
- errx(1, "do not wait in thread without blocked signals");
- if (threadunblock >= 0 && threadwaiter >= 0)
- errx(1, "do not unblock and wait together");
- if (sleepunblock && threadwaiter >= 0)
- errx(1, "do not sleep before unblock and wait together");
-
- /* Make sure that we do not hang forever. */
- ret = alarm(10);
- if (ret == -1)
- err(1, "alarm");
-
- if (sigemptyset(&set) == -1)
- err(1, "sigemptyset");
- if (sigaddset(&set, SIGUSR1) == -1)
- err(1, "sigaddset");
- /* Either deliver SIGUSR2 immediately, or mark it pending. */
- if (blocksignal) {
- if (sigaddset(&set, SIGUSR2) == -1)
- err(1, "sigaddset");
- }
- /* Block both SIGUSR1 and SIGUSR2 with set. */
- if (sigprocmask(SIG_BLOCK, &set, &oset) == -1)
- err(1, "sigprocmask");
-
- /* Prepare to wait for SIGUSR1, but block SIGUSR2 with oset. */
- if (sigaddset(&oset, SIGUSR2) == -1)
- err(1, "sigaddset");
- /* Unblock or wait for SIGUSR2 */
- if (sigemptyset(&set) == -1)
- err(1, "sigemptyset");
- if (sigaddset(&set, SIGUSR2) == -1)
- err(1, "sigaddset");
-
- memset(&act, 0, sizeof(act));
- act.sa_handler = handler;
- if (sigaction(SIGUSR1, &act, NULL) == -1)
- err(1, "sigaction SIGUSR1");
- if (sigaction(SIGUSR2, &act, NULL) == -1)
- err(1, "sigaction SIGUSR2");
-
- signaled = calloc(threadmax, sizeof(*signaled));
- if (signaled == NULL)
- err(1, "calloc signaled");
- threads = calloc(threadmax, sizeof(*threads));
- if (threads == NULL)
- err(1, "calloc threads");
-
- for (tnum = 1; tnum < threadmax; tnum++) {
- arg = tnum;
- errno = pthread_create(&threads[tnum], NULL, runner,
- (void *)arg);
- if (errno)
- err(1, "pthread_create %d", tnum);
- }
- /* Handle the main thread like thread 0. */
- threads[0] = pthread_self();
-
- /* Test what happens if thread is running when killed. */
- if (sleepmain)
- sleep(1);
-
- /* All threads are still alive. */
- if (threadkill < 0) {
- if (kill(getpid(), SIGUSR2) == -1)
- err(1, "kill SIGUSR2");
- } else {
- errno = pthread_kill(threads[threadkill], SIGUSR2);
- if (errno)
- err(1, "pthread_kill %d SIGUSR2", tnum);
- }
-
- /* Sending SIGUSR1 means threads can continue and finish. */
- for (tnum = 0; tnum < threadmax; tnum++) {
- errno = pthread_kill(threads[tnum], SIGUSR1);
- if (errno)
- err(1, "pthread_kill %d SIGUSR1", tnum);
- }
-
- val = runner(0);
- ret = (int)val;
-
- for (tnum = 1; tnum < threadmax; tnum++) {
- errno = pthread_join(threads[tnum], &val);
- if (errno)
- err(1, "pthread_join %d", tnum);
- ret = (int)val;
- if (ret)
- errx(1, "pthread %d returned %d", tnum, ret);
- }
- free(threads);
-
- for (tnum = 0; tnum < threadmax; tnum++) {
- int i;
-
- for (i = 0; i < signaled[tnum]; i++)
- printf("signal %d\n", tnum);
- }
- free((void *)signaled);
-
- return 0;
-}
-
-void
-handler(int sig)
-{
- pthread_t tid;
- int tnum;
-
- tid = pthread_self();
- for (tnum = 0; tnum < threadmax; tnum++) {
- if (tid == threads[tnum])
- break;
- }
- switch (sig) {
- case SIGUSR1:
- break;
- case SIGUSR2:
- signaled[tnum]++;
- break;
- default:
- errx(1, "unexpected signal %d thread %d", sig, tnum);
- }
-}
-
-void *
-runner(void *arg)
-{
- int tnum = (int)arg;
-
- /* Test what happens if thread is running when killed. */
- if (sleepthread)
- sleep(1);
-
- if (tnum == threadwaiter) {
- int sig;
-
- if (sigwait(&set, &sig) != 0)
- err(1, "sigwait thread %d", tnum);
- if (sig != SIGUSR2)
- errx(1, "unexpected signal %d thread %d", sig, tnum);
- signaled[tnum]++;
- }
-
- /*
- * Wait for SIGUSER1, continue to block SIGUSER2.
- * The thread is keeps running until it gets SIGUSER1.
- */
- if (sigsuspend(&oset) != -1 || errno != EINTR)
- err(1, "sigsuspend thread %d", tnum);
- if ((threadunblock < 0 || tnum == threadunblock) && threadwaiter < 0) {
- /* Test what happens if other threads exit before unblock. */
- if (sleepunblock)
- sleep(1);
-
- /* Also unblock SIGUSER2, if this thread should get it. */
- if (pthread_sigmask(SIG_UNBLOCK, &set, NULL) == -1)
- err(1, "pthread_sigmask thread %d", tnum);
- }
-
- return (void *)0;
-}
diff --git a/regress/sys/kern/sigsuspend/Makefile b/regress/sys/kern/sigsuspend/Makefile
deleted file mode 100644
index cb8bcf90327..00000000000
--- a/regress/sys/kern/sigsuspend/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-# $OpenBSD: Makefile,v 1.1 2005/05/31 09:27:28 art Exp $
-
-PROG= sigsuspend
-
-.include <bsd.regress.mk>
diff --git a/regress/sys/kern/sigsuspend/sigsuspend.c b/regress/sys/kern/sigsuspend/sigsuspend.c
deleted file mode 100644
index d32de50474b..00000000000
--- a/regress/sys/kern/sigsuspend/sigsuspend.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/* $OpenBSD: sigsuspend.c,v 1.2 2010/06/20 17:57:09 phessler Exp $ */
-/*
- * Written by Artur Grabowski <art@openbsd.org> 2005, Public domain.
- */
-
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <err.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-sig_atomic_t gotusr1;
-sig_atomic_t gotusr2;
-
-void
-usr1handler(int signo)
-{
- gotusr1 = 1;
-}
-
-void
-usr2handler(int signo)
-{
- gotusr2 = 1;
-}
-
-int
-main()
-{
- sigset_t set, oset;
- struct sigaction sa;
- pid_t pid, ppid;
- int status;
-
- ppid = getpid();
-
- memset(&sa, 0, sizeof(sa));
- sigemptyset(&sa.sa_mask);
- sa.sa_handler = usr1handler;
- if (sigaction(SIGUSR1, &sa, NULL))
- err(1, "sigaction(USR1)");
-
- sa.sa_handler = usr2handler;
- if (sigaction(SIGUSR2, &sa, NULL))
- err(1, "sigaction(USR2)");
-
- /*
- * Set the procmask to mask the early USR1 the child will send us.
- */
- sigemptyset(&set);
- sigaddset(&set, SIGUSR1);
- sigaddset(&set, SIGUSR2);
- if (sigprocmask(SIG_BLOCK, &set, &oset))
- err(1, "sigprocmask");
-
- switch((pid = fork())) {
- case 0:
- /*
- * In the child.
- */
-
- kill(ppid, SIGUSR1); /* Tell the parent we're ready. */
-
- sigemptyset(&set);
- sigaddset(&set, SIGUSR2);
- sigsuspend(&set);
-
- /*
- * Check that sigsuspend didn't change the signal mask.
- */
- if (sigprocmask(SIG_SETMASK, NULL, &oset))
- err(1, "sigprocmask");
- if (!sigismember(&oset, SIGUSR1) ||
- !sigismember(&oset, SIGUSR2))
- errx(1, "sigprocmask is bad");
-
- /* Check that we got the sigusr1 that we expected. */
- if (!gotusr1)
- errx(1, "didn't get usr1");
- if (gotusr2)
- errx(1, "got incorrect usr2");
-
- sigemptyset(&set);
- sigaddset(&set, SIGUSR1);
- sigsuspend(&set);
-
- if (!gotusr2)
- errx(1, "didn't get usr2");
-
- _exit(0);
- case -1:
- err(1, "fork");
- default:
- /*
- * In the parent.
- * Waiting for the initial USR1 that tells us the child
- * is ready.
- */
- while (gotusr1 == 0)
- sigsuspend(&oset);
-
- /*
- * Check that sigsuspend didn't change the signal mask.
- */
- if (sigprocmask(SIG_SETMASK, NULL, &oset))
- err(1, "sigprocmask");
- if (!sigismember(&oset, SIGUSR1) ||
- !sigismember(&oset, SIGUSR2))
- errx(1, "sigprocmask is bad");
-
- /*
- * Deliberately send USR2 first to confuse.
- */
- kill(pid, SIGUSR2);
- kill(pid, SIGUSR1);
-
- if (waitpid(pid, &status, 0) != pid)
- err(1, "waitpid");
-
- if (WIFEXITED(status))
- exit(WEXITSTATUS(status));
- exit(1);
- }
- /* NOTREACHED */
-}
-
-