]>
git.proxmox.com Git - systemd.git/blob - src/resolve/test-resolved-packet.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
4 #include "resolved-dns-packet.h"
7 static void test_dns_packet_new(void) {
9 _cleanup_(dns_packet_unrefp
) DnsPacket
*p2
= NULL
;
11 for (i
= 0; i
<= DNS_PACKET_SIZE_MAX
; i
++) {
12 _cleanup_(dns_packet_unrefp
) DnsPacket
*p
= NULL
;
14 assert_se(dns_packet_new(&p
, DNS_PROTOCOL_DNS
, i
, DNS_PACKET_SIZE_MAX
) == 0);
16 log_debug("dns_packet_new: %zu → %zu", i
, p
->allocated
);
17 assert_se(p
->allocated
>= MIN(DNS_PACKET_SIZE_MAX
, i
));
19 if (i
> DNS_PACKET_SIZE_START
+ 10 && i
< DNS_PACKET_SIZE_MAX
- 10)
20 i
= MIN(i
* 2, DNS_PACKET_SIZE_MAX
- 10);
23 assert_se(dns_packet_new(&p2
, DNS_PROTOCOL_DNS
, DNS_PACKET_SIZE_MAX
+ 1, DNS_PACKET_SIZE_MAX
) == -EFBIG
);
26 int main(int argc
, char **argv
) {
27 test_setup_logging(LOG_DEBUG
);
29 test_dns_packet_new();