Skip to content

Commit acf10a8

Browse files
kuba-mooPaolo Abeni
authored andcommitted
selftests: drv-net: use defer in the ping test
Make sure the test cleans up after itself. The XDP off statements at the end of the test may not be reached. Fixes: 75cc19c ("selftests: drv-net: add xdp cases for ping.py") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent d9c743b commit acf10a8

File tree

1 file changed

+8
-8
lines changed
  • tools/testing/selftests/drivers/net

1 file changed

+8
-8
lines changed

tools/testing/selftests/drivers/net/ping.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from lib.py import ksft_eq, KsftSkipEx, KsftFailEx
88
from lib.py import EthtoolFamily, NetDrvEpEnv
99
from lib.py import bkg, cmd, wait_port_listen, rand_port
10-
from lib.py import ethtool, ip
10+
from lib.py import defer, ethtool, ip
1111

1212
remote_ifname=""
1313
no_sleep=False
@@ -60,6 +60,7 @@ def _set_xdp_generic_sb_on(cfg) -> None:
6060
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
6161
cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote)
6262
cmd(f"ip link set dev {cfg.ifname} mtu 1500 xdpgeneric obj {prog} sec xdp", shell=True)
63+
defer(cmd, f"ip link set dev {cfg.ifname} xdpgeneric off")
6364

6465
if no_sleep != True:
6566
time.sleep(10)
@@ -68,7 +69,9 @@ def _set_xdp_generic_mb_on(cfg) -> None:
6869
test_dir = os.path.dirname(os.path.realpath(__file__))
6970
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
7071
cmd(f"ip link set dev {remote_ifname} mtu 9000", shell=True, host=cfg.remote)
72+
defer(ip, f"link set dev {remote_ifname} mtu 1500", host=cfg.remote)
7173
ip("link set dev %s mtu 9000 xdpgeneric obj %s sec xdp.frags" % (cfg.ifname, prog))
74+
defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdpgeneric off")
7275

7376
if no_sleep != True:
7477
time.sleep(10)
@@ -78,6 +81,7 @@ def _set_xdp_native_sb_on(cfg) -> None:
7881
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
7982
cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote)
8083
cmd(f"ip -j link set dev {cfg.ifname} mtu 1500 xdp obj {prog} sec xdp", shell=True)
84+
defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdp off")
8185
xdp_info = ip("-d link show %s" % (cfg.ifname), json=True)[0]
8286
if xdp_info['xdp']['mode'] != 1:
8387
"""
@@ -94,10 +98,11 @@ def _set_xdp_native_mb_on(cfg) -> None:
9498
test_dir = os.path.dirname(os.path.realpath(__file__))
9599
prog = test_dir + "/../../net/lib/xdp_dummy.bpf.o"
96100
cmd(f"ip link set dev {remote_ifname} mtu 9000", shell=True, host=cfg.remote)
101+
defer(ip, f"link set dev {remote_ifname} mtu 1500", host=cfg.remote)
97102
try:
98103
cmd(f"ip link set dev {cfg.ifname} mtu 9000 xdp obj {prog} sec xdp.frags", shell=True)
104+
defer(ip, f"link set dev {cfg.ifname} mtu 1500 xdp off")
99105
except Exception as e:
100-
cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote)
101106
raise KsftSkipEx('device does not support native-multi-buffer XDP')
102107

103108
if no_sleep != True:
@@ -111,6 +116,7 @@ def _set_xdp_offload_on(cfg) -> None:
111116
cmd(f"ip link set dev {cfg.ifname} xdpoffload obj {prog} sec xdp", shell=True)
112117
except Exception as e:
113118
raise KsftSkipEx('device does not support offloaded XDP')
119+
defer(ip, f"link set dev {cfg.ifname} xdpoffload off")
114120
cmd(f"ip link set dev {remote_ifname} mtu 1500", shell=True, host=cfg.remote)
115121

116122
if no_sleep != True:
@@ -157,7 +163,6 @@ def test_xdp_generic_sb(cfg, netnl) -> None:
157163
_test_v4(cfg)
158164
_test_v6(cfg)
159165
_test_tcp(cfg)
160-
ip("link set dev %s xdpgeneric off" % cfg.ifname)
161166

162167
def test_xdp_generic_mb(cfg, netnl) -> None:
163168
_set_xdp_generic_mb_on(cfg)
@@ -169,7 +174,6 @@ def test_xdp_generic_mb(cfg, netnl) -> None:
169174
_test_v4(cfg)
170175
_test_v6(cfg)
171176
_test_tcp(cfg)
172-
ip("link set dev %s xdpgeneric off" % cfg.ifname)
173177

174178
def test_xdp_native_sb(cfg, netnl) -> None:
175179
_set_xdp_native_sb_on(cfg)
@@ -181,7 +185,6 @@ def test_xdp_native_sb(cfg, netnl) -> None:
181185
_test_v4(cfg)
182186
_test_v6(cfg)
183187
_test_tcp(cfg)
184-
ip("link set dev %s xdp off" % cfg.ifname)
185188

186189
def test_xdp_native_mb(cfg, netnl) -> None:
187190
_set_xdp_native_mb_on(cfg)
@@ -193,14 +196,12 @@ def test_xdp_native_mb(cfg, netnl) -> None:
193196
_test_v4(cfg)
194197
_test_v6(cfg)
195198
_test_tcp(cfg)
196-
ip("link set dev %s xdp off" % cfg.ifname)
197199

198200
def test_xdp_offload(cfg, netnl) -> None:
199201
_set_xdp_offload_on(cfg)
200202
_test_v4(cfg)
201203
_test_v6(cfg)
202204
_test_tcp(cfg)
203-
ip("link set dev %s xdpoffload off" % cfg.ifname)
204205

205206
def main() -> None:
206207
with NetDrvEpEnv(__file__) as cfg:
@@ -213,7 +214,6 @@ def main() -> None:
213214
test_xdp_native_mb,
214215
test_xdp_offload],
215216
args=(cfg, EthtoolFamily()))
216-
set_interface_init(cfg)
217217
ksft_exit()
218218

219219

0 commit comments

Comments
 (0)