1*640235e2SEnji Cooper# $NetBSD: t_ifconf.sh,v 1.3 2016/08/10 22:30:02 kre Exp $
2*640235e2SEnji Cooper#
3*640235e2SEnji Cooper# Copyright (c) 2014 The NetBSD Foundation, Inc.
4*640235e2SEnji Cooper# All rights reserved.
5*640235e2SEnji Cooper#
6*640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without
7*640235e2SEnji Cooper# modification, are permitted provided that the following conditions
8*640235e2SEnji Cooper# are met:
9*640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright
10*640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer.
11*640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright
12*640235e2SEnji Cooper#    notice, this list of conditions and the following disclaimer in the
13*640235e2SEnji Cooper#    documentation and/or other materials provided with the distribution.
14*640235e2SEnji Cooper#
15*640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16*640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17*640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18*640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19*640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20*640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21*640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22*640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23*640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24*640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25*640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE.
26*640235e2SEnji Cooper#
27*640235e2SEnji Cooper
28*640235e2SEnji CooperRUMP_SERVER1=unix://./r1
29*640235e2SEnji Cooper
30*640235e2SEnji CooperRUMP_FLAGS=\
31*640235e2SEnji Cooper"-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif -lrumpdev"
32*640235e2SEnji Cooper
33*640235e2SEnji Cooperatf_test_case basic cleanup
34*640235e2SEnji Cooperbasic_head()
35*640235e2SEnji Cooper{
36*640235e2SEnji Cooper
37*640235e2SEnji Cooper	atf_set "descr" "basic ifconf (SIOCGIFCONF) test"
38*640235e2SEnji Cooper	atf_set "require.progs" "rump_server"
39*640235e2SEnji Cooper}
40*640235e2SEnji Cooper
41*640235e2SEnji Cooperbasic_body()
42*640235e2SEnji Cooper{
43*640235e2SEnji Cooper	local ifconf="$(atf_get_srcdir)/ifconf"
44*640235e2SEnji Cooper
45*640235e2SEnji Cooper	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
46*640235e2SEnji Cooper
47*640235e2SEnji Cooper	export RUMP_SERVER=${RUMP_SERVER1}
48*640235e2SEnji Cooper	export LD_PRELOAD=/usr/lib/librumphijack.so
49*640235e2SEnji Cooper
50*640235e2SEnji Cooper	# lo0 (127.0.0.1 and link local)
51*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'^2$' "$ifconf" total
52*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'lo0' "$ifconf" list
53*640235e2SEnji Cooper
54*640235e2SEnji Cooper	# Add shmif0 (no address)
55*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 create
56*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'^3$' "$ifconf" total
57*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'shmif0' "$ifconf" list
58*640235e2SEnji Cooper
59*640235e2SEnji Cooper	# Add shmif1 (no address)
60*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif1 create
61*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'^4$' "$ifconf" total
62*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'shmif1' "$ifconf" list
63*640235e2SEnji Cooper
64*640235e2SEnji Cooper	# Add an address to shmif0
65*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 linkstr shmbus
66*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 192.168.0.1/24
67*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'^5$' "$ifconf" total
68*640235e2SEnji Cooper
69*640235e2SEnji Cooper	# Vary the number of requesting interfaces
70*640235e2SEnji Cooper	atf_check -s exit:0 -o match:1 -x "$ifconf list 1 | wc -l"
71*640235e2SEnji Cooper	atf_check -s exit:0 -o match:2 -x "$ifconf list 2 | wc -l"
72*640235e2SEnji Cooper	atf_check -s exit:0 -o match:3 -x "$ifconf list 3 | wc -l"
73*640235e2SEnji Cooper	atf_check -s exit:0 -o match:4 -x "$ifconf list 4 | wc -l"
74*640235e2SEnji Cooper	atf_check -s exit:0 -o match:5 -x "$ifconf list 5 | wc -l"
75*640235e2SEnji Cooper	atf_check -s exit:0 -o match:5 -x "$ifconf list 6 | wc -l"
76*640235e2SEnji Cooper
77*640235e2SEnji Cooper	# Check if removing an interface is reflected
78*640235e2SEnji Cooper	atf_check -s exit:0 rump.ifconfig shmif0 destroy
79*640235e2SEnji Cooper	atf_check -s exit:0 -o match:'^3$' "$ifconf" total
80*640235e2SEnji Cooper	atf_check -s exit:0 -o not-match:'shmif0' "$ifconf" list
81*640235e2SEnji Cooper	atf_check -s exit:0 -o match:1 -x "$ifconf list 1 | wc -l"
82*640235e2SEnji Cooper	atf_check -s exit:0 -o match:2 -x "$ifconf list 2 | wc -l"
83*640235e2SEnji Cooper	atf_check -s exit:0 -o match:3 -x "$ifconf list 3 | wc -l"
84*640235e2SEnji Cooper	atf_check -s exit:0 -o match:3 -x "$ifconf list 4 | wc -l"
85*640235e2SEnji Cooper
86*640235e2SEnji Cooper	unset LD_PRELOAD
87*640235e2SEnji Cooper	unset RUMP_SERVER
88*640235e2SEnji Cooper}
89*640235e2SEnji Cooper
90*640235e2SEnji Cooperbasic_cleanup()
91*640235e2SEnji Cooper{
92*640235e2SEnji Cooper
93*640235e2SEnji Cooper	RUMP_SERVER=${RUMP_SERVER1} rump.halt
94*640235e2SEnji Cooper}
95*640235e2SEnji Cooper
96*640235e2SEnji Cooperatf_init_test_cases()
97*640235e2SEnji Cooper{
98*640235e2SEnji Cooper
99*640235e2SEnji Cooper	atf_add_test_case basic
100*640235e2SEnji Cooper}
101