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