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