Skip Menu |

This queue is for tickets about the Socket CPAN distribution.

Report information
The Basics
Id: 77248
Status: resolved
Priority: 0/
Queue: Socket

People
Owner: Nobody in particular
Requestors: ANDYD [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.001
Fixed in: 2.015



Subject: Test 10 in t/getnameinfo.t fails on Solaris 11 due to /etc/hosts format
This is a bug report for Socket version 2.001, as distributed with perl-5.16.0-RC2. Test 10 in cpan/Socket/t/getnameinfo.t test is failing for Solaris 11/x86 (both on my system and in the smoke reports.) I think the test is probably in error. Here's what's happening: My hostname is "HSC030". $ uname -a SunOS HSC030 5.11 snv_151a i86pc i386 i86pc The default Solaris 11 install puts the following lines in /etc/hosts: $ grep -v '^#' /etc/hosts ::1 HSC030 HSC030.local localhost loghost 127.0.0.1 HSC030 HSC030.local localhost loghost Here's what happens: $ ./perl -MTestInit cpan/Socket/t/getnameinfo.t 1..14 ok 1 - $err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICHOST|NI_NUMERICSERV ok 2 - $err eq "" for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICHOST|NI_NUMERICSERV ok 3 - $host is 127.0.0.1 for NH/NS ok 4 - $service is 80 for NH/NS ok 5 - $host is undef for NIx_NOHOST ok 6 - $service is 80 for NS, NIx_NOHOST ok 7 - $host is undef for NIx_NOSERV ok 8 - $service is 80 for NS, NIx_NOSERV ok 9 - $err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICSERV not ok 10 - $host is localhost for NS # Failed test '$host is localhost for NS' # at cpan/Socket/t/getnameinfo.t line 31. # got: 'HSC030' # expected: 'localhost' ok 11 - $service is 80 for NS ok 12 - $err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICHOST ok 13 - $host is 127.0.0.1 for NH ok 14 - $service is 80 for NH # Looks like you failed 1 test of 14. However, if I change the last line in /etc/hosts to just 127.0.0.1 localhost then the test passes. Hence I think the getnameinfo function is working, but the /etc/hosts file doesn't have the exact same structure as the test is expecting. I don't know if the Solaris /etc/hosts file is strictly correct or not, but it is what you get with a default install, so I don't think the test suite ought to complain about it. (This failure is not new -- it's present in perl-5.14.2 -- but I just got around to verifying that the /etc/hosts file is indeed as it was originally set up by Solaris, and the failure isn't due to my mucking around with /etc/hosts in some incorrect or misguided way.)
On Wed May 16 15:32:20 2012, ANDYD wrote: Show quoted text
> Hence I think the getnameinfo function is working, but the /etc/hosts > file doesn't have the exact same structure as the test is expecting. > I don't know if the Solaris /etc/hosts file is strictly correct or not, > but it is what you get with a default install, so I don't think the > test suite ought to complain about it.
So, the test doesn't hardcode "localhost" but simply compares what getnameinfo() returns as compared the legacy gethostbyaddr() resolver on the same address: 24 # Probably "localhost" but we'd better ask the system to be sure 25 my $expect_host = gethostbyaddr( inet_aton( "127.0.0.1" ), AF_INET ); 26 defined $expect_host or $expect_host = "127.0.0.1"; 27 28 ( $err, $host, $service ) = getnameinfo( pack_sockaddr_in( 80, inet_aton( "127.0.0.1" ) ), NI_NUMERICSERV ); 29 cmp_ok( $err, "==", 0, '$err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICSERV' ); 30 31 is( $host, $expect_host, "\$host is $expect_host for NS" ); 32 is( $service, "80", '$service is 80 for NS' ); If these are differing on your host then that suggests the two functions actually have different behaviour. I'm not entirely sure what to suggest in this setup. About the only test that would be in any way more robust would be to resolve the address into some name, then check the name resolves forward to the right IP address again; or at least the IP address was somewhere in the list. Which is starting to feel like an even weaker yet more complex test. -- Paul Evans
On Thu May 17 11:12:17 2012, PEVANS wrote: Show quoted text
> I'm not entirely sure what to suggest in this setup. About the only > test that > would be in any way more robust would be to resolve the address into > some name, > then check the name resolves forward to the right IP address again; or > at least > the IP address was somewhere in the list. Which is starting to feel > like an even > weaker yet more complex test.
This test has been failing in my core smoke tests on Solaris since it was introduced (in two different VMs). A simple skip on Solaris would be an improvement. Tony
I see no promise of getaddrinfo() and gethostbyaddr() results agreeing in either the SUS/POSIX spec: http://pubs.opengroup.org/onlinepubs/009695399/functions/getaddrinfo.html or in the Linux http://linux.die.net/man/3/getaddrinfo or in the BSD http://www.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3 So I think the failing subtest might be just too optimistic/overspecifying, and should be sadly removed.
On Wed Jul 02 07:49:10 2014, JHI wrote: Show quoted text
> So I think the failing subtest might be just too > optimistic/overspecifying, and should be sadly removed.
:( That may end up being the only real option. It's a shame because I keep deleting more and more of the tests because they turn out not to be reliable. It's hard to come up with a test of a C-library wrapper function without effectively also testing that C library function itself. -- Paul Evans
Patch attached. -- Paul Evans
Subject: rt77248.patch
=== modified file 't/getnameinfo.t' --- t/getnameinfo.t 2013-10-28 00:49:08 +0000 +++ t/getnameinfo.t 2014-08-15 21:47:50 +0000 @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 14; +use Test::More tests => 12; use Socket qw(:addrinfo AF_INET pack_sockaddr_in inet_aton); @@ -21,26 +21,14 @@ is( $host, "127.0.0.1", '$host is undef for NIx_NOSERV' ); is( $service, undef, '$service is 80 for NS, NIx_NOSERV' ); -# Probably "localhost" but we'd better ask the system to be sure -my $expect_host = gethostbyaddr( inet_aton( "127.0.0.1" ), AF_INET ); -defined $expect_host or $expect_host = "127.0.0.1"; - ( $err, $host, $service ) = getnameinfo( pack_sockaddr_in( 80, inet_aton( "127.0.0.1" ) ), NI_NUMERICSERV ); cmp_ok( $err, "==", 0, '$err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICSERV' ); -is( $host, $expect_host, "\$host is $expect_host for NS" ); -is( $service, "80", '$service is 80 for NS' ); - -# Probably "www" but we'd better ask the system to be sure -my $flags = NI_NUMERICHOST; -my $expect_service = getservbyport( 80, "tcp" ); -unless( defined $expect_service ) { - $expect_service = "80"; - $flags |= NI_NUMERICSERV; # don't seem to have a service name -} - -( $err, $host, $service ) = getnameinfo( pack_sockaddr_in( 80, inet_aton( "127.0.0.1" ) ), $flags ); -cmp_ok( $err, "==", 0, '$err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICHOST[|NI_NUMERICSERV]' ); - -is( $host, "127.0.0.1", '$host is 127.0.0.1 for NH' ); -is( $service, $expect_service, "\$service is $expect_service for NH" ); +# We can't meaningfully compare '$host' with anything specific, all we can be +# sure is it's not empty +ok( length $host, '$host is nonzero length for NS' ); + +( $err, $host, $service ) = getnameinfo( pack_sockaddr_in( 80, inet_aton( "127.0.0.1" ) ), NI_NUMERICHOST ); +cmp_ok( $err, "==", 0, '$err == 0 for {family=AF_INET,port=80,sinaddr=127.0.0.1}/NI_NUMERICHOST' ); + +ok( length $service, '$service is nonzero length for NH' );
Released in 2.015 -- Paul Evans