1 /* 2 * Copyright (c) 2009 Mark Heily <mark@heily.com> 3 * 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. 7 * 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. 15 * 16 * $FreeBSD$ 17 */ 18 19 #ifndef _COMMON_H 20 #define _COMMON_H 21 22 #include "config.h" /* Needed for HAVE_* defines */ 23 24 #if HAVE_ERR_H 25 # include <err.h> 26 #else 27 # define err(rc,msg,...) do { perror(msg); exit(rc); } while (0) 28 # define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0) 29 #endif 30 #include <errno.h> 31 #include <fcntl.h> 32 #include <signal.h> 33 #include <stdlib.h> 34 #include <stdio.h> 35 #include <string.h> 36 #include <stdint.h> 37 #include <sys/socket.h> 38 #include <sys/types.h> 39 #include <sys/stat.h> 40 #include <sys/wait.h> 41 #include <unistd.h> 42 43 #include <sys/event.h> 44 45 extern int vnode_fd; 46 extern int kqfd; 47 48 char * kevent_to_str(struct kevent *); 49 struct kevent * kevent_get(int); 50 struct kevent * kevent_get_timeout(int, int); 51 52 53 void kevent_cmp(struct kevent *, struct kevent *); 54 55 void 56 kevent_add(int kqfd, struct kevent *kev, 57 uintptr_t ident, 58 short filter, 59 u_short flags, 60 u_int fflags, 61 intptr_t data, 62 void *udata); 63 64 /* DEPRECATED: */ 65 #define KEV_CMP(kev,_ident,_filter,_flags) do { \ 66 if (kev.ident != (_ident) || \ 67 kev.filter != (_filter) || \ 68 kev.flags != (_flags)) \ 69 err(1, "kevent mismatch: got [%d,%d,%d] but expecting [%d,%d,%d]", \ 70 (int)_ident, (int)_filter, (int)_flags,\ 71 (int)kev.ident, kev.filter, kev.flags);\ 72 } while (0); 73 74 /* Checks if any events are pending, which is an error. */ 75 void test_no_kevents(void); 76 void test_no_kevents_quietly(void); 77 78 void test_begin(const char *); 79 void success(void); 80 81 void test_evfilt_read(void); 82 void test_evfilt_signal(void); 83 void test_evfilt_vnode(void); 84 void test_evfilt_timer(void); 85 void test_evfilt_proc(void); 86 #if HAVE_EVFILT_USER 87 void test_evfilt_user(void); 88 #endif 89 90 #endif /* _COMMON_H */ 91