Skip to content

Commit 66ffef3

Browse files
author
Paolo Abeni
committed
Merge branch 'selftests-net-introduce-deferred-commands'
Petr Machata says: ==================== selftests: net: Introduce deferred commands Recently, a defer helper was added to Python selftests. The idea is to keep cleanup commands close to their dirtying counterparts, thereby making it more transparent what is cleaning up what, making it harder to miss a cleanup, and make the whole cleanup business exception safe. All these benefits are applicable to bash as well, exception safety can be interpreted in terms of safety vs. a SIGINT. This patchset therefore introduces a framework of several helpers that serve to schedule cleanups in bash selftests. - Patch #1 has more details about the primitives being introduced. Patch #2 adds a fallback cleanup() function to lib.sh, because ideally selftests wouldn't need to introduce a dedicated cleanup function at all. - Patch #3 adds a parameter to stop_traffic(), which makes it possible to start other background processes after the traffic is started without confusing the cleanup. - Patches #4 to #10 convert a number of selftests. The goal was to convert all tests that use start_traffic / stop_traffic to the defer framework. Leftover traffic generators are a particularly painful sort of a missed cleanup. Normal unfinished cleanups can usually be cleaned up simply by rerunning the test and interrupting it early to let the cleanups run again / in full. This does not work with stop_traffic, because it is only issued at the end of the test case that starts the traffic. At the same time, leftover traffic generators influence follow-up test runs, and are hard to notice. The tests were however converted whole-sale, not just their traffic bits. Thus they form a proof of concept of the defer framework. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
2 parents c797cb9 + cebd281 commit 66ffef3

19 files changed

+591
-609
lines changed

tools/testing/selftests/drivers/net/mlxsw/devlink_trap_policer.sh

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,63 +45,52 @@ source $lib_dir/devlink_lib.sh
4545
h1_create()
4646
{
4747
simple_if_init $h1 192.0.2.1/24
48+
defer simple_if_fini $h1 192.0.2.1/24
49+
4850
mtu_set $h1 10000
51+
defer mtu_restore $h1
4952

5053
ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
51-
}
52-
53-
h1_destroy()
54-
{
55-
ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
56-
57-
mtu_restore $h1
58-
simple_if_fini $h1 192.0.2.1/24
54+
defer ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
5955
}
6056

6157
h2_create()
6258
{
6359
simple_if_init $h2 198.51.100.1/24
60+
defer simple_if_fini $h2 198.51.100.1/24
61+
6462
mtu_set $h2 10000
63+
defer mtu_restore $h2
6564

6665
ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
67-
}
68-
69-
h2_destroy()
70-
{
71-
ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
72-
73-
mtu_restore $h2
74-
simple_if_fini $h2 198.51.100.1/24
66+
defer ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
7567
}
7668

7769
router_create()
7870
{
7971
ip link set dev $rp1 up
72+
defer ip link set dev $rp1 down
73+
8074
ip link set dev $rp2 up
75+
defer ip link set dev $rp2 down
8176

8277
__addr_add_del $rp1 add 192.0.2.2/24
78+
defer __addr_add_del $rp1 del 192.0.2.2/24
79+
8380
__addr_add_del $rp2 add 198.51.100.2/24
81+
defer __addr_add_del $rp2 del 198.51.100.2/24
82+
8483
mtu_set $rp1 10000
84+
defer mtu_restore $rp1
85+
8586
mtu_set $rp2 10000
87+
defer mtu_restore $rp2
8688

8789
ip -4 route add blackhole 198.51.100.100
90+
defer ip -4 route del blackhole 198.51.100.100
8891

8992
devlink trap set $DEVLINK_DEV trap blackhole_route action trap
90-
}
91-
92-
router_destroy()
93-
{
94-
devlink trap set $DEVLINK_DEV trap blackhole_route action drop
95-
96-
ip -4 route del blackhole 198.51.100.100
97-
98-
mtu_restore $rp2
99-
mtu_restore $rp1
100-
__addr_add_del $rp2 del 198.51.100.2/24
101-
__addr_add_del $rp1 del 192.0.2.2/24
102-
103-
ip link set dev $rp2 down
104-
ip link set dev $rp1 down
93+
defer devlink trap set $DEVLINK_DEV trap blackhole_route action drop
10594
}
10695

10796
setup_prepare()
@@ -114,29 +103,18 @@ setup_prepare()
114103

115104
rp1_mac=$(mac_get $rp1)
116105

106+
# Reload to ensure devlink-trap settings are back to default.
107+
defer devlink_reload
108+
117109
vrf_prepare
110+
defer vrf_cleanup
118111

119112
h1_create
120113
h2_create
121114

122115
router_create
123116
}
124117

125-
cleanup()
126-
{
127-
pre_cleanup
128-
129-
router_destroy
130-
131-
h2_destroy
132-
h1_destroy
133-
134-
vrf_cleanup
135-
136-
# Reload to ensure devlink-trap settings are back to default.
137-
devlink_reload
138-
}
139-
140118
rate_limits_test()
141119
{
142120
RET=0
@@ -214,7 +192,10 @@ __rate_test()
214192
# by the policer. Make sure measured received rate is about 1000 pps
215193
log_info "=== Tx rate: Highest, Policer rate: 1000 pps ==="
216194

195+
defer_scope_push
196+
217197
start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
198+
defer stop_traffic $!
218199

219200
sleep 5 # Take measurements when rate is stable
220201

@@ -229,13 +210,16 @@ __rate_test()
229210
check_err $? "Expected non-zero policer drop rate, got 0"
230211
log_info "Measured policer drop rate of $drop_rate pps"
231212

232-
stop_traffic
213+
defer_scope_pop
233214

234215
# Send packets at a rate of 1000 pps and make sure they are not dropped
235216
# by the policer
236217
log_info "=== Tx rate: 1000 pps, Policer rate: 1000 pps ==="
237218

219+
defer_scope_push
220+
238221
start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -d 1msec
222+
defer stop_traffic $!
239223

240224
sleep 5 # Take measurements when rate is stable
241225

@@ -244,7 +228,7 @@ __rate_test()
244228
check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
245229
log_info "Measured policer drop rate of $drop_rate pps"
246230

247-
stop_traffic
231+
defer_scope_pop
248232

249233
# Unbind the policer and send packets at highest possible rate. Make
250234
# sure they are not dropped by the policer and that the measured
@@ -253,7 +237,10 @@ __rate_test()
253237

254238
devlink trap group set $DEVLINK_DEV group l3_drops nopolicer
255239

240+
defer_scope_push
241+
256242
start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
243+
defer stop_traffic $!
257244

258245
rate=$(trap_rate_get)
259246
(( rate > 1000 ))
@@ -265,7 +252,7 @@ __rate_test()
265252
check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
266253
log_info "Measured policer drop rate of $drop_rate pps"
267254

268-
stop_traffic
255+
defer_scope_pop
269256

270257
log_test "Trap policer rate"
271258
}

0 commit comments

Comments
 (0)