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 ERR_MSG="Flow actions may not be safe on all matching packets"
506 PRE_TEST=$(dmesg | grep -c "${ERR_MSG}")
507 ovs_add_flow "test_netlink_checks" nv0 \
508 'in_port(1),eth(),eth_type(0x0806),arp()' 'drop(0),2' \
509 &> /dev/null && return 1
510 POST_TEST=$(dmesg | grep -c "${ERR_MSG}")
511 if [ "$PRE_TEST" == "$POST_TEST" ]; then
512 info "failed - error not generated"
513 return 1
514 fi
515 return 0
516}
517
518test_upcall_interfaces() {
519 sbx_add "test_upcall_interfaces" || return 1
520
521 info "setting up new DP"
522 ovs_add_dp "test_upcall_interfaces" ui0 -V 2:1 || return 1
523
524 ovs_add_netns_and_veths "test_upcall_interfaces" ui0 upc left0 l0 \
525 172.31.110.1/24 -u || return 1
526
527 sleep 1
528 info "sending arping"
529 ip netns exec upc arping -I l0 172.31.110.20 -c 1 \
530 >$ovs_dir/arping.stdout 2>$ovs_dir/arping.stderr
531
532 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
533 return 0
534}
535
536run_test() {
537 (
538 tname="$1"
539 tdesc="$2"
540
541 if ! lsmod | grep openvswitch >/dev/null 2>&1; then
542 stdbuf -o0 printf "TEST: %-60s [NOMOD]\n" "${tdesc}"
543 return $ksft_skip
544 fi
545
546 if python3 ovs-dpctl.py -h 2>&1 | \
547 grep -E "Need to (install|upgrade) the python" >/dev/null 2>&1; then
548 stdbuf -o0 printf "TEST: %-60s [PYLIB]\n" "${tdesc}"
549 return $ksft_skip
550 fi
551 printf "TEST: %-60s [START]\n" "${tname}"
552
553 unset IFS
554
555 eval test_${tname}
556 ret=$?
557
558 if [ $ret -eq 0 ]; then
559 printf "TEST: %-60s [ OK ]\n" "${tdesc}"
560 ovs_exit_sig
561 rm -rf "$ovs_dir"
562 elif [ $ret -eq 1 ]; then
563 printf "TEST: %-60s [FAIL]\n" "${tdesc}"
564 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
565 echo
566 echo "Pausing. Logs in $ovs_dir/. Hit enter to continue"
567 read a
568 fi
569 ovs_exit_sig
570 [ "${PAUSE_ON_FAIL}" = "yes" ] || rm -rf "$ovs_dir"
571 exit 1
572 elif [ $ret -eq $ksft_skip ]; then
573 printf "TEST: %-60s [SKIP]\n" "${tdesc}"
574 elif [ $ret -eq 2 ]; then
575 rm -rf test_${tname}
576 run_test "$1" "$2"
577 fi
578
579 return $ret
580 )
581 ret=$?
582 case $ret in
583 0)
584 [ $all_skipped = true ] && [ $exitcode=$ksft_skip ] && exitcode=0
585 all_skipped=false
586 ;;
587 $ksft_skip)
588 [ $all_skipped = true ] && exitcode=$ksft_skip
589 ;;
590 *)
591 all_skipped=false
592 exitcode=1
593 ;;
594 esac
595
596 return $ret
597}
598
599
600exitcode=0
601desc=0
602all_skipped=true
603
604while getopts :pvt o
605do
606 case $o in
607 p) PAUSE_ON_FAIL=yes;;
608 v) VERBOSE=1;;
609 t) if which tcpdump > /dev/null 2>&1; then
610 TRACING=1
611 else
612 echo "=== tcpdump not available, tracing disabled"
613 fi
614 ;;
615 *) usage;;
616 esac
617done
618shift $(($OPTIND-1))
619
620IFS="
621"
622
623for arg do
624 # Check first that all requested tests are available before running any
625 command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }
626done
627
628name=""
629desc=""
630for t in ${tests}; do
631 [ "${name}" = "" ] && name="${t}" && continue
632 [ "${desc}" = "" ] && desc="${t}"
633
634 run_this=1
635 for arg do
636 [ "${arg}" != "${arg#--*}" ] && continue
637 [ "${arg}" = "${name}" ] && run_this=1 && break
638 run_this=0
639 done
640 if [ $run_this -eq 1 ]; then
641 run_test "${name}" "${desc}"
642 fi
643 name=""
644 desc=""
645done
646
647exit ${exitcode}