1cb5fe245SEnji Cooper /* 2cb5fe245SEnji Cooper * Copyright (c) 2009 Mark Heily <mark@heily.com> 3cb5fe245SEnji Cooper * 4cb5fe245SEnji Cooper * Permission to use, copy, modify, and distribute this software for any 5cb5fe245SEnji Cooper * purpose with or without fee is hereby granted, provided that the above 6cb5fe245SEnji Cooper * copyright notice and this permission notice appear in all copies. 7cb5fe245SEnji Cooper * 8cb5fe245SEnji Cooper * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9cb5fe245SEnji Cooper * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10cb5fe245SEnji Cooper * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11cb5fe245SEnji Cooper * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12cb5fe245SEnji Cooper * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13cb5fe245SEnji Cooper * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14cb5fe245SEnji Cooper * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15cb5fe245SEnji Cooper */ 16cb5fe245SEnji Cooper 17cb5fe245SEnji Cooper #ifndef _COMMON_H 18cb5fe245SEnji Cooper #define _COMMON_H 19cb5fe245SEnji Cooper 2095c05062SDavid Bright #include "config.h" /* Needed for HAVE_* defines */ 21cb5fe245SEnji Cooper 22cb5fe245SEnji Cooper #if HAVE_ERR_H 23cb5fe245SEnji Cooper # include <err.h> 24cb5fe245SEnji Cooper #else 25cb5fe245SEnji Cooper # define err(rc,msg,...) do { perror(msg); exit(rc); } while (0) 26cb5fe245SEnji Cooper # define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0) 27cb5fe245SEnji Cooper #endif 28cb5fe245SEnji Cooper #include <errno.h> 29cb5fe245SEnji Cooper #include <fcntl.h> 30cb5fe245SEnji Cooper #include <signal.h> 31cb5fe245SEnji Cooper #include <stdlib.h> 32cb5fe245SEnji Cooper #include <stdio.h> 33cb5fe245SEnji Cooper #include <string.h> 34cb5fe245SEnji Cooper #include <stdint.h> 35cb5fe245SEnji Cooper #include <sys/socket.h> 36cb5fe245SEnji Cooper #include <sys/types.h> 377259ca31SKyle Evans #include <sys/stat.h> 387259ca31SKyle Evans #include <sys/wait.h> 39cb5fe245SEnji Cooper #include <unistd.h> 40cb5fe245SEnji Cooper 41cb5fe245SEnji Cooper #include <sys/event.h> 42cb5fe245SEnji Cooper 43ce6a89e2SKyle Evans extern int vnode_fd; 44ce6a89e2SKyle Evans extern int kqfd; 45cb5fe245SEnji Cooper 46f527d7deSAlex Richardson char * kevent_to_str(struct kevent *); 47cb5fe245SEnji Cooper struct kevent * kevent_get(int); 48cb5fe245SEnji Cooper struct kevent * kevent_get_timeout(int, int); 49cb5fe245SEnji Cooper 50*c728c56cSMark Johnston #define kevent_cmp(a,b) _kevent_cmp(a,b, __FILE__, __LINE__) 51*c728c56cSMark Johnston void _kevent_cmp(struct kevent *expected, struct kevent *got, const char *file, int line); 52cb5fe245SEnji Cooper 53cb5fe245SEnji Cooper void 54cb5fe245SEnji Cooper kevent_add(int kqfd, struct kevent *kev, 55cb5fe245SEnji Cooper uintptr_t ident, 56cb5fe245SEnji Cooper short filter, 57cb5fe245SEnji Cooper u_short flags, 58cb5fe245SEnji Cooper u_int fflags, 59cb5fe245SEnji Cooper intptr_t data, 60cb5fe245SEnji Cooper void *udata); 61cb5fe245SEnji Cooper 62cb5fe245SEnji Cooper /* DEPRECATED: */ 63cb5fe245SEnji Cooper #define KEV_CMP(kev,_ident,_filter,_flags) do { \ 64cb5fe245SEnji Cooper if (kev.ident != (_ident) || \ 65cb5fe245SEnji Cooper kev.filter != (_filter) || \ 66cb5fe245SEnji Cooper kev.flags != (_flags)) \ 67cb5fe245SEnji Cooper err(1, "kevent mismatch: got [%d,%d,%d] but expecting [%d,%d,%d]", \ 68cb5fe245SEnji Cooper (int)_ident, (int)_filter, (int)_flags,\ 69cb5fe245SEnji Cooper (int)kev.ident, kev.filter, kev.flags);\ 70cb5fe245SEnji Cooper } while (0); 71cb5fe245SEnji Cooper 72cb5fe245SEnji Cooper /* Checks if any events are pending, which is an error. */ 73*c728c56cSMark Johnston #define test_no_kevents() _test_no_kevents(__FILE__, __LINE__) 74*c728c56cSMark Johnston void _test_no_kevents(const char *, int); 75f527d7deSAlex Richardson void test_no_kevents_quietly(void); 76cb5fe245SEnji Cooper 77f527d7deSAlex Richardson void test_begin(const char *); 78f527d7deSAlex Richardson void success(void); 79cb5fe245SEnji Cooper 80f527d7deSAlex Richardson void test_evfilt_read(void); 81f527d7deSAlex Richardson void test_evfilt_signal(void); 82f527d7deSAlex Richardson void test_evfilt_vnode(void); 83f527d7deSAlex Richardson void test_evfilt_timer(void); 84f527d7deSAlex Richardson void test_evfilt_proc(void); 85c9c283bdSAlex Richardson #if HAVE_EVFILT_USER 86f527d7deSAlex Richardson void test_evfilt_user(void); 87c9c283bdSAlex Richardson #endif 88c9c283bdSAlex Richardson 89cb5fe245SEnji Cooper #endif /* _COMMON_H */ 90