Tizen 2.1 base
[platform/upstream/gcd.git] / kqueue-1.0.4 / test / common.h
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
21 #if HAVE_ERR_H
22 # include <err.h>
23 #else
24 # define err(rc,msg,...) do { perror(msg); exit(rc); } while (0)
25 # define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0)
26 #endif
27
28 #define die(str)   do { \
29     fprintf(stderr, "%s(): %s: %s\n", __func__,str, strerror(errno));\
30     abort();\
31 } while (0)
32
33 #include <assert.h>
34 #include <errno.h>
35 #include <fcntl.h>
36 #include <signal.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <stdint.h>
41 #include <sys/socket.h>
42 #include <sys/types.h>
43 #include <unistd.h>
44
45 #include <sys/event.h>
46
47 #include "config.h"
48
49 void test_evfilt_read(int);
50 void test_evfilt_signal(int);
51 void test_evfilt_vnode(int);
52 void test_evfilt_timer(int);
53 void test_evfilt_proc(int);
54 #if HAVE_EVFILT_USER
55 void test_evfilt_user(int);
56 #endif
57
58 #define test(f,...) do {                                             \
59     test_begin("test_"#f"()\t"__VA_ARGS__);                                                  \
60     test_##f();\
61     test_end();                                                     \
62 } while (/*CONSTCOND*/0)
63
64 extern const char * kevent_to_str(struct kevent *);
65 struct kevent * kevent_get(int);
66
67
68 void kevent_update(int kqfd, struct kevent *kev);
69
70 void kevent_cmp(struct kevent *, struct kevent *);
71
72 void
73 kevent_add(int kqfd, struct kevent *kev, 
74         uintptr_t ident,
75         short     filter,
76         u_short   flags,
77         u_int     fflags,
78         intptr_t  data,
79         void      *udata);
80
81 /* DEPRECATED: */
82 #define KEV_CMP(kev,_ident,_filter,_flags) do {                 \
83     if (kev.ident != (_ident) ||                                \
84             kev.filter != (_filter) ||                          \
85             kev.flags != (_flags)) \
86         err(1, "kevent mismatch: got [%d,%d,%d] but expecting [%d,%d,%d]", \
87                 (int)_ident, (int)_filter, (int)_flags,\
88                 (int)kev.ident, kev.filter, kev.flags);\
89 } while (0);
90
91 /* Checks if any events are pending, which is an error. */
92 void test_no_kevents(int);
93
94 /* From test.c */
95 void    test_begin(const char *);
96 void    test_end(void);
97 void    test_atexit(void);
98 void    testing_begin(void);
99 void    testing_end(void);
100 int     testing_make_uid(void);
101
102 #endif  /* _COMMON_H */