]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-socket-util: fix test for address parsing w/o IPv6 support 18828/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 1 Mar 2021 10:25:45 +0000 (11:25 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 1 Mar 2021 10:27:03 +0000 (11:27 +0100)
sockaddr_pretty() is the function that is ultimately called to print
the address, and afaics, it'll always use 0.0.0.0 if family==AF_INET.
So the test must have always been broken on systems with IPv6 support.

Fixes a failure in semaphore debian autopkgtest ci:
"65535" → ✓ 0 → "0.0.0.0:65535" (expect 0 / "[::]:65535") 15:15
Assertion 'streq(out, expected ?: in)' failed at src/test/test-socket-netlink.c:32, function test_socket_address_parse_one(). Aborting. 15:15

src/test/test-socket-netlink.c

index 704cc01e6f39e0b864ef8520bfcd320af5dc9f7c..af3ccec166f6ccfb9b89d3c6d3b5d147ec22f01c 100644 (file)
@@ -47,7 +47,8 @@ static void test_socket_address_parse(void) {
 
         const int default_family = socket_ipv6_is_supported() ? AF_INET6 : AF_INET;
 
-        test_socket_address_parse_one("65535", 0, default_family, "[::]:65535");
+        test_socket_address_parse_one("65535", 0, default_family,
+                                      default_family == AF_INET6 ? "[::]:65535": "0.0.0.0:65535");
 
         /* The checks below will pass even if ipv6 is disabled in
          * kernel. The underlying glibc's inet_pton() is just a string
@@ -65,7 +66,8 @@ static void test_socket_address_parse(void) {
         test_socket_address_parse_one("[::1]%lo%lo:1234", -EINVAL, 0, NULL);
         test_socket_address_parse_one("[::1]% lo:1234", -EINVAL, 0, NULL);
 
-        test_socket_address_parse_one("8888", 0, default_family, "[::]:8888");
+        test_socket_address_parse_one("8888", 0, default_family,
+                                      default_family == AF_INET6 ? "[::]:8888": "0.0.0.0:8888");
         test_socket_address_parse_one("[2001:0db8:0000:85a3:0000:0000:ac1f:8001]:8888", 0, AF_INET6,
                                       "[2001:db8:0:85a3::ac1f:8001]:8888");
         test_socket_address_parse_one("[::1]:8888", 0, AF_INET6, NULL);