void test_kevent_socket_clear(struct test_context *ctx) { struct kevent kev, ret; test_no_kevents(ctx->kqfd); kevent_socket_drain(ctx); EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent1"); kevent_socket_fill(ctx); kevent_socket_fill(ctx); /* Solaris does not offer a way to get the amount of data pending */ #if defined(__sun__) kev.data = 1; #else kev.data = 2; #endif kevent_get(&ret, ctx->kqfd); kevent_cmp(&kev, &ret); /* We filled twice, but drain once. Edge-triggered would not generate additional events. */ kevent_socket_drain(ctx); test_no_kevents(ctx->kqfd); kevent_socket_drain(ctx); EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_DELETE, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent2"); }
void test_kevent_socket_clear(void) { const char *test_id = "kevent(EVFILT_READ, EV_CLEAR)"; struct kevent kev; test_begin(test_id); test_no_kevents(); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); kevent_socket_fill(); kevent_socket_fill(); kev.data = 2; kevent_cmp(&kev, kevent_get(kqfd)); /* We filled twice, but drain once. Edge-triggered would not generate additional events. */ kevent_socket_drain(); test_no_kevents(); kevent_socket_drain(); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_DELETE, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); success(); }
void test_kevent_socket_lowat(void) { const char *test_id = "kevent(EVFILT_READ, NOTE_LOWAT)"; struct kevent kev; test_begin(test_id); /* Re-add the watch and make sure no events are pending */ puts("-- re-adding knote, setting low watermark to 2 bytes"); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_ADD | EV_ONESHOT, NOTE_LOWAT, 2, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); test_no_kevents(); puts("-- checking that one byte does not trigger an event.."); kevent_socket_fill(); test_no_kevents(); puts("-- checking that two bytes triggers an event.."); kevent_socket_fill(); if (kevent(kqfd, NULL, 0, &kev, 1, NULL) != 1) err(1, "%s", test_id); KEV_CMP(kev, sockfd[0], EVFILT_READ, 0); test_no_kevents(); kevent_socket_drain(); kevent_socket_drain(); success(); }
void test_kevent_socket_lowat(struct test_context *ctx) { struct kevent kev; test_begin(test_id); /* Re-add the watch and make sure no events are pending */ puts("-- re-adding knote, setting low watermark to 2 bytes"); EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_ADD | EV_ONESHOT, NOTE_LOWAT, 2, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("%s", test_id); test_no_kevents(); puts("-- checking that one byte does not trigger an event.."); kevent_socket_fill(ctx); test_no_kevents(); puts("-- checking that two bytes triggers an event.."); kevent_socket_fill(ctx); if (kevent(ctx->kqfd, NULL, 0, &kev, 1, NULL) != 1) die("%s", test_id); KEV_CMP(kev, ctx->client_fd, EVFILT_READ, 0); test_no_kevents(); kevent_socket_drain(ctx); kevent_socket_drain(ctx); }
void test_kevent_socket_get(void) { const char *test_id = "kevent(EVFILT_READ) wait"; struct kevent kev; test_begin(test_id); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_ADD, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); kevent_socket_fill(); kev.data = 1; kevent_cmp(&kev, kevent_get(kqfd)); kevent_socket_drain(); test_no_kevents(); kev.flags = EV_DELETE; if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); success(); }
void test_kevent_socket_dispatch(void) { const char *test_id = "kevent(EVFILT_READ, EV_DISPATCH)"; test_begin(test_id); struct kevent kev; /* Re-add the watch and make sure no events are pending */ puts("-- re-adding knote"); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_ADD | EV_DISPATCH, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); test_no_kevents(); /* The event will occur only once, even though EV_CLEAR is not specified. */ kevent_socket_fill(); kev.data = 1; kevent_cmp(&kev, kevent_get(kqfd)); test_no_kevents(); /* Since the knote is disabled, the EV_DELETE operation succeeds. */ EV_SET(&kev, sockfd[0], EVFILT_READ, EV_DELETE, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); kevent_socket_drain(); success(); }
void test_kevent_socket_oneshot(void) { const char *test_id = "kevent(EVFILT_READ, EV_ONESHOT)"; struct kevent kev; test_begin(test_id); /* Re-add the watch and make sure no events are pending */ puts("-- re-adding knote"); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); test_no_kevents(); puts("-- getting one event"); kevent_socket_fill(); kev.data = 1; kevent_cmp(&kev, kevent_get(kqfd)); puts("-- checking knote disabled"); test_no_kevents(); /* Try to delete the knote, it should already be deleted */ EV_SET(&kev, sockfd[0], EVFILT_READ, EV_DELETE, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) == 0) err(1, "%s", test_id); kevent_socket_drain(); success(); }
void test_kevent_socket_disable_and_enable(void) { const char *test_id = "kevent(EVFILT_READ, EV_DISABLE)"; struct kevent kev; test_begin(test_id); /* Add an event, then disable it. */ EV_SET(&kev, sockfd[0], EVFILT_READ, EV_ADD, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_DISABLE, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); kevent_socket_fill(); test_no_kevents(); /* Re-enable the knote, then see if an event is generated */ kev.flags = EV_ENABLE; if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); kev.flags = EV_ADD; kev.data = 1; kevent_cmp(&kev, kevent_get(kqfd)); kevent_socket_drain(); kev.flags = EV_DELETE; if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); success(); }
void test_kevent_socket_dispatch(struct test_context *ctx) { struct kevent kev, ret; /* Re-add the watch and make sure no events are pending */ kevent_add(ctx->kqfd, &kev, ctx->client_fd, EVFILT_READ, EV_ADD | EV_DISPATCH, 0, 0, &ctx->client_fd); test_no_kevents(ctx->kqfd); /* The event will occur only once, even though EV_CLEAR is not specified. */ kevent_socket_fill(ctx); kev.data = 1; kevent_get(&ret, ctx->kqfd); kevent_cmp(&kev, &ret); test_no_kevents(ctx->kqfd); /* Re-enable the kevent */ /* FIXME- is EV_DISPATCH needed when rearming ? */ kevent_add(ctx->kqfd, &kev, ctx->client_fd, EVFILT_READ, EV_ENABLE | EV_DISPATCH, 0, 0, &ctx->client_fd); kev.data = 1; kev.flags = EV_ADD | EV_DISPATCH; /* FIXME: may not be portable */ kevent_get(&ret, ctx->kqfd); kevent_cmp(&kev, &ret); test_no_kevents(ctx->kqfd); /* Since the knote is disabled, the EV_DELETE operation succeeds. */ kevent_add(ctx->kqfd, &kev, ctx->client_fd, EVFILT_READ, EV_DELETE, 0, 0, &ctx->client_fd); kevent_socket_drain(ctx); }
void test_kevent_socket_oneshot(struct test_context *ctx) { struct kevent kev, ret; /* Re-add the watch and make sure no events are pending */ kevent_add(ctx->kqfd, &kev, ctx->client_fd, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, &ctx->client_fd); test_no_kevents(ctx->kqfd); kevent_socket_fill(ctx); kev.data = 1; kevent_get(&ret, ctx->kqfd); kevent_cmp(&kev, &ret); test_no_kevents(ctx->kqfd); /* Verify that the kernel watch has been deleted */ kevent_socket_fill(ctx); test_no_kevents(ctx->kqfd); kevent_socket_drain(ctx); /* Verify that the kevent structure does not exist. */ kev.flags = EV_DELETE; if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) == 0) die("kevent() should have failed"); }
void test_kevent_socket_disable_and_enable(struct test_context *ctx) { struct kevent kev, ret; /* Add an event, then disable it. */ EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_ADD, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent"); EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_DISABLE, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent"); kevent_socket_fill(ctx); test_no_kevents(ctx->kqfd); /* Re-enable the knote, then see if an event is generated */ kev.flags = EV_ENABLE; if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent"); kev.flags = EV_ADD; kev.data = 1; kevent_get(&ret, ctx->kqfd); kevent_cmp(&kev, &ret); kevent_socket_drain(ctx); kev.flags = EV_DELETE; if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent"); }
void test_kevent_socket_del(struct test_context *ctx) { struct kevent kev; EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_DELETE, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent"); kevent_socket_fill(ctx); test_no_kevents(ctx->kqfd); kevent_socket_drain(ctx); }
void test_kevent_socket_del(void) { const char *test_id = "kevent(EVFILT_READ, EV_DELETE)"; struct kevent kev; test_begin(test_id); EV_SET(&kev, sockfd[0], EVFILT_READ, EV_DELETE, 0, 0, &sockfd[0]); if (kevent(kqfd, &kev, 1, NULL, 0, NULL) < 0) err(1, "%s", test_id); kevent_socket_fill(); test_no_kevents(); kevent_socket_drain(); success(); }
void test_kevent_socket_add_without_ev_add(struct test_context *ctx) { struct kevent kev; /* Try to add a kevent without specifying EV_ADD */ EV_SET(&kev, ctx->client_fd, EVFILT_READ, 0, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) == 0) die("kevent should have failed"); kevent_socket_fill(ctx); test_no_kevents(ctx->kqfd); kevent_socket_drain(ctx); /* Try to delete a kevent which does not exist */ kev.flags = EV_DELETE; if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) == 0) die("kevent should have failed"); }
void test_kevent_socket_get(struct test_context *ctx) { struct kevent kev, ret; EV_SET(&kev, ctx->client_fd, EVFILT_READ, EV_ADD, 0, 0, &ctx->client_fd); if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent:1"); kevent_socket_fill(ctx); kev.data = 1; kevent_get(&ret, ctx->kqfd); kevent_cmp(&kev, &ret); kevent_socket_drain(ctx); test_no_kevents(ctx->kqfd); kev.flags = EV_DELETE; if (kevent(ctx->kqfd, &kev, 1, NULL, 0, NULL) < 0) die("kevent:2"); }