aboutsummaryrefslogtreecommitdiff
path: root/tests/ifconfig.test
blob: 34b84b735d2ddcbfa3693db9c3a35514335063fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# Copyright 2014 Cynthia Rempel <cynthia@rtems.org>
#
# Brief: Some cursery coverage tests of ifconfig...
# Note: requires permissions to run modprobe and all ifconfig options
# Commands used: grep, grep -i, ip link, ip tuntap, wc -l
#
# Possible improvements:
# 1. Verify the dummy interface actually has the modified characteristics
#    instead of relying on ifconfig output
# 2. Introduce more error cases, to verify ifconfig fails gracefully
# 3. Do more complex calls to ifconfig, while mixing the order of the
#    arguments
# 4. Cover more ifconfig options:
#    hw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...)
#    txqueuelen LEN - number of buffered packets before output blocks
#    Obsolete fields included for historical purposes:
#    irq|io_addr|mem_start ADDR - micromanage obsolete hardware
#    outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring
#    metric INTEGER - added to Linux 0.9.10 with comment "never used", still true

[ -f testing.sh ] && . testing.sh

if [ "$(id -u)" -ne 0 ]
then
  echo "$SHOWSKIP: ifconfig (not root)"
  return 2>/dev/null
  exit
fi

#testing "name" "command" "result" "infile" "stdin"

# Add a dummy interface to test with
modprobe dummy 2>/dev/null
if ! ifconfig dummy0 up 2>/dev/null
then
  echo "$SHOWSKIP: ifconfig dummy0 up failed"
fi

# Test Description: Disable the dummy0 interface
# Results Expected: After calling ifconfig, no lines with dummy0 are displayed
testing "dummy0 down and if config /-only" \
"ifconfig dummy0 down && ifconfig | grep dummy | wc -l" \
"0\n" "" ""

# Test Description: Enable the dummy0 interface
# Results Expected: After calling ifconfig, one line with dummy0 is displayed
testing "dummy0 up" \
"ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" \
"1\n" "" ""

# Test Description: Set the ip address of the dummy0 interface
# Results Expected: After calling ifconfig dummy0, one line displays the ip
#                   address selected
testing "dummy0 10.240.240.240" \
"ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
"1\n" "" ""

# Test Description: Change the netmask to the interface
# Results Expected: After calling ifconfig dummy0, one line displays the
#                   netmask selected
testing "dummy0 netmask 255.255.240.0" \
"ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \
"1\n" "" ""

# Test Description: Change the broadcast address to the interface
# Results Expected: After calling ifconfig dummy0, one line displays the
#                   broadcast address selected
testing "dummy0 broadcast 10.240.240.255" \
"ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \
"1\n" "" ""

# Test Description: Revert to the default ip address
# Results Expected: After calling ifconfig dummy0, there are no lines
#                   displaying the ip address previously selected
testing "dummy0 default" \
"ifconfig dummy0 default && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
"0\n" "" ""

# Test Description: Change the Maximum transmission unit (MTU) of the interface
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   selected MTU
testing "dummy0 mtu 1269" \
"ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \
"1\n" "" ""

# Test Description: Verify ifconfig add fails with such a small mtu
# Results Expected: There is one line of error message containing
#                   "No buffer space available"
testing "dummy0 add ::2 -- too small mtu" \
"ifconfig dummy0 add ::2 2>&1 | grep No\ buffer\ space\ available | wc -l" \
"1\n" "" ""

# Test Description: Change the Maximum transmission unit (MTU) of the interface
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   selected MTU
testing "dummy0 mtu 2000" \
"ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \
"1\n" "" ""

# Test Description: Verify ifconfig add succeeds with a larger mtu
# Results Expected: after calling ifconfig dummy0, there is one line with the
#                   selected ip address
testing "dummy0 add ::2" \
"ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2\/126 | wc -l" \
"1\n" "" ""

# Test Description: Verify ifconfig del removes the selected ip6 address
# Results Expected: after calling ifconfig dummy0, there are no lines with the
#                   selected ip address
testing "dummy0 del ::2" \
"ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2 | wc -l" \
"0\n" "" ""

# Test Description: Remove the noarp flag and bring the interface down in
#                   preparation for the next test
# Results Expected: After calling ifconfig dummy0, there are no lines with the
#                   NOARP flag
testing "dummy0 arp down" \
"ifconfig dummy0 arp down && ifconfig dummy0 | grep -i NOARP | wc -l" \
"0\n" "" ""

# Test Description: Call the pointopoint option with no argument
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   NOARP and UP flags
testing "dummy0 pointopoint" \
"ifconfig dummy0 pointopoint && ifconfig dummy0 | grep -i NOARP | grep -i UP | wc -l" \
"1\n" "" ""

# Test Description: Test the pointopoint option and set the ipaddress
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   word inet and the selected ip address
testing "dummy0 pointopoint 127.0.0.2" \
"ifconfig dummy0 pointopoint 127.0.0.2 && ifconfig dummy0 | grep -i inet | grep -i 127\.0\.0\.2 | wc -l" \
"1\n" "" ""

####### Flags you can set on an interface (or -remove by prefixing with -): ###############

# Test Description: Enable allmulti mode on the interface
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   allmulti flag
testing "dummy0 allmulti" \
"ifconfig dummy0 allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "1\n" \
"" ""

# Test Description: Disable multicast mode the interface
# Results Expected: After calling ifconfig dummy0, there are no lines with the
#                   allmulti flag
testing "dummy0 -allmulti" \
"ifconfig dummy0 -allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "0\n" \
"" ""

# Test Description: Disable NOARP mode on the interface
# Results Expected: After calling ifconfig dummy0, there are no lines with the
#                   NOARP flag
testing "dummy0 arp" \
"ifconfig dummy0 arp && ifconfig dummy0 | grep -i NOARP | wc -l" "0\n" \
"" ""

# Test Description: Enable NOARP mode on the interface
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   NOARP flag
testing "dummy0 -arp" \
"ifconfig dummy0 -arp && ifconfig dummy0 | grep -i NOARP | wc -l" "1\n" \
"" ""

# Test Description: Enable multicast mode on the interface
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   multicast flag
testing "dummy0 multicast" \
"ifconfig dummy0 multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
"1\n" "" ""

# Test Description: Disable multicast mode the interface
# Results Expected: After calling ifconfig dummy0, there are no lines with the
#                   multicast flag
testing "dummy0 -multicast" \
"ifconfig dummy0 -multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
"0\n" "" ""

# Test Description: Enable promiscuous mode the interface
# Results Expected: After calling ifconfig dummy0, there is one line with the
#                   promisc flag
testing "dummy0 promisc" \
"ifconfig dummy0 promisc && ifconfig dummy0 | grep -i promisc | wc -l" "1\n" \
"" ""

# Disable promiscuous mode the interface
# Results Expected: After calling ifconfig dummy0, there are no lines with the
#                   promisc flag
testing "dummy0 -promisc" \
"ifconfig dummy0 -promisc && ifconfig dummy0 | grep -i promisc | wc -l" "0\n" \
"" ""

# Disable the dummy interface
ifconfig dummy0 down