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