2 * Copyright (c) 2009 Mark Heily <mark@heily.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 static int __thread kqfd;
22 test_kevent_user_add_and_delete(void)
26 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD, 0, 0, NULL);
27 test_no_kevents(kqfd);
29 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_DELETE, 0, 0, NULL);
30 test_no_kevents(kqfd);
34 test_kevent_user_get(void)
38 test_no_kevents(kqfd);
40 /* Add the event, and then trigger it */
41 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, NULL);
42 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
44 kev.fflags &= ~NOTE_FFCTRLMASK;
45 kev.fflags &= ~NOTE_TRIGGER;
47 kevent_cmp(&kev, kevent_get(kqfd));
49 test_no_kevents(kqfd);
53 test_kevent_user_disable_and_enable(void)
57 test_no_kevents(kqfd);
59 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD, 0, 0, NULL);
60 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_DISABLE, 0, 0, NULL);
62 /* Trigger the event, but since it is disabled, nothing will happen. */
63 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
64 test_no_kevents(kqfd);
66 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ENABLE, 0, 0, NULL);
67 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
70 kev.fflags &= ~NOTE_FFCTRLMASK;
71 kev.fflags &= ~NOTE_TRIGGER;
72 kevent_cmp(&kev, kevent_get(kqfd));
76 test_kevent_user_oneshot(void)
80 test_no_kevents(kqfd);
82 kevent_add(kqfd, &kev, 2, EVFILT_USER, EV_ADD | EV_ONESHOT, 0, 0, NULL);
85 kevent_add(kqfd, &kev, 2, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
87 kev.flags = EV_ONESHOT;
88 kev.fflags &= ~NOTE_FFCTRLMASK;
89 kev.fflags &= ~NOTE_TRIGGER;
90 kevent_cmp(&kev, kevent_get(kqfd));
92 test_no_kevents(kqfd);
97 test_kevent_user_dispatch(void)
101 test_no_kevents(kqfd);
103 /* Add the event, and then trigger it */
104 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD | EV_CLEAR | EV_DISPATCH, 0, 0, NULL);
105 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
107 /* Retrieve one event */
108 kev.fflags &= ~NOTE_FFCTRLMASK;
109 kev.fflags &= ~NOTE_TRIGGER;
110 kev.flags = EV_CLEAR;
111 kevent_cmp(&kev, kevent_get(kqfd));
113 /* Confirm that the knote is disabled automatically */
114 test_no_kevents(kqfd);
116 /* Re-enable the kevent */
117 /* FIXME- is EV_DISPATCH needed when rearming ? */
118 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ENABLE | EV_CLEAR | EV_DISPATCH, 0, 0, NULL);
119 test_no_kevents(kqfd);
121 /* Trigger the event */
122 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
123 kev.fflags &= ~NOTE_FFCTRLMASK;
124 kev.fflags &= ~NOTE_TRIGGER;
125 kev.flags = EV_CLEAR;
126 kevent_cmp(&kev, kevent_get(kqfd));
127 test_no_kevents(kqfd);
129 /* Delete the watch */
130 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_DELETE, 0, 0, NULL);
131 test_no_kevents(kqfd);
133 #endif /* HAVE_EV_DISPATCH */
136 test_evfilt_user(int _kqfd)
140 test(kevent_user_add_and_delete);
141 test(kevent_user_get);
142 test(kevent_user_disable_and_enable);
143 test(kevent_user_oneshot);
145 test(kevent_user_dispatch);
147 /* TODO: try different fflags operations */