diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-05-21 10:14:51 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2018-05-21 10:14:51 +0000 |
commit | 1b18bd3c7d3eba968254f06864a46779c8b1907c (patch) | |
tree | c0d667cf1c6adb8ea2658edebb787b70a107cd57 | |
parent | d061aad3384898ad6decc52594f9a0b474276ba0 (diff) |
In general I like verbose tests as output makes debugging easier.
But this one just fills the log file by writing characters from the
running threads. Pipe stdout to wc to show performance. Run test
multiple times with various number of threads and print cpu time.
Replace atoi(3) with strtonum(3). Fix white spaces.
-rw-r--r-- | regress/lib/libpthread/switch/Makefile | 8 | ||||
-rw-r--r-- | regress/lib/libpthread/switch/switch.c | 55 |
2 files changed, 30 insertions, 33 deletions
diff --git a/regress/lib/libpthread/switch/Makefile b/regress/lib/libpthread/switch/Makefile index e15cfa97be8..6b5b9a37254 100644 --- a/regress/lib/libpthread/switch/Makefile +++ b/regress/lib/libpthread/switch/Makefile @@ -1,5 +1,11 @@ -# $OpenBSD: Makefile,v 1.2 2002/01/03 00:43:48 art Exp $ +# $OpenBSD: Makefile,v 1.3 2018/05/21 10:14:50 bluhm Exp $ PROG= switch +.for count in 2 3 4 6 8 20 26 +REGRESS_TARGETS += run-regress-${PROG}-${count} +run-regress-${PROG}-${count}: ${PROG} + time ./${PROG} -c ${count} | wc -c +.endfor + .include <bsd.regress.mk> diff --git a/regress/lib/libpthread/switch/switch.c b/regress/lib/libpthread/switch/switch.c index 5352bde20ca..4f41f370b16 100644 --- a/regress/lib/libpthread/switch/switch.c +++ b/regress/lib/libpthread/switch/switch.c @@ -1,8 +1,8 @@ -/* $OpenBSD: switch.c,v 1.5 2003/12/23 20:09:42 miod Exp $ */ +/* $OpenBSD: switch.c,v 1.6 2018/05/21 10:14:50 bluhm Exp $ */ /* - * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, + * Copyright (c) 1993, 1994, 1995, 1996 by Chris Provenzano and contributors, * proven@mit.edu All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -30,7 +30,7 @@ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ + */ /* ==== test_switch.c ======================================================== * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu @@ -43,6 +43,7 @@ #include <pthread.h> #include <stdio.h> +#include <err.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> @@ -51,20 +52,18 @@ const char buf[] = "abcdefghijklmnopqrstuvwxyz"; char x[sizeof(buf)]; -int fd = 1; volatile int ending = 0; /* ========================================================================== * usage(); */ -static void +static __dead void usage(void) { - extern char *__progname; - printf("usage: %s [-?] [-c count]\n", __progname); - printf("count must be between 2 and 26\n"); - errno = 0; + fprintf(stderr, "usage: %s [-?] [-c count]\n", getprogname()); + fprintf(stderr, "count is number of theads, between 2 and 26\n"); + exit(1); } static void * @@ -74,7 +73,7 @@ new_thread(void *arg) SET_NAME("writer"); while (!ending) { - CHECKe(write (fd, (char *) arg, 1)); + CHECKe(write(STDOUT_FILENO, (char *) arg, 1)); x[(char *)arg - buf] = 1; for (i = 0; i < 999999; i += 1) ; @@ -88,31 +87,23 @@ main(int argc, char *argv[]) pthread_t thread; int ch, count = 4; long i; + const char *errstr; - /* Getopt variables. */ - extern int optind, opterr; - extern char *optarg; - - while ((ch = getopt(argc, argv, "c:?")) != -1) - switch (ch) - { - case 'c': - count = atoi(optarg); - if ((count > 26) || (count < 2)) { - count = 2; - } - break; - case '?': - usage(); - return(OK); - default: - usage(); - return(NOTOK); - } + while ((ch = getopt(argc, argv, "c:?")) != -1) { + switch (ch) { + case 'c': + count = strtonum(optarg, 2, 26, &errstr); + if (errstr != NULL) + errx(1, "count is %s: %s", errstr, optarg); + break; + default: + usage(); + } + } /* create the threads */ for (i = 0; i < count; i++) - CHECKr(pthread_create(&thread, NULL, new_thread, + CHECKr(pthread_create(&thread, NULL, new_thread, (void*)(buf+i))); /* give all threads a chance to run */ |