From 395dd198cb64f03bf0fc12a4dbb33999906dc9d7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 1 Dec 2007 09:30:07 +0000 Subject: [PATCH] r15096@tombo: nickm | 2007-12-01 04:29:39 -0500 Test for corner-cases of re-adding non-persistent events from one another's handlers svn:r568 --- test/regress.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/test/regress.c b/test/regress.c index b1dac202..2b389110 100644 --- a/test/regress.c +++ b/test/regress.c @@ -806,6 +806,59 @@ test_loopbreak(void) cleanup_test(); } +static struct event *readd_test_event_last_added = NULL; +static void +re_add_read_cb(int fd, short event, void *arg) +{ + char buf[256]; + int len; + struct event *ev_other = arg; + readd_test_event_last_added = ev_other; + len = read(fd, buf, sizeof(buf)); + event_add(ev_other, NULL); + ++test_ok; +} + +static void +test_nonpersist_readd(void) +{ + struct event ev1, ev2; + int n, m; + + setup_test("Re-add nonpersistent events: "); + event_set(&ev1, pair[0], EV_READ, re_add_read_cb, &ev2); + event_set(&ev2, pair[1], EV_READ, re_add_read_cb, &ev1); + n = write(pair[0], "Hello", 5); + m = write(pair[1], "Hello", 5); + if (event_add(&ev1, NULL) == -1 || + event_add(&ev2, NULL) == -1) { + test_ok = 0; + } + if (test_ok != 0) + exit(1); + event_loop(EVLOOP_ONCE); + if (test_ok != 2) + exit(1); + /* At this point, we executed both callbacks. Whichever one got + * called first added the second, but the second then immediately got + * deleted before its callback was called. At this point, though, it + * re-added the first. + */ + if (!readd_test_event_last_added) { + test_ok = 0; + } else if (readd_test_event_last_added == &ev1) { + if (!event_pending(&ev1, EV_READ, NULL) || + event_pending(&ev2, EV_READ, NULL)) + test_ok = 0; + } else { + if (event_pending(&ev1, EV_READ, NULL) || + !event_pending(&ev2, EV_READ, NULL)) + test_ok = 0; + } + + cleanup_test(); +} + static void test_evbuffer(void) { @@ -1533,6 +1586,8 @@ main (int argc, char **argv) test_loopexit(); test_loopbreak(); + test_nonpersist_readd(); + test_multiple_events_for_same_fd(); test_want_only_once(); -- 2.40.0