Skip to content

Commit 313fb18

Browse files
committed
Merge branch 'selftests-bonding-use-slowwait-when-waiting'
Hangbin Liu says: ==================== selftests: bonding: use slowwait when waiting There are a lot waitings in bonding tests use sleep. Let's replace them with slowwait(added in the first patch). This could save much test time. e.g. bond-break-lacpdu-tx.sh before: 0m16.346s after: 0m2.824s bond_options.sh before: 9m25.299s after: 6m14.439s bond-lladdr-target.sh before: 0m7.090s after: 0m6.148s In total, we could save about 180 seconds. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents b27696c + e1f0da9 commit 313fb18

File tree

6 files changed

+97
-29
lines changed

6 files changed

+97
-29
lines changed

tools/testing/selftests/drivers/net/bonding/bond-break-lacpdu-tx.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020
# +------+ +------+
2121
#
2222
# We use veths instead of physical interfaces
23+
REQUIRE_MZ=no
24+
NUM_NETIFS=0
25+
lib_dir=$(dirname "$0")
26+
source "$lib_dir"/../../../net/forwarding/lib.sh
2327

2428
set -e
25-
tmp=$(mktemp -q dump.XXXXXX)
2629
cleanup() {
2730
ip link del fab-br0 >/dev/null 2>&1 || :
2831
ip link del fbond >/dev/null 2>&1 || :
2932
ip link del veth1-bond >/dev/null 2>&1 || :
3033
ip link del veth2-bond >/dev/null 2>&1 || :
31-
modprobe -r bonding >/dev/null 2>&1 || :
32-
rm -f -- ${tmp}
3334
}
3435

3536
trap cleanup 0 1 2
3637
cleanup
37-
sleep 1
3838

3939
# create the bridge
4040
ip link add fab-br0 address 52:54:00:3B:7C:A6 mtu 1500 type bridge \
@@ -67,13 +67,12 @@ ip link set fab-br0 up
6767
ip link set fbond up
6868
ip addr add dev fab-br0 10.0.0.3
6969

70-
tcpdump -n -i veth1-end -e ether proto 0x8809 >${tmp} 2>&1 &
71-
sleep 15
72-
pkill tcpdump >/dev/null 2>&1
7370
rc=0
74-
num=$(grep "packets captured" ${tmp} | awk '{print $1}')
75-
if test "$num" -gt 0; then
76-
echo "PASS, captured ${num}"
71+
tc qdisc add dev veth1-end clsact
72+
tc filter add dev veth1-end ingress protocol 0x8809 pref 1 handle 101 flower skip_hw action pass
73+
if slowwait_for_counter 15 2 \
74+
tc_rule_handle_stats_get "dev veth1-end ingress" 101 ".packets" "" &> /dev/null; then
75+
echo "PASS, captured 2"
7776
else
7877
echo "FAIL"
7978
rc=1

tools/testing/selftests/drivers/net/bonding/bond-lladdr-target.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
# +----------------+
1818
#
1919
# We use veths instead of physical interfaces
20+
REQUIRE_MZ=no
21+
NUM_NETIFS=0
22+
lib_dir=$(dirname "$0")
23+
source "$lib_dir"/../../../net/forwarding/lib.sh
24+
2025
sw="sw-$(mktemp -u XXXXXX)"
2126
host="ns-$(mktemp -u XXXXXX)"
2227

@@ -26,6 +31,16 @@ cleanup()
2631
ip netns del $host
2732
}
2833

34+
wait_lladdr_dad()
35+
{
36+
$@ | grep fe80 | grep -qv tentative
37+
}
38+
39+
wait_bond_up()
40+
{
41+
$@ | grep -q 'state UP'
42+
}
43+
2944
trap cleanup 0 1 2
3045

3146
ip netns add $sw
@@ -37,8 +52,8 @@ ip -n $host link add veth1 type veth peer name veth1 netns $sw
3752
ip -n $sw link add br0 type bridge
3853
ip -n $sw link set br0 up
3954
sw_lladdr=$(ip -n $sw addr show br0 | awk '/fe80/{print $2}' | cut -d'/' -f1)
40-
# sleep some time to make sure bridge lladdr pass DAD
41-
sleep 2
55+
# wait some time to make sure bridge lladdr pass DAD
56+
slowwait 2 wait_lladdr_dad ip -n $sw addr show br0
4257

4358
ip -n $host link add bond0 type bond mode 1 ns_ip6_target ${sw_lladdr} \
4459
arp_validate 3 arp_interval 1000
@@ -53,7 +68,7 @@ ip -n $sw link set veth1 master br0
5368
ip -n $sw link set veth0 up
5469
ip -n $sw link set veth1 up
5570

56-
sleep 5
71+
slowwait 5 wait_bond_up ip -n $host link show bond0
5772

5873
rc=0
5974
if ip -n $host link show bond0 | grep -q LOWER_UP; then

tools/testing/selftests/drivers/net/bonding/bond_options.sh

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,23 @@ skip_ns()
4545
}
4646

4747
active_slave=""
48+
active_slave_changed()
49+
{
50+
local old_active_slave=$1
51+
local new_active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" \
52+
".[].linkinfo.info_data.active_slave")
53+
test "$old_active_slave" != "$new_active_slave"
54+
}
55+
4856
check_active_slave()
4957
{
5058
local target_active_slave=$1
59+
slowwait 2 active_slave_changed $active_slave
5160
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
5261
test "$active_slave" = "$target_active_slave"
5362
check_err $? "Current active slave is $active_slave but not $target_active_slave"
5463
}
5564

56-
5765
# Test bonding prio option
5866
prio_test()
5967
{
@@ -84,13 +92,13 @@ prio_test()
8492

8593
# active slave should be the higher prio slave
8694
ip -n ${s_ns} link set $active_slave down
87-
bond_check_connection "fail over"
8895
check_active_slave eth2
96+
bond_check_connection "fail over"
8997

9098
# when only 1 slave is up
9199
ip -n ${s_ns} link set $active_slave down
92-
bond_check_connection "only 1 slave up"
93100
check_active_slave eth0
101+
bond_check_connection "only 1 slave up"
94102

95103
# when a higher prio slave change to up
96104
ip -n ${s_ns} link set eth2 up
@@ -140,8 +148,8 @@ prio_test()
140148
check_active_slave "eth1"
141149

142150
ip -n ${s_ns} link set $active_slave down
143-
bond_check_connection "change slave prio"
144151
check_active_slave "eth0"
152+
bond_check_connection "change slave prio"
145153
fi
146154
}
147155

@@ -199,6 +207,15 @@ prio()
199207
prio_ns "active-backup"
200208
}
201209

210+
wait_mii_up()
211+
{
212+
for i in $(seq 0 2); do
213+
mii_status=$(cmd_jq "ip -n ${s_ns} -j -d link show eth$i" ".[].linkinfo.info_slave_data.mii_status")
214+
[ ${mii_status} != "UP" ] && return 1
215+
done
216+
return 0
217+
}
218+
202219
arp_validate_test()
203220
{
204221
local param="$1"
@@ -211,7 +228,7 @@ arp_validate_test()
211228
[ $RET -ne 0 ] && log_test "arp_validate" "$retmsg"
212229

213230
# wait for a while to make sure the mii status stable
214-
sleep 5
231+
slowwait 5 wait_mii_up
215232
for i in $(seq 0 2); do
216233
mii_status=$(cmd_jq "ip -n ${s_ns} -j -d link show eth$i" ".[].linkinfo.info_slave_data.mii_status")
217234
if [ ${mii_status} != "UP" ]; then
@@ -276,10 +293,13 @@ garp_test()
276293
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
277294
ip -n ${s_ns} link set ${active_slave} down
278295

279-
exp_num=$(echo "${param}" | cut -f6 -d ' ')
280-
sleep $((exp_num + 2))
296+
# wait for active link change
297+
slowwait 2 active_slave_changed $active_slave
281298

299+
exp_num=$(echo "${param}" | cut -f6 -d ' ')
282300
active_slave=$(cmd_jq "ip -n ${s_ns} -d -j link show bond0" ".[].linkinfo.info_data.active_slave")
301+
slowwait_for_counter $((exp_num + 5)) $exp_num \
302+
tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}"
283303

284304
# check result
285305
real_num=$(tc_rule_handle_stats_get "dev s${active_slave#eth} ingress" 101 ".packets" "-n ${g_ns}")
@@ -296,8 +316,8 @@ garp_test()
296316
num_grat_arp()
297317
{
298318
local val
299-
for val in 10 20 30 50; do
300-
garp_test "mode active-backup miimon 100 num_grat_arp $val peer_notify_delay 1000"
319+
for val in 10 20 30; do
320+
garp_test "mode active-backup miimon 10 num_grat_arp $val peer_notify_delay 100"
301321
log_test "num_grat_arp" "active-backup miimon num_grat_arp $val"
302322
done
303323
}

tools/testing/selftests/drivers/net/bonding/bond_topo_2d1c.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ server_create()
7373
ip -n ${s_ns} link set bond0 up
7474
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
7575
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
76-
sleep 2
7776
}
7877

7978
# Reset bond with new mode and options
@@ -96,7 +95,8 @@ bond_reset()
9695
ip -n ${s_ns} link set bond0 up
9796
ip -n ${s_ns} addr add ${s_ip4}/24 dev bond0
9897
ip -n ${s_ns} addr add ${s_ip6}/24 dev bond0
99-
sleep 2
98+
# Wait for IPv6 address ready as it needs DAD
99+
slowwait 2 ip netns exec ${s_ns} ping6 ${c_ip6} -c 1 -W 0.1 &> /dev/null
100100
}
101101

102102
server_destroy()
@@ -150,7 +150,7 @@ bond_check_connection()
150150
{
151151
local msg=${1:-"check connection"}
152152

153-
sleep 2
153+
slowwait 2 ip netns exec ${s_ns} ping ${c_ip4} -c 1 -W 0.1 &> /dev/null
154154
ip netns exec ${s_ns} ping ${c_ip4} -c5 -i 0.1 &>/dev/null
155155
check_err $? "${msg}: ping failed"
156156
ip netns exec ${s_ns} ping6 ${c_ip6} -c5 -i 0.1 &>/dev/null

tools/testing/selftests/drivers/net/bonding/lag_lib.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,12 @@ lag_setup2x2()
107107
NAMESPACES="${namespaces}"
108108
}
109109

110-
# cleanup all lag related namespaces and remove the bonding module
110+
# cleanup all lag related namespaces
111111
lag_cleanup()
112112
{
113113
for n in ${NAMESPACES}; do
114114
ip netns delete ${n} >/dev/null 2>&1 || true
115115
done
116-
modprobe -r bonding
117116
}
118117

119118
SWITCH="lag_node1"
@@ -159,7 +158,7 @@ test_bond_recovery()
159158
create_bond $@
160159

161160
# verify connectivity
162-
ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 >/dev/null 2>&1
161+
slowwait 2 ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 -W 0.1 &> /dev/null
163162
check_err $? "No connectivity"
164163

165164
# force the links of the bond down
@@ -169,7 +168,7 @@ test_bond_recovery()
169168
ip netns exec ${SWITCH} ip link set eth1 down
170169

171170
# re-verify connectivity
172-
ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 >/dev/null 2>&1
171+
slowwait 2 ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 -W 0.1 &> /dev/null
173172

174173
local rc=$?
175174
check_err $rc "Bond failed to recover"

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@ fi
3737

3838
source "$net_forwarding_dir/../lib.sh"
3939

40+
# timeout in seconds
41+
slowwait()
42+
{
43+
local timeout=$1; shift
44+
45+
local start_time="$(date -u +%s)"
46+
while true
47+
do
48+
local out
49+
out=$("$@")
50+
local ret=$?
51+
if ((!ret)); then
52+
echo -n "$out"
53+
return 0
54+
fi
55+
56+
local current_time="$(date -u +%s)"
57+
if ((current_time - start_time > timeout)); then
58+
echo -n "$out"
59+
return 1
60+
fi
61+
62+
sleep 0.1
63+
done
64+
}
65+
4066
##############################################################################
4167
# Sanity checks
4268

@@ -478,6 +504,15 @@ busywait_for_counter()
478504
busywait "$timeout" until_counter_is ">= $((base + delta))" "$@"
479505
}
480506

507+
slowwait_for_counter()
508+
{
509+
local timeout=$1; shift
510+
local delta=$1; shift
511+
512+
local base=$("$@")
513+
slowwait "$timeout" until_counter_is ">= $((base + delta))" "$@"
514+
}
515+
481516
setup_wait_dev()
482517
{
483518
local dev=$1; shift

0 commit comments

Comments
 (0)