From c0bff4e7394cc3b06865b6c352d420e66f3648bc Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Wed, 28 Jul 2004 21:32:52 +0000 Subject: Very crude tests that check that itimers are at least pretending to work. --- regress/sys/kern/itimer/Makefile | 17 +++++++ regress/sys/kern/itimer/itimer.c | 95 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 regress/sys/kern/itimer/Makefile create mode 100644 regress/sys/kern/itimer/itimer.c 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 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 2004 Public Domain. + */ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +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++; +} -- cgit v1.2.3