main.c (288683) | main.c (295012) |
---|---|
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 * | 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: head/tests/sys/kqueue/main.c 223845 2011-07-07 18:07:03Z jonathan $ | 16 * $FreeBSD: head/tests/sys/kqueue/main.c 295012 2016-01-28 20:24:15Z vangyzen $ |
17 */ 18 19#include <sys/types.h> 20 21#include "config.h" 22#include "common.h" 23 24int testnum = 1; --- 39 unchanged lines hidden (view full) --- 64 65 nfds = kevent(kqfd, NULL, 0, kev, 1, NULL); 66 if (nfds < 1) 67 err(1, "kevent(2)"); 68 69 return (kev); 70} 71 | 17 */ 18 19#include <sys/types.h> 20 21#include "config.h" 22#include "common.h" 23 24int testnum = 1; --- 39 unchanged lines hidden (view full) --- 64 65 nfds = kevent(kqfd, NULL, 0, kev, 1, NULL); 66 if (nfds < 1) 67 err(1, "kevent(2)"); 68 69 return (kev); 70} 71 |
72/* Retrieve a single kevent, specifying a maximum time to wait for it. */ 73struct kevent * 74kevent_get_timeout(int kqfd, int seconds) 75{ 76 int nfds; 77 struct kevent *kev; 78 struct timespec timeout = {seconds, 0}; 79 80 if ((kev = calloc(1, sizeof(*kev))) == NULL) 81 err(1, "out of memory"); 82 83 nfds = kevent(kqfd, NULL, 0, kev, 1, &timeout); 84 if (nfds < 0) { 85 err(1, "kevent(2)"); 86 } else if (nfds == 0) { 87 free(kev); 88 kev = NULL; 89 } 90 91 return (kev); 92} 93 |
|
72char * 73kevent_fflags_dump(struct kevent *kev) 74{ 75 char *buf; 76 77#define KEVFFL_DUMP(attrib) \ 78 if (kev->fflags & attrib) \ 79 strncat(buf, #attrib" ", 64); 80 81 if ((buf = calloc(1, 1024)) == NULL) 82 abort(); 83 84 /* Not every filter has meaningful fflags */ | 94char * 95kevent_fflags_dump(struct kevent *kev) 96{ 97 char *buf; 98 99#define KEVFFL_DUMP(attrib) \ 100 if (kev->fflags & attrib) \ 101 strncat(buf, #attrib" ", 64); 102 103 if ((buf = calloc(1, 1024)) == NULL) 104 abort(); 105 106 /* Not every filter has meaningful fflags */ |
85 if (kev->filter != EVFILT_VNODE) { 86 snprintf(buf, 1024, "fflags = %d", kev->fflags); 87 return (buf); 88 } 89 90 snprintf(buf, 1024, "fflags = %d (", kev->fflags); 91 KEVFFL_DUMP(NOTE_DELETE); 92 KEVFFL_DUMP(NOTE_WRITE); 93 KEVFFL_DUMP(NOTE_EXTEND); | 107 if (kev->filter == EVFILT_PROC) { 108 snprintf(buf, 1024, "fflags = %x (", kev->fflags); 109 KEVFFL_DUMP(NOTE_EXIT); 110 KEVFFL_DUMP(NOTE_FORK); 111 KEVFFL_DUMP(NOTE_EXEC); 112 KEVFFL_DUMP(NOTE_CHILD); 113 KEVFFL_DUMP(NOTE_TRACKERR); 114 KEVFFL_DUMP(NOTE_TRACK); 115 buf[strlen(buf) - 1] = ')'; 116 } else if (kev->filter == EVFILT_PROCDESC) { 117 snprintf(buf, 1024, "fflags = %x (", kev->fflags); 118 KEVFFL_DUMP(NOTE_EXIT); 119 KEVFFL_DUMP(NOTE_FORK); 120 KEVFFL_DUMP(NOTE_EXEC); 121 buf[strlen(buf) - 1] = ')'; 122 } else if (kev->filter == EVFILT_VNODE) { 123 snprintf(buf, 1024, "fflags = %x (", kev->fflags); 124 KEVFFL_DUMP(NOTE_DELETE); 125 KEVFFL_DUMP(NOTE_WRITE); 126 KEVFFL_DUMP(NOTE_EXTEND); |
94#if HAVE_NOTE_TRUNCATE | 127#if HAVE_NOTE_TRUNCATE |
95 KEVFFL_DUMP(NOTE_TRUNCATE); | 128 KEVFFL_DUMP(NOTE_TRUNCATE); |
96#endif | 129#endif |
97 KEVFFL_DUMP(NOTE_ATTRIB); 98 KEVFFL_DUMP(NOTE_LINK); 99 KEVFFL_DUMP(NOTE_RENAME); | 130 KEVFFL_DUMP(NOTE_ATTRIB); 131 KEVFFL_DUMP(NOTE_LINK); 132 KEVFFL_DUMP(NOTE_RENAME); |
100#if HAVE_NOTE_REVOKE | 133#if HAVE_NOTE_REVOKE |
101 KEVFFL_DUMP(NOTE_REVOKE); | 134 KEVFFL_DUMP(NOTE_REVOKE); |
102#endif | 135#endif |
103 buf[strlen(buf) - 1] = ')'; | 136 buf[strlen(buf) - 1] = ')'; 137 } else { 138 snprintf(buf, 1024, "fflags = %x", kev->fflags); 139 } |
104 105 return (buf); 106} 107 108char * 109kevent_flags_dump(struct kevent *kev) 110{ 111 char *buf; --- 143 unchanged lines hidden (view full) --- 255 if (strcmp(argv[0], "--no-vnode") == 0) 256 test_vnode = 0; 257 if (strcmp(argv[0], "--no-user") == 0) 258 test_user = 0; 259 argv++; 260 argc--; 261 } 262 | 140 141 return (buf); 142} 143 144char * 145kevent_flags_dump(struct kevent *kev) 146{ 147 char *buf; --- 143 unchanged lines hidden (view full) --- 291 if (strcmp(argv[0], "--no-vnode") == 0) 292 test_vnode = 0; 293 if (strcmp(argv[0], "--no-user") == 0) 294 test_user = 0; 295 argv++; 296 argc--; 297 } 298 |
299 /* 300 * Some tests fork. If output is fully buffered, 301 * the children inherit some buffered data and flush 302 * it when they exit, causing some data to be printed twice. 303 * Use line buffering to avoid this problem. 304 */ 305 setlinebuf(stdout); 306 setlinebuf(stderr); 307 |
|
263 test_kqueue(); 264 test_kqueue_close(); 265 266 if (test_socket) 267 test_evfilt_read(); 268 if (test_signal) 269 test_evfilt_signal(); 270 if (test_vnode) --- 14 unchanged lines hidden --- | 308 test_kqueue(); 309 test_kqueue_close(); 310 311 if (test_socket) 312 test_evfilt_read(); 313 if (test_signal) 314 test_evfilt_signal(); 315 if (test_vnode) --- 14 unchanged lines hidden --- |