From ebf57dfc03c9f3bda5ee065d45c28feb6ebb1c97 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Fri, 30 Oct 2026 03:25:35 +0100 Subject: Reduce syscalls and add helper to count them --- tests/t_event.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/t_event.c') diff --git a/tests/t_event.c b/tests/t_event.c index 5509f19..ad3948f 100644 --- a/tests/t_event.c +++ b/tests/t_event.c @@ -4,6 +4,7 @@ $id$ */ /* System */ +#include #include #include #include @@ -205,6 +206,41 @@ static void case_unknown_descriptor(void) { CHECK_INT(event_del(4096), -1); } +/* event_close exists so that the mechanisms which drop a closed descriptor + by themselves are not asked to do it twice. The one that keeps its own + list has to be told, and forgetting would leave the entry there to be + reported for ever, so what is checked here is the silence afterwards. */ +static void case_close_takes_it_out(void) { + int other[2], closed, count, i, strays = 0; + + test_case("a closed descriptor is gone from the set and really closed"); + pair_open(); + CHECK(sv[0] != -1); + CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, other), 0); + CHECK_INT(event_add(sv[0], EVENT_IN, 1), 0); + CHECK_INT(event_add(other[0], EVENT_IN, 2), 0); + + closed = sv[0]; + CHECK_INT(event_close(closed), 0); + sv[0] = -1; + CHECK_INT(fcntl(closed, F_GETFD), -1); + + /* The survivor is made ready so the wait has something to come back with, + and anything left over from the closed one shows up beside it */ + CHECK_INT((int)write(other[1], "x", 1), 1); + count = event_wait(ready, EVENTS, 200); + CHECK(count >= 1); + for (i = 0; i < count; ++i) + if (ready[i].fd != other[0]) + ++strays; + CHECK_INT(strays, 0); + + event_del(other[0]); + close(other[0]); + close(other[1]); + pair_close(); +} + void test_event(void) { CHECK_INT(event_init(), 0); CHECK(event_mechanism() != NULL); @@ -217,6 +253,7 @@ void test_event(void) { case_delete_from_the_middle(); case_timeout(); case_unknown_descriptor(); + case_close_takes_it_out(); event_deinit(); } -- cgit v1.3