int main(int argc, char **argv) { int test_proc = 1; int test_socket = 1; int test_signal = 1; int test_vnode = 1; int test_timer = 1; #ifdef __FreeBSD__ int test_user = 1; #else /* XXX-FIXME temporary */ int test_user = 0; #endif while (argc) { if (strcmp(argv[0], "--no-proc") == 0) test_proc = 0; if (strcmp(argv[0], "--no-socket") == 0) test_socket = 0; if (strcmp(argv[0], "--no-timer") == 0) test_timer = 0; if (strcmp(argv[0], "--no-signal") == 0) test_signal = 0; if (strcmp(argv[0], "--no-vnode") == 0) test_vnode = 0; if (strcmp(argv[0], "--no-user") == 0) test_user = 0; argv++; argc--; } test_kqueue(); test_kqueue_close(); if (test_socket) test_evfilt_read(); if (test_signal) test_evfilt_signal(); if (test_vnode) test_evfilt_vnode(); #if HAVE_EVFILT_USER if (test_user) test_evfilt_user(); #endif if (test_timer) test_evfilt_timer(); if (test_proc) test_evfilt_proc(); printf("\n---\n" "+OK All %d tests completed.\n", testnum - 1); return (0); }
/* * Basic registration exercise for kqueue(2). Create several types/brands of * sockets, and confirm that we can register for various events on them. */ int main(void) { int kq, sv[2]; printf("1..49\n"); kq = kqueue(); if (kq == -1) fail(errno, "kqueue", NULL, NULL); OK("kqueue()"); /* * Create a UNIX domain datagram socket, and attach/test/detach a * read filter on it. */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, sv) == -1) fail(errno, "socketpair", "PF_UNIX, SOCK_DGRAM", NULL); OK("socketpair() 1"); if (fcntl(sv[0], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_DGRAM", "O_NONBLOCK"); OK("fcntl() 1"); if (fcntl(sv[1], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_DGRAM", "O_NONBLOCK"); OK("fnctl() 2"); test_evfilt_read(kq, sv, "PF_UNIX, SOCK_DGRAM"); if (close(sv[0]) == -1) fail(errno, "close", "PF_UNIX/SOCK_DGRAM", "sv[0]"); OK("close() 1"); if (close(sv[1]) == -1) fail(errno, "close", "PF_UNIX/SOCK_DGRAM", "sv[1]"); OK("close() 2"); #if 0 /* * XXXRW: We disable the write test in the case of datagram sockets, * as kqueue can't tell when the remote socket receive buffer is * full, whereas the UNIX domain socket implementation can tell and * returns ENOBUFS. */ /* * Create a UNIX domain datagram socket, and attach/test/detach a * write filter on it. */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, sv) == -1) fail(errno, "socketpair", "PF_UNIX, SOCK_DGRAM", NULL); if (fcntl(sv[0], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_DGRAM", "O_NONBLOCK"); if (fcntl(sv[1], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_DGRAM", "O_NONBLOCK"); test_evfilt_write(kq, sv, "PF_UNIX, SOCK_DGRAM"); if (close(sv[0]) == -1) fail(errno, "close", "PF_UNIX/SOCK_DGRAM", "sv[0]"); if (close(sv[1]) == -1) fail(errno, "close", "PF_UNIX/SOCK_DGRAM", "sv[1]"); #endif /* * Create a UNIX domain stream socket, and attach/test/detach a * read filter on it. */ if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) fail(errno, "socketpair", "PF_UNIX, SOCK_STREAM", NULL); OK("socketpair() 2"); if (fcntl(sv[0], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_STREAM", "O_NONBLOCK"); OK("fcntl() 3"); if (fcntl(sv[1], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_STREAM", "O_NONBLOCK"); OK("fcntl() 4"); test_evfilt_read(kq, sv, "PF_UNIX, SOCK_STREAM"); if (close(sv[0]) == -1) fail(errno, "close", "PF_UNIX/SOCK_STREAM", "sv[0]"); OK("close() 3"); if (close(sv[1]) == -1) fail(errno, "close", "PF_UNIX/SOCK_STREAM", "sv[1]"); OK("close() 4"); /* * Create a UNIX domain stream socket, and attach/test/detach a * write filter on it. */ if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) fail(errno, "socketpair", "PF_UNIX, SOCK_STREAM", NULL); OK("socketpair() 3"); if (fcntl(sv[0], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_STREAM", "O_NONBLOCK"); OK("fcntl() 5"); if (fcntl(sv[1], F_SETFL, O_NONBLOCK) != 0) fail(errno, "fcntl", "PF_UNIX, SOCK_STREAM", "O_NONBLOCK"); OK("fcntl() 6"); test_evfilt_write(kq, sv, "PF_UNIX, SOCK_STREAM"); if (close(sv[0]) == -1) fail(errno, "close", "PF_UNIX/SOCK_STREAM", "sv[0]"); OK("close() 5"); if (close(sv[1]) == -1) fail(errno, "close", "PF_UNIX/SOCK_STREAM", "sv[1]"); OK("close() 6"); if (close(kq) == -1) fail(errno, "close", "kq", NULL); OK("close() 7"); return (0); }
int main(int argc, char **argv) { int test_proc = 1; int test_socket = 1; int test_signal = 1; int test_vnode = 1; int test_timer = 1; #ifdef __FreeBSD__ int test_user = 1; #else /* XXX-FIXME temporary */ int test_user = 0; #endif while (argc) { if (strcmp(argv[0], "--no-proc") == 0) test_proc = 0; if (strcmp(argv[0], "--no-socket") == 0) test_socket = 0; if (strcmp(argv[0], "--no-timer") == 0) test_timer = 0; if (strcmp(argv[0], "--no-signal") == 0) test_signal = 0; if (strcmp(argv[0], "--no-vnode") == 0) test_vnode = 0; if (strcmp(argv[0], "--no-user") == 0) test_user = 0; argv++; argc--; } /* * Some tests fork. If output is fully buffered, * the children inherit some buffered data and flush * it when they exit, causing some data to be printed twice. * Use line buffering to avoid this problem. */ setlinebuf(stdout); setlinebuf(stderr); test_kqueue(); test_kqueue_close(); if (test_socket) test_evfilt_read(); if (test_signal) test_evfilt_signal(); if (test_vnode) test_evfilt_vnode(); #if HAVE_EVFILT_USER if (test_user) test_evfilt_user(); #endif if (test_timer) test_evfilt_timer(); if (test_proc) test_evfilt_proc(); printf("\n---\n" "+OK All %d tests completed.\n", testnum - 1); return (0); }