1200483Srwatson/*
2200483Srwatson * Copyright (c) 2009 Mark Heily <mark@heily.com>
3200483Srwatson *
4200483Srwatson * Permission to use, copy, modify, and distribute this software for any
5200483Srwatson * purpose with or without fee is hereby granted, provided that the above
6200483Srwatson * copyright notice and this permission notice appear in all copies.
7200483Srwatson *
8200483Srwatson * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9200483Srwatson * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10200483Srwatson * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11200483Srwatson * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12200483Srwatson * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13200483Srwatson * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14200483Srwatson * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15200483Srwatson *
16200483Srwatson * $FreeBSD: stable/10/tests/sys/kqueue/libkqueue/common.h 305467 2016-09-06 08:45:29Z ngie $
17200483Srwatson */
18200483Srwatson
19200483Srwatson#ifndef _COMMON_H
20200483Srwatson#define _COMMON_H
21200483Srwatson
22200483Srwatson
23200483Srwatson#if HAVE_ERR_H
24200483Srwatson# include <err.h>
25200483Srwatson#else
26200483Srwatson# define err(rc,msg,...) do { perror(msg); exit(rc); } while (0)
27200483Srwatson# define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0)
28200483Srwatson#endif
29200483Srwatson#include <errno.h>
30200483Srwatson#include <fcntl.h>
31200483Srwatson#include <signal.h>
32200483Srwatson#include <stdlib.h>
33200483Srwatson#include <stdio.h>
34200483Srwatson#include <string.h>
35200483Srwatson#include <stdint.h>
36200483Srwatson#include <sys/socket.h>
37200483Srwatson#include <sys/types.h>
38200483Srwatson#include <unistd.h>
39200483Srwatson
40200483Srwatson#include <sys/event.h>
41200483Srwatson
42200483Srwatson#include "config.h"
43200483Srwatson
44200483Srwatsonextern char *cur_test_id;
45200483Srwatsonint vnode_fd;
46200483Srwatson
47200483Srwatsonextern const char * kevent_to_str(struct kevent *);
48200483Srwatsonstruct kevent * kevent_get(int);
49295012Svangyzenstruct kevent * kevent_get_timeout(int, int);
50200483Srwatson
51200483Srwatson
52200483Srwatsonvoid kevent_cmp(struct kevent *, struct kevent *);
53200483Srwatson
54200483Srwatsonvoid
55200483Srwatsonkevent_add(int kqfd, struct kevent *kev,
56200483Srwatson        uintptr_t ident,
57200483Srwatson        short     filter,
58200483Srwatson        u_short   flags,
59200483Srwatson        u_int     fflags,
60200483Srwatson        intptr_t  data,
61200483Srwatson        void      *udata);
62200483Srwatson
63200483Srwatson/* DEPRECATED: */
64200483Srwatson#define KEV_CMP(kev,_ident,_filter,_flags) do {                 \
65200483Srwatson    if (kev.ident != (_ident) ||                                \
66200483Srwatson            kev.filter != (_filter) ||                          \
67200483Srwatson            kev.flags != (_flags)) \
68200483Srwatson        err(1, "kevent mismatch: got [%d,%d,%d] but expecting [%d,%d,%d]", \
69200483Srwatson                (int)_ident, (int)_filter, (int)_flags,\
70200483Srwatson                (int)kev.ident, kev.filter, kev.flags);\
71200483Srwatson} while (0);
72200483Srwatson
73200483Srwatson/* Checks if any events are pending, which is an error. */
74200483Srwatsonextern void test_no_kevents(void);
75200483Srwatson
76200483Srwatsonextern void test_begin(const char *);
77200483Srwatsonextern void success(void);
78200483Srwatson
79200483Srwatson#endif  /* _COMMON_H */
80