Date: Thu, 16 Apr 2020 20:33:51 -0600 From: Ian Lepore <ian@freebsd.org> To: Kyle Evans <kevans@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r360033 - head/tests/sys/kqueue/libkqueue Message-ID: <28f9262a36dc4b7d4437ef3860ac8e472f6df2ff.camel@freebsd.org> In-Reply-To: <202004170222.03H2MFso026451@repo.freebsd.org> References: <202004170222.03H2MFso026451@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2020-04-17 at 02:22 +0000, Kyle Evans wrote: > 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(); Not caused by you, but this change made me notice: using 'long' to hold the number of microseconds since the unix epoch will only work on amd64 and arm64. Everything involved with that needs to use uint64_t to work on all arches. -- Ian
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?28f9262a36dc4b7d4437ef3860ac8e472f6df2ff.camel>