Path: blob/main/tests/sys/kqueue/libkqueue/common.h
39566 views
/*1* Copyright (c) 2009 Mark Heily <[email protected]>2*3* Permission to use, copy, modify, and distribute this software for any4* purpose with or without fee is hereby granted, provided that the above5* copyright notice and this permission notice appear in all copies.6*7* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES8* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF9* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR10* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES11* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN12* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF13* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.14*/1516#ifndef _COMMON_H17#define _COMMON_H1819#include "config.h" /* Needed for HAVE_* defines */2021#if HAVE_ERR_H22# include <err.h>23#else24# define err(rc,msg,...) do { perror(msg); exit(rc); } while (0)25# define errx(rc,msg,...) do { puts(msg); exit(rc); } while (0)26#endif27#include <errno.h>28#include <fcntl.h>29#include <signal.h>30#include <stdlib.h>31#include <stdio.h>32#include <string.h>33#include <stdint.h>34#include <sys/socket.h>35#include <sys/types.h>36#include <sys/stat.h>37#include <sys/wait.h>38#include <unistd.h>3940#include <sys/event.h>4142extern int vnode_fd;43extern int kqfd;4445char * kevent_to_str(struct kevent *);46struct kevent * kevent_get(int);47struct kevent * kevent_get_timeout(int, int);4849#define kevent_cmp(a,b) _kevent_cmp(a,b, __FILE__, __LINE__)50void _kevent_cmp(struct kevent *expected, struct kevent *got, const char *file, int line);5152void53kevent_add(int kqfd, struct kevent *kev,54uintptr_t ident,55short filter,56u_short flags,57u_int fflags,58intptr_t data,59void *udata);6061/* DEPRECATED: */62#define KEV_CMP(kev,_ident,_filter,_flags) do { \63if (kev.ident != (_ident) || \64kev.filter != (_filter) || \65kev.flags != (_flags)) \66err(1, "kevent mismatch: got [%d,%d,%d] but expecting [%d,%d,%d]", \67(int)_ident, (int)_filter, (int)_flags,\68(int)kev.ident, kev.filter, kev.flags);\69} while (0);7071/* Checks if any events are pending, which is an error. */72#define test_no_kevents() _test_no_kevents(__FILE__, __LINE__)73void _test_no_kevents(const char *, int);74void test_no_kevents_quietly(void);7576void test_begin(const char *);77void success(void);7879void test_evfilt_read(void);80void test_evfilt_signal(void);81void test_evfilt_vnode(void);82void test_evfilt_timer(void);83void test_evfilt_proc(void);84#if HAVE_EVFILT_USER85void test_evfilt_user(void);86#endif8788#endif /* _COMMON_H */899091