diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-08-07 18:25:40 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2024-08-07 18:25:40 +0000 |
commit | 418a72e9ea4545ab27333d4f3e98eeed68be152e (patch) | |
tree | 081e4d94c99f9ca7dd3c5e548625d996d0bb0e5c | |
parent | 799268a50e39ee8bba6f7f0fab7b85ace39b741f (diff) |
Rework fork-exit regress to work with any pagesize not only 4k.
Also mmap PROT_READ|PROT_WRITE instead of write only.
Add a bit more extra space for the stack allocations.
With all of this this test no longer fails on sparc64
OK deraadt@ bluhm@
-rw-r--r-- | regress/sys/kern/fork-exit/Makefile | 18 | ||||
-rw-r--r-- | regress/sys/kern/fork-exit/fork-exit.c | 24 |
2 files changed, 24 insertions, 18 deletions
diff --git a/regress/sys/kern/fork-exit/Makefile b/regress/sys/kern/fork-exit/Makefile index 8d7032870e5..44448adeb2c 100644 --- a/regress/sys/kern/fork-exit/Makefile +++ b/regress/sys/kern/fork-exit/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.4 2021/05/21 20:21:10 bluhm Exp $ +# $OpenBSD: Makefile,v 1.5 2024/08/07 18:25:39 claudio Exp $ # Copyright (c) 2021 Alexander Bluhm <bluhm@openbsd.org> # @@ -57,42 +57,42 @@ run-fork-thread: ${PROG} REGRESS_TARGETS += run-fork1-heap run-fork1-heap: ${PROG} # allocate 400 MB of heap memory - ulimit -p 500 -n 1000; ./fork-exit -h 100000 + ulimit -p 500 -n 1000; ./fork-exit -h 400000 REGRESS_TARGETS += run-fork-heap run-fork-heap: ${PROG} # allocate 400 MB of heap memory in processes - ulimit -p 500 -n 1000; ./fork-exit -p 100 -h 1000 + ulimit -p 500 -n 1000; ./fork-exit -p 100 -h 4000 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 + ulimit -p 500 -n 1000; ./fork-exit -t 1 -h 400000 REGRESS_TARGETS += run-fork-thread-heap run-fork-thread-heap: ${PROG} # allocate 400 MB of heap memory in threads - ulimit -p 500 -n 1000; ./fork-exit -p 10 -t 100 -h 100 + ulimit -p 500 -n 1000; ./fork-exit -p 10 -t 100 -h 400 REGRESS_TARGETS += run-fork1-stack run-fork1-stack: ${PROG} # allocate 32 MB of stack memory - ulimit -p 500 -n 1000; ulimit -s 32768; ./fork-exit -s 8000 + ulimit -p 500 -n 1000; ulimit -s 32768; ./fork-exit -s 32000 REGRESS_TARGETS += run-fork-stack 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 + ulimit -p 500 -n 1000; ulimit -s 32768; ./fork-exit -p 100 -s 4000 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 + ulimit -p 500 -n 1000; ./fork-exit -t 1 -s 400000 REGRESS_TARGETS += run-fork-thread-stack run-fork-thread-stack: ${PROG} # allocate 400 MB of stack memory in threads - ulimit -p 500 -n 1000; ./fork-exit -p 10 -t 100 -s 100 + ulimit -p 500 -n 1000; ./fork-exit -p 10 -t 100 -s 400 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 857750431b6..5fd20052ae8 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.7 2021/07/06 11:50:34 bluhm Exp $ */ +/* $OpenBSD: fork-exit.c,v 1.8 2024/08/07 18:25:39 claudio Exp $ */ /* * Copyright (c) 2021 Alexander Bluhm <bluhm@openbsd.org> @@ -39,6 +39,8 @@ int stack = 0; int threads = 0; int timeout = 30; +int pagesize; + pthread_barrier_t thread_barrier; char timeoutstr[sizeof("-2147483647")]; @@ -48,9 +50,9 @@ usage(void) fprintf(stderr, "fork-exit [-ed] [-p procs] [-t threads] [-T timeout]\n" " -e child execs sleep(1), default call sleep(3)\n" " -d daemonize, use if already process group leader\n" - " -h heap allocate pages of heap memory, default 0\n" + " -h heap allocate number of kB of heap memory, default 0\n" " -p procs number of processes to fork, default 1\n" - " -s stack allocate pages of stack memory, default 0\n" + " -s stack allocate number of kB of stack memory, default 0\n" " -t threads number of threads to create, default 0\n" " -T timeout parent and children will exit, default 30 sec\n"); exit(2); @@ -71,7 +73,7 @@ recurse_page(int depth) static void alloc_stack(void) { - recurse_page(stack); + recurse_page((stack * 1024) / (4096 + 200)); } static void @@ -80,8 +82,9 @@ alloc_heap(void) int *p; int i; - for(i = 0; i < heap; i++) { - p = mmap(0, 4096, PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0); + for (i = 0; i < heap / (pagesize / 1024); i++) { + p = mmap(0, pagesize, PROT_WRITE|PROT_READ, + MAP_SHARED|MAP_ANON, -1, 0); if (p == MAP_FAILED) err(1, "mmap"); p[1] = 0x12345678; @@ -123,7 +126,7 @@ create_threads(void) if (stack) { /* thread start and function call overhead needs a bit more */ error = pthread_attr_setstacksize(&tattr, - (stack + 2) * (4096 + 64)); + (stack + 2) * (1024ULL + 50)); if (error) errc(1, error, "pthread_attr_setstacksize"); } @@ -213,6 +216,8 @@ main(int argc, char *argv[]) pid_t pgrp; struct timeval tv; + pagesize = sysconf(_SC_PAGESIZE); + while ((ch = getopt(argc, argv, "edh:p:s:T:t:")) != -1) { switch (ch) { case 'e': @@ -228,14 +233,15 @@ main(int argc, char *argv[]) errstr, optarg); break; case 'p': - procs = strtonum(optarg, 0, INT_MAX / 4096, &errstr); + procs = strtonum(optarg, 0, INT_MAX / pagesize, + &errstr); if (errstr != NULL) errx(1, "number of procs is %s: %s", errstr, optarg); break; case 's': stack = strtonum(optarg, 0, - (INT_MAX / (4096 + 64)) - 2, &errstr); + (INT_MAX / (1024 + 50)) - 2, &errstr); if (errstr != NULL) errx(1, "number of stack allocations is %s: %s", errstr, optarg); |