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.
23 const char *test_id = "kevent(EVFILT_USER, EV_ADD and EV_DELETE)";
28 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD, 0, 0, NULL);
31 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_DELETE, 0, 0, NULL);
40 const char *test_id = "kevent(EVFILT_USER, wait)";
47 /* Add the event, and then trigger it */
48 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, NULL);
49 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
51 kev.fflags &= ~NOTE_FFCTRLMASK;
52 kev.fflags &= ~NOTE_TRIGGER;
54 kevent_cmp(&kev, kevent_get(kqfd));
62 event_wait_keepudata(void)
64 const char *test_id = "kevent(EVFILT_USER, wait w/ EV_KEEPUDATA)";
71 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD | EV_CLEAR, 0, 0, &kev);
72 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_KEEPUDATA, NOTE_TRIGGER, 0,
75 kev.fflags &= ~NOTE_FFCTRLMASK;
76 kev.fflags &= ~NOTE_TRIGGER;
79 kevent_cmp(&kev, kevent_get(kqfd));
88 disable_and_enable(void)
90 const char *test_id = "kevent(EVFILT_USER, EV_DISABLE and EV_ENABLE)";
97 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD, 0, 0, NULL);
98 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_DISABLE, 0, 0, NULL);
100 /* Trigger the event, but since it is disabled, nothing will happen. */
101 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
104 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ENABLE, 0, 0, NULL);
105 kevent_add(kqfd, &kev, 1, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
107 kev.flags = EV_CLEAR;
108 kev.fflags &= ~NOTE_FFCTRLMASK;
109 kev.fflags &= ~NOTE_TRIGGER;
110 kevent_cmp(&kev, kevent_get(kqfd));
116 disable_and_enable_keepudata(void)
118 const char *test_id =
119 "kevent(EVFILT_USER, EV_DISABLE and EV_ENABLE w/ EV_KEEPUDATA)";
126 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ADD, 0, 0, &kev);
127 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_DISABLE | EV_KEEPUDATA, 0, 0,
130 /* Trigger the event, but since it is disabled, nothing will happen. */
131 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_KEEPUDATA, NOTE_TRIGGER, 0, NULL);
134 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_ENABLE | EV_KEEPUDATA, 0, 0,
136 kevent_add(kqfd, &kev, 1, EVFILT_USER, EV_KEEPUDATA, NOTE_TRIGGER, 0, NULL);
138 kev.flags = EV_CLEAR;
139 kev.fflags &= ~NOTE_FFCTRLMASK;
140 kev.fflags &= ~NOTE_TRIGGER;
142 kevent_cmp(&kev, kevent_get(kqfd));
150 const char *test_id = "kevent(EVFILT_USER, EV_ONESHOT)";
157 kevent_add(kqfd, &kev, 2, EVFILT_USER, EV_ADD | EV_ONESHOT, 0, 0, NULL);
160 kevent_add(kqfd, &kev, 2, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
162 kev.flags = EV_ONESHOT;
163 kev.fflags &= ~NOTE_FFCTRLMASK;
164 kev.fflags &= ~NOTE_TRIGGER;
165 kevent_cmp(&kev, kevent_get(kqfd));
173 test_evfilt_user(void)
179 event_wait_keepudata();
180 disable_and_enable();
181 disable_and_enable_keepudata();
183 /* TODO: try different fflags operations */