mirror of
https://github.com/darlinghq/darling-libkqueue.git
synced 2024-11-23 03:39:51 +00:00
Add a test for high-resolution kevent() calls on Linux
git-svn-id: svn://svn.code.sf.net/p/libkqueue/code/trunk@467 fb4e3144-bc1c-4b72-a658-5bcd248dd7f7
This commit is contained in:
parent
4e607edd42
commit
10ec7ad485
@ -72,6 +72,7 @@ void test_evfilt_user(int);
|
||||
|
||||
extern const char * kevent_to_str(struct kevent *);
|
||||
struct kevent * kevent_get(int);
|
||||
struct kevent * kevent_get_hires(int);
|
||||
|
||||
|
||||
void kevent_update(int kqfd, struct kevent *kev);
|
||||
|
@ -50,6 +50,26 @@ kevent_get(int kqfd)
|
||||
return (&kev);
|
||||
}
|
||||
|
||||
/* In Linux, a kevent() call with less than 1ms resolution
|
||||
will perform a pselect() call to obtain the higer resolution.
|
||||
This test exercises that codepath.
|
||||
*/
|
||||
struct kevent *
|
||||
kevent_get_hires(int kqfd)
|
||||
{
|
||||
int nfds;
|
||||
struct timespec timeo;
|
||||
static struct kevent __thread kev;
|
||||
|
||||
timeo.tv_sec = 0;
|
||||
timeo.tv_nsec = 500000;
|
||||
nfds = kevent(kqfd, NULL, 0, &kev, 1, &timeo);
|
||||
if (nfds < 1)
|
||||
die("kevent(2)");
|
||||
|
||||
return (&kev);
|
||||
}
|
||||
|
||||
char *
|
||||
kevent_fflags_dump(struct kevent *kev)
|
||||
{
|
||||
|
20
test/user.c
20
test/user.c
@ -49,6 +49,25 @@ test_kevent_user_get(void)
|
||||
test_no_kevents(kqfd);
|
||||
}
|
||||
|
||||
static void
|
||||
test_kevent_user_get_hires(void)
|
||||
{
|
||||
struct kevent kev;
|
||||
|
||||
test_no_kevents(kqfd);
|
||||
|
||||
/* Add the event, and then trigger it */
|
||||
kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, NULL);
|
||||
kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
|
||||
|
||||
kev.fflags &= ~NOTE_FFCTRLMASK;
|
||||
kev.fflags &= ~NOTE_TRIGGER;
|
||||
kev.flags = EV_CLEAR;
|
||||
kevent_cmp(&kev, kevent_get_hires(kqfd));
|
||||
|
||||
test_no_kevents(kqfd);
|
||||
}
|
||||
|
||||
static void
|
||||
test_kevent_user_disable_and_enable(void)
|
||||
{
|
||||
@ -139,6 +158,7 @@ test_evfilt_user(int _kqfd)
|
||||
|
||||
test(kevent_user_add_and_delete);
|
||||
test(kevent_user_get);
|
||||
test(kevent_user_get_hires);
|
||||
test(kevent_user_disable_and_enable);
|
||||
test(kevent_user_oneshot);
|
||||
#if HAVE_EV_DISPATCH
|
||||
|
Loading…
Reference in New Issue
Block a user