Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# OVS kernel module self tests
5
6trap ovs_exit_sig EXIT TERM INT ERR
7
8# Kselftest framework requirement - SKIP code is 4.
9ksft_skip=4
10
11PAUSE_ON_FAIL=no
12VERBOSE=0
13TRACING=0
14
15tests="
16 arp_ping eth-arp: Basic arp ping between two NS
17 ct_connect_v4 ip4-ct-xon: Basic ipv4 tcp connection using ct
18 connect_v4 ip4-xon: Basic ipv4 ping between two NS
19 nat_connect_v4 ip4-nat-xon: Basic ipv4 tcp connection via NAT
20 netlink_checks ovsnl: validate netlink attrs and settings
21 upcall_interfaces ovs: test the upcall interfaces
22 drop_reason drop: test drop reasons are emitted"
23
24info() {
25 [ $VERBOSE = 0 ] || echo $*
26}
27
28ovs_base=`pwd`
29sbxs=
30sbx_add () {
31 info "adding sandbox '$1'"
32
33 sbxs="$sbxs $1"
34
35 NO_BIN=0
36
37 # Create sandbox.
38 local d="$ovs_base"/$1
39 if [ -e $d ]; then
40 info "removing $d"
41 rm -rf "$d"
42 fi
43 mkdir "$d" || return 1
44 ovs_setenv $1
45}
46
47ovs_exit_sig() {
48 [ -e ${ovs_dir}/cleanup ] && . "$ovs_dir/cleanup"
49}
50
51on_exit() {
52 echo "$1" > ${ovs_dir}/cleanup.tmp
53 cat ${ovs_dir}/cleanup >> ${ovs_dir}/cleanup.tmp
54 mv ${ovs_dir}/cleanup.tmp ${ovs_dir}/cleanup
55}
56
57ovs_setenv() {
58 sandbox=$1
59
60 ovs_dir=$ovs_base${1:+/$1}; export ovs_dir
61
62 test -e ${ovs_dir}/cleanup || : > ${ovs_dir}/cleanup
63}
64
65ovs_sbx() {
66 if test "X$2" != X; then
67 (ovs_setenv $1; shift; "$@" >> ${ovs_dir}/debug.log)
68 else
69 ovs_setenv $1
70 fi
71}
72
73ovs_add_dp () {
74 info "Adding DP/Bridge IF: sbx:$1 dp:$2 {$3, $4, $5}"
75 sbxname="$1"
76 shift
77 ovs_sbx "$sbxname" python3 $ovs_base/ovs-dpctl.py add-dp $*
78 on_exit "ovs_sbx $sbxname python3 $ovs_base/ovs-dpctl.py del-dp $1;"
79}
80
81ovs_add_if () {
82 info "Adding IF to DP: br:$2 if:$3"
83 if [ "$4" != "-u" ]; then
84 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if "$2" "$3" \
85 || return 1
86 else
87 python3 $ovs_base/ovs-dpctl.py add-if \
88 -u "$2" "$3" >$ovs_dir/$3.out 2>$ovs_dir/$3.err &
89 pid=$!
90 on_exit "ovs_sbx $1 kill -TERM $pid 2>/dev/null"
91 fi
92}
93
94ovs_del_if () {
95 info "Deleting IF from DP: br:$2 if:$3"
96 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-if "$2" "$3" || return 1
97}
98
99ovs_netns_spawn_daemon() {
100 sbx=$1
101 shift
102 netns=$1
103 shift
104 info "spawning cmd: $*"
105 ip netns exec $netns $* >> $ovs_dir/stdout 2>> $ovs_dir/stderr &
106 pid=$!
107 ovs_sbx "$sbx" on_exit "kill -TERM $pid 2>/dev/null"
108}
109
110ovs_add_netns_and_veths () {
111 info "Adding netns attached: sbx:$1 dp:$2 {$3, $4, $5}"
112 ovs_sbx "$1" ip netns add "$3" || return 1
113 on_exit "ovs_sbx $1 ip netns del $3"
114 ovs_sbx "$1" ip link add "$4" type veth peer name "$5" || return 1
115 on_exit "ovs_sbx $1 ip link del $4 >/dev/null 2>&1"
116 ovs_sbx "$1" ip link set "$4" up || return 1
117 ovs_sbx "$1" ip link set "$5" netns "$3" || return 1
118 ovs_sbx "$1" ip netns exec "$3" ip link set "$5" up || return 1
119
120 if [ "$6" != "" ]; then
121 ovs_sbx "$1" ip netns exec "$3" ip addr add "$6" dev "$5" \
122 || return 1
123 fi
124
125 if [ "$7" != "-u" ]; then
126 ovs_add_if "$1" "$2" "$4" || return 1
127 else
128 ovs_add_if "$1" "$2" "$4" -u || return 1
129 fi
130
131 [ $TRACING -eq 1 ] && ovs_netns_spawn_daemon "$1" "$ns" \
132 tcpdump -i any -s 65535
133
134 return 0
135}
136
137ovs_add_flow () {
138 info "Adding flow to DP: sbx:$1 br:$2 flow:$3 act:$4"
139 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-flow "$2" "$3" "$4"
140 if [ $? -ne 0 ]; then
141 echo "Flow [ $3 : $4 ] failed" >> ${ovs_dir}/debug.log
142 return 1
143 fi
144 return 0
145}
146
147ovs_del_flows () {
148 info "Deleting all flows from DP: sbx:$1 br:$2"
149 ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py del-flows "$2"
150 return 0
151}
152
153ovs_drop_record_and_run () {
154 local sbx=$1
155 shift
156
157 perf record -a -q -e skb:kfree_skb -o ${ovs_dir}/perf.data $* \
158 >> ${ovs_dir}/stdout 2>> ${ovs_dir}/stderr
159 return $?
160}
161
162ovs_drop_reason_count()
163{
164 local reason=$1
165
166 local perf_output=`perf script -i ${ovs_dir}/perf.data -F trace:event,trace`
167 local pattern="skb:kfree_skb:.*reason: $reason"
168
169 return `echo "$perf_output" | grep "$pattern" | wc -l`
170}
171
172usage() {
173 echo
174 echo "$0 [OPTIONS] [TEST]..."
175 echo "If no TEST argument is given, all tests will be run."
176 echo
177 echo "Options"
178 echo " -t: capture traffic via tcpdump"
179 echo " -v: verbose"
180 echo " -p: pause on failure"
181 echo
182 echo "Available tests${tests}"
183 exit 1
184}
185
186# drop_reason test
187# - drop packets and verify the right drop reason is reported
188test_drop_reason() {
189 which perf >/dev/null 2>&1 || return $ksft_skip
190
191 sbx_add "test_drop_reason" || return $?
192
193 ovs_add_dp "test_drop_reason" dropreason || return 1
194
195 info "create namespaces"
196 for ns in client server; do
197 ovs_add_netns_and_veths "test_drop_reason" "dropreason" "$ns" \
198 "${ns:0:1}0" "${ns:0:1}1" || return 1
199 done
200
201 # Setup client namespace
202 ip netns exec client ip addr add 172.31.110.10/24 dev c1
203 ip netns exec client ip link set c1 up
204
205 # Setup server namespace
206 ip netns exec server ip addr add 172.31.110.20/24 dev s1
207 ip netns exec server ip link set s1 up
208
209 # Check if drop reasons can be sent
210 ovs_add_flow "test_drop_reason" dropreason \
211 'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(10)' 2>/dev/null
212 if [ $? == 1 ]; then
213 info "no support for drop reasons - skipping"
214 ovs_exit_sig
215 return $ksft_skip
216 fi
217
218 ovs_del_flows "test_drop_reason" dropreason
219
220 # Allow ARP
221 ovs_add_flow "test_drop_reason" dropreason \
222 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
223 ovs_add_flow "test_drop_reason" dropreason \
224 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
225
226 # Allow client ICMP traffic but drop return path
227 ovs_add_flow "test_drop_reason" dropreason \
228 "in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10,proto=1),icmp()" '2'
229 ovs_add_flow "test_drop_reason" dropreason \
230 "in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20,proto=1),icmp()" 'drop'
231
232 ovs_drop_record_and_run "test_drop_reason" ip netns exec client ping -c 2 172.31.110.20
233 ovs_drop_reason_count 0x30001 # OVS_DROP_FLOW_ACTION
234 if [[ "$?" -ne "2" ]]; then
235 info "Did not detect expected drops: $?"
236 return 1
237 fi
238
239 # Drop UDP 6000 traffic with an explicit action and an error code.
240 ovs_add_flow "test_drop_reason" dropreason \
241 "in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10,proto=17),udp(dst=6000)" \
242 'drop(42)'
243 # Drop UDP 7000 traffic with an explicit action with no error code.
244 ovs_add_flow "test_drop_reason" dropreason \
245 "in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10,proto=17),udp(dst=7000)" \
246 'drop(0)'
247
248 ovs_drop_record_and_run \
249 "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 6000
250 ovs_drop_reason_count 0x30004 # OVS_DROP_EXPLICIT_ACTION_ERROR
251 if [[ "$?" -ne "1" ]]; then
252 info "Did not detect expected explicit error drops: $?"
253 return 1
254 fi
255
256 ovs_drop_record_and_run \
257 "test_drop_reason" ip netns exec client nc -i 1 -zuv 172.31.110.20 7000
258 ovs_drop_reason_count 0x30003 # OVS_DROP_EXPLICIT_ACTION
259 if [[ "$?" -ne "1" ]]; then
260 info "Did not detect expected explicit drops: $?"
261 return 1
262 fi
263
264 return 0
265}
266
267# arp_ping test
268# - client has 1500 byte MTU
269# - server has 1500 byte MTU
270# - send ARP ping between two ns
271test_arp_ping () {
272
273 which arping >/dev/null 2>&1 || return $ksft_skip
274
275 sbx_add "test_arp_ping" || return $?
276
277 ovs_add_dp "test_arp_ping" arpping || return 1
278
279 info "create namespaces"
280 for ns in client server; do
281 ovs_add_netns_and_veths "test_arp_ping" "arpping" "$ns" \
282 "${ns:0:1}0" "${ns:0:1}1" || return 1
283 done
284
285 # Setup client namespace
286 ip netns exec client ip addr add 172.31.110.10/24 dev c1
287 ip netns exec client ip link set c1 up
288 HW_CLIENT=`ip netns exec client ip link show dev c1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
289 info "Client hwaddr: $HW_CLIENT"
290
291 # Setup server namespace
292 ip netns exec server ip addr add 172.31.110.20/24 dev s1
293 ip netns exec server ip link set s1 up
294 HW_SERVER=`ip netns exec server ip link show dev s1 | grep -E 'link/ether [0-9a-f:]+' | awk '{print $2;}'`
295 info "Server hwaddr: $HW_SERVER"
296
297 ovs_add_flow "test_arp_ping" arpping \
298 "in_port(1),eth(),eth_type(0x0806),arp(sip=172.31.110.10,tip=172.31.110.20,sha=$HW_CLIENT,tha=ff:ff:ff:ff:ff:ff)" '2' || return 1
299 ovs_add_flow "test_arp_ping" arpping \
300 "in_port(2),eth(),eth_type(0x0806),arp()" '1' || return 1
301
302 ovs_sbx "test_arp_ping" ip netns exec client arping -I c1 172.31.110.20 -c 1 || return 1
303
304 return 0
305}
306
307# ct_connect_v4 test
308# - client has 1500 byte MTU
309# - server has 1500 byte MTU
310# - use ICMP to ping in each direction
311# - only allow CT state stuff to pass through new in c -> s
312test_ct_connect_v4 () {
313
314 which nc >/dev/null 2>/dev/null || return $ksft_skip
315
316 sbx_add "test_ct_connect_v4" || return $?
317
318 ovs_add_dp "test_ct_connect_v4" ct4 || return 1
319 info "create namespaces"
320 for ns in client server; do
321 ovs_add_netns_and_veths "test_ct_connect_v4" "ct4" "$ns" \
322 "${ns:0:1}0" "${ns:0:1}1" || return 1
323 done
324
325 ip netns exec client ip addr add 172.31.110.10/24 dev c1
326 ip netns exec client ip link set c1 up
327 ip netns exec server ip addr add 172.31.110.20/24 dev s1
328 ip netns exec server ip link set s1 up
329
330 # Add forwarding for ARP and ip packets - completely wildcarded
331 ovs_add_flow "test_ct_connect_v4" ct4 \
332 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
333 ovs_add_flow "test_ct_connect_v4" ct4 \
334 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
335 ovs_add_flow "test_ct_connect_v4" ct4 \
336 'ct_state(-trk),eth(),eth_type(0x0800),ipv4()' \
337 'ct(commit),recirc(0x1)' || return 1
338 ovs_add_flow "test_ct_connect_v4" ct4 \
339 'recirc_id(0x1),ct_state(+trk+new),in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10)' \
340 '2' || return 1
341 ovs_add_flow "test_ct_connect_v4" ct4 \
342 'recirc_id(0x1),ct_state(+trk+est),in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10)' \
343 '2' || return 1
344 ovs_add_flow "test_ct_connect_v4" ct4 \
345 'recirc_id(0x1),ct_state(+trk+est),in_port(2),eth(),eth_type(0x0800),ipv4(dst=172.31.110.10)' \
346 '1' || return 1
347 ovs_add_flow "test_ct_connect_v4" ct4 \
348 'recirc_id(0x1),ct_state(+trk+inv),eth(),eth_type(0x0800),ipv4()' 'drop' || \
349 return 1
350
351 # do a ping
352 ovs_sbx "test_ct_connect_v4" ip netns exec client ping 172.31.110.20 -c 3 || return 1
353
354 # create an echo server in 'server'
355 echo "server" | \
356 ovs_netns_spawn_daemon "test_ct_connect_v4" "server" \
357 nc -lvnp 4443
358 ovs_sbx "test_ct_connect_v4" ip netns exec client nc -i 1 -zv 172.31.110.20 4443 || return 1
359
360 # Now test in the other direction (should fail)
361 echo "client" | \
362 ovs_netns_spawn_daemon "test_ct_connect_v4" "client" \
363 nc -lvnp 4443
364 ovs_sbx "test_ct_connect_v4" ip netns exec client nc -i 1 -zv 172.31.110.10 4443
365 if [ $? == 0 ]; then
366 info "ct connect to client was successful"
367 return 1
368 fi
369
370 info "done..."
371 return 0
372}
373
374# connect_v4 test
375# - client has 1500 byte MTU
376# - server has 1500 byte MTU
377# - use ICMP to ping in each direction
378test_connect_v4 () {
379
380 sbx_add "test_connect_v4" || return $?
381
382 ovs_add_dp "test_connect_v4" cv4 || return 1
383
384 info "create namespaces"
385 for ns in client server; do
386 ovs_add_netns_and_veths "test_connect_v4" "cv4" "$ns" \
387 "${ns:0:1}0" "${ns:0:1}1" || return 1
388 done
389
390
391 ip netns exec client ip addr add 172.31.110.10/24 dev c1
392 ip netns exec client ip link set c1 up
393 ip netns exec server ip addr add 172.31.110.20/24 dev s1
394 ip netns exec server ip link set s1 up
395
396 # Add forwarding for ARP and ip packets - completely wildcarded
397 ovs_add_flow "test_connect_v4" cv4 \
398 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
399 ovs_add_flow "test_connect_v4" cv4 \
400 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
401 ovs_add_flow "test_connect_v4" cv4 \
402 'in_port(1),eth(),eth_type(0x0800),ipv4(src=172.31.110.10)' '2' || return 1
403 ovs_add_flow "test_connect_v4" cv4 \
404 'in_port(2),eth(),eth_type(0x0800),ipv4(src=172.31.110.20)' '1' || return 1
405
406 # do a ping
407 ovs_sbx "test_connect_v4" ip netns exec client ping 172.31.110.20 -c 3 || return 1
408
409 info "done..."
410 return 0
411}
412
413# nat_connect_v4 test
414# - client has 1500 byte MTU
415# - server has 1500 byte MTU
416# - use ICMP to ping in each direction
417# - only allow CT state stuff to pass through new in c -> s
418test_nat_connect_v4 () {
419 which nc >/dev/null 2>/dev/null || return $ksft_skip
420
421 sbx_add "test_nat_connect_v4" || return $?
422
423 ovs_add_dp "test_nat_connect_v4" nat4 || return 1
424 info "create namespaces"
425 for ns in client server; do
426 ovs_add_netns_and_veths "test_nat_connect_v4" "nat4" "$ns" \
427 "${ns:0:1}0" "${ns:0:1}1" || return 1
428 done
429
430 ip netns exec client ip addr add 172.31.110.10/24 dev c1
431 ip netns exec client ip link set c1 up
432 ip netns exec server ip addr add 172.31.110.20/24 dev s1
433 ip netns exec server ip link set s1 up
434
435 ip netns exec client ip route add default via 172.31.110.20
436
437 ovs_add_flow "test_nat_connect_v4" nat4 \
438 'in_port(1),eth(),eth_type(0x0806),arp()' '2' || return 1
439 ovs_add_flow "test_nat_connect_v4" nat4 \
440 'in_port(2),eth(),eth_type(0x0806),arp()' '1' || return 1
441 ovs_add_flow "test_nat_connect_v4" nat4 \
442 "ct_state(-trk),in_port(1),eth(),eth_type(0x0800),ipv4(dst=192.168.0.20)" \
443 "ct(commit,nat(dst=172.31.110.20)),recirc(0x1)"
444 ovs_add_flow "test_nat_connect_v4" nat4 \
445 "ct_state(-trk),in_port(2),eth(),eth_type(0x0800),ipv4()" \
446 "ct(commit,nat),recirc(0x2)"
447
448 ovs_add_flow "test_nat_connect_v4" nat4 \
449 "recirc_id(0x1),ct_state(+trk-inv),in_port(1),eth(),eth_type(0x0800),ipv4()" "2"
450 ovs_add_flow "test_nat_connect_v4" nat4 \
451 "recirc_id(0x2),ct_state(+trk-inv),in_port(2),eth(),eth_type(0x0800),ipv4()" "1"
452
453 # do a ping
454 ovs_sbx "test_nat_connect_v4" ip netns exec client ping 192.168.0.20 -c 3 || return 1
455
456 # create an echo server in 'server'
457 echo "server" | \
458 ovs_netns_spawn_daemon "test_nat_connect_v4" "server" \
459 nc -lvnp 4443
460 ovs_sbx "test_nat_connect_v4" ip netns exec client nc -i 1 -zv 192.168.0.20 4443 || return 1
461
462 # Now test in the other direction (should fail)
463 echo "client" | \
464 ovs_netns_spawn_daemon "test_nat_connect_v4" "client" \
465 nc -lvnp 4443
466 ovs_sbx "test_nat_connect_v4" ip netns exec client nc -i 1 -zv 172.31.110.10 4443
467 if [ $? == 0 ]; then
468 info "connect to client was successful"
469 return 1
470 fi
471
472 info "done..."
473 return 0
474}
475
476# netlink_validation
477# - Create a dp
478# - check no warning with "old version" simulation
479test_netlink_checks () {
480 sbx_add "test_netlink_checks" || return 1
481
482 info "setting up new DP"
483 ovs_add_dp "test_netlink_checks" nv0 || return 1
484 # now try again
485 PRE_TEST=$(dmesg | grep -E "RIP: [0-9a-fA-Fx]+:ovs_dp_cmd_new\+")
486 ovs_add_dp "test_netlink_checks" nv0 -V 0 || return 1
487 POST_TEST=$(dmesg | grep -E "RIP: [0-9a-fA-Fx]+:ovs_dp_cmd_new\+")
488 if [ "$PRE_TEST" != "$POST_TEST" ]; then
489 info "failed - gen warning"
490 return 1
491 fi
492
493 ovs_add_netns_and_veths "test_netlink_checks" nv0 left left0 l0 || \
494 return 1
495 ovs_add_netns_and_veths "test_netlink_checks" nv0 right right0 r0 || \
496 return 1
497 [ $(python3 $ovs_base/ovs-dpctl.py show nv0 | grep port | \
498 wc -l) == 3 ] || \
499 return 1
500 ovs_del_if "test_netlink_checks" nv0 right0 || return 1
501 [ $(python3 $ovs_base/ovs-dpctl.py show nv0 | grep port | \
502 wc -l) == 2 ] || \
503 return 1
504
505 info "Checking clone depth"
506 ERR_MSG="Flow actions may not be safe on all matching packets"
507 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
508 ovs_add_flow "test_netlink_checks" nv0 \
509 'in_port(1),eth(),eth_type(0x800),ipv4()' \
510 'clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(clone(drop)))))))))))))))))' \
511 >/dev/null 2>&1 && return 1
512 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
513
514 if [ "$PRE_TEST" == "$POST_TEST" ]; then
515 info "failed - clone depth too large"
516 return 1
517 fi
518
519 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
520 ovs_add_flow "test_netlink_checks" nv0 \
521 'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(0),2' \
522 &> /dev/null && return 1
523 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
524 if [ "$PRE_TEST" == "$POST_TEST" ]; then
525 info "failed - error not generated"
526 return 1
527 fi
528 return 0
529}
530
531test_upcall_interfaces() {
532 sbx_add "test_upcall_interfaces" || return 1
533
534 info "setting up new DP"
535 ovs_add_dp "test_upcall_interfaces" ui0 -V 2:1 || return 1
536
537 ovs_add_netns_and_veths "test_upcall_interfaces" ui0 upc left0 l0 \
538 172.31.110.1/24 -u || return 1
539
540 sleep 1
541 info "sending arping"
542 ip netns exec upc arping -I l0 172.31.110.20 -c 1 \
543 >$ovs_dir/arping.stdout 2>$ovs_dir/arping.stderr
544
545 grep -E "MISS upcall\[0/yes\]: .*arp\(sip=172.31.110.1,tip=172.31.110.20,op=1,sha=" $ovs_dir/left0.out >/dev/null 2>&1 || return 1
546 return 0
547}
548
549run_test() {
550 (
551 tname="$1"
552 tdesc="$2"
553
554 if ! lsmod | grep openvswitch >/dev/null 2>&1; then
555 stdbuf -o0 printf "TEST: %-60s [NOMOD]\n" "${tdesc}"
556 return $ksft_skip
557 fi
558
559 if python3 ovs-dpctl.py -h 2>&1 | \
560 grep -E "Need to (install|upgrade) the python" >/dev/null 2>&1; then
561 stdbuf -o0 printf "TEST: %-60s [PYLIB]\n" "${tdesc}"
562 return $ksft_skip
563 fi
564 printf "TEST: %-60s [START]\n" "${tname}"
565
566 unset IFS
567
568 eval test_${tname}
569 ret=$?
570
571 if [ $ret -eq 0 ]; then
572 printf "TEST: %-60s [ OK ]\n" "${tdesc}"
573 ovs_exit_sig
574 rm -rf "$ovs_dir"
575 elif [ $ret -eq 1 ]; then
576 printf "TEST: %-60s [FAIL]\n" "${tdesc}"
577 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
578 echo
579 echo "Pausing. Logs in $ovs_dir/. Hit enter to continue"
580 read a
581 fi
582 ovs_exit_sig
583 [ "${PAUSE_ON_FAIL}" = "yes" ] || rm -rf "$ovs_dir"
584 exit 1
585 elif [ $ret -eq $ksft_skip ]; then
586 printf "TEST: %-60s [SKIP]\n" "${tdesc}"
587 elif [ $ret -eq 2 ]; then
588 rm -rf test_${tname}
589 run_test "$1" "$2"
590 fi
591
592 return $ret
593 )
594 ret=$?
595 case $ret in
596 0)
597 [ $all_skipped = true ] && [ $exitcode=$ksft_skip ] && exitcode=0
598 all_skipped=false
599 ;;
600 $ksft_skip)
601 [ $all_skipped = true ] && exitcode=$ksft_skip
602 ;;
603 *)
604 all_skipped=false
605 exitcode=1
606 ;;
607 esac
608
609 return $ret
610}
611
612
613exitcode=0
614desc=0
615all_skipped=true
616
617while getopts :pvt o
618do
619 case $o in
620 p) PAUSE_ON_FAIL=yes;;
621 v) VERBOSE=1;;
622 t) if which tcpdump > /dev/null 2>&1; then
623 TRACING=1
624 else
625 echo "=== tcpdump not available, tracing disabled"
626 fi
627 ;;
628 *) usage;;
629 esac
630done
631shift $(($OPTIND-1))
632
633IFS="
634"
635
636for arg do
637 # Check first that all requested tests are available before running any
638 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }
639done
640
641name=""
642desc=""
643for t in ${tests}; do
644 [ "${name}" = "" ] && name="${t}" && continue
645 [ "${desc}" = "" ] && desc="${t}"
646
647 run_this=1
648 for arg do
649 [ "${arg}" != "${arg#--*}" ] && continue
650 [ "${arg}" = "${name}" ] && run_this=1 && break
651 run_this=0
652 done
653 if [ $run_this -eq 1 ]; then
654 run_test "${name}" "${desc}"
655 fi
656 name=""
657 desc=""
658done
659
660exit ${exitcode}