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 test_kevent_signal_add(void)
25 const char *test_id = "kevent(EVFILT_SIGNAL, EV_ADD)";
30 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
31 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
32 err(1, "%s", test_id);
38 test_kevent_signal_get(void)
40 const char *test_id = "kevent(EVFILT_SIGNAL, wait)";
45 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
46 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
47 err(1, "%s", test_id);
49 /* Block SIGUSR1, then send it to ourselves */
52 sigaddset(&mask, SIGUSR1);
53 if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
54 err(1, "sigprocmask");
55 if (kill(getpid(), SIGUSR1) < 0)
58 kev.flags |= EV_CLEAR;
60 kevent_cmp(&kev, kevent_get(kqfd));
66 test_kevent_signal_disable(void)
68 const char *test_id = "kevent(EVFILT_SIGNAL, EV_DISABLE)";
73 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_DISABLE, 0, 0, NULL);
74 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
75 err(1, "%s", test_id);
77 /* Block SIGUSR1, then send it to ourselves */
80 sigaddset(&mask, SIGUSR1);
81 if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
82 err(1, "sigprocmask");
83 if (kill(getpid(), SIGUSR1) < 0)
92 test_kevent_signal_enable(void)
94 const char *test_id = "kevent(EVFILT_SIGNAL, EV_ENABLE)";
99 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ENABLE, 0, 0, NULL);
100 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
101 err(1, "%s", test_id);
103 /* Block SIGUSR1, then send it to ourselves */
106 sigaddset(&mask, SIGUSR1);
107 if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
108 err(1, "sigprocmask");
109 if (kill(getpid(), SIGUSR1) < 0)
112 kev.flags = EV_ADD | EV_CLEAR;
114 kev.data = 1; /* WORKAROUND */
116 kev.data = 2; // one extra time from test_kevent_signal_disable()
118 kevent_cmp(&kev, kevent_get(kqfd));
120 /* Delete the watch */
121 kev.flags = EV_DELETE;
122 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
123 err(1, "%s", test_id);
129 test_kevent_signal_del(void)
131 const char *test_id = "kevent(EVFILT_SIGNAL, EV_DELETE)";
136 /* Delete the kevent */
137 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_DELETE, 0, 0, NULL);
138 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
139 err(1, "%s", test_id);
141 /* Block SIGUSR1, then send it to ourselves */
144 sigaddset(&mask, SIGUSR1);
145 if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
146 err(1, "sigprocmask");
147 if (kill(getpid(), SIGUSR1) < 0)
155 test_kevent_signal_oneshot(void)
157 const char *test_id = "kevent(EVFILT_SIGNAL, EV_ONESHOT)";
162 EV_SET(&kev, SIGUSR1, EVFILT_SIGNAL, EV_ADD | EV_ONESHOT, 0, 0, NULL);
163 if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0)
164 err(1, "%s", test_id);
166 /* Block SIGUSR1, then send it to ourselves */
169 sigaddset(&mask, SIGUSR1);
170 if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
171 err(1, "sigprocmask");
172 if (kill(getpid(), SIGUSR1) < 0)
175 kev.flags |= EV_CLEAR;
177 kevent_cmp(&kev, kevent_get(kqfd));
179 /* Send another one and make sure we get no events */
180 if (kill(getpid(), SIGUSR1) < 0)
188 test_evfilt_signal(void)
191 test_kevent_signal_add();
192 test_kevent_signal_del();
193 test_kevent_signal_get();
194 test_kevent_signal_disable();
195 test_kevent_signal_enable();
196 test_kevent_signal_oneshot();