2 # Copyright (c) 2014 Spectra Logic Corporation
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
30 # Authors: Alan Somers (Spectra Logic Corporation)
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
42 atf_test_case epair_stress cleanup
45 atf_set "descr" "Simultaneously create and destroy an epair(4)"
46 atf_set "require.user" "root"
52 epair_stress_cleanup()
57 atf_test_case epair_up_stress cleanup
58 epair_up_stress_head()
60 atf_set "descr" "Simultaneously up and detroy an epair(4)"
61 atf_set "require.user" "root"
63 epair_up_stress_body()
65 do_up_stress "epair" "" ""
67 epair_up_stress_cleanup()
72 atf_test_case epair_destroy_race cleanup
73 epair_destroy_race_head()
75 atf_set "descr" "Race if_detach() and if_vmove()"
76 atf_set "require.user" "root"
78 epair_destroy_race_body()
82 epair_a=$(ifconfig epair create)
83 echo $epair_a >> devices_to_cleanup
86 jail -c vnet name="epair_destroy" nopersist path=/ \
87 host.hostname="epair_destroy" vnet.interface="$epair_b" \
88 command=sh -c "ifconfig $epair_b 192.0.2.1/24; sleep 0.1"&
90 ifconfig "$epair_a" destroy
95 epair_destroy_race_cleanup()
100 atf_test_case epair_ipv6_up_stress cleanup
101 epair_ipv6_up_stress_head()
103 atf_set "descr" "Simultaneously up and destroy an epair(4) with IPv6"
104 atf_set "require.user" "root"
106 epair_ipv6_up_stress_body()
108 do_up_stress "epair" "6" ""
110 epair_ipv6_up_stress_cleanup()
115 atf_test_case faith_stress cleanup
118 atf_set "descr" "Simultaneously create and destroy a faith(4)"
119 atf_set "require.user" "root"
125 faith_stress_cleanup()
130 atf_test_case faith_up_stress cleanup
131 faith_up_stress_head()
133 atf_set "descr" "Simultaneously up and destroy a faith(4)"
134 atf_set "require.user" "root"
136 faith_up_stress_body()
138 do_up_stress "faith" "" ""
140 faith_up_stress_cleanup()
145 atf_test_case faith_ipv6_up_stress cleanup
146 faith_ipv6_up_stress_head()
148 atf_set "descr" "Simultaneously up and destroy a faith(4) with IPv6"
149 atf_set "require.user" "root"
151 faith_ipv6_up_stress_body()
153 do_up_stress "faith" "6" ""
155 faith_ipv6_up_stress_cleanup()
160 atf_test_case gif_stress cleanup
163 atf_set "descr" "Simultaneously create and destroy a gif(4)"
164 atf_set "require.user" "root"
175 atf_test_case gif_up_stress cleanup
178 atf_set "descr" "Simultaneously up and destroy a gif(4)"
179 atf_set "require.user" "root"
183 do_up_stress "gif" "" "p2p"
185 gif_up_stress_cleanup()
190 atf_test_case gif_ipv6_up_stress cleanup
191 gif_ipv6_up_stress_head()
193 atf_set "descr" "Simultaneously up and destroy a gif(4) with IPv6"
194 atf_set "require.user" "root"
196 gif_ipv6_up_stress_body()
198 do_up_stress "gif" "6" "p2p"
200 gif_ipv6_up_stress_cleanup()
205 atf_test_case lo_stress cleanup
208 atf_set "descr" "Simultaneously create and destroy an lo(4)"
209 atf_set "require.user" "root"
220 atf_test_case lo_up_stress cleanup
223 atf_set "descr" "Simultaneously up and destroy an lo(4)"
224 atf_set "require.user" "root"
228 do_up_stress "lo" "" ""
230 lo_up_stress_cleanup()
235 atf_test_case lo_ipv6_up_stress cleanup
236 lo_ipv6_up_stress_head()
238 atf_set "descr" "Simultaneously up and destroy an lo(4) with IPv6"
239 atf_set "require.user" "root"
241 lo_ipv6_up_stress_body()
243 do_up_stress "lo" "6" ""
245 lo_ipv6_up_stress_cleanup()
250 atf_test_case tap_stress cleanup
253 atf_set "descr" "Simultaneously create and destroy a tap(4)"
254 atf_set "require.user" "root"
265 atf_test_case tap_up_stress cleanup
268 atf_set "descr" "Simultaneously up and destroy a tap(4)"
269 atf_set "require.user" "root"
273 do_up_stress "tap" "" ""
275 tap_up_stress_cleanup()
280 atf_test_case tap_ipv6_up_stress cleanup
281 tap_ipv6_up_stress_head()
283 atf_set "descr" "Simultaneously up and destroy a tap(4) with IPv6"
284 atf_set "require.user" "root"
286 tap_ipv6_up_stress_body()
288 atf_skip "Quickly panics: if_delmulti_locked: inconsistent ifp 0xfffff80150e44000"
289 do_up_stress "tap" "6" ""
291 tap_ipv6_up_stress_cleanup()
296 atf_test_case tun_stress cleanup
299 atf_set "descr" "Simultaneously create and destroy a tun(4)"
300 atf_set "require.user" "root"
311 atf_test_case tun_up_stress cleanup
314 atf_set "descr" "Simultaneously up and destroy a tun(4)"
315 atf_set "require.user" "root"
319 do_up_stress "tun" "" "p2p"
321 tun_up_stress_cleanup()
326 atf_test_case tun_ipv6_up_stress cleanup
327 tun_ipv6_up_stress_head()
329 atf_set "descr" "Simultaneously up and destroy a tun(4) with IPv6"
330 atf_set "require.user" "root"
332 tun_ipv6_up_stress_body()
334 do_up_stress "tun" "6" "p2p"
336 tun_ipv6_up_stress_cleanup()
341 atf_test_case vlan_stress cleanup
344 atf_set "descr" "Simultaneously create and destroy a vlan(4)"
345 atf_set "require.user" "root"
351 vlan_stress_cleanup()
356 atf_test_case vlan_up_stress cleanup
357 vlan_up_stress_head()
359 atf_set "descr" "Simultaneously up and destroy a vlan(4)"
360 atf_set "require.user" "root"
362 vlan_up_stress_body()
364 do_up_stress "vlan" "" ""
366 vlan_up_stress_cleanup()
371 atf_test_case vlan_ipv6_up_stress cleanup
372 vlan_ipv6_up_stress_head()
374 atf_set "descr" "Simultaneously up and destroy a vlan(4) with IPv6"
375 atf_set "require.user" "root"
377 vlan_ipv6_up_stress_body()
379 do_up_stress "vlan" "6" ""
381 vlan_ipv6_up_stress_cleanup()
386 atf_test_case vmnet_stress cleanup
389 atf_set "descr" "Simultaneously create and destroy a vmnet(4)"
390 atf_set "require.user" "root"
396 vmnet_stress_cleanup()
401 atf_test_case vmnet_up_stress cleanup
402 vmnet_up_stress_head()
404 atf_set "descr" "Simultaneously up and destroy a vmnet(4)"
405 atf_set "require.user" "root"
407 vmnet_up_stress_body()
409 do_up_stress "vmnet" "" ""
411 vmnet_up_stress_cleanup()
416 atf_test_case vmnet_ipv6_up_stress cleanup
417 vmnet_ipv6_up_stress_head()
419 atf_set "descr" "Simultaneously up and destroy a vmnet(4) with IPv6"
420 atf_set "require.user" "root"
422 vmnet_ipv6_up_stress_body()
424 do_up_stress "vmnet" "6" ""
426 vmnet_ipv6_up_stress_cleanup()
431 atf_init_test_cases()
433 atf_add_test_case epair_ipv6_up_stress
434 atf_add_test_case epair_stress
435 atf_add_test_case epair_up_stress
436 atf_add_test_case epair_destroy_race
437 atf_add_test_case faith_ipv6_up_stress
438 atf_add_test_case faith_stress
439 atf_add_test_case faith_up_stress
440 atf_add_test_case gif_ipv6_up_stress
441 atf_add_test_case gif_stress
442 atf_add_test_case gif_up_stress
443 # Don't test lagg; it has its own test program
444 atf_add_test_case lo_ipv6_up_stress
445 atf_add_test_case lo_stress
446 atf_add_test_case lo_up_stress
447 atf_add_test_case tap_ipv6_up_stress
448 atf_add_test_case tap_stress
449 atf_add_test_case tap_up_stress
450 atf_add_test_case tun_ipv6_up_stress
451 atf_add_test_case tun_stress
452 atf_add_test_case tun_up_stress
453 atf_add_test_case vlan_ipv6_up_stress
454 atf_add_test_case vlan_stress
455 atf_add_test_case vlan_up_stress
456 atf_add_test_case vmnet_ipv6_up_stress
457 atf_add_test_case vmnet_stress
458 atf_add_test_case vmnet_up_stress
463 local IFACE CREATOR_PID DESTROYER_PID
467 # First thread: create the interface
469 ifconfig ${IFACE%a} create 2>/dev/null && \
470 echo -n . >> creator_count.txt
474 # Second thread: destroy the lagg
476 ifconfig $IFACE destroy 2>/dev/null && \
477 echo -n . >> destroyer_count.txt
484 echo "Created ${IFACE%a} `stat -f %z creator_count.txt` times."
485 echo "Destroyed it `stat -f %z destroyer_count.txt` times."
488 # Implement the up stress tests
490 # $1 Interface class, etc "lo" or "tap"
491 # $2 "6" to enable IPv6 auto address assignment, anything else otherwise
492 # $3 p2p for point to point interfaces, anything else for normal interfaces
495 local ADDR DSTADDR MASK MEAN_SLEEP_SECONDS MAX_SLEEP_USECS \
496 IFACE IPV6 P2P SRCDIR LOOP_PID ipv6_cmd up_cmd
498 # Configure the interface to use an RFC5737 nonrouteable addresses
502 # ifconfig takes about 10ms to run. To increase race coverage,
503 # randomly delay the two commands relative to each other by 5ms either
505 MEAN_SLEEP_SECONDS=.005
506 MAX_SLEEP_USECS=10000
512 SRCDIR=$( atf_get_srcdir )
513 if [ "$IPV6" = 6 ]; then
516 ipv6_cmd="ifconfig $IFACE inet6 ifdisabled"
518 if [ "$P2P" = "p2p" ]; then
519 up_cmd="ifconfig $IFACE up ${ADDR}/${MASK} ${DSTADDR}"
521 up_cmd="ifconfig $IFACE up ${ADDR}/${MASK}"
525 { sleep ${MEAN_SLEEP_SECONDS} && \
526 eval "$up_cmd" 2> /dev/null &&
527 echo -n . >> up_count.txt ; } &
528 { ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
529 ifconfig $IFACE destroy &&
530 echo -n . >> destroy_count.txt ; } &
532 ifconfig ${IFACE%a} create
538 echo "Upped ${IFACE} `stat -f %z up_count.txt` times."
539 echo "Destroyed it `stat -f %z destroy_count.txt` times."
542 # Creates a new cloned interface, registers it for cleanup, and echoes it
543 # params: $1 Interface class name (tap, gif, etc)
550 while ! ifconfig ${CLASS}${N} create > /dev/null 2>&1; do
551 if [ "$N" -ge 8 ]; then
552 atf_skip "Could not create a ${CLASS} interface"
557 if [ ${CLASS} = "epair" ]; then
562 # Record the device so we can clean it up later
563 echo ${DEV} >> "devices_to_cleanup"
572 for DEV in `cat "devices_to_cleanup"`; do
573 ifconfig ${DEV} destroy