diff options
author | Thomas Nordin <nordin@cvs.openbsd.org> | 2002-02-21 09:21:31 +0000 |
---|---|---|
committer | Thomas Nordin <nordin@cvs.openbsd.org> | 2002-02-21 09:21:31 +0000 |
commit | 513da1581358840391615c9229f6e80dce6a8bad (patch) | |
tree | dd7c363e65a9b915376fb4a738dcf624374bd58d /regress/sys/kern | |
parent | 35b1b00251f2e5eaee9424187e52cd05b6479f08 (diff) |
Test for monotonically increasing timeofday.
Diffstat (limited to 'regress/sys/kern')
-rw-r--r-- | regress/sys/kern/gettimeofday/Makefile | 5 | ||||
-rw-r--r-- | regress/sys/kern/gettimeofday/gettimeofday.c | 31 |
2 files changed, 36 insertions, 0 deletions
diff --git a/regress/sys/kern/gettimeofday/Makefile b/regress/sys/kern/gettimeofday/Makefile new file mode 100644 index 00000000000..72706202f99 --- /dev/null +++ b/regress/sys/kern/gettimeofday/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2002/02/21 09:21:30 nordin Exp $ + +PROG= gettimeofday + +.include <bsd.regress.mk> diff --git a/regress/sys/kern/gettimeofday/gettimeofday.c b/regress/sys/kern/gettimeofday/gettimeofday.c new file mode 100644 index 00000000000..b27d16f9c0a --- /dev/null +++ b/regress/sys/kern/gettimeofday/gettimeofday.c @@ -0,0 +1,31 @@ +/* $OpenBSD: gettimeofday.c,v 1.1 2002/02/21 09:21:30 nordin Exp $ */ +/* + * Written by Thomas Nordin <nordin@openbsd.org> 2002 Public Domain. + */ +#include <err.h> +#include <stdio.h> + +#include <sys/time.h> + +int +main() +{ + struct timeval s; + struct timeval t1; + struct timeval t2; + + if (gettimeofday(&s, NULL) == -1) + err(1, "gettimeofday"); + + do { + if (gettimeofday(&t1, NULL) == -1) + err(1, "gettimeofday"); + if (gettimeofday(&t2, NULL) == -1) + err(1, "gettimeofday"); + + if (timercmp(&t2, &t1, <)) + errx(1, "time of day decreased"); + } while (t1.tv_sec - s.tv_sec < 7); + + return 0; +} |