svn commit: r360033 - head/tests/sys/kqueue/libkqueue
Kyle Evans
kevans at FreeBSD.org
Fri Apr 17 02:22:15 UTC 2020
Author: kevans
Date: Fri Apr 17 02:22:15 2020
New Revision: 360033
URL: https://svnweb.freebsd.org/changeset/base/360033
Log:
tests: kqueue: use a more precise timer for the NOTE_ABSTIME test
Originally noticed while attempting to run the kqueue tests under
qemu-user-static, this apparently just happens sometimes when running in a
jail in general -- the timer will fire off "too early," but it's really just
the result of imprecise measurements (noted by cem).
Kicking this over to NOTE_USECONDS still tests the correct thing while
allowing it to work more consistently; a basic sanity test reveals that we
often end up coming in just less than 200 microseconds after the timer
fired off.
MFC after: 3 days
Modified:
head/tests/sys/kqueue/libkqueue/timer.c
Modified: head/tests/sys/kqueue/libkqueue/timer.c
==============================================================================
--- head/tests/sys/kqueue/libkqueue/timer.c Fri Apr 17 02:21:46 2020 (r360032)
+++ head/tests/sys/kqueue/libkqueue/timer.c Fri Apr 17 02:22:15 2020 (r360033)
@@ -216,17 +216,17 @@ test_abstime(void)
{
const char *test_id = "kevent(EVFILT_TIMER, EV_ONESHOT, NOTE_ABSTIME)";
struct kevent kev;
- time_t start;
- time_t stop;
- const int timeout = 3;
+ long end, start, stop;
+ const int timeout_sec = 3;
test_begin(test_id);
test_no_kevents();
- start = time(NULL);
+ start = now();
+ end = start + SEC_TO_US(timeout_sec);
EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
- NOTE_ABSTIME | NOTE_SECONDS, start + timeout, NULL);
+ NOTE_ABSTIME | NOTE_USECONDS, end, NULL);
if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
err(1, "%s", test_id);
@@ -235,10 +235,10 @@ test_abstime(void)
kev.data = 1;
kev.fflags = 0;
kevent_cmp(&kev, kevent_get(kqfd));
- stop = time(NULL);
- if (stop < start + timeout)
- err(1, "too early %jd %jd", (intmax_t)stop, (intmax_t)(start + timeout));
+ stop = now();
+ if (stop < end)
+ err(1, "too early %jd %jd", (intmax_t)stop, (intmax_t)end);
/* Check if the event occurs again */
sleep(3);
test_no_kevents();
More information about the svn-src-all
mailing list