From: mvs Date: Fri, 10 Dec 2021 00:50:18 +0000 (+0000) Subject: Move 'unconacc' test to regress/sys/kern/unixsockets/ directory. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=eb897bf188ac5e11052fcbd6bf96a67fa26da039;p=openbsd Move 'unconacc' test to regress/sys/kern/unixsockets/ directory. --- diff --git a/regress/sys/kern/Makefile b/regress/sys/kern/Makefile index 0de4efc41fc..d3e78b86a16 100644 --- a/regress/sys/kern/Makefile +++ b/regress/sys/kern/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.100 2021/12/10 00:33:25 mvs Exp $ +# $OpenBSD: Makefile,v 1.101 2021/12/10 00:50:18 mvs Exp $ SUBDIR+= __syscall SUBDIR+= accept access @@ -23,7 +23,7 @@ SUBDIR+= setuid .endif SUBDIR+= signal sosplice stackjmp stackpivot syscall syscall_segment SUBDIR+= sysvmsg sysvsem sysvshm -SUBDIR+= unalign unconacc unfdpass unixsockets unixsock unveil unveil-unmount +SUBDIR+= unalign unfdpass unixsockets unixsock unveil unveil-unmount SUBDIR+= wait install: diff --git a/regress/sys/kern/unconacc/Makefile b/regress/sys/kern/unconacc/Makefile deleted file mode 100644 index d945c71a169..00000000000 --- a/regress/sys/kern/unconacc/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $OpenBSD: Makefile,v 1.2 2021/11/29 21:21:26 mvs Exp $ - -# Copyright (c) 2021 Makkoveev Vitaliy -# -# 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. - -WARNINGS = yes - -PROG = unconacc -LDADD+= -lpthread - -CLEANFILES += unconacc.socket - -.include diff --git a/regress/sys/kern/unconacc/unconacc.c b/regress/sys/kern/unconacc/unconacc.c deleted file mode 100644 index 52ca734e192..00000000000 --- a/regress/sys/kern/unconacc/unconacc.c +++ /dev/null @@ -1,187 +0,0 @@ -/* $OpenBSD: unconacc.c,v 1.4 2021/12/01 10:24:40 mvs Exp $ */ - -/* - * Copyright (c) 2021 Vitaliy Makkoveev - * - * 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. - */ - -/* - * Provide multithreaded connect(2) and accept(2) stress test on - * unix(4) socket. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static pthread_mutex_t therr_mtx = PTHREAD_MUTEX_INITIALIZER; - -static void -therr(int eval, const char *fmt, ...) -{ - va_list ap; - - pthread_mutex_lock(&therr_mtx); - - va_start(ap, fmt); - verr(eval, fmt, ap); - va_end(ap); -} - -static void -therrc(int eval, int code, const char *fmt, ...) -{ - va_list ap; - - pthread_mutex_lock(&therr_mtx); - - va_start(ap, fmt); - verrc(eval, code, fmt, ap); - va_end(ap); -} - -static void * -thr_acc(void *arg) -{ - int s = *(int *)arg; - - while (1) { - int n; - - if ((n = accept(s, NULL, NULL)) < 0) { - switch (errno) { - case EMFILE: - case ENFILE: - continue; - default: - therr(1, "accept"); - } - } - - close(n); - } - - return NULL; -} - -static void * -thr_conn(void *arg) -{ - struct sockaddr_un *sun = arg; - int s; - - while (1) { - if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - switch (errno) { - case EMFILE: - case ENFILE: - case ENOBUFS: - continue; - default: - therr(1, "socket"); - } - } - - if (connect(s, (struct sockaddr *)sun, sizeof(*sun)) < 0) { - switch (errno) { - case ECONNREFUSED: - continue; - default: - therr(1, "connect"); - } - } - - close(s); - } - - return NULL; -} - -static struct sockaddr_un sun; - -int -main(int argc, char *argv[]) -{ - struct timespec testtime = { - .tv_sec = 60, - .tv_nsec = 0, - }; - - int s; - - int mib[2], ncpu; - size_t len; - - int i; - - umask(0077); - - if (argc == 2 && !strcmp(argv[1], "--infinite")) - testtime.tv_sec = (10 * 365 * 86400); - - mib[0] = CTL_HW; - mib[1] = HW_NCPUONLINE; - len = sizeof(ncpu); - - if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0) - err(1, "sysctl"); - if (ncpu <= 0) - errx(1, "Wrong number of CPUs online: %d", ncpu); - - memset(&sun, 0, sizeof(sun)); - sun.sun_len = sizeof(sun); - sun.sun_family = AF_UNIX; - snprintf(sun.sun_path, sizeof(sun.sun_path) - 1, "unconacc.socket"); - - if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) - err(1, "socket"); - - unlink(sun.sun_path); - - if (bind(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) - err(1, "bind"); - if (listen(s, 10) < 0) - err(1, "listen"); - - for (i = 0; i < (ncpu * 2); ++i) { - pthread_t thr; - int error; - - if ((error = pthread_create(&thr, NULL, thr_acc, &s))) - therrc(1, error, "pthread_create"); - } - - for (i = 0; i < (ncpu * 2); ++i) { - pthread_t thr; - int error; - - if ((error = pthread_create(&thr, NULL, thr_conn, &sun))) - therrc(1, error, "pthread_create"); - } - - nanosleep(&testtime, NULL); - - return 0; -} diff --git a/regress/sys/kern/unixsockets/Makefile b/regress/sys/kern/unixsockets/Makefile index 3895d1e761f..3c308c0b3dc 100644 --- a/regress/sys/kern/unixsockets/Makefile +++ b/regress/sys/kern/unixsockets/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.5 2021/12/10 00:33:25 mvs Exp $ +# $OpenBSD: Makefile,v 1.6 2021/12/10 00:50:18 mvs Exp $ # Copyright (c) 2021 Makkoveev Vitaliy # @@ -18,6 +18,9 @@ WARNINGS = yes PROGS = undgram_selfconn ungc +PROGS += unconacc +LDADD_unconacc = -lpthread + PROGS += undgram_conclose LDADD_undgram_conclose = -lpthread diff --git a/regress/sys/kern/unixsockets/unconacc.c b/regress/sys/kern/unixsockets/unconacc.c new file mode 100644 index 00000000000..bb298fdb2ad --- /dev/null +++ b/regress/sys/kern/unixsockets/unconacc.c @@ -0,0 +1,187 @@ +/* $OpenBSD: unconacc.c,v 1.1 2021/12/10 00:50:18 mvs Exp $ */ + +/* + * Copyright (c) 2021 Vitaliy Makkoveev + * + * 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. + */ + +/* + * Provide multithreaded connect(2) and accept(2) stress test on + * unix(4) socket. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static pthread_mutex_t therr_mtx = PTHREAD_MUTEX_INITIALIZER; + +static void +therr(int eval, const char *fmt, ...) +{ + va_list ap; + + pthread_mutex_lock(&therr_mtx); + + va_start(ap, fmt); + verr(eval, fmt, ap); + va_end(ap); +} + +static void +therrc(int eval, int code, const char *fmt, ...) +{ + va_list ap; + + pthread_mutex_lock(&therr_mtx); + + va_start(ap, fmt); + verrc(eval, code, fmt, ap); + va_end(ap); +} + +static void * +thr_acc(void *arg) +{ + int s = *(int *)arg; + + while (1) { + int n; + + if ((n = accept(s, NULL, NULL)) < 0) { + switch (errno) { + case EMFILE: + case ENFILE: + continue; + default: + therr(1, "accept"); + } + } + + close(n); + } + + return NULL; +} + +static void * +thr_conn(void *arg) +{ + struct sockaddr_un *sun = arg; + int s; + + while (1) { + if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + switch (errno) { + case EMFILE: + case ENFILE: + case ENOBUFS: + continue; + default: + therr(1, "socket"); + } + } + + if (connect(s, (struct sockaddr *)sun, sizeof(*sun)) < 0) { + switch (errno) { + case ECONNREFUSED: + continue; + default: + therr(1, "connect"); + } + } + + close(s); + } + + return NULL; +} + +static struct sockaddr_un sun; + +int +main(int argc, char *argv[]) +{ + struct timespec testtime = { + .tv_sec = 60, + .tv_nsec = 0, + }; + + int s; + + int mib[2], ncpu; + size_t len; + + int i; + + umask(0077); + + if (argc == 2 && !strcmp(argv[1], "--infinite")) + testtime.tv_sec = (10 * 365 * 86400); + + mib[0] = CTL_HW; + mib[1] = HW_NCPUONLINE; + len = sizeof(ncpu); + + if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0) + err(1, "sysctl"); + if (ncpu <= 0) + errx(1, "Wrong number of CPUs online: %d", ncpu); + + memset(&sun, 0, sizeof(sun)); + sun.sun_len = sizeof(sun); + sun.sun_family = AF_UNIX; + snprintf(sun.sun_path, sizeof(sun.sun_path) - 1, "unconacc.socket"); + + if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) + err(1, "socket"); + + unlink(sun.sun_path); + + if (bind(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) + err(1, "bind"); + if (listen(s, 10) < 0) + err(1, "listen"); + + for (i = 0; i < (ncpu * 2); ++i) { + pthread_t thr; + int error; + + if ((error = pthread_create(&thr, NULL, thr_acc, &s))) + therrc(1, error, "pthread_create"); + } + + for (i = 0; i < (ncpu * 2); ++i) { + pthread_t thr; + int error; + + if ((error = pthread_create(&thr, NULL, thr_conn, &sun))) + therrc(1, error, "pthread_create"); + } + + nanosleep(&testtime, NULL); + + return 0; +}