2 # Copyright 2014 Cynthia Rempel <cynthia@rtems.org>
4 # Brief: Some cursery coverage tests of ifconfig...
5 # Note: requires permissions to run modprobe and all ifconfig options
6 # Commands used: grep, grep -i, ip link, ip tuntap, wc -l
8 # Possible improvements:
9 # 1. Verify the dummy interface actually has the modified characteristics
10 # instead of relying on ifconfig output
11 # 2. Introduce more error cases, to verify ifconfig fails gracefully
12 # 3. Do more complex calls to ifconfig, while mixing the order of the
14 # 4. Cover more ifconfig options:
15 # hw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...)
16 # txqueuelen LEN - number of buffered packets before output blocks
17 # Obsolete fields included for historical purposes:
18 # irq|io_addr|mem_start ADDR - micromanage obsolete hardware
19 # outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring
20 # metric INTEGER - added to Linux 0.9.10 with comment "never used", still true
22 [ -f testing.sh ] && . testing.sh
24 if [ "$(id -u)" -ne 0 ]
26 echo "$SHOWSKIP: ifconfig (not root)"
31 #testing "name" "command" "result" "infile" "stdin"
33 # Add a dummy interface to test with
36 # Test Description: Disable the dummy0 interface
37 # Results Expected: After calling ifconfig, no lines with dummy0 are displayed
38 testing "dummy0 down and if config /-only" \
39 "ifconfig dummy0 down && ifconfig dummy0 | grep dummy | wc -l" \
42 # Test Description: Enable the dummy0 interface
43 # Results Expected: After calling ifconfig, one line with dummy0 is displayed
45 "ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" \
48 # Test Description: Set the ip address of the dummy0 interface
49 # Results Expected: After calling ifconfig dummy0, one line displays the ip
51 testing "dummy0 10.240.240.240" \
52 "ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
55 # Test Description: Change the netmask to the interface
56 # Results Expected: After calling ifconfig dummy0, one line displays the
58 testing "dummy0 netmask 255.255.240.0" \
59 "ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \
62 # Test Description: Change the broadcast address to the interface
63 # Results Expected: After calling ifconfig dummy0, one line displays the
64 # broadcast address selected
65 testing "dummy0 broadcast 10.240.240.255" \
66 "ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \
69 # Test Description: Revert to the default ip address
70 # Results Expected: After calling ifconfig dummy0, there are no lines
71 # displaying the ip address previously selected
72 testing "dummy0 default" \
73 "ifconfig dummy0 default && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
76 # Test Description: Change the Maximum transmission unit (MTU) of the interface
77 # Results Expected: After calling ifconfig dummy0, there is one line with the
79 testing "dummy0 mtu 1269" \
80 "ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \
83 # Test Description: Verify ifconfig add fails with such a small mtu
84 # Results Expected: There is one line of error message containing
85 # "No buffer space available"
86 testing "dummy0 add ::2 -- too small mtu" \
87 "ifconfig dummy0 add ::2 2>&1 | grep No\ buffer\ space\ available | wc -l" \
90 # Test Description: Change the Maximum transmission unit (MTU) of the interface
91 # Results Expected: After calling ifconfig dummy0, there is one line with the
93 testing "dummy0 mtu 2000" \
94 "ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \
97 # Test Description: Verify ifconfig add succeeds with a larger mtu
98 # Results Expected: after calling ifconfig dummy0, there is one line with the
100 testing "dummy0 add ::2" \
101 "ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2\/126 | wc -l" \
104 # Test Description: Verify ifconfig del removes the selected ip6 address
105 # Results Expected: after calling ifconfig dummy0, there are no lines with the
106 # selected ip address
107 testing "dummy0 del ::2" \
108 "ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2 | wc -l" \
111 # Test Description: Remove the noarp flag and bring the interface down in
112 # preparation for the next test
113 # Results Expected: After calling ifconfig dummy0, there are no lines with the
115 testing "dummy0 arp down" \
116 "ifconfig dummy0 arp down && ifconfig dummy0 | grep -i NOARP | wc -l" \
119 # Test Description: Call the pointtopoint option with no argument
120 # Results Expected: After calling ifconfig dummy0, there is one line with the
122 testing "dummy0 pointtopoint" \
123 "ifconfig dummy0 pointtopoint && ifconfig dummy0 | grep -i NOARP | grep -i UP | wc -l" \
126 # Test Description: Test the pointtopoint option and set the ipaddress
127 # Results Expected: After calling ifconfig dummy0, there is one line with the
128 # word inet and the selected ip address
129 testing "dummy0 pointtopoint 127.0.0.2" \
130 "ifconfig dummy0 pointtopoint 127.0.0.2 && ifconfig dummy0 | grep -i inet | grep -i 127\.0\.0\.2 | wc -l" \
133 ####### Flags you can set on an interface (or -remove by prefixing with -): ###############
135 # Test Description: Enable allmulti mode on the interface
136 # Results Expected: After calling ifconfig dummy0, there is one line with the
138 testing "dummy0 allmulti" \
139 "ifconfig dummy0 allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "1\n" \
142 # Test Description: Disable multicast mode the interface
143 # Results Expected: After calling ifconfig dummy0, there are no lines with the
145 testing "dummy0 -allmulti" \
146 "ifconfig dummy0 -allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "0\n" \
149 # Test Description: Disable NOARP mode on the interface
150 # Results Expected: After calling ifconfig dummy0, there are no lines with the
152 testing "dummy0 arp" \
153 "ifconfig dummy0 arp && ifconfig dummy0 | grep -i NOARP | wc -l" "0\n" \
156 # Test Description: Enable NOARP mode on the interface
157 # Results Expected: After calling ifconfig dummy0, there is one line with the
159 testing "dummy0 -arp" \
160 "ifconfig dummy0 -arp && ifconfig dummy0 | grep -i NOARP | wc -l" "1\n" \
163 # Test Description: Enable multicast mode on the interface
164 # Results Expected: After calling ifconfig dummy0, there is one line with the
166 testing "dummy0 multicast" \
167 "ifconfig dummy0 multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
170 # Test Description: Disable multicast mode the interface
171 # Results Expected: After calling ifconfig dummy0, there are no lines with the
173 testing "dummy0 -multicast" \
174 "ifconfig dummy0 -multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
177 # Test Description: Enable promiscuous mode the interface
178 # Results Expected: After calling ifconfig dummy0, there is one line with the
180 testing "dummy0 promisc" \
181 "ifconfig dummy0 promisc && ifconfig dummy0 | grep -i promisc | wc -l" "1\n" \
184 # Disable promiscuous mode the interface
185 # Results Expected: After calling ifconfig dummy0, there are no lines with the
187 testing "dummy0 -promisc" \
188 "ifconfig dummy0 -promisc && ifconfig dummy0 | grep -i promisc | wc -l" "0\n" \
191 # Disable the dummy interface