]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/net/if_clone_test.sh
MFV r361936:
[FreeBSD/FreeBSD.git] / tests / sys / net / if_clone_test.sh
1 #
2 #  Copyright (c) 2014 Spectra Logic Corporation
3 #  All rights reserved.
4 #
5 #  Redistribution and use in source and binary forms, with or without
6 #  modification, are permitted provided that the following conditions
7 #  are met:
8 #  1. Redistributions of source code must retain the above copyright
9 #     notice, this list of conditions, and the following disclaimer,
10 #     without modification.
11 #  2. Redistributions in binary form must reproduce at minimum a disclaimer
12 #     substantially similar to the "NO WARRANTY" disclaimer below
13 #     ("Disclaimer") and any redistribution must be conditioned upon
14 #     including a substantially similar Disclaimer requirement for further
15 #     binary redistribution.
16 #
17 #  NO WARRANTY
18 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 #  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 #  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 #  HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 #  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 #  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 #  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 #  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 #  IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 #  POSSIBILITY OF SUCH DAMAGES.
29 #
30 #  Authors: Alan Somers         (Spectra Logic Corporation)
31 #
32 # $FreeBSD$
33
34 # Outline:
35 # For each cloned interface type, do three tests
36 # 1) Create and destroy it
37 # 2) Create, up, and destroy it
38 # 3) Create, disable IPv6 auto address assignment, up, and destroy it
39
40 TESTLEN=10      # seconds
41
42 atf_test_case epair_stress cleanup
43 epair_stress_head()
44 {
45         atf_set "descr" "Simultaneously create and destroy an epair(4)"
46         atf_set "require.user" "root"
47 }
48 epair_stress_body()
49 {
50         if [ "$(atf_config_get ci false)" = "true" ]; then
51                 atf_skip "https://bugs.freebsd.org/246443"
52         fi
53         do_stress "epair"
54 }
55 epair_stress_cleanup()
56 {
57         cleanup_ifaces
58 }
59
60 atf_test_case epair_up_stress cleanup
61 epair_up_stress_head()
62 {
63         atf_set "descr" "Simultaneously up and detroy an epair(4)"
64         atf_set "require.user" "root"
65 }
66 epair_up_stress_body()
67 {
68         do_up_stress "epair" "" ""
69 }
70 epair_up_stress_cleanup()
71 {
72         cleanup_ifaces
73 }
74
75 atf_test_case epair_ipv6_up_stress cleanup
76 epair_ipv6_up_stress_head()
77 {
78         atf_set "descr" "Simultaneously up and destroy an epair(4) with IPv6"
79         atf_set "require.user" "root"
80 }
81 epair_ipv6_up_stress_body()
82 {
83         atf_skip "Quickly panics: page fault in in6_unlink_ifa (PR 225438)"
84         do_up_stress "epair" "6" ""
85 }
86 epair_ipv6_up_stress_cleanup()
87 {
88         cleanup_ifaces
89 }
90
91 atf_test_case faith_stress cleanup
92 faith_stress_head()
93 {
94         atf_set "descr" "Simultaneously create and destroy a faith(4)"
95         atf_set "require.user" "root"
96 }
97 faith_stress_body()
98 {
99         do_stress "faith"
100 }
101 faith_stress_cleanup()
102 {
103         cleanup_ifaces
104 }
105
106 atf_test_case faith_up_stress cleanup
107 faith_up_stress_head()
108 {
109         atf_set "descr" "Simultaneously up and destroy a faith(4)"
110         atf_set "require.user" "root"
111 }
112 faith_up_stress_body()
113 {
114         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
115         do_up_stress "faith" "" ""
116 }
117 faith_up_stress_cleanup()
118 {
119         cleanup_ifaces
120 }
121
122 atf_test_case faith_ipv6_up_stress cleanup
123 faith_ipv6_up_stress_head()
124 {
125         atf_set "descr" "Simultaneously up and destroy a faith(4) with IPv6"
126         atf_set "require.user" "root"
127 }
128 faith_ipv6_up_stress_body()
129 {
130         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
131         do_up_stress "faith" "6" ""
132 }
133 faith_ipv6_up_stress_cleanup()
134 {
135         cleanup_ifaces
136 }
137
138 atf_test_case gif_stress cleanup
139 gif_stress_head()
140 {
141         atf_set "descr" "Simultaneously create and destroy a gif(4)"
142         atf_set "require.user" "root"
143 }
144 gif_stress_body()
145 {
146         do_stress "gif"
147 }
148 gif_stress_cleanup()
149 {
150         cleanup_ifaces
151 }
152
153 atf_test_case gif_up_stress cleanup
154 gif_up_stress_head()
155 {
156         atf_set "descr" "Simultaneously up and destroy a gif(4)"
157         atf_set "require.user" "root"
158 }
159 gif_up_stress_body()
160 {
161         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
162         do_up_stress "gif" "" "p2p"
163 }
164 gif_up_stress_cleanup()
165 {
166         cleanup_ifaces
167 }
168
169 atf_test_case gif_ipv6_up_stress cleanup
170 gif_ipv6_up_stress_head()
171 {
172         atf_set "descr" "Simultaneously up and destroy a gif(4) with IPv6"
173         atf_set "require.user" "root"
174 }
175 gif_ipv6_up_stress_body()
176 {
177         atf_skip "Quickly panics: rt_tables_get_rnh_ptr: fam out of bounds."
178         do_up_stress "gif" "6" "p2p"
179 }
180 gif_ipv6_up_stress_cleanup()
181 {
182         cleanup_ifaces
183 }
184
185 atf_test_case lo_stress cleanup
186 lo_stress_head()
187 {
188         atf_set "descr" "Simultaneously create and destroy an lo(4)"
189         atf_set "require.user" "root"
190 }
191 lo_stress_body()
192 {
193         do_stress "lo"
194 }
195 lo_stress_cleanup()
196 {
197         cleanup_ifaces
198 }
199
200 atf_test_case lo_up_stress cleanup
201 lo_up_stress_head()
202 {
203         atf_set "descr" "Simultaneously up and destroy an lo(4)"
204         atf_set "require.user" "root"
205 }
206 lo_up_stress_body()
207 {
208         atf_skip "Quickly panics: GPF in rtsock_routemsg"
209         do_up_stress "lo" "" ""
210 }
211 lo_up_stress_cleanup()
212 {
213         cleanup_ifaces
214 }
215
216 atf_test_case lo_ipv6_up_stress cleanup
217 lo_ipv6_up_stress_head()
218 {
219         atf_set "descr" "Simultaneously up and destroy an lo(4) with IPv6"
220         atf_set "require.user" "root"
221 }
222 lo_ipv6_up_stress_body()
223 {
224         atf_skip "Quickly panics: page fault in rtsock_addrmsg"
225         do_up_stress "lo" "6" ""
226 }
227 lo_ipv6_up_stress_cleanup()
228 {
229         cleanup_ifaces
230 }
231
232 atf_test_case tap_stress cleanup
233 tap_stress_head()
234 {
235         atf_set "descr" "Simultaneously create and destroy a tap(4)"
236         atf_set "require.user" "root"
237 }
238 tap_stress_body()
239 {
240         do_stress "tap"
241 }
242 tap_stress_cleanup()
243 {
244         cleanup_ifaces
245 }
246
247 atf_test_case tap_up_stress cleanup
248 tap_up_stress_head()
249 {
250         atf_set "descr" "Simultaneously up and destroy a tap(4)"
251         atf_set "require.user" "root"
252 }
253 tap_up_stress_body()
254 {
255         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
256         do_up_stress "tap" "" ""
257 }
258 tap_up_stress_cleanup()
259 {
260         cleanup_ifaces
261 }
262
263 atf_test_case tap_ipv6_up_stress cleanup
264 tap_ipv6_up_stress_head()
265 {
266         atf_set "descr" "Simultaneously up and destroy a tap(4) with IPv6"
267         atf_set "require.user" "root"
268 }
269 tap_ipv6_up_stress_body()
270 {
271         atf_skip "Quickly panics: if_delmulti_locked: inconsistent ifp 0xfffff80150e44000"
272         do_up_stress "tap" "6" ""
273 }
274 tap_ipv6_up_stress_cleanup()
275 {
276         cleanup_ifaces
277 }
278
279 atf_test_case tun_stress cleanup
280 tun_stress_head()
281 {
282         atf_set "descr" "Simultaneously create and destroy a tun(4)"
283         atf_set "require.user" "root"
284 }
285 tun_stress_body()
286 {
287         do_stress "tun"
288 }
289 tun_stress_cleanup()
290 {
291         cleanup_ifaces
292 }
293
294 atf_test_case tun_up_stress cleanup
295 tun_up_stress_head()
296 {
297         atf_set "descr" "Simultaneously up and destroy a tun(4)"
298         atf_set "require.user" "root"
299 }
300 tun_up_stress_body()
301 {
302         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
303         do_up_stress "tun" "" "p2p"
304 }
305 tun_up_stress_cleanup()
306 {
307         cleanup_ifaces
308 }
309
310 atf_test_case tun_ipv6_up_stress cleanup
311 tun_ipv6_up_stress_head()
312 {
313         atf_set "descr" "Simultaneously up and destroy a tun(4) with IPv6"
314         atf_set "require.user" "root"
315 }
316 tun_ipv6_up_stress_body()
317 {
318         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
319         do_up_stress "tun" "6" "p2p"
320 }
321 tun_ipv6_up_stress_cleanup()
322 {
323         cleanup_ifaces
324 }
325
326 atf_test_case vlan_stress cleanup
327 vlan_stress_head()
328 {
329         atf_set "descr" "Simultaneously create and destroy a vlan(4)"
330         atf_set "require.user" "root"
331 }
332 vlan_stress_body()
333 {
334         do_stress "vlan"
335 }
336 vlan_stress_cleanup()
337 {
338         cleanup_ifaces
339 }
340
341 atf_test_case vlan_up_stress cleanup
342 vlan_up_stress_head()
343 {
344         atf_set "descr" "Simultaneously up and destroy a vlan(4)"
345         atf_set "require.user" "root"
346 }
347 vlan_up_stress_body()
348 {
349         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
350         do_up_stress "vlan" "" ""
351 }
352 vlan_up_stress_cleanup()
353 {
354         cleanup_ifaces
355 }
356
357 atf_test_case vlan_ipv6_up_stress cleanup
358 vlan_ipv6_up_stress_head()
359 {
360         atf_set "descr" "Simultaneously up and destroy a vlan(4) with IPv6"
361         atf_set "require.user" "root"
362 }
363 vlan_ipv6_up_stress_body()
364 {
365         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
366         do_up_stress "vlan" "6" ""
367 }
368 vlan_ipv6_up_stress_cleanup()
369 {
370         cleanup_ifaces
371 }
372
373 atf_test_case vmnet_stress cleanup
374 vmnet_stress_head()
375 {
376         atf_set "descr" "Simultaneously create and destroy a vmnet(4)"
377         atf_set "require.user" "root"
378 }
379 vmnet_stress_body()
380 {
381         do_stress "vmnet"
382 }
383 vmnet_stress_cleanup()
384 {
385         cleanup_ifaces
386 }
387
388 atf_test_case vmnet_up_stress cleanup
389 vmnet_up_stress_head()
390 {
391         atf_set "descr" "Simultaneously up and destroy a vmnet(4)"
392         atf_set "require.user" "root"
393 }
394 vmnet_up_stress_body()
395 {
396         do_up_stress "vmnet" "" ""
397 }
398 vmnet_up_stress_cleanup()
399 {
400         cleanup_ifaces
401 }
402
403 atf_test_case vmnet_ipv6_up_stress cleanup
404 vmnet_ipv6_up_stress_head()
405 {
406         atf_set "descr" "Simultaneously up and destroy a vmnet(4) with IPv6"
407         atf_set "require.user" "root"
408 }
409 vmnet_ipv6_up_stress_body()
410 {
411         atf_skip "Quickly panics: if_freemulti: protospec not NULL"
412         do_up_stress "vmnet" "6" ""
413 }
414 vmnet_ipv6_up_stress_cleanup()
415 {
416         cleanup_ifaces
417 }
418
419 atf_init_test_cases()
420 {
421         atf_add_test_case epair_ipv6_up_stress
422         atf_add_test_case epair_stress
423         atf_add_test_case epair_up_stress
424         atf_add_test_case faith_ipv6_up_stress
425         atf_add_test_case faith_stress
426         atf_add_test_case faith_up_stress
427         atf_add_test_case gif_ipv6_up_stress
428         atf_add_test_case gif_stress
429         atf_add_test_case gif_up_stress
430         # Don't test lagg; it has its own test program
431         atf_add_test_case lo_ipv6_up_stress
432         atf_add_test_case lo_stress
433         atf_add_test_case lo_up_stress
434         atf_add_test_case tap_ipv6_up_stress
435         atf_add_test_case tap_stress
436         atf_add_test_case tap_up_stress
437         atf_add_test_case tun_ipv6_up_stress
438         atf_add_test_case tun_stress
439         atf_add_test_case tun_up_stress
440         atf_add_test_case vlan_ipv6_up_stress
441         atf_add_test_case vlan_stress
442         atf_add_test_case vlan_up_stress
443         atf_add_test_case vmnet_ipv6_up_stress
444         atf_add_test_case vmnet_stress
445         atf_add_test_case vmnet_up_stress
446 }
447
448 do_stress()
449 {
450         local IFACE CREATOR_PID DESTROYER_PID
451
452         IFACE=`get_iface $1`
453
454         # First thread: create the interface
455         while true; do
456                 ifconfig ${IFACE%a} create 2>/dev/null && \
457                         echo -n . >> creator_count.txt
458         done &
459         CREATOR_PID=$!
460
461         # Second thread: destroy the lagg
462         while true; do
463                 ifconfig $IFACE destroy 2>/dev/null && \
464                         echo -n . >> destroyer_count.txt
465         done &
466         DESTROYER_PID=$!
467
468         sleep ${TESTLEN}
469         kill $CREATOR_PID
470         kill $DESTROYER_PID
471         echo "Created ${IFACE%a} `stat -f %z creator_count.txt` times."
472         echo "Destroyed it `stat -f %z destroyer_count.txt` times."
473 }
474
475 # Implement the up stress tests
476 # Parameters
477 # $1    Interface class, etc "lo" or "tap"
478 # $2    "6" to enable IPv6 auto address assignment, anything else otherwise
479 # $3    p2p for point to point interfaces, anything else for normal interfaces
480 do_up_stress()
481 {
482         local ADDR DSTADDR MASK MEAN_SLEEP_SECONDS MAX_SLEEP_USECS \
483             IFACE IPV6 P2P SRCDIR LOOP_PID ipv6_cmd up_cmd
484
485         # Configure the interface to use an RFC5737 nonrouteable addresses
486         ADDR="192.0.2.2"
487         DSTADDR="192.0.2.3"
488         MASK="24"
489         # ifconfig takes about 10ms to run.  To increase race coverage,
490         # randomly delay the two commands relative to each other by 5ms either
491         # way.
492         MEAN_SLEEP_SECONDS=.005
493         MAX_SLEEP_USECS=10000
494
495         IFACE=`get_iface $1`
496         IPV6=$2
497         P2P=$3
498
499         SRCDIR=$( atf_get_srcdir )
500         if [ "$IPV6" = 6 ]; then
501                 ipv6_cmd="true"
502         else
503                 ipv6_cmd="ifconfig $IFACE inet6 ifdisabled"
504         fi
505         if [ "$P2P" = "p2p" ]; then
506                 up_cmd="ifconfig $IFACE up ${ADDR}/${MASK} ${DSTADDR}"
507         else
508                 up_cmd="ifconfig $IFACE up ${ADDR}/${MASK}"
509         fi
510         while true; do
511                 eval "$ipv6_cmd"
512                 { sleep ${MEAN_SLEEP_SECONDS} && \
513                         eval "$up_cmd" 2> /dev/null &&
514                         echo -n . >> up_count.txt ; } &
515                 { ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
516                         ifconfig $IFACE destroy &&
517                         echo -n . >> destroy_count.txt ; } &
518                 wait
519                 ifconfig ${IFACE%a} create
520         done &
521         LOOP_PID=$!
522
523         sleep ${TESTLEN}
524         kill $LOOP_PID
525         echo "Upped ${IFACE} `stat -f %z up_count.txt` times."
526         echo "Destroyed it `stat -f %z destroy_count.txt` times."
527 }
528
529 # Creates a new cloned interface, registers it for cleanup, and echoes it
530 # params: $1    Interface class name (tap, gif, etc)
531 get_iface()
532 {
533         local CLASS DEV N
534
535         CLASS=$1
536         N=0
537         while ! ifconfig ${CLASS}${N} create > /dev/null 2>&1; do
538                 if [ "$N" -ge 8 ]; then
539                         atf_skip "Could not create a ${CLASS} interface"
540                 else
541                         N=$(($N + 1))
542                 fi
543         done
544         if [ ${CLASS} = "epair" ]; then
545                 DEV=${CLASS}${N}a
546         else
547                 DEV=${CLASS}${N}
548         fi
549         # Record the device so we can clean it up later
550         echo ${DEV} >> "devices_to_cleanup"
551         echo ${DEV}
552 }
553
554
555 cleanup_ifaces()
556 {
557         local DEV
558
559         for DEV in `cat "devices_to_cleanup"`; do
560                 ifconfig ${DEV} destroy
561         done
562         true
563 }