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_ipv6_up_stress cleanup
73 epair_ipv6_up_stress_head()
75 atf_set "descr" "Simultaneously up and destroy an epair(4) with IPv6"
76 atf_set "require.user" "root"
78 epair_ipv6_up_stress_body()
80 do_up_stress "epair" "6" ""
82 epair_ipv6_up_stress_cleanup()
87 atf_test_case faith_stress cleanup
90 atf_set "descr" "Simultaneously create and destroy a faith(4)"
91 atf_set "require.user" "root"
97 faith_stress_cleanup()
102 atf_test_case faith_up_stress cleanup
103 faith_up_stress_head()
105 atf_set "descr" "Simultaneously up and destroy a faith(4)"
106 atf_set "require.user" "root"
108 faith_up_stress_body()
110 do_up_stress "faith" "" ""
112 faith_up_stress_cleanup()
117 atf_test_case faith_ipv6_up_stress cleanup
118 faith_ipv6_up_stress_head()
120 atf_set "descr" "Simultaneously up and destroy a faith(4) with IPv6"
121 atf_set "require.user" "root"
123 faith_ipv6_up_stress_body()
125 do_up_stress "faith" "6" ""
127 faith_ipv6_up_stress_cleanup()
132 atf_test_case gif_stress cleanup
135 atf_set "descr" "Simultaneously create and destroy a gif(4)"
136 atf_set "require.user" "root"
147 atf_test_case gif_up_stress cleanup
150 atf_set "descr" "Simultaneously up and destroy a gif(4)"
151 atf_set "require.user" "root"
155 do_up_stress "gif" "" "p2p"
157 gif_up_stress_cleanup()
162 atf_test_case gif_ipv6_up_stress cleanup
163 gif_ipv6_up_stress_head()
165 atf_set "descr" "Simultaneously up and destroy a gif(4) with IPv6"
166 atf_set "require.user" "root"
168 gif_ipv6_up_stress_body()
170 do_up_stress "gif" "6" "p2p"
172 gif_ipv6_up_stress_cleanup()
177 atf_test_case lo_stress cleanup
180 atf_set "descr" "Simultaneously create and destroy an lo(4)"
181 atf_set "require.user" "root"
192 atf_test_case lo_up_stress cleanup
195 atf_set "descr" "Simultaneously up and destroy an lo(4)"
196 atf_set "require.user" "root"
200 do_up_stress "lo" "" ""
202 lo_up_stress_cleanup()
207 atf_test_case lo_ipv6_up_stress cleanup
208 lo_ipv6_up_stress_head()
210 atf_set "descr" "Simultaneously up and destroy an lo(4) with IPv6"
211 atf_set "require.user" "root"
213 lo_ipv6_up_stress_body()
215 do_up_stress "lo" "6" ""
217 lo_ipv6_up_stress_cleanup()
222 atf_test_case tap_stress cleanup
225 atf_set "descr" "Simultaneously create and destroy a tap(4)"
226 atf_set "require.user" "root"
237 atf_test_case tap_up_stress cleanup
240 atf_set "descr" "Simultaneously up and destroy a tap(4)"
241 atf_set "require.user" "root"
245 do_up_stress "tap" "" ""
247 tap_up_stress_cleanup()
252 atf_test_case tap_ipv6_up_stress cleanup
253 tap_ipv6_up_stress_head()
255 atf_set "descr" "Simultaneously up and destroy a tap(4) with IPv6"
256 atf_set "require.user" "root"
258 tap_ipv6_up_stress_body()
260 atf_skip "Quickly panics: if_delmulti_locked: inconsistent ifp 0xfffff80150e44000"
261 do_up_stress "tap" "6" ""
263 tap_ipv6_up_stress_cleanup()
268 atf_test_case tun_stress cleanup
271 atf_set "descr" "Simultaneously create and destroy a tun(4)"
272 atf_set "require.user" "root"
283 atf_test_case tun_up_stress cleanup
286 atf_set "descr" "Simultaneously up and destroy a tun(4)"
287 atf_set "require.user" "root"
291 do_up_stress "tun" "" "p2p"
293 tun_up_stress_cleanup()
298 atf_test_case tun_ipv6_up_stress cleanup
299 tun_ipv6_up_stress_head()
301 atf_set "descr" "Simultaneously up and destroy a tun(4) with IPv6"
302 atf_set "require.user" "root"
304 tun_ipv6_up_stress_body()
306 do_up_stress "tun" "6" "p2p"
308 tun_ipv6_up_stress_cleanup()
313 atf_test_case vlan_stress cleanup
316 atf_set "descr" "Simultaneously create and destroy a vlan(4)"
317 atf_set "require.user" "root"
323 vlan_stress_cleanup()
328 atf_test_case vlan_up_stress cleanup
329 vlan_up_stress_head()
331 atf_set "descr" "Simultaneously up and destroy a vlan(4)"
332 atf_set "require.user" "root"
334 vlan_up_stress_body()
336 do_up_stress "vlan" "" ""
338 vlan_up_stress_cleanup()
343 atf_test_case vlan_ipv6_up_stress cleanup
344 vlan_ipv6_up_stress_head()
346 atf_set "descr" "Simultaneously up and destroy a vlan(4) with IPv6"
347 atf_set "require.user" "root"
349 vlan_ipv6_up_stress_body()
351 do_up_stress "vlan" "6" ""
353 vlan_ipv6_up_stress_cleanup()
358 atf_test_case vmnet_stress cleanup
361 atf_set "descr" "Simultaneously create and destroy a vmnet(4)"
362 atf_set "require.user" "root"
368 vmnet_stress_cleanup()
373 atf_test_case vmnet_up_stress cleanup
374 vmnet_up_stress_head()
376 atf_set "descr" "Simultaneously up and destroy a vmnet(4)"
377 atf_set "require.user" "root"
379 vmnet_up_stress_body()
381 do_up_stress "vmnet" "" ""
383 vmnet_up_stress_cleanup()
388 atf_test_case vmnet_ipv6_up_stress cleanup
389 vmnet_ipv6_up_stress_head()
391 atf_set "descr" "Simultaneously up and destroy a vmnet(4) with IPv6"
392 atf_set "require.user" "root"
394 vmnet_ipv6_up_stress_body()
396 do_up_stress "vmnet" "6" ""
398 vmnet_ipv6_up_stress_cleanup()
403 atf_init_test_cases()
405 atf_add_test_case epair_ipv6_up_stress
406 atf_add_test_case epair_stress
407 atf_add_test_case epair_up_stress
408 atf_add_test_case faith_ipv6_up_stress
409 atf_add_test_case faith_stress
410 atf_add_test_case faith_up_stress
411 atf_add_test_case gif_ipv6_up_stress
412 atf_add_test_case gif_stress
413 atf_add_test_case gif_up_stress
414 # Don't test lagg; it has its own test program
415 atf_add_test_case lo_ipv6_up_stress
416 atf_add_test_case lo_stress
417 atf_add_test_case lo_up_stress
418 atf_add_test_case tap_ipv6_up_stress
419 atf_add_test_case tap_stress
420 atf_add_test_case tap_up_stress
421 atf_add_test_case tun_ipv6_up_stress
422 atf_add_test_case tun_stress
423 atf_add_test_case tun_up_stress
424 atf_add_test_case vlan_ipv6_up_stress
425 atf_add_test_case vlan_stress
426 atf_add_test_case vlan_up_stress
427 atf_add_test_case vmnet_ipv6_up_stress
428 atf_add_test_case vmnet_stress
429 atf_add_test_case vmnet_up_stress
434 local IFACE CREATOR_PID DESTROYER_PID
438 # First thread: create the interface
440 ifconfig ${IFACE%a} create 2>/dev/null && \
441 echo -n . >> creator_count.txt
445 # Second thread: destroy the lagg
447 ifconfig $IFACE destroy 2>/dev/null && \
448 echo -n . >> destroyer_count.txt
455 echo "Created ${IFACE%a} `stat -f %z creator_count.txt` times."
456 echo "Destroyed it `stat -f %z destroyer_count.txt` times."
459 # Implement the up stress tests
461 # $1 Interface class, etc "lo" or "tap"
462 # $2 "6" to enable IPv6 auto address assignment, anything else otherwise
463 # $3 p2p for point to point interfaces, anything else for normal interfaces
466 local ADDR DSTADDR MASK MEAN_SLEEP_SECONDS MAX_SLEEP_USECS \
467 IFACE IPV6 P2P SRCDIR LOOP_PID ipv6_cmd up_cmd
469 # Configure the interface to use an RFC5737 nonrouteable addresses
473 # ifconfig takes about 10ms to run. To increase race coverage,
474 # randomly delay the two commands relative to each other by 5ms either
476 MEAN_SLEEP_SECONDS=.005
477 MAX_SLEEP_USECS=10000
483 SRCDIR=$( atf_get_srcdir )
484 if [ "$IPV6" = 6 ]; then
487 ipv6_cmd="ifconfig $IFACE inet6 ifdisabled"
489 if [ "$P2P" = "p2p" ]; then
490 up_cmd="ifconfig $IFACE up ${ADDR}/${MASK} ${DSTADDR}"
492 up_cmd="ifconfig $IFACE up ${ADDR}/${MASK}"
496 { sleep ${MEAN_SLEEP_SECONDS} && \
497 eval "$up_cmd" 2> /dev/null &&
498 echo -n . >> up_count.txt ; } &
499 { ${SRCDIR}/randsleep ${MAX_SLEEP_USECS} && \
500 ifconfig $IFACE destroy &&
501 echo -n . >> destroy_count.txt ; } &
503 ifconfig ${IFACE%a} create
509 echo "Upped ${IFACE} `stat -f %z up_count.txt` times."
510 echo "Destroyed it `stat -f %z destroy_count.txt` times."
513 # Creates a new cloned interface, registers it for cleanup, and echoes it
514 # params: $1 Interface class name (tap, gif, etc)
521 while ! ifconfig ${CLASS}${N} create > /dev/null 2>&1; do
522 if [ "$N" -ge 8 ]; then
523 atf_skip "Could not create a ${CLASS} interface"
528 if [ ${CLASS} = "epair" ]; then
533 # Record the device so we can clean it up later
534 echo ${DEV} >> "devices_to_cleanup"
543 for DEV in `cat "devices_to_cleanup"`; do
544 ifconfig ${DEV} destroy