diff options
Diffstat (limited to 'tests/t_event.c')
| -rw-r--r-- | tests/t_event.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/t_event.c b/tests/t_event.c index ad3948f..1908dc9 100644 --- a/tests/t_event.c +++ b/tests/t_event.c | |||
| @@ -241,9 +241,40 @@ static void case_close_takes_it_out(void) { | |||
| 241 | pair_close(); | 241 | pair_close(); |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | /* A descriptor can be taken on before anybody waits for anything on it: the | ||
| 245 | full scrape parks a connection while a worker thread builds the reply. The | ||
| 246 | mechanisms disagree about what registering nothing means, so what is | ||
| 247 | checked is that asking for a filter afterwards still works. */ | ||
| 248 | static void case_add_nothing_then_ask(void) { | ||
| 249 | test_case("a descriptor added with no interest can be given some later"); | ||
| 250 | pair_open(); | ||
| 251 | CHECK(sv[0] != -1); | ||
| 252 | CHECK_INT(event_add(sv[0], 0, 7), 0); | ||
| 253 | CHECK_INT((int)write(sv[1], "x", 1), 1); | ||
| 254 | CHECK_INT(wait_for(sv[0], EVENT_IN, 200, NULL), 0); | ||
| 255 | |||
| 256 | CHECK_INT(event_modify(sv[0], EVENT_IN, 7), 0); | ||
| 257 | { | ||
| 258 | uint32_t generation = 0; | ||
| 259 | CHECK_INT(wait_for(sv[0], EVENT_IN, 500, &generation), 1); | ||
| 260 | CHECK_INT((int)generation, 7); | ||
| 261 | } | ||
| 262 | event_del(sv[0]); | ||
| 263 | pair_close(); | ||
| 264 | } | ||
| 265 | |||
| 266 | /* Whether a worker thread may register a descriptor while this one waits | ||
| 267 | depends on who keeps the set. Tying the answer to the mechanism's name | ||
| 268 | here means a backend added later cannot quietly forget to say. */ | ||
| 269 | static void case_sharing_matches_the_mechanism(void) { | ||
| 270 | test_case("only a set the kernel keeps may be changed from another thread"); | ||
| 271 | CHECK_INT(event_can_share(), strcmp(event_mechanism(), "poll") ? 1 : 0); | ||
| 272 | } | ||
| 273 | |||
| 244 | void test_event(void) { | 274 | void test_event(void) { |
| 245 | CHECK_INT(event_init(), 0); | 275 | CHECK_INT(event_init(), 0); |
| 246 | CHECK(event_mechanism() != NULL); | 276 | CHECK(event_mechanism() != NULL); |
| 277 | case_sharing_matches_the_mechanism(); | ||
| 247 | 278 | ||
| 248 | case_readable(); | 279 | case_readable(); |
| 249 | case_writable(); | 280 | case_writable(); |
| @@ -254,6 +285,7 @@ void test_event(void) { | |||
| 254 | case_timeout(); | 285 | case_timeout(); |
| 255 | case_unknown_descriptor(); | 286 | case_unknown_descriptor(); |
| 256 | case_close_takes_it_out(); | 287 | case_close_takes_it_out(); |
| 288 | case_add_nothing_then_ask(); | ||
| 257 | 289 | ||
| 258 | event_deinit(); | 290 | event_deinit(); |
| 259 | } | 291 | } |
