xref: /freebsd/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh (revision 9268022b74279434ed6300244e3f977e56a8ceb5)
1#	$NetBSD: t_getaddrinfo.sh,v 1.2 2011/06/15 07:54:32 jmmv Exp $
2
3#
4# Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project.
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15# 3. Neither the name of the project nor the names of its contributors
16#    may be used to endorse or promote products derived from this software
17#    without specific prior written permission.
18#
19# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22# ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29# SUCH DAMAGE.
30#
31
32check_output()
33{
34	if [ "$2" = "none" ] ; then
35		exp="${1}.exp"
36	elif [ "$2" = "hosts" ] ; then
37		# Determine if localhost has an IPv6 address or not
38		lcl=$( cat /etc/hosts					| \
39			 sed -e 's/#.*$//' -e 's/[ 	][ 	]*/ /g'	| \
40			 awk '/ localhost($| )/ {printf "%s ", $1}' )
41		if [ "${lcl%*::*}" = "${lcl}" ] ; then
42			exp="${1}_v4.exp"
43		else
44			exp="${1}_v4v6.exp"
45		fi
46	elif [ "$2" = "ifconfig" ] ; then
47		lcl=$( ifconfig lo0 | grep inet6 )
48		if [ -n "${lcl}" ] ; then
49			exp="${1}_v4v6.exp"
50		else
51			exp="${1}_v4.exp"
52		fi
53	else
54		atf_fail "Invalid family_match_type $2 requested."
55	fi
56
57	cmp  -s $(atf_get_srcdir)/data/${exp} out && return
58	diff -u $(atf_get_srcdir)/data/${exp} out && \
59	atf_fail "Actual output does not match expected output"
60}
61
62atf_test_case basic
63basic_head()
64{
65	atf_set "descr" "Testing basic ones"
66}
67basic_body()
68{
69	TEST=$(atf_get_srcdir)/h_gai
70
71	( $TEST ::1 http
72	  $TEST 127.0.0.1 http
73	  $TEST localhost http
74	  $TEST ::1 tftp
75	  $TEST 127.0.0.1 tftp
76	  $TEST localhost tftp
77	  $TEST ::1 echo
78	  $TEST 127.0.0.1 echo
79	  $TEST localhost echo ) > out 2>&1
80
81	check_output basics hosts
82}
83
84atf_test_case specific
85specific_head()
86{
87	atf_set "descr" "Testing specific address family"
88}
89specific_body()
90{
91	TEST=$(atf_get_srcdir)/h_gai
92
93	( $TEST -4 localhost http
94	  $TEST -6 localhost http ) > out 2>&1
95
96	check_output spec_fam hosts
97}
98
99atf_test_case empty_hostname
100empty_hostname_head()
101{
102	atf_set "descr" "Testing empty hostname"
103}
104empty_hostname_body()
105{
106	TEST=$(atf_get_srcdir)/h_gai
107
108	( $TEST '' http
109	  $TEST '' echo
110	  $TEST '' tftp
111	  $TEST '' 80
112	  $TEST -P '' http
113	  $TEST -P '' echo
114	  $TEST -P '' tftp
115	  $TEST -P '' 80
116	  $TEST -S '' 80
117	  $TEST -D '' 80 ) > out 2>&1
118
119	check_output no_host ifconfig
120}
121
122atf_test_case empty_servname
123empty_servname_head()
124{
125	atf_set "descr" "Testing empty service name"
126}
127empty_servname_body()
128{
129	TEST=$(atf_get_srcdir)/h_gai
130
131	( $TEST ::1 ''
132	  $TEST 127.0.0.1 ''
133	  $TEST localhost ''
134	  $TEST '' '' ) > out 2>&1
135
136	check_output no_serv hosts
137}
138
139atf_test_case sock_raw
140sock_raw_head()
141{
142	atf_set "descr" "Testing raw socket"
143}
144sock_raw_body()
145{
146	TEST=$(atf_get_srcdir)/h_gai
147
148	( $TEST -R -p 0 localhost ''
149	  $TEST -R -p 59 localhost ''
150	  $TEST -R -p 59 localhost 80
151	  $TEST -R -p 59 localhost www
152	  $TEST -R -p 59 ::1 '' ) > out 2>&1
153
154	check_output sock_raw hosts
155}
156
157atf_test_case unsupported_family
158unsupported_family_head()
159{
160	atf_set "descr" "Testing unsupported family"
161}
162unsupported_family_body()
163{
164	TEST=$(atf_get_srcdir)/h_gai
165
166	( $TEST -f 99 localhost '' ) > out 2>&1
167
168	check_output unsup_fam none
169}
170
171atf_test_case scopeaddr
172scopeaddr_head()
173{
174	atf_set "descr" "Testing scoped address format"
175}
176scopeaddr_body()
177{
178	TEST=$(atf_get_srcdir)/h_gai
179
180	( $TEST fe80::1%lo0 http
181#	  IF=`ifconfig -a | grep -v '^	' | \
182#		sed -e 's/:.*//' | head -1 | awk '{print $1}'`
183#	  $TEST fe80::1%$IF http
184	) > out 2>&1
185
186	check_output scoped none
187}
188
189atf_init_test_cases()
190{
191	atf_add_test_case basic
192	atf_add_test_case specific
193	atf_add_test_case empty_hostname
194	atf_add_test_case empty_servname
195	atf_add_test_case sock_raw
196	atf_add_test_case unsupported_family
197	atf_add_test_case scopeaddr
198}
199