summaryrefslogtreecommitdiff
path: root/regress/sys/kern
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2021-05-21 20:21:11 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2021-05-21 20:21:11 +0000
commitcb5d7ab7fe3aa6dccf46f24a3718de1447ece248 (patch)
tree3457bcc5a67c6ef960fb57d317ef84acc558cbf6 /regress/sys/kern
parentda5f78cbe3c624f1f230a876a4d200f560d2010f (diff)
Set the stack size attribute of the pthreads large enough to allocate
the specified amount of stack memory. On 32 bit architectures regress fork-exit failed as the default stack size for pthreads is smaller. With the limit set to the expected size we can test even larger thread stacks.
Diffstat (limited to 'regress/sys/kern')
-rw-r--r--regress/sys/kern/fork-exit/Makefile14
-rw-r--r--regress/sys/kern/fork-exit/fork-exit.c23
2 files changed, 30 insertions, 7 deletions
diff --git a/regress/sys/kern/fork-exit/Makefile b/regress/sys/kern/fork-exit/Makefile
index a45ac4bb7b1..8d7032870e5 100644
--- a/regress/sys/kern/fork-exit/Makefile
+++ b/regress/sys/kern/fork-exit/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.3 2021/05/04 13:24:49 bluhm Exp $
+# $OpenBSD: Makefile,v 1.4 2021/05/21 20:21:10 bluhm Exp $
# Copyright (c) 2021 Alexander Bluhm <bluhm@openbsd.org>
#
@@ -64,6 +64,11 @@ run-fork-heap: ${PROG}
# allocate 400 MB of heap memory in processes
ulimit -p 500 -n 1000; ./fork-exit -p 100 -h 1000
+REGRESS_TARGETS += run-fork1-thread1-heap
+run-fork1-thread1-heap: ${PROG}
+ # allocate 400 MB of heap memory in single child and one thread
+ ulimit -p 500 -n 1000; ./fork-exit -t 1 -h 100000
+
REGRESS_TARGETS += run-fork-thread-heap
run-fork-thread-heap: ${PROG}
# allocate 400 MB of heap memory in threads
@@ -79,10 +84,15 @@ run-fork-stack: ${PROG}
# allocate 400 MB of stack memory in processes
ulimit -p 500 -n 1000; ulimit -s 32768; ./fork-exit -p 100 -s 1000
+REGRESS_TARGETS += run-fork1-thread1-stack
+run-fork1-thread1-stack: ${PROG}
+ # allocate 400 MB of stack memory in single child and one thread
+ ulimit -p 500 -n 1000; ./fork-exit -t 1 -s 100000
+
REGRESS_TARGETS += run-fork-thread-stack
run-fork-thread-stack: ${PROG}
# allocate 400 MB of stack memory in threads
- ulimit -p 500 -n 1000; ulimit -s 32768; ./fork-exit -p 10 -t 100 -s 100
+ ulimit -p 500 -n 1000; ./fork-exit -p 10 -t 100 -s 100
REGRESS_CLEANUP = cleanup
cleanup:
diff --git a/regress/sys/kern/fork-exit/fork-exit.c b/regress/sys/kern/fork-exit/fork-exit.c
index 2eba0ffdeba..6d52ade44ef 100644
--- a/regress/sys/kern/fork-exit/fork-exit.c
+++ b/regress/sys/kern/fork-exit/fork-exit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fork-exit.c,v 1.3 2021/05/04 13:24:49 bluhm Exp $ */
+/* $OpenBSD: fork-exit.c,v 1.4 2021/05/21 20:21:10 bluhm Exp $ */
/*
* Copyright (c) 2021 Alexander Bluhm <bluhm@openbsd.org>
@@ -113,19 +113,31 @@ run_thread(void *arg)
static void
create_threads(void)
{
+ pthread_attr_t tattr;
pthread_t *thrs;
int i, error;
+ error = pthread_attr_init(&tattr);
+ if (error)
+ errc(1, error, "pthread_attr_init");
+ if (stack) {
+ /* thread start and function call overhead needs a bit more */
+ error = pthread_attr_setstacksize(&tattr,
+ (stack + 2) * (4096 + 32));
+ if (error)
+ errc(1, error, "pthread_attr_setstacksize");
+ }
+
error = pthread_barrier_init(&thread_barrier, NULL, threads + 1);
if (error)
- errc(1, errno, "pthread_barrier_init");
+ errc(1, error, "pthread_barrier_init");
thrs = reallocarray(NULL, threads, sizeof(pthread_t));
if (thrs == NULL)
err(1, "thrs");
for (i = 0; i < threads; i++) {
- error = pthread_create(&thrs[i], NULL, run_thread, NULL);
+ error = pthread_create(&thrs[i], &tattr, run_thread, NULL);
if (error)
errc(1, error, "pthread_create");
}
@@ -217,13 +229,14 @@ main(int argc, char *argv[])
errstr, optarg);
break;
case 'p':
- procs = strtonum(optarg, 0, INT_MAX, &errstr);
+ procs = strtonum(optarg, 0, INT_MAX / 4096, &errstr);
if (errstr != NULL)
errx(1, "number of procs is %s: %s", errstr,
optarg);
break;
case 's':
- stack = strtonum(optarg, 0, INT_MAX, &errstr);
+ stack = strtonum(optarg, 0,
+ (INT_MAX - 2) / (4096 + 32), &errstr);
if (errstr != NULL)
errx(1, "number of stack allocations is %s: %s",
errstr, optarg);