From nobody Wed Jun 08 00:45:00 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F189784264E; Wed, 8 Jun 2022 00:45:00 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LHpR04VsHz4nqW; Wed, 8 Jun 2022 00:45:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654649100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=26cyOwZHPGYYMIa513bdga2wE0kZBPqZsAYZGOjrJDY=; b=ZvU8fIrNhDtWOIjPbyFJhGEKn8DEVnm3fGnXIWhmqVu8Npg9Ymtn75A3OrRNALd9qsPzHY G+a/EOO4ZyR6Mf/HoLl9/MLMgRn6RAgIpXloCQdT3StWWFQkYBq1IbFH0l0GV6CJ8O7POh SwGEDmoqYSyx3/ezGMMGu6++YfN3m9eBoO7YHcd3V5YAM8eNGhb5A1b65MZ5eI5/e+vANW M/vmu/Vt70xF+K1/DjQ47obH/vXAgBAZoPUpquPSGhdOIY50RiMDBaq1B/ObvYUH/Py6Vy FBU+gf7WlR9bT1wZA382V2gqIu0/8CYHgN1qodETD8Uee0HKgzJXgTJlUUXXXQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5853525569; Wed, 8 Jun 2022 00:45:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2580j0xr060691; Wed, 8 Jun 2022 00:45:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2580j0Ar060690; Wed, 8 Jun 2022 00:45:00 GMT (envelope-from git) Date: Wed, 8 Jun 2022 00:45:00 GMT Message-Id: <202206080045.2580j0Ar060690@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: f2ce33a640fd - stable/13 - kqueue tests: Add new EVFILT_TIMER regression tests from upstream List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f2ce33a640fddeb0763d4114bc7f06aa521effd0 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1654649100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=26cyOwZHPGYYMIa513bdga2wE0kZBPqZsAYZGOjrJDY=; b=YckzWsbvYOpzvSpESQRbwWd3TNtzhjgmyt43IBxrVeHVEG1E4qT3H29/SWBu/NnFkb6QUm Gql9/eSMkfOLJ/WDuQFYAZTDwECGSWMKNIFYiQNgwn2gcptELKdWWiZQZhMCL2+fNEDxky +/mGmMrZnmHb9Nrz9anM/JsW7kk10PrD+ZUzhDE0ROJN8sQbGINInCMqZBbDR0Eiu5veGi fhi2k6A9BLx0cskPo2Ky8aYfbHsaS8dEB2U1bV0zW91XIwiLJjhzyAPe5I5k95ZThS5og9 0NOjObMDrk6Wvjk1bSXZBAx2jmT3WdH1weHwNRSBRIGLzHond6A09KpJqWLnsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1654649100; a=rsa-sha256; cv=none; b=ohR6Y7Zo3XaoBk5NBh6juNE/WqNswaipd2heefuwGCUWqH4IK6Y0Rg+YCw6oeEyRipTnnh QmVm9vNeE3Tiy2CAWfmVIbb/ndiSlnk/XhkCcl7c6icHl0CC8GUseWnmDyeKDQuIWSLpPe nFyU479bhZL2FtyXMyEwuiv2t6L0uBWmGUqoRhg+8nNgC69g740tqFew6Dstwl8Al5dAMm 26QtJPsKN74A7hFNlgjtaKzmREpdWfGM0r5I3mp8FPygU5STQs7PX5vfBzd0c4dpfR4IgZ R4Nkm1g+LsvW42fod4OdgC+lrUp3uL/fJ1uLW/DHXIKWmfaV0gRVZp0MxRFnqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f2ce33a640fddeb0763d4114bc7f06aa521effd0 commit f2ce33a640fddeb0763d4114bc7f06aa521effd0 Author: Mark Johnston AuthorDate: 2022-05-25 00:16:32 +0000 Commit: Mark Johnston CommitDate: 2022-06-08 00:42:25 +0000 kqueue tests: Add new EVFILT_TIMER regression tests from upstream One of the tests exposes the regression reported in PR 264131. One test is disabled because FreeBSD does not support setting EV_ONESHOT on an already-added periodic timer. Though, in this case the flag is simply ignored, which isn't ideal. One test is slightly modified to set EV_ADD when reconfiguring a disabled timer per some commentary in PR 258412. Ideally we would re-import the test suite from libkqueue but there is a fair bit of divergence so this will require some effort. This just gets us one small step closer while increasing test coverage. PR: 258412 Sponsored by: The FreeBSD Foundation (cherry picked from commit d6d4f9b45e0be306bdaf53b2133b2cd0f7642167) --- tests/sys/kqueue/libkqueue/config.h | 1 + tests/sys/kqueue/libkqueue/timer.c | 129 +++++++++++++++++++++++++++++++++++- 2 files changed, 128 insertions(+), 2 deletions(-) diff --git a/tests/sys/kqueue/libkqueue/config.h b/tests/sys/kqueue/libkqueue/config.h index a204092a2ab2..41a67837efe8 100644 --- a/tests/sys/kqueue/libkqueue/config.h +++ b/tests/sys/kqueue/libkqueue/config.h @@ -7,6 +7,7 @@ #undef HAVE_NOTE_TRUNCATE #define HAVE_EVFILT_TIMER 1 #define HAVE_EVFILT_USER 1 +#define WITH_NATIVE_KQUEUE_BUGS 0 #define PROGRAM "libkqueue-test" #define VERSION "0.1" #define TARGET "freebsd" diff --git a/tests/sys/kqueue/libkqueue/timer.c b/tests/sys/kqueue/libkqueue/timer.c index 330c22c62bc5..aa9d41ce6bf8 100644 --- a/tests/sys/kqueue/libkqueue/timer.c +++ b/tests/sys/kqueue/libkqueue/timer.c @@ -182,7 +182,84 @@ test_periodic(void) } static void -disable_and_enable(void) +test_periodic_modify(void) +{ + const char *test_id = "kevent(EVFILT_TIMER, periodic_modify)"; + struct kevent kev; + + test_begin(test_id); + + test_no_kevents(); + + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD, 0, 1000, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + + /* Retrieve the event */ + kev.flags = EV_ADD | EV_CLEAR; + kev.data = 1; + kevent_cmp(&kev, kevent_get(kqfd)); + + /* Check if the event occurs again */ + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD, 0, 500, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + + kev.flags = EV_ADD | EV_CLEAR; + sleep(1); + kev.data = 2; /* Should have fired twice */ + + kevent_cmp(&kev, kevent_get(kqfd)); + + /* Delete the event */ + kev.flags = EV_DELETE; + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + + success(); +} + +#if WITH_NATIVE_KQUEUE_BUGS +static void +test_periodic_to_oneshot(void) +{ + const char *test_id = "kevent(EVFILT_TIMER, period_to_oneshot)"; + struct kevent kev; + + test_begin(test_id); + + test_no_kevents(); + + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD, 0, 1000, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + + /* Retrieve the event */ + kev.flags = EV_ADD | EV_CLEAR; + kev.data = 1; + kevent_cmp(&kev, kevent_get(kqfd)); + + /* Check if the event occurs again */ + sleep(1); + kevent_cmp(&kev, kevent_get(kqfd)); + + /* Switch to oneshot */ + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 500, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + kev.flags = EV_ADD | EV_CLEAR | EV_ONESHOT; + + sleep(1); + kev.data = 1; /* Should have fired once */ + + kevent_cmp(&kev, kevent_get(kqfd)); + + success(); +} +#endif + +static void +test_disable_and_enable(void) { const char *test_id = "kevent(EVFILT_TIMER, EV_DISABLE and EV_ENABLE)"; struct kevent kev; @@ -618,6 +695,49 @@ test_update_timing(void) success(); } +static void +test_dispatch(void) +{ + const char *test_id = "kevent(EVFILT_TIMER, EV_ADD | EV_DISPATCH)"; + struct kevent kev; + + test_no_kevents(); + + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_DISPATCH, 0, 200, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + + /* Get one event */ + kev.flags = EV_ADD | EV_CLEAR | EV_DISPATCH; + kev.data = 1; + kevent_cmp(&kev, kevent_get(kqfd)); + + /* Confirm that the knote is disabled due to EV_DISPATCH */ + usleep(500000); + test_no_kevents(); + + /* Enable the knote and make sure no events are pending */ + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ENABLE | EV_DISPATCH, 0, 200, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + test_no_kevents(); + + /* Get the next event */ + usleep(1100000); /* 1100 ms */ + kev.flags = EV_ADD | EV_CLEAR | EV_DISPATCH; + kev.data = 5; + kevent_cmp(&kev, kevent_get(kqfd)); + + /* Remove the knote and ensure the event no longer fires */ + EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_DELETE, 0, 0, NULL); + if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) + err(1, "%s", test_id); + usleep(500000); /* 500ms */ + test_no_kevents(); + + success(); +} + void test_evfilt_timer(void) { @@ -627,6 +747,10 @@ test_evfilt_timer(void) test_kevent_timer_get(); test_oneshot(); test_periodic(); + test_periodic_modify(); +#if WITH_NATIVE_KQUEUE_BUGS + test_periodic_to_oneshot(); +#endif test_abstime(); test_abstime_epoch(); test_abstime_preboot(); @@ -636,6 +760,7 @@ test_evfilt_timer(void) test_update_expired(); test_update_timing(); test_update_periodic(); - disable_and_enable(); + test_disable_and_enable(); + test_dispatch(); close(kqfd); }