test: drop timeout handlers

Fixes file descriptor leak reported in #22576.
This commit is contained in:
Yu Watanabe
2022-02-22 21:50:32 +09:00
parent 62d4b3b36e
commit 2e37084fc9
4 changed files with 16 additions and 52 deletions
+3 -14
View File
@@ -31,13 +31,6 @@ static bool verbose = true;
static int test_fd[2];
static test_callback_recv_t callback_recv;
static be32_t xid;
static sd_event_source *test_hangcheck;
static int test_dhcp_hangcheck(sd_event_source *s, uint64_t usec, void *userdata) {
assert_not_reached();
return 0;
}
static void test_request_basic(sd_event *e) {
int r;
@@ -514,19 +507,15 @@ static void test_addr_acq(sd_event *e) {
callback_recv = test_addr_acq_recv_discover;
assert_se(sd_event_add_time_relative(
e, &test_hangcheck,
clock_boottime_or_monotonic(),
2 * USEC_PER_SEC, 0,
test_dhcp_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(),
2 * USEC_PER_SEC, 0,
NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0);
res = sd_dhcp_client_start(client);
assert_se(IN_SET(res, 0, -EINPROGRESS));
assert_se(sd_event_loop(e) >= 0);
test_hangcheck = sd_event_source_unref(test_hangcheck);
assert_se(sd_dhcp_client_set_callback(client, NULL, NULL) >= 0);
assert_se(sd_dhcp_client_stop(client) >= 0);
sd_dhcp_client_unref(client);
+1 -1
View File
@@ -981,7 +981,7 @@ static void test_dhcp6_client(void) {
assert_se(sd_event_new(&e) >= 0);
assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(),
2 * USEC_PER_SEC, 0,
NULL, INT_TO_PTR(ETIMEDOUT)) >= 0);
NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0);
assert_se(sd_dhcp6_client_new(&client) >= 0);
assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0);
+4 -15
View File
@@ -51,7 +51,6 @@ static uint8_t advertisement[] = {
0x72, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
static sd_event_source *test_hangcheck;
static bool test_stopped;
static int test_fd[2];
static sd_event_source *recv_router_advertisement;
@@ -101,13 +100,6 @@ static const struct in6_addr test_rdnss = { { { 0x20, 0x01, 0x0d, 0xb8,
static const char *test_dnssl[] = { "lab.intra",
NULL };
static int test_rs_hangcheck(sd_event_source *s, uint64_t usec,
void *userdata) {
assert_se(false);
return 0;
}
static void test_radv_prefix(void) {
sd_radv_prefix *p;
@@ -341,16 +333,13 @@ static void test_ra(void) {
assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0],
EPOLLIN, radv_recv, ra) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck, clock_boottime_or_monotonic(),
2 *USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(),
2 * USEC_PER_SEC, 0,
NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0);
assert_se(sd_radv_start(ra) >= 0);
sd_event_loop(e);
test_hangcheck = sd_event_source_unref(test_hangcheck);
assert_se(sd_event_loop(e) >= 0);
ra = sd_radv_unref(ra);
assert_se(!ra);
+8 -22
View File
@@ -22,7 +22,6 @@ static struct ether_addr mac_addr = {
};
static bool verbose = false;
static sd_event_source *test_hangcheck;
static int test_fd[2];
static sd_ndisc *test_timeout_nd;
@@ -166,13 +165,6 @@ static void router_dump(sd_ndisc_router *rt) {
}
}
static int test_rs_hangcheck(sd_event_source *s, uint64_t usec,
void *userdata) {
assert_se(false);
return 0;
}
int icmp6_bind_router_solicitation(int ifindex) {
assert_se(ifindex == 42);
@@ -285,10 +277,9 @@ static void test_rs(void) {
assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0);
assert_se(sd_ndisc_set_callback(nd, test_callback, e) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck, clock_boottime_or_monotonic(),
30 * USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(),
30 * USEC_PER_SEC, 0,
NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0);
assert_se(sd_ndisc_stop(nd) >= 0);
assert_se(sd_ndisc_start(nd) >= 0);
@@ -297,9 +288,7 @@ static void test_rs(void) {
assert_se(sd_ndisc_start(nd) >= 0);
sd_event_loop(e);
test_hangcheck = sd_event_source_unref(test_hangcheck);
assert_se(sd_event_loop(e) >= 0);
nd = sd_ndisc_unref(nd);
assert_se(!nd);
@@ -379,16 +368,13 @@ static void test_timeout(void) {
assert_se(sd_ndisc_set_ifindex(nd, 42) >= 0);
assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck, clock_boottime_or_monotonic(),
30 * USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(),
30 * USEC_PER_SEC, 0,
NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0);
assert_se(sd_ndisc_start(nd) >= 0);
sd_event_loop(e);
test_hangcheck = sd_event_source_unref(test_hangcheck);
assert_se(sd_event_loop(e) >= 0);
nd = sd_ndisc_unref(nd);