summaryrefslogtreecommitdiff
path: root/regress/lib/libpthread
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2012-02-22 20:33:52 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2012-02-22 20:33:52 +0000
commit7c32bb0e88a0036463e4984b1b5be8d82df344d1 (patch)
treefd2387ec17dea4d8788c6ffbb354aa278ae13fed /regress/lib/libpthread
parent7da07a100aed584e772f6fa26e54d85b4a55cda0 (diff)
similar change to the setsockopt1.c one: use the resolution of the monotonic
clock from clock_getres(). while here use a different port when binding.
Diffstat (limited to 'regress/lib/libpthread')
-rw-r--r--regress/lib/libpthread/setsockopt/3/setsockopt3.c4
-rw-r--r--regress/lib/libpthread/setsockopt/3a/setsockopt3a.c41
2 files changed, 29 insertions, 16 deletions
diff --git a/regress/lib/libpthread/setsockopt/3/setsockopt3.c b/regress/lib/libpthread/setsockopt/3/setsockopt3.c
index ee106c72c7f..3a1b1257210 100644
--- a/regress/lib/libpthread/setsockopt/3/setsockopt3.c
+++ b/regress/lib/libpthread/setsockopt/3/setsockopt3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setsockopt3.c,v 1.3 2011/12/12 15:53:08 fgsch Exp $ */
+/* $OpenBSD: setsockopt3.c,v 1.4 2012/02/22 20:33:51 fgsch Exp $ */
/*
* Federico G. Schwindt <fgsch@openbsd.org>, 2009. Public Domain.
*/
@@ -54,7 +54,7 @@ sock_accept(void *arg)
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
- sin.sin_port = htons(6543);
+ sin.sin_port = htons(6545);
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
CHECKe(bind(s, (struct sockaddr *)&sin, sizeof(sin)));
CHECKe(listen(s, 2));
diff --git a/regress/lib/libpthread/setsockopt/3a/setsockopt3a.c b/regress/lib/libpthread/setsockopt/3a/setsockopt3a.c
index c613191d278..3cd5a058e41 100644
--- a/regress/lib/libpthread/setsockopt/3a/setsockopt3a.c
+++ b/regress/lib/libpthread/setsockopt/3a/setsockopt3a.c
@@ -1,9 +1,10 @@
-/* $OpenBSD: setsockopt3a.c,v 1.5 2012/02/20 01:31:12 fgsch Exp $ */
+/* $OpenBSD: setsockopt3a.c,v 1.6 2012/02/22 20:33:51 fgsch Exp $ */
/*
* Federico G. Schwindt <fgsch@openbsd.org>, 2009. Public Domain.
*/
#include <sys/types.h>
+#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <err.h>
@@ -14,6 +15,9 @@
#include <unistd.h>
#include "test.h"
+/* resolution of the monotonic clock */
+struct timespec mono_res;
+
static void
alarm_handler(int sig)
{
@@ -21,22 +25,28 @@ alarm_handler(int sig)
}
void
-check_timeout(int s, int sec, struct timeval *to)
+check_timeout(int s, int sec, const struct timespec *to)
{
- struct timeval t1, t2;
- struct timeval e;
+ struct timespec t1, t2, e;
char buf[BUFSIZ];
ASSERT(signal(SIGALRM, alarm_handler) != SIG_ERR);
CHECKe(alarm(sec));
- CHECKe(gettimeofday(&t1, NULL));
+ CHECKe(clock_gettime(CLOCK_MONOTONIC, &t1));
ASSERT(read(s, &buf, sizeof(buf)) == -1);
- CHECKe(gettimeofday(&t2, NULL));
+ CHECKe(clock_gettime(CLOCK_MONOTONIC, &t2));
ASSERT(errno == EAGAIN);
- timersub(&t2, &t1, &e);
- if (!timercmp(&e, to, <))
- PANIC("%ld.%ld > %ld.%ld",
- e.tv_sec, e.tv_usec, to->tv_sec, to->tv_usec);
+ timespecsub(&t2, &t1, &e);
+
+ /*
+ * verify that the difference between the duration and the
+ * timeout is less than the resolution of the clock
+ */
+ if (timespeccmp(&e, to, <))
+ timespecsub(to, &e, &t1);
+ else
+ timespecsub(&e, to, &t1);
+ ASSERT(timespeccmp(&t1, &mono_res, <=));
}
static void *
@@ -44,22 +54,25 @@ sock_accept(void *arg)
{
struct sockaddr_in sin;
struct timeval to;
+ struct timespec ts;
int s, s2, s3;
+ CHECKe(clock_getres(CLOCK_MONOTONIC, &mono_res));
CHECKe(s = strtol(arg, NULL, 10));
bzero(&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_len = sizeof(sin);
- sin.sin_port = htons(6543);
+ sin.sin_port = htons(6545);
sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
CHECKe(connect(s, (struct sockaddr *)&sin, sizeof(sin)));
to.tv_sec = 2;
to.tv_usec = 0.5 * 1e6;
- check_timeout(s, 3, &to);
+ TIMEVAL_TO_TIMESPEC(&to, &ts);
+ check_timeout(s, 3, &ts);
CHECKe(s2 = dup(s));
CHECKe(s3 = fcntl(s, F_DUPFD, s));
- check_timeout(s2, 3, &to);
- check_timeout(s3, 3, &to);
+ check_timeout(s2, 3, &ts);
+ check_timeout(s3, 3, &ts);
return (NULL);
}