diff options
| author | yamt <yamt@NetBSD.org> | 2011-11-02 16:49:12 +0000 |
|---|---|---|
| committer | yamt <yamt@NetBSD.org> | 2011-11-02 16:49:12 +0000 |
| commit | bc6f4a2ffdc45b08ce378331d8a521004ec4ef1d (patch) | |
| tree | da3abb3bfb63fe5343a4c5e779e0d2407a4e26c4 /regress | |
| parent | 3026f72c479dd51d302a71e330fe0bd5b4b02b08 (diff) | |
- count the number of bits correctly
- more check
- tweak numbers
- use more accurate time
Diffstat (limited to 'regress')
| -rw-r--r-- | regress/sys/kern/select/select.c | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/regress/sys/kern/select/select.c b/regress/sys/kern/select/select.c index 7682a817c66..5ccacf84f0f 100644 --- a/regress/sys/kern/select/select.c +++ b/regress/sys/kern/select/select.c @@ -1,4 +1,4 @@ -/* $NetBSD: select.c,v 1.2 2008/03/21 16:03:33 ad Exp $ */ +/* $NetBSD: select.c,v 1.3 2011/11/02 16:49:12 yamt Exp $ */ /*- * Copyright (c)2008 YAMAMOTO Takashi, @@ -29,10 +29,13 @@ #define FD_SETSIZE 65536 #include <sys/select.h> #include <sys/atomic.h> +#include <sys/time.h> +#include <assert.h> #include <errno.h> #include <fcntl.h> #include <pthread.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -40,6 +43,7 @@ #define NPIPE 128 #define NTHREAD 64 +#define NBALLS 5 #define VERBOSE 0 #if !defined(RANDOM_MAX) @@ -48,7 +52,7 @@ int fds[NPIPE][2]; -unsigned count; +volatile unsigned count; pthread_barrier_t barrier; @@ -97,10 +101,11 @@ f(void *dummy) abort(); } if (random() & 1) { + assert(!FD_ISSET(fd, &set)); FD_SET(fd, &set); + nfd++; if (fd > maxfd) { maxfd = fd; - nfd++; } } } @@ -127,6 +132,12 @@ f(void *dummy) (void *)pthread_self(), ret); abort(); } + if (ret > NBALLS) { + fprintf(stderr, "[%p] unexpected return value %d" + " > NBALLS\n", + (void *)pthread_self(), ret); + abort(); + } nfd = 0; for (fd = 0; fd <= maxfd; fd++) { if (FD_ISSET(fd, &set)) { @@ -167,6 +178,10 @@ main(int argc, char *argv[]) pthread_t pt[NTHREAD]; int i; unsigned int secs; + struct timeval start_tv; + struct timeval end_tv; + uint64_t usecs; + unsigned int result; secs = atoi(argv[1]); @@ -190,12 +205,17 @@ main(int argc, char *argv[]) } } pthread_barrier_wait(&barrier); - dowrite(); - dowrite(); - dowrite(); - dowrite(); - + gettimeofday(&start_tv, NULL); + assert(count == 0); + for (i = 0; i < NBALLS; i++) { + dowrite(); + } sleep(secs); - printf("%u / %u = %lf\n", count, secs, (double)count / secs); + gettimeofday(&end_tv, NULL); + result = count; + usecs = (end_tv.tv_sec - start_tv.tv_sec) * 1000000 + + end_tv.tv_usec - start_tv.tv_usec; + printf("%u / %f = %f\n", result, (double)usecs / 1000000, + (double)result / usecs * 1000000); exit(EXIT_SUCCESS); } |
