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:
mheily 2011-04-09 01:24:59 +00:00
parent 4e607edd42
commit 10ec7ad485
3 changed files with 41 additions and 0 deletions

View File

@ -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);

View File

@ -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)
{

View File

@ -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