File tree Expand file tree Collapse file tree 3 files changed +87
-27
lines changed
tools/testing/selftests/net Expand file tree Collapse file tree 3 files changed +87
-27
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ TEST_PROGS += ip_local_port_range.sh
54
54
TEST_PROGS += rps_default_mask.sh
55
55
TEST_PROGS += big_tcp.sh
56
56
TEST_PROGS_EXTENDED := in_netns.sh setup_loopback.sh setup_veth.sh
57
- TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh
57
+ TEST_PROGS_EXTENDED += toeplitz_client.sh toeplitz.sh lib.sh
58
58
TEST_GEN_FILES = socket nettest
59
59
TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
60
60
TEST_GEN_FILES += tcp_mmap tcp_inq psock_snd txring_overwrite
Original file line number Diff line number Diff line change 4
4
# #############################################################################
5
5
# Defines
6
6
7
- # Kselftest framework requirement - SKIP code is 4.
8
- ksft_skip=4
9
-
10
7
# Can be overridden by the configuration file.
11
8
PING=${PING:= ping}
12
9
PING6=${PING6:= ping6}
@@ -41,6 +38,7 @@ if [[ -f $relative_path/forwarding.config ]]; then
41
38
source " $relative_path /forwarding.config"
42
39
fi
43
40
41
+ source ../lib.sh
44
42
# #############################################################################
45
43
# Sanity checks
46
44
@@ -395,29 +393,6 @@ log_info()
395
393
echo " INFO: $msg "
396
394
}
397
395
398
- busywait ()
399
- {
400
- local timeout=$1 ; shift
401
-
402
- local start_time=" $( date -u +%s%3N) "
403
- while true
404
- do
405
- local out
406
- out=$( " $@ " )
407
- local ret=$?
408
- if (( ! ret)) ; then
409
- echo -n " $out "
410
- return 0
411
- fi
412
-
413
- local current_time=" $( date -u +%s%3N) "
414
- if (( current_time - start_time > timeout)) ; then
415
- echo -n " $out "
416
- return 1
417
- fi
418
- done
419
- }
420
-
421
396
not ()
422
397
{
423
398
" $@ "
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ # SPDX-License-Identifier: GPL-2.0
3
+
4
+ # #############################################################################
5
+ # Defines
6
+
7
+ # Kselftest framework requirement - SKIP code is 4.
8
+ ksft_skip=4
9
+
10
+ # #############################################################################
11
+ # Helpers
12
+ busywait ()
13
+ {
14
+ local timeout=$1 ; shift
15
+
16
+ local start_time=" $( date -u +%s%3N) "
17
+ while true
18
+ do
19
+ local out
20
+ out=$( " $@ " )
21
+ local ret=$?
22
+ if (( ! ret)) ; then
23
+ echo -n " $out "
24
+ return 0
25
+ fi
26
+
27
+ local current_time=" $( date -u +%s%3N) "
28
+ if (( current_time - start_time > timeout)) ; then
29
+ echo -n " $out "
30
+ return 1
31
+ fi
32
+ done
33
+ }
34
+
35
+ cleanup_ns ()
36
+ {
37
+ local ns=" "
38
+ local errexit=0
39
+ local ret=0
40
+
41
+ # disable errexit temporary
42
+ if [[ $- =~ " e" ]]; then
43
+ errexit=1
44
+ set +e
45
+ fi
46
+
47
+ for ns in " $@ " ; do
48
+ ip netns delete " ${ns} " & > /dev/null
49
+ if ! busywait 2 ip netns list \| grep -vq " ^$ns $" & > /dev/null; then
50
+ echo " Warn: Failed to remove namespace $ns "
51
+ ret=1
52
+ fi
53
+ done
54
+
55
+ [ $errexit -eq 1 ] && set -e
56
+ return $ret
57
+ }
58
+
59
+ # setup netns with given names as prefix. e.g
60
+ # setup_ns local remote
61
+ setup_ns ()
62
+ {
63
+ local ns=" "
64
+ local ns_name=" "
65
+ local ns_list=" "
66
+ for ns_name in " $@ " ; do
67
+ # Some test may setup/remove same netns multi times
68
+ if unset ${ns_name} 2> /dev/null; then
69
+ ns=" ${ns_name,,} -$( mktemp -u XXXXXX) "
70
+ eval readonly ${ns_name} =" $ns "
71
+ else
72
+ eval ns=' $' ${ns_name}
73
+ cleanup_ns " $ns "
74
+
75
+ fi
76
+
77
+ if ! ip netns add " $ns " ; then
78
+ echo " Failed to create namespace $ns_name "
79
+ cleanup_ns " $ns_list "
80
+ return $ksft_skip
81
+ fi
82
+ ip -n " $ns " link set lo up
83
+ ns_list=" $ns_list $ns "
84
+ done
85
+ }
You can’t perform that action at this time.
0 commit comments