diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-30 03:25:35 +0100 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2026-10-30 03:25:35 +0100 |
| commit | ebf57dfc03c9f3bda5ee065d45c28feb6ebb1c97 (patch) | |
| tree | 4304f3242ffbc3d34dbbda5d1d7bb232fd16d1f8 /tests/t_event.c | |
| parent | cc684e79c38e0aa5ff44820a31658f457691d979 (diff) | |
Diffstat (limited to 'tests/t_event.c')
| -rw-r--r-- | tests/t_event.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 @@ | |||
| 4 | $id$ */ | 4 | $id$ */ |
| 5 | 5 | ||
| 6 | /* System */ | 6 | /* System */ |
| 7 | #include <fcntl.h> | ||
| 7 | #include <string.h> | 8 | #include <string.h> |
| 8 | #include <sys/socket.h> | 9 | #include <sys/socket.h> |
| 9 | #include <sys/time.h> | 10 | #include <sys/time.h> |
| @@ -205,6 +206,41 @@ static void case_unknown_descriptor(void) { | |||
| 205 | CHECK_INT(event_del(4096), -1); | 206 | CHECK_INT(event_del(4096), -1); |
| 206 | } | 207 | } |
| 207 | 208 | ||
| 209 | /* event_close exists so that the mechanisms which drop a closed descriptor | ||
| 210 | by themselves are not asked to do it twice. The one that keeps its own | ||
| 211 | list has to be told, and forgetting would leave the entry there to be | ||
| 212 | reported for ever, so what is checked here is the silence afterwards. */ | ||
| 213 | static void case_close_takes_it_out(void) { | ||
| 214 | int other[2], closed, count, i, strays = 0; | ||
| 215 | |||
| 216 | test_case("a closed descriptor is gone from the set and really closed"); | ||
| 217 | pair_open(); | ||
| 218 | CHECK(sv[0] != -1); | ||
| 219 | CHECK_INT(socketpair(AF_UNIX, SOCK_STREAM, 0, other), 0); | ||
| 220 | CHECK_INT(event_add(sv[0], EVENT_IN, 1), 0); | ||
| 221 | CHECK_INT(event_add(other[0], EVENT_IN, 2), 0); | ||
| 222 | |||
| 223 | closed = sv[0]; | ||
| 224 | CHECK_INT(event_close(closed), 0); | ||
| 225 | sv[0] = -1; | ||
| 226 | CHECK_INT(fcntl(closed, F_GETFD), -1); | ||
| 227 | |||
| 228 | /* The survivor is made ready so the wait has something to come back with, | ||
| 229 | and anything left over from the closed one shows up beside it */ | ||
| 230 | CHECK_INT((int)write(other[1], "x", 1), 1); | ||
| 231 | count = event_wait(ready, EVENTS, 200); | ||
| 232 | CHECK(count >= 1); | ||
| 233 | for (i = 0; i < count; ++i) | ||
| 234 | if (ready[i].fd != other[0]) | ||
| 235 | ++strays; | ||
| 236 | CHECK_INT(strays, 0); | ||
| 237 | |||
| 238 | event_del(other[0]); | ||
| 239 | close(other[0]); | ||
| 240 | close(other[1]); | ||
| 241 | pair_close(); | ||
| 242 | } | ||
| 243 | |||
| 208 | void test_event(void) { | 244 | void test_event(void) { |
| 209 | CHECK_INT(event_init(), 0); | 245 | CHECK_INT(event_init(), 0); |
| 210 | CHECK(event_mechanism() != NULL); | 246 | CHECK(event_mechanism() != NULL); |
| @@ -217,6 +253,7 @@ void test_event(void) { | |||
| 217 | case_delete_from_the_middle(); | 253 | case_delete_from_the_middle(); |
| 218 | case_timeout(); | 254 | case_timeout(); |
| 219 | case_unknown_descriptor(); | 255 | case_unknown_descriptor(); |
| 256 | case_close_takes_it_out(); | ||
| 220 | 257 | ||
| 221 | event_deinit(); | 258 | event_deinit(); |
| 222 | } | 259 | } |
