t_shmif.sh revision 1.1 1 # $NetBSD: t_shmif.sh,v 1.1 2024/08/20 08:20:19 ozaki-r Exp $
2 #
3 # Copyright (c) 2024 Internet Initiative Japan 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
28 RUMP_SERVER1=unix://./r1
29 RUMP_SERVER2=unix://./r2
30
31 TIMEOUT=3
32
33 atf_test_case shmif_linkstate cleanup
34 shmif_linkstate_head()
35 {
36 atf_set "descr" "tests of ifconfig media on shmif"
37 atf_set "require.progs" "rump_server"
38 }
39
40 shmif_linkstate_body()
41 {
42 local auto="Ethernet autoselect"
43 local none="Ethernet none"
44
45 rump_server_start $RUMP_SERVER1
46 rump_server_add_iface $RUMP_SERVER1 shmif0 bus1
47
48 export RUMP_SERVER=$RUMP_SERVER1
49 # After ifconfig linkstr, the state becomes UP
50 atf_check -o match:'linkstate: up' \
51 -o match:"media: $auto" \
52 -o not-match:"<UP" rump.ifconfig -v shmif0
53 atf_check rump.ifconfig shmif0 up
54 atf_check -o match:'linkstate: up' \
55 -o match:"media: $auto" \
56 -o match:"<UP" rump.ifconfig -v shmif0
57 # ifconfig media none makes the state DOWN
58 atf_check rump.ifconfig shmif0 media none
59 atf_check -o match:'linkstate: down' \
60 -o match:"media: $none" \
61 -o match:"<UP" rump.ifconfig -v shmif0
62 # ifconfig media auto makes the state UP
63 atf_check rump.ifconfig shmif0 media auto
64 atf_check -o match:'linkstate: up' \
65 -o match:"media: $auto" \
66 -o match:"<UP" rump.ifconfig -v shmif0
67 atf_check rump.ifconfig shmif0 down
68 atf_check -o match:'linkstate: up' \
69 -o match:"media: $auto" \
70 -o not-match:"<UP" rump.ifconfig -v shmif0
71 # After ifconfig -linkstr, the state becomes UNKNOWN
72 atf_check rump.ifconfig shmif0 -linkstr
73 atf_check -o match:'linkstate: unknown' \
74 -o match:"media: $auto" \
75 -o not-match:"<UP" rump.ifconfig -v shmif0
76
77 rump_server_destroy_ifaces
78 }
79
80 shmif_linkstate_cleanup()
81 {
82
83 $DEBUG && dump
84 cleanup
85 }
86
87 atf_test_case shmif_linkstate_down cleanup
88 shmif_linkstate_down_head()
89 {
90 atf_set "descr" "tests of behaviors of down shmif"
91 atf_set "require.progs" "rump_server"
92 }
93
94 shmif_linkstate_down_body()
95 {
96
97 rump_server_start $RUMP_SERVER1
98 rump_server_start $RUMP_SERVER2
99 rump_server_add_iface $RUMP_SERVER1 shmif0 bus1
100 rump_server_add_iface $RUMP_SERVER2 shmif0 bus1
101
102 export RUMP_SERVER=$RUMP_SERVER1
103 atf_check rump.sysctl -q -w net.inet.ip.dad_count=0
104 atf_check rump.ifconfig shmif0 10.0.0.1/24 up
105 export RUMP_SERVER=$RUMP_SERVER2
106 atf_check rump.sysctl -q -w net.inet.ip.dad_count=0
107 atf_check rump.ifconfig shmif0 10.0.0.2/24 up
108
109 export RUMP_SERVER=$RUMP_SERVER1
110 atf_check -o ignore rump.ping -c 1 -w $TIMEOUT 10.0.0.2
111
112 atf_check rump.ifconfig shmif0 media none
113 atf_check -o match:'linkstate: down' rump.ifconfig -v shmif0
114
115 # shmif doesn't send any packets on link down
116 atf_check -s not-exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT 10.0.0.2
117
118 atf_check rump.ifconfig shmif0 media auto
119 atf_check -o match:'linkstate: up' rump.ifconfig -v shmif0
120
121 atf_check -o ignore rump.ping -c 1 -w $TIMEOUT 10.0.0.2
122
123 rump_server_destroy_ifaces
124 }
125
126 shmif_linkstate_down_cleanup()
127 {
128
129 $DEBUG && dump
130 cleanup
131 }
132
133 atf_init_test_cases()
134 {
135
136 atf_add_test_case shmif_linkstate
137 atf_add_test_case shmif_linkstate_down
138 }
139