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.
17 #include <sys/types.h>
29 * Test the method for detecting when one end of a socketpair
30 * has been closed. This technique is used in kqueue_validate()
33 test_peer_close_detection(void)
39 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockfd) < 0)
43 pfd.events = POLLIN | POLLHUP;
46 if (poll(&pfd, 1, 0) > 0)
47 die("unexpected data");
49 if (close(sockfd[1]) < 0)
52 if (poll(&pfd, 1, 0) > 0) {
53 if (recv(sockfd[0], buf, sizeof(buf), MSG_PEEK | MSG_DONTWAIT) != 0)
54 die("failed to detect peer shutdown");
63 if ((kqfd = kqueue()) < 0)
65 test_no_kevents(kqfd);
76 if ((kq = kqueue()) < 0)
80 EV_SET(&kev, SIGUSR2, EVFILT_SIGNAL, EV_ADD | EV_RECEIPT, 0, 0, NULL);
81 if (kevent(kq, &kev, 1, &kev, 1, NULL) < 0)
84 /* TODO: check the receipt */
88 memset(&kev, 0, sizeof(kev));
89 puts("Skipped -- EV_RECEIPT is not available");
94 main(int argc, char **argv)
96 struct unit_test tests[] = {
97 { "socket", 1, test_evfilt_read },
98 { "signal", 1, test_evfilt_signal },
100 { "proc", 1, test_evfilt_proc },
102 { "vnode", 1, test_evfilt_vnode },
103 { "timer", 1, test_evfilt_timer },
105 { "user", 1, test_evfilt_user },
109 struct unit_test *test;
113 /* If specific tests are requested, disable all tests by default */
115 for (test = &tests[0]; test->ut_name != NULL; test++) {
116 test->ut_enabled = 0;
123 for (test = &tests[0]; test->ut_name != NULL; test++) {
124 if (strcmp(arg, test->ut_name) == 0) {
125 test->ut_enabled = 1;
131 printf("ERROR: invalid option: %s\n", arg);
134 printf("enabled test: %s\n", arg);
142 test(peer_close_detection);
146 if ((kqfd = kqueue()) < 0)
149 for (test = &tests[0]; test->ut_name != NULL; test++) {
150 if (test->ut_enabled)