aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2017-06-17 00:57:26 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2017-06-17 00:57:26 +0000
commit2b34e84335149a2d464c8e4b1334fb8f65a1fa8f (patch)
treed91d2c296ad043d944aa75f9d9a8635198860982 /tests
parentf2eb97b2cded8209e6d0d35930507dcfcf5bc794 (diff)
downloadsrc-2b34e84335149a2d464c8e4b1334fb8f65a1fa8f.tar.gz
src-2b34e84335149a2d464c8e4b1334fb8f65a1fa8f.zip
Add abstime kqueue(2) timers and expand struct kevent members.
This change implements NOTE_ABSTIME flag for EVFILT_TIMER, which specifies that the data field contains absolute time to fire the event. To make this useful, data member of the struct kevent must be extended to 64bit. Using the opportunity, I also added ext members. This changes struct kevent almost to Apple struct kevent64, except I did not changed type of ident and udata, the later would cause serious API incompatibilities. The type of ident was kept uintptr_t since EVFILT_AIO returns a pointer in this field, and e.g. CHERI is sensitive to the type (discussed with brooks, jhb). Unlike Apple kevent64, symbol versioning allows us to claim ABI compatibility and still name the new syscall kevent(2). Compat shims are provided for both host native and compat32. Requested by: bapt Reviewed by: bapt, brooks, ngie (previous version) Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D11025
Notes
Notes: svn path=/head/; revision=320043
Diffstat (limited to 'tests')
-rw-r--r--tests/sys/kqueue/libkqueue/main.c19
-rw-r--r--tests/sys/kqueue/libkqueue/timer.c35
2 files changed, 49 insertions, 5 deletions
diff --git a/tests/sys/kqueue/libkqueue/main.c b/tests/sys/kqueue/libkqueue/main.c
index 553478a514f5..aaf88bdc9d5a 100644
--- a/tests/sys/kqueue/libkqueue/main.c
+++ b/tests/sys/kqueue/libkqueue/main.c
@@ -180,13 +180,18 @@ kevent_to_str(struct kevent *kev)
char buf[512];
snprintf(&buf[0], sizeof(buf),
- "[ident=%d, filter=%d, %s, %s, data=%d, udata=%p]",
- (u_int) kev->ident,
+ "[ident=%ju, filter=%d, %s, %s, data=%jd, udata=%p, "
+ "ext=[%jx %jx %jx %jx]",
+ (uintmax_t) kev->ident,
kev->filter,
kevent_flags_dump(kev),
kevent_fflags_dump(kev),
- (int) kev->data,
- kev->udata);
+ (uintmax_t)kev->data,
+ kev->udata,
+ (uintmax_t)kev->ext[0],
+ (uintmax_t)kev->ext[1],
+ (uintmax_t)kev->ext[2],
+ (uintmax_t)kev->ext[3]);
return (strdup(buf));
}
@@ -218,7 +223,11 @@ kevent_cmp(struct kevent *k1, struct kevent *k2)
if (k1->flags & EV_ADD)
k2->flags |= EV_ADD;
#endif
- if (memcmp(k1, k2, sizeof(*k1)) != 0) {
+ if (k1->ident != k2->ident || k1->filter != k2->filter ||
+ k1->flags != k2->flags || k1->fflags != k2->fflags ||
+ k1->data != k2->data || k1->udata != k2->udata ||
+ k1->ext[0] != k2->ext[0] || k1->ext[1] != k2->ext[1] ||
+ k1->ext[0] != k2->ext[2] || k1->ext[0] != k2->ext[3]) {
printf("kevent_cmp: mismatch:\n %s !=\n %s\n",
kevent_to_str(k1), kevent_to_str(k2));
abort();
diff --git a/tests/sys/kqueue/libkqueue/timer.c b/tests/sys/kqueue/libkqueue/timer.c
index 766125d857e8..12b324b4eef8 100644
--- a/tests/sys/kqueue/libkqueue/timer.c
+++ b/tests/sys/kqueue/libkqueue/timer.c
@@ -17,6 +17,7 @@
*/
#include "common.h"
+#include <sys/time.h>
int kqfd;
@@ -164,6 +165,39 @@ disable_and_enable(void)
success();
}
+static void
+test_abstime(void)
+{
+ const char *test_id = "kevent(EVFILT_TIMER, EV_ONESHOT, NOTE_ABSTIME)";
+ struct kevent kev;
+ time_t when;
+ const int timeout = 3;
+
+ test_begin(test_id);
+
+ test_no_kevents();
+
+ when = time(NULL);
+ EV_SET(&kev, vnode_fd, EVFILT_TIMER, EV_ADD | EV_ONESHOT,
+ NOTE_ABSTIME | NOTE_SECONDS, when + timeout, NULL);
+ if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
+ err(1, "%s", test_id);
+
+ /* Retrieve the event */
+ kev.flags = EV_ADD | EV_ONESHOT;
+ kev.data = 1;
+ kev.fflags = 0;
+ kevent_cmp(&kev, kevent_get(kqfd));
+ if (time(NULL) < when + timeout)
+ err(1, "too early %jd %jd", time(), when + timeout);
+
+ /* Check if the event occurs again */
+ sleep(3);
+ test_no_kevents();
+
+ success();
+}
+
void
test_evfilt_timer()
{
@@ -173,6 +207,7 @@ test_evfilt_timer()
test_kevent_timer_get();
test_oneshot();
test_periodic();
+ test_abstime();
disable_and_enable();
close(kqfd);
}