xref: /netbsd-src/tests/net/mcast/t_mcast.sh (revision 3f30ca4e9f4d8db1147cd69b679114b037c6e370)
1#	$NetBSD: t_mcast.sh,v 1.6 2017/08/03 03:16:27 ozaki-r Exp $
2#
3# Copyright (c) 2015 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28export RUMP_SERVER=unix://commsock
29
30DEBUG=${DEBUG:-false}
31
32run_test()
33{
34	local name="$1"
35	local opts="$2"
36	local mcast="$(atf_get_srcdir)/mcast"
37
38	rump_server_start $RUMP_SERVER netinet6
39	rump_server_add_iface $RUMP_SERVER shmif0 bus1
40	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.2/24
41	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2/64
42	atf_check -s exit:0 rump.ifconfig shmif0 up
43
44	atf_check -s exit:0 rump.ifconfig -w 10
45	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep -q tentative"
46
47	# A route to the mcast address is required to join the mcast group
48	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
49	atf_check -s exit:0 -o ignore rump.route add -inet6 default fc00::1
50
51	$DEBUG && rump.ifconfig
52	$DEBUG && rump.netstat -nr
53
54	export LD_PRELOAD=/usr/lib/librumphijack.so
55	#$DEBUG && /usr/sbin/ifmcstat  # Not yet run on rump kernel
56	if $DEBUG; then
57		atf_check -s exit:0 -o ignore $mcast -d ${opts}
58	else
59		atf_check -s exit:0 $mcast ${opts}
60	fi
61	#$DEBUG && /usr/sbin/ifmcstat  # Not yet run on rump kernel
62	unset LD_PRELOAD
63}
64
65run_test_destroyif()
66{
67	local name="$1"
68	local opts="$2"
69	local mcast="$(atf_get_srcdir)/mcast"
70	local sleep=3
71
72	rump_server_start $RUMP_SERVER netinet6
73	rump_server_add_iface $RUMP_SERVER shmif0 bus1
74	export RUMP_SERVER=$RUMP_SERVER
75	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.2/24
76	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2/64
77	atf_check -s exit:0 rump.ifconfig shmif0 up
78
79	atf_check -s exit:0 rump.ifconfig -w 10
80	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep -q tentative"
81
82	# A route to the mcast address is required to join the mcast group
83	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
84	atf_check -s exit:0 -o ignore rump.route add -inet6 default fc00::1
85
86	$DEBUG && rump.ifconfig
87	$DEBUG && rump.netstat -nr
88
89	export LD_PRELOAD=/usr/lib/librumphijack.so
90	#$DEBUG && /usr/sbin/ifmcstat  # Not yet run on rump kernel
91	if $DEBUG; then
92		$mcast -d ${opts} -s $sleep &
93	else
94		$mcast ${opts} -s $sleep &
95	fi
96	#$DEBUG && /usr/sbin/ifmcstat  # Not yet run on rump kernel
97	unset LD_PRELOAD
98
99	# Give a chance to setup mcast
100	sleep 1
101
102	# Try to destroy an interface that the mcast program is running on
103	atf_check -s exit:0 rump.ifconfig shmif0 destroy
104
105	wait
106	atf_check -s exit:0 -o ignore rump.ifconfig
107}
108
109add_test()
110{
111	local name=$1
112	local opts="$2"
113	local desc="$3"
114	local fulldesc=
115
116	fulldesc="Checks $desc"
117	atf_test_case "mcast_${name}" cleanup
118	eval "mcast_${name}_head() {
119			atf_set descr \"${fulldesc}\"
120			atf_set require.progs rump_server
121		}
122	    mcast_${name}_body() {
123			run_test ${name} \"${opts}\"
124			rump_server_destroy_ifaces
125		}
126	    mcast_${name}_cleanup() {
127			\${DEBUG} && dump
128			cleanup
129		}"
130	atf_add_test_case "mcast_${name}"
131
132	fulldesc="Destroying interface while testing ${desc}"
133	atf_test_case "mcast_destroyif_${name}" cleanup
134	eval "mcast_destroyif_${name}_head() {
135			atf_set descr \"${fulldesc}\"
136			atf_set require.progs rump_server
137		}
138	    mcast_destroyif_${name}_body() {
139			run_test_destroyif ${name} \"${opts}\"
140		}
141	    mcast_destroyif_${name}_cleanup() {
142			\${DEBUG} && dump
143			cleanup
144		}"
145	atf_add_test_case "mcast_destroyif_${name}"
146}
147
148atf_init_test_cases()
149{
150
151	add_test conninet4            "-c -4" \
152	    "connected multicast for ipv4"
153	add_test connmappedinet4      "-c -m -4" \
154	    "connected multicast for mapped ipv4"
155	add_test connmappedbuginet4   "-c -m -b -4" \
156	    "connected multicast for mapped ipv4 using the v4 ioctls"
157	add_test conninet6            "-c -6" \
158	    "connected multicast for ipv6"
159	add_test unconninet4          "-4" \
160	    "unconnected multicast for ipv4"
161	add_test unconnmappedinet4    "-m -4" \
162	    "unconnected multicast for mapped ipv4"
163	add_test unconnmappedbuginet4 "-m -b -4" \
164	    "unconnected multicast for mapped ipv4 using the v4 ioctls"
165	add_test unconninet6          "-6" \
166	    "unconnected multicast for ipv6"
167}
168