summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2004-07-28 21:32:52 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2004-07-28 21:32:52 +0000
commitc0bff4e7394cc3b06865b6c352d420e66f3648bc (patch)
tree3ef3574df539296e05cd7de482a3f0baf9fe9212
parent8d682adee2aab53e3135271c2c4ca0e417a3340c (diff)
Very crude tests that check that itimers are at least pretending to work.
-rw-r--r--regress/sys/kern/itimer/Makefile17
-rw-r--r--regress/sys/kern/itimer/itimer.c95
2 files changed, 112 insertions, 0 deletions
diff --git a/regress/sys/kern/itimer/Makefile b/regress/sys/kern/itimer/Makefile
new file mode 100644
index 00000000000..e9e2d0a1c32
--- /dev/null
+++ b/regress/sys/kern/itimer/Makefile
@@ -0,0 +1,17 @@
+# $OpenBSD: Makefile,v 1.1 2004/07/28 21:32:51 art Exp $
+
+PROG= itimer
+SRCS= itimer.c
+
+real: itimer
+ ./itimer -r
+
+virtual: itimer
+ ./itimer -v
+
+prof: itimer
+ ./itimer -p
+
+REGRESS_TARGETS=real virtual prof
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/kern/itimer/itimer.c b/regress/sys/kern/itimer/itimer.c
new file mode 100644
index 00000000000..cdaf2849e40
--- /dev/null
+++ b/regress/sys/kern/itimer/itimer.c
@@ -0,0 +1,95 @@
+/* $OpenBSD: itimer.c,v 1.1 2004/07/28 21:32:51 art Exp $ */
+/*
+ * Written by Artur Grabowski <art@openbsd.org> 2004 Public Domain.
+ */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <time.h>
+#include <err.h>
+#include <signal.h>
+
+void sighand(int);
+
+volatile sig_atomic_t ticks;
+
+#define TIMEOUT 2
+
+int
+main(int argc, char **argv)
+{
+ struct timeval stv, tv;
+ struct itimerval itv;
+ struct rusage ru;
+ int which, sig;
+ int ch;
+
+ while ((ch = getopt(argc, argv, "rvp")) != -1) {
+ switch (ch) {
+ case 'r':
+ which = ITIMER_REAL;
+ sig = SIGALRM;
+ break;
+ case 'v':
+ which = ITIMER_VIRTUAL;
+ sig = SIGVTALRM;
+ break;
+ case 'p':
+ which = ITIMER_PROF;
+ sig = SIGPROF;
+ break;
+ default:
+ fprintf(stderr, "Usage: itimer [-rvp]\n");
+ exit(1);
+ }
+ }
+
+ signal(sig, sighand);
+
+ itv.it_value.tv_sec = 0;
+ itv.it_value.tv_usec = 100000;
+ itv.it_interval = itv.it_value;
+
+ if (setitimer(which, &itv, NULL) != 0)
+ err(1, "setitimer");
+
+ gettimeofday(&stv, NULL);
+ while (ticks != TIMEOUT * 10)
+ ;
+
+ switch (which) {
+ case ITIMER_REAL:
+ gettimeofday(&tv, NULL);
+ timersub(&tv, &stv, &tv);
+ break;
+ case ITIMER_VIRTUAL:
+ case ITIMER_PROF:
+ if (getrusage(RUSAGE_SELF, &ru) != 0)
+ err(1, "getrusage");
+ tv = ru.ru_utime;
+ break;
+ }
+ stv.tv_sec = TIMEOUT;
+ stv.tv_usec = 0;
+
+ if (timercmp(&stv, &tv, <))
+ timersub(&tv, &stv, &tv);
+ else
+ timersub(&stv, &tv, &tv);
+
+ if (tv.tv_sec != 0 || tv.tv_usec > 100000)
+ errx(1, "timer difference too big: %ld.%ld", (long)tv.tv_sec,
+ (long)tv.tv_usec);
+
+ return (0);
+}
+
+void
+sighand(int signum)
+{
+ ticks++;
+}