[systemd-devel] [PATCH] test-socket-util: Fix tests on machines without ipv6 support

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed May 6 05:04:16 PDT 2015


On Thu, Apr 30, 2015 at 10:18:31AM +0200, Sjoerd Simons wrote:
> The test for socket-util already has some code to only do certain tests
> on machines with ipv6 support. However this was incomplete causing the
> test to still fail on such machines, this patch adds the remaining cases
> required to make it pass on machine without ipv6 support.
> ---
>  src/test/test-socket-util.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/src/test/test-socket-util.c b/src/test/test-socket-util.c
> index f257af4..b58f5e3 100644
> --- a/src/test/test-socket-util.c
> +++ b/src/test/test-socket-util.c
> @@ -111,9 +111,11 @@ static void test_socket_address_equal(void) {
>          assert_se(socket_address_parse(&b, "/foo/bar") >= 0);
>          assert_se(socket_address_equal(&a, &b));
>  
> -        assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
> -        assert_se(socket_address_parse(&b, "[::1]:8888") >= 0);
> -        assert_se(socket_address_equal(&a, &b));
> +        if (socket_ipv6_is_supported()) {
> +                assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
> +                assert_se(socket_address_parse(&b, "[::1]:8888") >= 0);
> +                assert_se(socket_address_equal(&a, &b));
> +        }
Instead of skipping the test, what about doing something like
  int expect = socket_ipv6_is_supported() ? 0 : -EAFNOSUPPORT;
  assert_se(socket_address_parse(...) == expect);

? We want to exercise as many paths through the code as possible.

Zbyszek

>  
>          assert_se(socket_address_parse(&a, "@abstract") >= 0);
>          assert_se(socket_address_parse(&b, "@abstract") >= 0);
> @@ -133,8 +135,10 @@ static void test_socket_address_get_path(void) {
>          assert_se(socket_address_parse(&a, "@abstract") >= 0);
>          assert_se(!socket_address_get_path(&a));
>  
> -        assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
> -        assert_se(!socket_address_get_path(&a));
> +        if (socket_ipv6_is_supported()) {
> +                assert_se(socket_address_parse(&a, "[::1]:8888") >= 0);
> +                assert_se(!socket_address_get_path(&a));
> +        }
>  
>          assert_se(socket_address_parse(&a, "/foo/bar") >= 0);
>          assert_se(streq(socket_address_get_path(&a), "/foo/bar"));
> -- 
> 2.1.4
> 
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel


More information about the systemd-devel mailing list