From 86d060892988975be937e713c5dfdff1a1ffa4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 21:41:41 +0000 Subject: [PATCH] test-resolved-packet: skip most of the loop We want to test the edge cases, but testing all the values in between is mostly pointless and slow on slow architectures (>1s on rpi). --- src/resolve/resolved-dns-packet.c | 1 - src/resolve/resolved-dns-packet.h | 8 ++++++-- src/resolve/test-resolved-packet.c | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 49a04615d4e..bf879475d40 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -28,7 +28,6 @@ #define EDNS0_OPT_DO (1<<15) -#define DNS_PACKET_SIZE_START 512u assert_cc(DNS_PACKET_SIZE_START > DNS_PACKET_HEADER_SIZE) typedef struct DnsPacketRewinder { diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h index a65d6d38cf9..d4c6b3c9cbe 100644 --- a/src/resolve/resolved-dns-packet.h +++ b/src/resolve/resolved-dns-packet.h @@ -56,10 +56,14 @@ struct DnsPacketHeader { #define UDP_PACKET_HEADER_SIZE (sizeof(struct iphdr) + sizeof(struct udphdr)) /* The various DNS protocols deviate in how large a packet can grow, - but the TCP transport has a 16bit size field, hence that appears to - be the absolute maximum. */ + * but the TCP transport has a 16bit size field, hence that appears to + * be the absolute maximum. */ #define DNS_PACKET_SIZE_MAX 0xFFFFu +/* The default size to use for allocation when we don't know how large + * the packet will turn out to be. */ +#define DNS_PACKET_SIZE_START 512u + /* RFC 1035 say 512 is the maximum, for classic unicast DNS */ #define DNS_PACKET_UNICAST_SIZE_MAX 512u diff --git a/src/resolve/test-resolved-packet.c b/src/resolve/test-resolved-packet.c index 1b0041214bb..cf886b1bf2c 100644 --- a/src/resolve/test-resolved-packet.c +++ b/src/resolve/test-resolved-packet.c @@ -31,6 +31,9 @@ static void test_dns_packet_new(void) { log_debug("dns_packet_new: %zu → %zu", i, p->allocated); assert_se(p->allocated >= MIN(DNS_PACKET_SIZE_MAX, i)); + + if (i > DNS_PACKET_SIZE_START + 10 && i < DNS_PACKET_SIZE_MAX - 10) + i = MIN(i * 2, DNS_PACKET_SIZE_MAX - 10); } assert_se(dns_packet_new(&p2, DNS_PROTOCOL_DNS, DNS_PACKET_SIZE_MAX + 1) == -EFBIG);