Unit test for event_remove_timer with EV_PERSIST.

Patch from dcicppin on sourceforge.
This commit is contained in:
Nick Mathewson 2013-02-13 11:38:57 -05:00
parent 5623e80371
commit 96150dd0c6

View File

@ -1430,11 +1430,21 @@ static void send_a_byte_cb(evutil_socket_t fd, short what, void *arg)
(void) fd; (void) what;
write(*sockp, "A", 1);
}
struct read_not_timeout_param
{
struct event **ev;
int events;
int count;
};
static void read_not_timeout_cb(evutil_socket_t fd, short what, void *arg)
{
int *intp = arg;
struct read_not_timeout_param *rntp = arg;
char c;
(void) fd; (void) what;
*intp |= what;
read(fd, &c, 1);
rntp->events |= what;
++rntp->count;
if(2 == rntp->count) event_del(rntp->ev[0]);
}
static void
@ -1442,21 +1452,25 @@ test_event_remove_timeout(void *ptr)
{
struct basic_test_data *data = ptr;
struct event_base *base = data->base;
struct event *ev[4];
int ev0_fired=0, ev1_fired=0;
struct event *ev[5];
int ev1_fired=0;
struct timeval ms25 = { 0, 25*1000 },
ms40 = { 0, 40*1000 },
ms75 = { 0, 75*1000 },
ms125 = { 0, 125*1000 };
struct read_not_timeout_param rntp = { ev, 0, 0 };
event_base_assert_ok_(base);
ev[0] = event_new(base, data->pair[0], EV_READ,
read_not_timeout_cb, &ev0_fired);
ev[0] = event_new(base, data->pair[0], EV_READ|EV_PERSIST,
read_not_timeout_cb, &rntp);
ev[1] = evtimer_new(base, incr_arg_cb, &ev1_fired);
ev[2] = evtimer_new(base, remove_timers_cb, ev);
ev[3] = evtimer_new(base, send_a_byte_cb, &data->pair[1]);
ev[4] = evtimer_new(base, send_a_byte_cb, &data->pair[1]);
tt_assert(base);
event_add(ev[2], &ms25); /* remove timers */
event_add(ev[4], &ms40); /* write to test if timer re-activates */
event_add(ev[0], &ms75); /* read */
event_add(ev[1], &ms75); /* timer */
event_add(ev[3], &ms125); /* timeout. */
@ -1465,7 +1479,7 @@ test_event_remove_timeout(void *ptr)
event_base_dispatch(base);
tt_int_op(ev1_fired, ==, 0);
tt_int_op(ev0_fired, ==, EV_READ);
tt_int_op(rntp.events, ==, EV_READ);
event_base_assert_ok_(base);
end:
@ -1473,6 +1487,7 @@ end:
event_free(ev[1]);
event_free(ev[2]);
event_free(ev[3]);
event_free(ev[4]);
}
static void