xref: /freebsd/contrib/netbsd-tests/net/mcast/t_mcast.sh (revision d370fd1cd8fc69e87dc63f4f4a82e5a8b4956c93)
1*cdebaff8SEnji Cooper#	$NetBSD: t_mcast.sh,v 1.4 2016/11/25 08:51:16 ozaki-r Exp $
2640235e2SEnji Cooper#
3640235e2SEnji Cooper# Copyright (c) 2015 The NetBSD Foundation, Inc.
4640235e2SEnji Cooper# All rights reserved.
5640235e2SEnji Cooper#
6640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without
7640235e2SEnji Cooper# modification, are permitted provided that the following conditions
8640235e2SEnji Cooper# are met:
9640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright
10640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer.
11640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
12640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
13640235e2SEnji Cooper#    documentation and/or other materials provided with the distribution.
14640235e2SEnji Cooper#
15640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
26640235e2SEnji Cooper#
27640235e2SEnji Cooper
28640235e2SEnji Cooperexport RUMP_SERVER=unix://commsock
29640235e2SEnji Cooper
30*cdebaff8SEnji CooperDEBUG=${DEBUG:-false}
31640235e2SEnji Cooper
32640235e2SEnji Cooperrun_test()
33640235e2SEnji Cooper{
34640235e2SEnji Cooper	local name="$1"
35640235e2SEnji Cooper	local opts="$2"
36640235e2SEnji Cooper	local mcast="$(atf_get_srcdir)/mcast"
37640235e2SEnji Cooper
38*cdebaff8SEnji Cooper	rump_server_start $RUMP_SERVER netinet6
39*cdebaff8SEnji Cooper	rump_server_add_iface $RUMP_SERVER shmif0 bus1
40640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.2/24
41640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 inet6 fc00::2/64
42640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 up
43640235e2SEnji Cooper
44640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig -w 10
45640235e2SEnji Cooper	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep -q tentative"
46640235e2SEnji Cooper
47640235e2SEnji Cooper	# A route to the mcast address is required to join the mcast group
48640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1
49640235e2SEnji Cooper	atf_check -s exit:0 -o ignore rump.route add -inet6 default fc00::1
50640235e2SEnji Cooper
51640235e2SEnji Cooper	$DEBUG && rump.ifconfig
52640235e2SEnji Cooper	$DEBUG && rump.netstat -nr
53640235e2SEnji Cooper
54640235e2SEnji Cooper	export LD_PRELOAD=/usr/lib/librumphijack.so
55640235e2SEnji Cooper	#$DEBUG && /usr/sbin/ifmcstat  # Not yet run on rump kernel
56640235e2SEnji Cooper	if $DEBUG; then
57640235e2SEnji Cooper		atf_check -s exit:0 -o ignore $mcast -d ${opts}
58640235e2SEnji Cooper	else
59640235e2SEnji Cooper		atf_check -s exit:0 $mcast ${opts}
60640235e2SEnji Cooper	fi
61640235e2SEnji Cooper	#$DEBUG && /usr/sbin/ifmcstat  # Not yet run on rump kernel
62640235e2SEnji Cooper	unset LD_PRELOAD
63640235e2SEnji Cooper}
64640235e2SEnji Cooper
65640235e2SEnji Cooperadd_test()
66640235e2SEnji Cooper{
67640235e2SEnji Cooper	local name=$1
68640235e2SEnji Cooper	local opts="$2"
69640235e2SEnji Cooper	local desc="$3"
70640235e2SEnji Cooper
71640235e2SEnji Cooper	atf_test_case "mcast_${name}" cleanup
72640235e2SEnji Cooper	eval "mcast_${name}_head() { \
73640235e2SEnji Cooper			atf_set \"descr\" \"${desc}\"; \
74640235e2SEnji Cooper			atf_set \"require.progs\" \"rump_server\"; \
75640235e2SEnji Cooper		}; \
76640235e2SEnji Cooper	    mcast_${name}_body() { \
77640235e2SEnji Cooper			run_test \"${name}\" \"${opts}\"; \
78*cdebaff8SEnji Cooper			rump_server_destroy_ifaces; \
79640235e2SEnji Cooper		}; \
80640235e2SEnji Cooper	    mcast_${name}_cleanup() { \
81*cdebaff8SEnji Cooper			${DEBUG} && dump; \
82*cdebaff8SEnji Cooper			cleanup; \
83640235e2SEnji Cooper		}"
84640235e2SEnji Cooper	atf_add_test_case "mcast_${name}"
85640235e2SEnji Cooper}
86640235e2SEnji Cooper
87640235e2SEnji Cooperatf_init_test_cases()
88640235e2SEnji Cooper{
89640235e2SEnji Cooper
90640235e2SEnji Cooper	add_test conninet4            "-c -4" \
91640235e2SEnji Cooper	    "Checks connected multicast for ipv4"
92640235e2SEnji Cooper	add_test connmappedinet4      "-c -m -4" \
93640235e2SEnji Cooper	    "Checks connected multicast for mapped ipv4"
94640235e2SEnji Cooper	add_test connmappedbuginet4   "-c -m -b -4" \
95640235e2SEnji Cooper	    "Checks connected multicast for mapped ipv4 using the v4 ioctls"
96640235e2SEnji Cooper	add_test conninet6            "-c -6" \
97640235e2SEnji Cooper	    "Checks connected multicast for ipv6"
98640235e2SEnji Cooper	add_test unconninet4          "-4" \
99640235e2SEnji Cooper	    "Checks unconnected multicast for ipv4"
100640235e2SEnji Cooper	add_test unconnmappedinet4    "-m -4" \
101640235e2SEnji Cooper	    "Checks unconnected multicast for mapped ipv4"
102640235e2SEnji Cooper	add_test unconnmappedbuginet4 "-m -b -4" \
103640235e2SEnji Cooper	    "Checks unconnected multicast for mapped ipv4 using the v4 ioctls"
104640235e2SEnji Cooper	add_test unconninet6          "-6" \
105640235e2SEnji Cooper	    "Checks unconnected multicast for ipv6"
106640235e2SEnji Cooper}
107