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 * $FreeBSD: stable/10/tests/sys/kqueue/libkqueue/common.h 305467 2016-09-06 08:45:29Z ngie $ 17 */ 18 19#ifndef _COMMON_H 20#define _COMMON_H 21 22 23#if HAVE_ERR_H 24# include <err.h> 25#else 26# define err(rc,msg,...) do { perror(msg); exit(rc); } while (0) 27# define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0) 28#endif 29#include <errno.h> 30#include <fcntl.h> 31#include <signal.h> 32#include <stdlib.h> 33#include <stdio.h> 34#include <string.h> 35#include <stdint.h> 36#include <sys/socket.h> 37#include <sys/types.h> 38#include <unistd.h> 39 40#include <sys/event.h> 41 42#include "config.h" 43 44extern char *cur_test_id; 45int vnode_fd; 46 47extern const char * kevent_to_str(struct kevent *); 48struct kevent * kevent_get(int); 49struct kevent * kevent_get_timeout(int, int); 50 51 52void kevent_cmp(struct kevent *, struct kevent *); 53 54void 55kevent_add(int kqfd, struct kevent *kev, 56 uintptr_t ident, 57 short filter, 58 u_short flags, 59 u_int fflags, 60 intptr_t data, 61 void *udata); 62 63/* DEPRECATED: */ 64#define KEV_CMP(kev,_ident,_filter,_flags) do { \ 65 if (kev.ident != (_ident) || \ 66 kev.filter != (_filter) || \ 67 kev.flags != (_flags)) \ 68 err(1, "kevent mismatch: got [%d,%d,%d] but expecting [%d,%d,%d]", \ 69 (int)_ident, (int)_filter, (int)_flags,\ 70 (int)kev.ident, kev.filter, kev.flags);\ 71} while (0); 72 73/* Checks if any events are pending, which is an error. */ 74extern void test_no_kevents(void); 75 76extern void test_begin(const char *); 77extern void success(void); 78 79#endif /* _COMMON_H */ 80