Date: Mon, 30 Jul 2018 14:21:49 +0000 (UTC) From: David Bright <dab@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336905 - head/tests/sys/kqueue/libkqueue Message-ID: <201807301421.w6UELnWf076212@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dab Date: Mon Jul 30 14:21:49 2018 New Revision: 336905 URL: https://svnweb.freebsd.org/changeset/base/336905 Log: Correct possible misleading error message in kqtest. ian@ pointed out that in the test_abstime() function time(NULL) is used twice; once in an "if" test and again in the enclosed error message. If the true branch was taken and the process got preempted before the second time(NULL) call, by the time the error message was generated enough time could have elapsed that the message could claim that the event came "too early" but print an event time that was after the expected timeout. Correct by making the time(NULL) call only once and using that returned time in both the "if" test and the error message. Reported by: ian@ MFC after: 4 days X-MFC-with: r336761, r336781, r336802 Sponsored by: Dell EMC Modified: head/tests/sys/kqueue/libkqueue/timer.c Modified: head/tests/sys/kqueue/libkqueue/timer.c ============================================================================== --- head/tests/sys/kqueue/libkqueue/timer.c Mon Jul 30 12:58:33 2018 (r336904) +++ head/tests/sys/kqueue/libkqueue/timer.c Mon Jul 30 14:21:49 2018 (r336905) @@ -220,16 +220,17 @@ test_abstime(void) { const char *test_id = "kevent(EVFILT_TIMER, EV_ONESHOT, NOTE_ABSTIME)"; struct kevent kev; - time_t when; + time_t start; + time_t stop; const int timeout = 3; test_begin(test_id); test_no_kevents(); - when = time(NULL); + start = time(NULL); EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT, - NOTE_ABSTIME | NOTE_SECONDS, when + timeout, NULL); + NOTE_ABSTIME | NOTE_SECONDS, start + timeout, NULL); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); @@ -238,8 +239,9 @@ test_abstime(void) kev.data = 1; kev.fflags = 0; kevent_cmp(&kev, kevent_get(kqfd)); - if (time(NULL) < when + timeout) - err(1, "too early %jd %jd", (intmax_t)time(NULL), (intmax_t)(when + timeout)); + stop = time(NULL); + if (stop < start + timeout) + err(1, "too early %jd %jd", (intmax_t)stop, (intmax_t)(start + timeout)); /* Check if the event occurs again */ sleep(3);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807301421.w6UELnWf076212>