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
This commit is contained in:
Kyle Evans 2020-04-17 02:22:15 +00:00
parent 82164bdd76
commit c17dd0e88b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=360033

View File

@ -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();