From owner-svn-src-all@freebsd.org Fri Apr 24 13:29:08 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C55492B43B0; Fri, 24 Apr 2020 13:29:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 497w4N4plNz4LTN; Fri, 24 Apr 2020 13:29:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9C02B1E918; Fri, 24 Apr 2020 13:29:08 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03ODT8Yd076692; Fri, 24 Apr 2020 13:29:08 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03ODT8qt076691; Fri, 24 Apr 2020 13:29:08 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202004241329.03ODT8qt076691@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Fri, 24 Apr 2020 13:29:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360257 - stable/12/tests/sys/kqueue/libkqueue X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/12/tests/sys/kqueue/libkqueue X-SVN-Commit-Revision: 360257 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Apr 2020 13:29:08 -0000 Author: kevans Date: Fri Apr 24 13:29:08 2020 New Revision: 360257 URL: https://svnweb.freebsd.org/changeset/base/360257 Log: MFC r360033, r360108: better precision in kqueue timer tests r360033: 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. r360108: tests: kqueue: fix some issues with now() on ILP32 platforms There were ultimately two separate problems here: - a 32-bit long cannot represent microseconds since 1970 (noted by ian) - time_t is 32-bit on i386, so now() was wrong anyways even with the correct return type. For the first, just explicitly use a uint64_t for now() and all of the callers. For the second, we need to explicitly cast tv_sec to uint64_t before it gets multiplied in the SEC_TO_US macro. Casting this instance rather than generally in the macro was arbitrarily chosen simply because all other uses are converting small relative time values. The tests now pass on i386, at least; presumably other ILP32 will be fine now as well. Modified: stable/12/tests/sys/kqueue/libkqueue/timer.c Directory Properties: stable/12/ (props changed) Modified: stable/12/tests/sys/kqueue/libkqueue/timer.c ============================================================================== --- stable/12/tests/sys/kqueue/libkqueue/timer.c Fri Apr 24 13:25:02 2020 (r360256) +++ stable/12/tests/sys/kqueue/libkqueue/timer.c Fri Apr 24 13:29:08 2020 (r360257) @@ -30,13 +30,14 @@ /* Get the current time with microsecond precision. Used for * sub-second timing to make some timer tests run faster. */ -static long +static uint64_t now(void) { struct timeval tv; gettimeofday(&tv, NULL); - return SEC_TO_US(tv.tv_sec) + tv.tv_usec; + /* Promote potentially 32-bit time_t to uint64_t before conversion. */ + return SEC_TO_US((uint64_t)tv.tv_sec) + tv.tv_usec; } /* Sleep for a given number of milliseconds. The timeout is assumed to @@ -216,17 +217,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; + uint64_t 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 +236,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(); @@ -252,7 +253,7 @@ test_update(void) const char *test_id = "kevent(EVFILT_TIMER (UPDATE), EV_ADD | EV_ONESHOT)"; struct kevent kev; long elapsed; - long start; + uint64_t start; test_begin(test_id); @@ -297,7 +298,7 @@ test_update_equal(void) const char *test_id = "kevent(EVFILT_TIMER (UPDATE=), EV_ADD | EV_ONESHOT)"; struct kevent kev; long elapsed; - long start; + uint64_t start; test_begin(test_id); @@ -341,7 +342,7 @@ test_update_expired(void) const char *test_id = "kevent(EVFILT_TIMER (UPDATE EXP), EV_ADD | EV_ONESHOT)"; struct kevent kev; long elapsed; - long start; + uint64_t start; test_begin(test_id); @@ -392,8 +393,7 @@ test_update_periodic(void) const char *test_id = "kevent(EVFILT_TIMER (UPDATE), periodic)"; struct kevent kev; long elapsed; - long start; - long stop; + uint64_t start, stop; test_begin(test_id); @@ -450,8 +450,7 @@ test_update_timing(void) int iteration; int sleeptime; long elapsed; - long start; - long stop; + uint64_t start, stop; test_begin(test_id);