test: fix benchmark-ping-udp (#2817)

- Fixes the declaration of the benchmark in benchmark-list.h (it was not
  previously runnable at all)
- Fixes the benchmark itself hanging infinitely because the data was
  being dropped via ICMP Destination Unreachable errors (meaning nread
  was always zero in pinger_read_cb)
    + The data getting lost was fixed by binding the udp socket
- Properly checks for UV_UDP_MMSG_CHUNK, just as an example of what
  should generally be done (buf_free is actually a no-op as the buf is
  allocated on the stack)
This commit is contained in:
Ryan Liptak 2022-02-12 22:04:41 -08:00 committed by GitHub
parent 8ec1732af0
commit 912bb8c577
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -23,7 +23,9 @@ BENCHMARK_DECLARE (sizes)
BENCHMARK_DECLARE (loop_count)
BENCHMARK_DECLARE (loop_count_timed)
BENCHMARK_DECLARE (ping_pongs)
BENCHMARK_DECLARE (ping_udp)
BENCHMARK_DECLARE (ping_udp1)
BENCHMARK_DECLARE (ping_udp10)
BENCHMARK_DECLARE (ping_udp100)
BENCHMARK_DECLARE (tcp_write_batch)
BENCHMARK_DECLARE (tcp4_pound_100)
BENCHMARK_DECLARE (tcp4_pound_1000)
@ -91,6 +93,10 @@ TASK_LIST_START
BENCHMARK_ENTRY (ping_pongs)
BENCHMARK_HELPER (ping_pongs, tcp4_echo_server)
BENCHMARK_ENTRY (ping_udp1)
BENCHMARK_ENTRY (ping_udp10)
BENCHMARK_ENTRY (ping_udp100)
BENCHMARK_ENTRY (tcp_write_batch)
BENCHMARK_HELPER (tcp_write_batch, tcp4_blackhole_server)

View File

@ -94,6 +94,9 @@ static void pinger_read_cb(uv_udp_t* udp,
pinger_t* pinger;
pinger = (pinger_t*)udp->data;
/* No data here means something went wrong */
ASSERT(nread > 0);
/* Now we count the pings */
for (i = 0; i < nread; i++) {
ASSERT(buf->base[i] == PING[pinger->state]);
@ -108,7 +111,8 @@ static void pinger_read_cb(uv_udp_t* udp,
}
}
buf_free(buf);
if (buf && !(flags & UV_UDP_MMSG_CHUNK))
buf_free(buf);
}
static void udp_pinger_new(void) {
@ -122,6 +126,8 @@ static void udp_pinger_new(void) {
/* Try to do NUM_PINGS ping-pongs (connection-less). */
r = uv_udp_init(loop, &pinger->udp);
ASSERT(r == 0);
r = uv_udp_bind(&pinger->udp, (const struct sockaddr*) &pinger->server_addr, 0);
ASSERT(r == 0);
pinger->udp.data = pinger;